add file selector text area

This commit is contained in:
David 2021-08-01 15:50:11 -04:00
parent d6acfe235b
commit ebbdb99f37
1 changed files with 26 additions and 3 deletions

View File

@ -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()