Skip to content

Commit 4e3290c

Browse files
engalarako
authored andcommitted
feat(tui): command bar, commands, shortcuts, help overlay
1 parent 9996a96 commit 4e3290c

3 files changed

Lines changed: 310 additions & 6 deletions

File tree

tui/cmdbar.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package tui
2+
3+
import (
4+
"strings"
5+
6+
"github.com/charmbracelet/bubbles/textinput"
7+
tea "github.com/charmbracelet/bubbletea"
8+
"github.com/charmbracelet/lipgloss"
9+
)
10+
11+
// CmdBar is the bottom command input bar activated by ":".
12+
type CmdBar struct {
13+
input textinput.Model
14+
visible bool
15+
}
16+
17+
func NewCmdBar() CmdBar {
18+
ti := textinput.New()
19+
ti.Placeholder = "command (run, check, callers, callees, context, impact, refs, diagram, search <kw>)"
20+
ti.Prompt = ": "
21+
ti.CharLimit = 200
22+
return CmdBar{input: ti}
23+
}
24+
25+
func (c *CmdBar) Show() {
26+
c.visible = true
27+
c.input.SetValue("")
28+
c.input.Focus()
29+
}
30+
31+
func (c *CmdBar) Hide() {
32+
c.visible = false
33+
c.input.Blur()
34+
}
35+
36+
func (c CmdBar) IsVisible() bool { return c.visible }
37+
38+
// Command returns the current input value split into verb + args.
39+
func (c CmdBar) Command() (verb string, rest string) {
40+
parts := strings.SplitN(strings.TrimSpace(c.input.Value()), " ", 2)
41+
if len(parts) == 0 {
42+
return "", ""
43+
}
44+
verb = strings.ToLower(parts[0])
45+
if len(parts) > 1 {
46+
rest = parts[1]
47+
}
48+
return verb, rest
49+
}
50+
51+
func (c CmdBar) Update(msg tea.Msg) (CmdBar, tea.Cmd) {
52+
var cmd tea.Cmd
53+
c.input, cmd = c.input.Update(msg)
54+
return c, cmd
55+
}
56+
57+
func (c CmdBar) View() string {
58+
if !c.visible {
59+
return lipgloss.NewStyle().
60+
Foreground(lipgloss.Color("240")).
61+
Render(" :run :check :callers :callees :context :impact :refs :diagram :search")
62+
}
63+
return lipgloss.NewStyle().
64+
Bold(true).Foreground(lipgloss.Color("214")).
65+
Render(c.input.View())
66+
}

tui/help.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package tui
2+
3+
import "github.com/charmbracelet/lipgloss"
4+
5+
const helpText = `
6+
mxcli tui — Keyboard Reference
7+
8+
NAVIGATION
9+
h / ← move focus left
10+
l / → / Enter open / move focus right
11+
j / ↓ move down
12+
k / ↑ move up
13+
Tab cycle panel focus
14+
/ search/filter in current column
15+
Esc back / close
16+
17+
COMMANDS (press : to activate)
18+
:run run MDL file
19+
:check check MDL syntax
20+
:callers show callers of selected element
21+
:callees show callees
22+
:context show context
23+
:impact show impact
24+
:refs show references
25+
:diagram open diagram in browser
26+
:search <kw> full-text search
27+
28+
OTHER
29+
d open diagram in browser
30+
r refresh project tree
31+
? show/hide this help
32+
q quit
33+
`
34+
35+
func renderHelp(width, height int) string {
36+
helpWidth := width / 2
37+
if helpWidth < 60 {
38+
helpWidth = 60
39+
}
40+
return lipgloss.NewStyle().
41+
Border(lipgloss.RoundedBorder()).
42+
BorderForeground(lipgloss.Color("63")).
43+
Width(helpWidth).
44+
Padding(1, 2).
45+
Render(helpText)
46+
}

0 commit comments

Comments
 (0)