fix help properly

This commit is contained in:
2025-07-13 21:05:32 -07:00
parent 5543a9a8e0
commit 491416a575
10 changed files with 45 additions and 40 deletions

View File

@@ -152,15 +152,11 @@ func (m *EditCellModel) View() string {
content := fmt.Sprintf("%s\n\n", TitleStyle.Render(fmt.Sprintf("Edit Cell: %s", columnName)))
content += fmt.Sprintf("Value: %s\n\n", m.input.View())
var helpText string
if m.showFullHelp {
helpText = m.help.FullHelpView(m.keyMap.FullHelp())
content += m.help.FullHelpView(m.keyMap.FullHelp())
} else {
helpText = m.help.ShortHelpView(m.keyMap.ShortHelp())
// Add ctrl+g to short help
helpText += " • " + HelpStyle.Render("ctrl+g: toggle help")
content += m.help.ShortHelpView(m.keyMap.ShortHelp())
}
content += helpText
return content
}

View File

@@ -14,6 +14,7 @@ type EditCellKeyMap struct {
LineEnd key.Binding
DeleteWord key.Binding
DeleteChar key.Binding
ToggleHelp key.Binding
}
// DefaultEditCellKeyMap returns the default keybindings for edit cell
@@ -59,12 +60,16 @@ func DefaultEditCellKeyMap() EditCellKeyMap {
key.WithKeys("backspace"),
key.WithHelp("backspace", "delete char"),
),
ToggleHelp: key.NewBinding(
key.WithKeys("ctrl+g"),
key.WithHelp("ctrl+g", "toggle help"),
),
}
}
// ShortHelp returns keybindings to be shown in the mini help view
func (k EditCellKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Save, k.Cancel}
return []key.Binding{k.Save, k.Cancel, k.ToggleHelp}
}
// FullHelp returns keybindings for the expanded help view
@@ -72,6 +77,6 @@ func (k EditCellKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Save, k.Cancel},
{k.CursorLeft, k.CursorRight, k.WordLeft, k.WordRight},
{k.LineStart, k.LineEnd, k.DeleteWord, k.DeleteChar},
{k.LineStart, k.LineEnd, k.DeleteWord, k.DeleteChar, k.ToggleHelp},
}
}

View File

@@ -456,15 +456,11 @@ func (m *QueryModel) View() string {
if m.FocusOnInput {
content.WriteString(HelpStyle.Render("enter: execute • esc: back • ctrl+g: toggle help"))
} else {
var helpText string
if m.showFullHelp {
helpText = m.help.FullHelpView(m.keyMap.FullHelp())
content.WriteString(m.help.FullHelpView(m.keyMap.FullHelp()))
} else {
helpText = m.help.ShortHelpView(m.keyMap.ShortHelp())
// Add ctrl+g to short help
helpText += " • " + HelpStyle.Render("ctrl+g: toggle help")
content.WriteString(m.help.ShortHelpView(m.keyMap.ShortHelp()))
}
content.WriteString(helpText)
}
return content.String()

View File

@@ -26,6 +26,7 @@ type QueryKeyMap struct {
GoToStart key.Binding
GoToEnd key.Binding
Back key.Binding
ToggleHelp key.Binding
}
// DefaultQueryKeyMap returns the default keybindings for query view
@@ -98,12 +99,16 @@ func DefaultQueryKeyMap() QueryKeyMap {
key.WithKeys("q"),
key.WithHelp("q", "back"),
),
ToggleHelp: key.NewBinding(
key.WithKeys("ctrl+g"),
key.WithHelp("ctrl+g", "toggle help"),
),
}
}
// ShortHelp returns keybindings to be shown in the mini help view
func (k QueryKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Execute, k.Up, k.Down, k.GoToStart, k.GoToEnd, k.EditQuery}
return []key.Binding{k.Execute, k.Up, k.Down, k.GoToStart, k.GoToEnd, k.EditQuery, k.ToggleHelp}
}
// FullHelp returns keybindings for the expanded help view
@@ -112,6 +117,6 @@ func (k QueryKeyMap) FullHelp() [][]key.Binding {
{k.Execute, k.Escape, k.EditQuery, k.Back},
{k.Up, k.Down, k.Enter, k.GoToStart, k.GoToEnd},
{k.CursorLeft, k.CursorRight, k.WordLeft, k.WordRight},
{k.LineStart, k.LineEnd, k.DeleteWord},
{k.LineStart, k.LineEnd, k.DeleteWord, k.ToggleHelp},
}
}

View File

@@ -181,15 +181,11 @@ func (m *RowDetailModel) View() string {
}
content.WriteString("\n")
var helpText string
if m.showFullHelp {
helpText = m.help.FullHelpView(m.keyMap.FullHelp())
content.WriteString(m.help.FullHelpView(m.keyMap.FullHelp()))
} else {
helpText = m.help.ShortHelpView(m.keyMap.ShortHelp())
// Add ctrl+g to short help
helpText += " • " + HelpStyle.Render("ctrl+g: toggle help")
content.WriteString(m.help.ShortHelpView(m.keyMap.ShortHelp()))
}
content.WriteString(helpText)
return content.String()
}

View File

@@ -14,6 +14,7 @@ type RowDetailKeyMap struct {
Back key.Binding
GoToStart key.Binding
GoToEnd key.Binding
ToggleHelp key.Binding
}
// DefaultRowDetailKeyMap returns the default keybindings for row detail
@@ -47,18 +48,22 @@ func DefaultRowDetailKeyMap() RowDetailKeyMap {
key.WithKeys("G"),
key.WithHelp("G", "go to end"),
),
ToggleHelp: key.NewBinding(
key.WithKeys("ctrl+g"),
key.WithHelp("ctrl+g", "toggle help"),
),
}
}
// ShortHelp returns keybindings to be shown in the mini help view
func (k RowDetailKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Up, k.Down, k.Enter, k.GoToStart, k.GoToEnd, k.Back}
return []key.Binding{k.Up, k.Down, k.Enter, k.GoToStart, k.GoToEnd, k.Back, k.ToggleHelp}
}
// FullHelp returns keybindings for the expanded help view
func (k RowDetailKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down, k.Enter},
{k.Escape, k.Back, k.GoToStart, k.GoToEnd},
{k.Escape, k.Back, k.GoToStart, k.GoToEnd, k.ToggleHelp},
}
}

View File

@@ -445,15 +445,11 @@ func (m *TableDataModel) View() string {
if m.searching {
content.WriteString(HelpStyle.Render("Type to search • enter/esc: finish search"))
} else {
var helpText string
if m.showFullHelp {
helpText = m.help.FullHelpView(m.keyMap.FullHelp())
content.WriteString(m.help.FullHelpView(m.keyMap.FullHelp()))
} else {
helpText = m.help.ShortHelpView(m.keyMap.ShortHelp())
// Add ctrl+g to short help
helpText += " • " + HelpStyle.Render("ctrl+g: toggle help")
content.WriteString(m.help.ShortHelpView(m.keyMap.ShortHelp()))
}
content.WriteString(helpText)
}
return content.String()

View File

@@ -19,6 +19,7 @@ type TableDataKeyMap struct {
GoToEnd key.Binding
Refresh key.Binding
SQLMode key.Binding
ToggleHelp key.Binding
}
// DefaultTableDataKeyMap returns the default keybindings for table data
@@ -72,12 +73,16 @@ func DefaultTableDataKeyMap() TableDataKeyMap {
key.WithKeys("s"),
key.WithHelp("s", "SQL mode"),
),
ToggleHelp: key.NewBinding(
key.WithKeys("ctrl+g"),
key.WithHelp("ctrl+g", "toggle help"),
),
}
}
// ShortHelp returns keybindings to be shown in the mini help view
func (k TableDataKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Up, k.Down, k.Enter, k.GoToStart, k.GoToEnd, k.Search}
return []key.Binding{k.Up, k.Down, k.Enter, k.GoToStart, k.GoToEnd, k.Search, k.ToggleHelp}
}
// FullHelp returns keybindings for the expanded help view
@@ -85,6 +90,6 @@ func (k TableDataKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down, k.Left, k.Right},
{k.Enter, k.Search, k.Escape, k.Back},
{k.GoToStart, k.GoToEnd, k.Refresh, k.SQLMode},
{k.GoToStart, k.GoToEnd, k.Refresh, k.SQLMode, k.ToggleHelp},
}
}

View File

@@ -411,15 +411,11 @@ func (m *TableListModel) View() string {
if m.searching {
content.WriteString(HelpStyle.Render("Type to search • enter/esc: finish search"))
} else {
var helpText string
if m.showFullHelp {
helpText = m.help.FullHelpView(m.keyMap.FullHelp())
content.WriteString(m.help.FullHelpView(m.keyMap.FullHelp()))
} else {
helpText = m.help.ShortHelpView(m.keyMap.ShortHelp())
// Add ctrl+g to short help
helpText += " • " + HelpStyle.Render("ctrl+g: toggle help")
content.WriteString(m.help.ShortHelpView(m.keyMap.ShortHelp()))
}
content.WriteString(helpText)
}
return content.String()

View File

@@ -18,6 +18,7 @@ type TableListKeyMap struct {
GoToEnd key.Binding
Refresh key.Binding
SQLMode key.Binding
ToggleHelp key.Binding
}
// DefaultTableListKeyMap returns the default keybindings for table list
@@ -67,12 +68,16 @@ func DefaultTableListKeyMap() TableListKeyMap {
key.WithKeys("s"),
key.WithHelp("s", "SQL mode"),
),
ToggleHelp: key.NewBinding(
key.WithKeys("ctrl+g"),
key.WithHelp("ctrl+g", "toggle help"),
),
}
}
// ShortHelp returns keybindings to be shown in the mini help view
func (k TableListKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Up, k.Down, k.Enter, k.GoToStart, k.GoToEnd, k.Search}
return []key.Binding{k.Up, k.Down, k.Enter, k.GoToStart, k.GoToEnd, k.Search, k.ToggleHelp}
}
// FullHelp returns keybindings for the expanded help view
@@ -80,6 +85,6 @@ func (k TableListKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down, k.Left, k.Right},
{k.Enter, k.Search, k.Escape, k.Refresh},
{k.GoToStart, k.GoToEnd, k.SQLMode},
{k.GoToStart, k.GoToEnd, k.SQLMode, k.ToggleHelp},
}
}