From 226b39609f24521c962cc699aae39ebf30820cc3 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 18 Dec 2022 22:29:23 -0800 Subject: [PATCH] Cleanup TUI code now that we persist table entries in the model --- client/lib/tui.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/client/lib/tui.go b/client/lib/tui.go index f73768e..f95f907 100644 --- a/client/lib/tui.go +++ b/client/lib/tui.go @@ -25,7 +25,7 @@ import ( const TABLE_HEIGHT = 20 const PADDED_NUM_ENTRIES = TABLE_HEIGHT * 5 -var selectedRow string = "" +var selectedCommand string = "" var baseStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.NormalBorder()). @@ -186,18 +186,7 @@ func (m model) View() string { return fmt.Sprintf("An unrecoverable error occured: %v\n", m.fatalErr) } if m.selected { - indexOfCommand := -1 - 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] + selectedCommand = m.tableEntries[m.table.Cursor()].Command return "" } if m.quitting { @@ -476,10 +465,10 @@ func TuiQuery(ctx *context.Context, initialQuery string) error { if err != nil { 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 - selectedRow = initialQuery + selectedCommand = initialQuery } - fmt.Printf("%s\n", strings.ReplaceAll(selectedRow, "\\n", "\n")) + fmt.Printf("%s\n", strings.ReplaceAll(selectedCommand, "\\n", "\n")) return nil }