diff options
author | Joe <rbo@gmx.us> | 2024-02-12 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-02-12 20:20:20 +0100 |
commit | ca05de5f08a61229d2db747950487e928e36c2b5 (patch) | |
tree | 02124ebee4d4a914387e2dbe7a45db2e0918d178 /src | |
parent | tmp (diff) | |
download | hardflip-ca05de5f08a61229d2db747950487e928e36c2b5.tar.gz hardflip-ca05de5f08a61229d2db747950487e928e36c2b5.tar.bz2 hardflip-ca05de5f08a61229d2db747950487e928e36c2b5.tar.xz hardflip-ca05de5f08a61229d2db747950487e928e36c2b5.tar.zst hardflip-ca05de5f08a61229d2db747950487e928e36c2b5.zip |
go
Diffstat (limited to 'src')
-rw-r--r-- | src/c_utils.go | 53 | ||||
-rw-r--r-- | src/i_ui.go | 17 |
2 files changed, 49 insertions, 21 deletions
diff --git a/src/c_utils.go b/src/c_utils.go index cfcba8e..667ecbc 100644 --- a/src/c_utils.go +++ b/src/c_utils.go @@ -55,6 +55,7 @@ import ( "bytes" "errors" "fmt" + "io" "os" "os/exec" "strings" @@ -171,32 +172,48 @@ func c_decrypt_str(str string) (string, error) { return string(out), err } -func c_get_secret_gpg_keyring(ui *HardUI) []string { - var keys []string - var out bytes.Buffer - cmd_fmt := []string{ +func c_get_secret_gpg_keyring(ui *HardUI) [][2]string { + var keys [][2]string + var sed_out bytes.Buffer + gpg_fmt := []string{ `gpg`, `--list-secret-keys`, - `|`, + } + grep_fmt := []string{ `grep`, `-A`, `2`, - `'^sec'`, - `|`, + `^sec`, + } + sed_fmt := []string{ `sed`, - `'{/^sec/d;/--/d;s/^uid.*] //;}'`, + `{/^sec/d;/--/d;s/^uid.*] //;s/^\s*//;}`, } - ui.s.Fini() - cmd := exec.Command(cmd_fmt[0], cmd_fmt[1:]...) - cmd.Stdout = &out - if err := cmd.Run(); err != nil { - c_die("failed to list gpg secret keys", err) - c_error_mode("failed to list gpg secret keys", err, ui) - return nil + gpg := exec.Command(gpg_fmt[0], gpg_fmt[1:]...) + grep := exec.Command(grep_fmt[0], grep_fmt[1:]...) + sed := exec.Command(sed_fmt[0], sed_fmt[1:]...) + gpg_r, gpg_w := io.Pipe() + grep_r, grep_w := io.Pipe() + gpg.Stdout = gpg_w + grep.Stdin = gpg_r + grep.Stdout = grep_w + sed.Stdin = grep_r + sed.Stdout = &sed_out + gpg.Start() + grep.Start() + sed.Start() + gpg.Wait() + gpg_w.Close() + grep.Wait() + grep_w.Close() + sed.Wait() + lines := strings.Split(sed_out.String(), "\n") + for i := 0; i < len(lines); i+= 2 { + if i + 1 < len(lines) { + keys = append(keys, [2]string{lines[i], lines[i + 1]}) + } } - fmt.Printf("%s\n", out.String()) - os.Exit(0) - // keys[0] = string(cmd) + keys = append(keys, [2]string{"plain", ""}) return keys } diff --git a/src/i_ui.go b/src/i_ui.go index ba2f5e3..e7e7947 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -270,11 +270,22 @@ func i_draw_welcome_box(ui HardUI) { i_draw_text(ui.s, l, line, r, line, ui.style[STYLE_DEF], text) } -func i_prompt_gpg(ui HardUI, keys []string) { +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 ") - i_draw_text(ui.s, 0, 0, 80, 12, ui.style[STYLE_DEF], keys[0]) + for k, v := range keys { + text := "" + if v[0] != "plain" { + text = "[" + strconv.Itoa(k + 1) + "] " + + v[1] + " " + v[0][:10] + "... " + } else { + 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, 1, ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, ui.style[STYLE_DEF], text) @@ -433,7 +444,7 @@ func i_load_ui(data_dir string, } func i_ui(data_dir string) { - var keys []string + var keys [][2]string ui := HardUI{} opts := HardOpts{} var err error |