From ebbdb99f377c235806a309af3f70b26d5a935d2b Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 1 Aug 2021 15:50:11 -0400 Subject: [PATCH] add file selector text area --- cmd/manage/main.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/manage/main.go b/cmd/manage/main.go index 143087b..3606b52 100644 --- a/cmd/manage/main.go +++ b/cmd/manage/main.go @@ -145,7 +145,19 @@ func main() { ) // import pop-up - popup := ui.NewBox("import", []string{"⏎ submit", "(esc)close"}, nil, ui.StyleActive, false) + wd, _ := os.Getwd() + fileSelector := ui.NewEditableTextLine(wd) + fileSelector.ResetCursor(false) + fileSelector.SetStyle(ui.StyleActive.Underline(true)) + popup := ui.NewBox( + "import csv file", + []string{"⏎ submit", "(esc)close"}, + ui.Contents{ + {Container: fileSelector, Offsets: ui.Offsets{Top: 2, Left: 2}}, + }, + ui.StyleActive, + false, + ) popup.SetVisible(false) // init @@ -192,8 +204,20 @@ func main() { } } else if curr == IN_IMPORT { if v.Key() == tcell.KeyEsc { + fileSelector.SetText(wd) + fileSelector.ResetCursor(false) screen.PostEvent(NewEventCloseImport()) } + if v.Key() == tcell.KeyBackspace || v.Key() == tcell.KeyBackspace2 { + fileSelector.DeleteAtCursor() + } else if v.Key() == tcell.KeyRight { + fileSelector.MoveCursor(1) + + } else if v.Key() == tcell.KeyLeft { + fileSelector.MoveCursor(-1) + } else if v.Rune() != 0 { + fileSelector.InsertAtCursor(v.Rune()) + } } case *tcell.EventResize: // screen redraw w, h := screen.Size() @@ -214,7 +238,7 @@ func main() { state.Set("ui_state", IN_IMPORT) menu.SetStyle(ui.StyleInactive) popup.SetVisible(true) - popup.SetSize(6, 3, 10, 80) + popup.SetSize(6, 3, 5, 80) case *EventCloseImport: state.Set("ui_state", IN_MENU) menu.SetStyle(ui.StyleActive) @@ -229,7 +253,6 @@ func main() { default: } // repaint - screen.Clear() container.Draw(screen) popup.Draw(screen) screen.Show()