summaryrefslogtreecommitdiff
path: root/widgets/getpasswd.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-03-03 16:20:07 -0500
committerDrew DeVault <sir@cmpwn.com>2020-03-03 16:49:52 -0500
commitf3158b36f1f210ff54febbe82b571c1379b30c98 (patch)
tree10cde839c9517609f55b8f1057b1cf84ac592632 /widgets/getpasswd.go
parent89f1684ea4b5e680db7ff06a54b2d4e78212cd12 (diff)
downloadaerc-f3158b36f1f210ff54febbe82b571c1379b30c98.zip
Initial support for PGP decryption & signatures
Diffstat (limited to 'widgets/getpasswd.go')
-rw-r--r--widgets/getpasswd.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/widgets/getpasswd.go b/widgets/getpasswd.go
new file mode 100644
index 0000000..08702c5
--- /dev/null
+++ b/widgets/getpasswd.go
@@ -0,0 +1,61 @@
+package widgets
+
+import (
+ "github.com/gdamore/tcell"
+
+ "git.sr.ht/~sircmpwn/aerc/lib/ui"
+)
+
+type GetPasswd struct {
+ ui.Invalidatable
+ callback func(string)
+ title string
+ prompt string
+ input *ui.TextInput
+}
+
+func NewGetPasswd(title string, prompt string, cb func(string)) *GetPasswd {
+ getpasswd := &GetPasswd{
+ callback: cb,
+ title: title,
+ prompt: prompt,
+ input: ui.NewTextInput("").Password(true).Prompt("Password: "),
+ }
+ getpasswd.input.OnInvalidate(func(_ ui.Drawable) {
+ getpasswd.Invalidate()
+ })
+ getpasswd.input.Focus(true)
+ return getpasswd
+}
+
+func (gp *GetPasswd) Draw(ctx *ui.Context) {
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+ ctx.Fill(0, 0, ctx.Width(), 1, ' ', tcell.StyleDefault.Reverse(true))
+ ctx.Printf(1, 0, tcell.StyleDefault.Reverse(true), "%s", gp.title)
+ ctx.Printf(1, 1, tcell.StyleDefault, gp.prompt)
+ gp.input.Draw(ctx.Subcontext(1, 3, ctx.Width()-2, 1))
+}
+
+func (gp *GetPasswd) Invalidate() {
+ gp.DoInvalidate(gp)
+}
+
+func (gp *GetPasswd) Event(event tcell.Event) bool {
+ switch event := event.(type) {
+ case *tcell.EventKey:
+ switch event.Key() {
+ case tcell.KeyEnter:
+ gp.input.Focus(false)
+ gp.callback(gp.input.String())
+ default:
+ gp.input.Event(event)
+ }
+ default:
+ gp.input.Event(event)
+ }
+ return true
+}
+
+func (gp *GetPasswd) Focus(f bool) {
+ // Who cares
+}