Cleanup TUI code now that we persist table entries in the model

This commit is contained in:
David Dworken 2022-12-18 22:29:23 -08:00
parent fe161a2132
commit 226b39609f
No known key found for this signature in database

View File

@ -25,7 +25,7 @@ import (
const TABLE_HEIGHT = 20 const TABLE_HEIGHT = 20
const PADDED_NUM_ENTRIES = TABLE_HEIGHT * 5 const PADDED_NUM_ENTRIES = TABLE_HEIGHT * 5
var selectedRow string = "" var selectedCommand string = ""
var baseStyle = lipgloss.NewStyle(). var baseStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()). BorderStyle(lipgloss.NormalBorder()).
@ -186,18 +186,7 @@ func (m model) View() string {
return fmt.Sprintf("An unrecoverable error occured: %v\n", m.fatalErr) return fmt.Sprintf("An unrecoverable error occured: %v\n", m.fatalErr)
} }
if m.selected { if m.selected {
indexOfCommand := -1 selectedCommand = m.tableEntries[m.table.Cursor()].Command
for i, columnName := range hctx.GetConf(m.ctx).DisplayedColumns {
if columnName == "Command" {
indexOfCommand = i
break
}
}
if indexOfCommand == -1 {
selectedRow = "Error: Table doesn't have a column named `Command`?"
return ""
}
selectedRow = m.table.SelectedRow()[indexOfCommand]
return "" return ""
} }
if m.quitting { if m.quitting {
@ -476,10 +465,10 @@ func TuiQuery(ctx *context.Context, initialQuery string) error {
if err != nil { if err != nil {
return err return err
} }
if selectedRow == "" && os.Getenv("HISHTORY_TERM_INTEGRATION") != "" { if selectedCommand == "" && os.Getenv("HISHTORY_TERM_INTEGRATION") != "" {
// Print out the initialQuery instead so that we don't clear the terminal // Print out the initialQuery instead so that we don't clear the terminal
selectedRow = initialQuery selectedCommand = initialQuery
} }
fmt.Printf("%s\n", strings.ReplaceAll(selectedRow, "\\n", "\n")) fmt.Printf("%s\n", strings.ReplaceAll(selectedCommand, "\\n", "\n"))
return nil return nil
} }