on main help sign in
feat(tui): show / hint when editor is empty (#1512)
47b50d4Amolith
internal/tui/components/chat/editor/editor.go+6−1
@@ -41,6 +41,7 @@ type Editor interface {
41 SetSession(session session.Session) tea.Cmd
41 SetSession(session session.Session) tea.Cmd
42 IsCompletionsOpen() bool
42 IsCompletionsOpen() bool
43 HasAttachments() bool
43 HasAttachments() bool
44+ IsEmpty() bool
44 Cursor() *tea.Cursor
45 Cursor() *tea.Cursor
45}
46}
46
47
@@ -261,7 +262,7 @@ func (m *editorCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) {
261 curIdx := m.textarea.Width()*cur.Y + cur.X
262 curIdx := m.textarea.Width()*cur.Y + cur.X
262 switch {
263 switch {
263 // Open command palette when "/" is pressed on empty prompt
264 // Open command palette when "/" is pressed on empty prompt
264− case msg.String() == "/" && len(strings.TrimSpace(m.textarea.Value())) == 0:
265+ case msg.String() == "/" && m.IsEmpty():
265 return m, util.CmdHandler(dialogs.OpenDialogMsg{
266 return m, util.CmdHandler(dialogs.OpenDialogMsg{
266 Model: commands.NewCommandDialog(m.session.ID),
267 Model: commands.NewCommandDialog(m.session.ID),
267 })
268 })
@@ -542,6 +543,10 @@ func (c *editorCmp) HasAttachments() bool {
542 return len(c.attachments) > 0
543 return len(c.attachments) > 0
543}
544}
544
545
546+func (c *editorCmp) IsEmpty() bool {
547+ return strings.TrimSpace(c.textarea.Value()) == ""
548+}
549+
545func normalPromptFunc(info textarea.PromptInfo) string {
550func normalPromptFunc(info textarea.PromptInfo) string {
546 t := styles.CurrentTheme()
551 t := styles.CurrentTheme()
547 if info.LineNumber == 0 {
552 if info.LineNumber == 0 {
internal/tui/page/chat/chat.go+3
@@ -1024,6 +1024,9 @@ func (p *chatPage) Help() help.KeyMap {
1024 key.WithKeys("ctrl+p"),
1024 key.WithKeys("ctrl+p"),
1025 key.WithHelp("ctrl+p", "commands"),
1025 key.WithHelp("ctrl+p", "commands"),
1026 )
1026 )
1027+ if p.focusedPane == PanelTypeEditor && p.editor.IsEmpty() {
1028+ commandsBinding.SetHelp("/ or ctrl+p", "commands")
1029+ }
1027 modelsBinding := key.NewBinding(
1030 modelsBinding := key.NewBinding(
1028 key.WithKeys("ctrl+m", "ctrl+l"),
1031 key.WithKeys("ctrl+m", "ctrl+l"),
1029 key.WithHelp("ctrl+l", "models"),
1032 key.WithHelp("ctrl+l", "models"),