From 299cc7237f775f4972199647c8319f90d1963e8f Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 13 Feb 2024 20:20:20 +0100 Subject: tmp --- src/c_hardflip.go | 1 + src/i_events.go | 32 ++++++++++++++++++++------------ src/i_ui.go | 31 +++++++++++++++++++------------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/c_hardflip.go b/src/c_hardflip.go index 68e4f10..72a8f2e 100644 --- a/src/c_hardflip.go +++ b/src/c_hardflip.go @@ -60,6 +60,7 @@ type HardData struct { folds map[*DirsNode]*ItemsList data_dir string load_err []error + keys [][2]string } func main() { diff --git a/src/i_events.go b/src/i_events.go index 48db64c..4a82404 100644 --- a/src/i_events.go +++ b/src/i_events.go @@ -53,6 +53,7 @@ package main import ( "os" + "fmt" "github.com/gdamore/tcell/v2" "golang.org/x/term" @@ -352,18 +353,10 @@ func i_events(data *HardData) { os.Exit(0) } if len(data.opts.GPG) == 0 { - if len(data.ui.buff) > 0 && - (event.Key() == tcell.KeyBackspace || - event.Key() == tcell.KeyBackspace2) { - data.ui.buff = data.ui.buff[:len(data.ui.buff) - 1] - } else if event.Key() == tcell.KeyCtrlU { - data.ui.buff = "" - } else if event.Key() == tcell.KeyEnter { - data.opts.GPG = data.ui.buff - data.ui.buff = "" - data.ui.s.HideCursor() - } else if event.Rune() >= 32 && event.Rune() <= 126 { - data.ui.buff += string(event.Rune()) + if event.Rune() < '1' || event.Rune() > '9' { + break + } else { + data.opts.GPG = data.keys[event.Rune() - 48 - 1][0] } } else { // TODO: confirm @@ -372,3 +365,18 @@ func i_events(data *HardData) { } } + +// readline type beat +// if len(data.ui.buff) > 0 && +// (event.Key() == tcell.KeyBackspace || +// event.Key() == tcell.KeyBackspace2) { +// data.ui.buff = data.ui.buff[:len(data.ui.buff) - 1] +// } else if event.Key() == tcell.KeyCtrlU { +// data.ui.buff = "" +// } else if event.Key() == tcell.KeyEnter { +// data.opts.GPG = data.ui.buff +// data.ui.buff = "" +// data.ui.s.HideCursor() +// } else if event.Rune() >= 32 && event.Rune() <= 126 { +// data.ui.buff += string(event.Rune()) +// } diff --git a/src/i_ui.go b/src/i_ui.go index e7e7947..b0cea23 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -246,7 +246,7 @@ func i_draw_welcome_box(ui HardUI) { l, r = ui.dim[W] / 2 - len(text) / 2, ui.dim[W] / 2 + len(text) / 2 + 1 if l < l_max { l = l_max }; if r > r_max { r = r_max } i_draw_text(ui.s, l, line, r, line, ui.style[STYLE_DEF], text) - text = `storage, please type ` + text = `storage, please select ` text_2 := `plain` text_3 := ` (plaintext passwords` if line += 1; line > b_max { return } @@ -271,9 +271,11 @@ func i_draw_welcome_box(ui HardUI) { } func i_prompt_gpg(ui HardUI, keys [][2]string) { - text := "gpg: " - // TODO: 0 keys - i_draw_msg(ui.s, len(keys), ui.style[STYLE_DEF], ui.dim, " GnuPG keys ") + lines := len(keys) + if lines == 1 { + lines = 2 + } + i_draw_msg(ui.s, lines, ui.style[STYLE_DEF], ui.dim, " GnuPG keys ") for k, v := range keys { text := "" if v[0] != "plain" { @@ -283,15 +285,18 @@ func i_prompt_gpg(ui HardUI, keys [][2]string) { text = "[" + strconv.Itoa(k + 1) + "] " + "plain" } line := ui.dim[H] - 2 - len(keys) + k - // TODO: here - i_draw_text(ui.s, 2, line, ui.dim[W] - 2, line, ui.style[STYLE_DEF], text) + i_draw_text(ui.s, 2, line, ui.dim[W] - 2, line, + ui.style[STYLE_DEF], text) + } + if len(keys) == 1 { + i_draw_text(ui.s, 2, ui.dim[H] - 4, ui.dim[W] - 1, ui.dim[H] - 4, + ui.style[STYLE_DEF], + "No gpg key! Creating your gpg key first is recommended") } i_draw_text(ui.s, 1, ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, - ui.style[STYLE_DEF], text) + ui.style[STYLE_BOT], "gpg: ") ui.s.ShowCursor(6 + len(ui.buff), ui.dim[H] - 1) - i_draw_text(ui.s, 6, ui.dim[H] - 1, ui.dim[W], ui.dim[H] - 1, - ui.style[STYLE_DEF], ui.buff) } func i_draw_zhosts_box(ui HardUI) { @@ -444,7 +449,6 @@ func i_load_ui(data_dir string, } func i_ui(data_dir string) { - var keys [][2]string ui := HardUI{} opts := HardOpts{} var err error @@ -495,10 +499,11 @@ func i_ui(data_dir string) { make(map[*DirsNode]*ItemsList), data_dir, load_err, + [][2]string{}, } if data.opts.GPG == DEFAULT_OPTS.GPG && data.litems.head == nil { data.ui.mode = WELCOME_MODE - keys = c_get_secret_gpg_keyring(&data.ui) + data.keys = c_get_secret_gpg_keyring(&data.ui) } for { data.ui.s.Clear() @@ -512,8 +517,10 @@ func i_ui(data_dir string) { if data.ui.mode == WELCOME_MODE { i_draw_welcome_box(data.ui) if len(data.opts.GPG) == 0 { - i_prompt_gpg(data.ui, keys) + i_prompt_gpg(data.ui, data.keys) } else { + i_prompt_confirm_gpg(data.ui, data.opts) + // TODO: here } } else if data.litems.head == nil { i_draw_zhosts_box(data.ui) -- cgit v1.2.3