aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-02-12 20:20:20 +0100
committerJoe <rbo@gmx.us>2024-02-12 20:20:20 +0100
commit97dfd4023230d2351e2850a05f30a6ea3cda7273 (patch)
tree9bedf1aca638fa3721f36858de2c51285e7294e7 /src
parentfine actually (diff)
downloadhardflip-97dfd4023230d2351e2850a05f30a6ea3cda7273.tar.gz
hardflip-97dfd4023230d2351e2850a05f30a6ea3cda7273.tar.bz2
hardflip-97dfd4023230d2351e2850a05f30a6ea3cda7273.tar.xz
hardflip-97dfd4023230d2351e2850a05f30a6ea3cda7273.tar.zst
hardflip-97dfd4023230d2351e2850a05f30a6ea3cda7273.zip
tmp
Diffstat (limited to 'src')
-rw-r--r--src/c_utils.go31
-rw-r--r--src/i_ui.go23
2 files changed, 44 insertions, 10 deletions
diff --git a/src/c_utils.go b/src/c_utils.go
index 3b94cc1..cfcba8e 100644
--- a/src/c_utils.go
+++ b/src/c_utils.go
@@ -52,6 +52,7 @@
package main
import (
+ "bytes"
"errors"
"fmt"
"os"
@@ -169,3 +170,33 @@ func c_decrypt_str(str string) (string, error) {
out, err := cmd.Output()
return string(out), err
}
+
+func c_get_secret_gpg_keyring(ui *HardUI) []string {
+ var keys []string
+ var out bytes.Buffer
+ cmd_fmt := []string{
+ `gpg`,
+ `--list-secret-keys`,
+ `|`,
+ `grep`,
+ `-A`,
+ `2`,
+ `'^sec'`,
+ `|`,
+ `sed`,
+ `'{/^sec/d;/--/d;s/^uid.*] //;}'`,
+ }
+
+ 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
+ }
+ fmt.Printf("%s\n", out.String())
+ os.Exit(0)
+ // keys[0] = string(cmd)
+ return keys
+}
diff --git a/src/i_ui.go b/src/i_ui.go
index 312f8b5..ba2f5e3 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -196,13 +196,11 @@ func i_draw_welcome_box(ui HardUI) {
i_draw_box(ui.s,
l_max - 1, 0, r_max, b_max + 1,
ui.style[STYLE_BOX], ui.style[STYLE_HEAD], "", true)
- art := [6]string{
- ` _ __`,
- `| | / _|`,
- `| |__ | |_`,
- `| '_ \| _|`,
- `| | | | |`,
- `|_| |_|_|`,
+ art := [4]string{
+ ` _ __`,
+ `| |_ / _|`,
+ `| ' \| _|`,
+ `|_||_|_|`,
}
line := 0
for k, v := range art {
@@ -228,7 +226,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 = `Please enter the public gpg key ID to be used`
+ text = `Please select the gpg key ID to be used`
if line += 1; line > b_max { return }
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 }
@@ -272,8 +270,11 @@ 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) {
+func i_prompt_gpg(ui HardUI, keys []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])
i_draw_text(ui.s,
1, ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1,
ui.style[STYLE_DEF], text)
@@ -432,6 +433,7 @@ func i_load_ui(data_dir string,
}
func i_ui(data_dir string) {
+ var keys []string
ui := HardUI{}
opts := HardOpts{}
var err error
@@ -485,6 +487,7 @@ func i_ui(data_dir 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)
}
for {
data.ui.s.Clear()
@@ -498,7 +501,7 @@ 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)
+ i_prompt_gpg(data.ui, keys)
} else {
}
} else if data.litems.head == nil {