6 "charm.land/bubbles/v2/help"
7 tea "charm.land/bubbletea/v2"
8 "charm.land/lipgloss/v2"
9 "github.com/charmbracelet/crush/internal/tui/styles"
10 "github.com/charmbracelet/crush/internal/tui/util"
11 "github.com/charmbracelet/x/ansi"
14type StatusCmp interface {
17 SetKeyMap(keyMap help.KeyMap)
20type statusCmp struct {
23 messageTTL time.Duration
28// clearMessageCmd is a command that clears status messages after a timeout
29func (m *statusCmp) clearMessageCmd(ttl time.Duration) tea.Cmd {
30 return tea.Tick(ttl, func(time.Time) tea.Msg {
31 return util.ClearStatusMsg{}
35func (m *statusCmp) Init() tea.Cmd {
39func (m *statusCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) {
40 switch msg := msg.(type) {
41 case tea.WindowSizeMsg:
43 m.help.SetWidth(msg.Width - 2)
53 return m, m.clearMessageCmd(ttl)
54 case util.ClearStatusMsg:
55 m.info = util.InfoMsg{}
60func (m *statusCmp) View() string {
61 t := styles.CurrentTheme()
62 status := t.S().Base.Padding(0, 1, 1, 1).Render(m.help.View(m.keyMap))
69func (m *statusCmp) infoMsg() string {
70 t := styles.CurrentTheme()
74 case util.InfoTypeError:
75 infoType = t.S().Base.Background(t.Red).Padding(0, 1).Render("ERROR")
76 widthLeft := m.width - (lipgloss.Width(infoType) + 2)
77 info := ansi.Truncate(m.info.Msg, widthLeft, "…")
78 message = t.S().Base.Background(t.Error).Width(widthLeft+2).Foreground(t.White).Padding(0, 1).Render(info)
79 case util.InfoTypeWarn:
80 infoType = t.S().Base.Foreground(t.BgOverlay).Background(t.Yellow).Padding(0, 1).Render("WARNING")
81 widthLeft := m.width - (lipgloss.Width(infoType) + 2)
82 info := ansi.Truncate(m.info.Msg, widthLeft, "…")
83 message = t.S().Base.Foreground(t.BgOverlay).Width(widthLeft+2).Background(t.Warning).Padding(0, 1).Render(info)
86 if m.info.Type == util.InfoTypeUpdate {
89 infoType = t.S().Base.Foreground(t.BgSubtle).Background(t.Green).Padding(0, 1).Bold(true).Render(note)
90 widthLeft := m.width - (lipgloss.Width(infoType) + 2)
91 info := ansi.Truncate(m.info.Msg, widthLeft, "…")
92 message = t.S().Base.Background(t.GreenDark).Width(widthLeft+2).Foreground(t.BgSubtle).Padding(0, 1).Render(info)
94 return ansi.Truncate(infoType+message, m.width, "…")
97func (m *statusCmp) ToggleFullHelp() {
98 m.help.ShowAll = !m.help.ShowAll
101func (m *statusCmp) SetKeyMap(keyMap help.KeyMap) {
105func NewStatusCmp() StatusCmp {
106 t := styles.CurrentTheme()
108 help.Styles = t.S().Help
110 messageTTL: 5 * time.Second,
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list