summary refs log blame commit diff stats
path: root/widgets/getpasswd.go
blob: 08702c582d044d4d06273af639ff8ea67d94594d (plain) (tree)




























































                                                                                  
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
}
rames=[..] , [..] , [..], [..] # # One of "on", "off", or "auto". # # Default: auto render-account-tabs=auto # # Width of the sidebar, including the border. # # Default: 20 sidebar-width=20 # # Height of the message preview, including the border. # # Default: 12 preview-height=12 # # Message to display when viewing an empty folder. # # Default: (no messages) empty-message=(no messages) [viewer] # # We can use different programs to display various kinds of email attachments. # These programs will have the mail piped into them and are expected to output # it ready to display on a terminal (you can include terminal control # characters if you like, for colors and such). Emails will be stripped of # non-printable characters before being piped into these commands, and will be # encoded with UTF-8. These commands are invoked with sh and run # non-interactively, and their output is piped into your pager command # (interactively). The following environment variables will be set: # # $WIDTH: the width of the terminal window # $HEIGHT: the height of the terminal window # $MIMETYPE: the email's mimetype # # You can use * as a wildcard for any subtype of a given mimetype. When # displaying a text/* message and no command matches, the message will just be # piped directly into your pager (after being stripped of non-printable # characters). # Examples: # #text/html=w3m -T text/html -cols $WIDTH -dump -o display_image=false -o display_link_number=true text/*=fold -sw $WIDTH # # Default: less -r pager=less -r # # If an email offers several versions (multipart), you can configure which # mimetype to prefer. For example, this can be used to prefer plaintext over # html emails. # # Default: text/plain,text/html alternatives=text/plain,text/html [lbinds] # # Binds are of the form <input keys> = <output keys> # Pressing <input keys> in sequence will then simulate pressing <output keys> # # Use <C-*> to refer to control+something. # # lbinds are effective in the list view # mbinds are effective in the message view q = :quit<Enter> <C-c> = :quit<Enter> j = :next-message<Enter> <Down> = :next-message<Enter> <C-d> = :next-message 50%<Enter> <C-f> = :next-message 100%<Enter> <PgDn> = :next-message 100%<Enter> k = :prev-message<Enter> <Up> = :prev-message<Enter> <C-u> = :prev-message 50%<Enter> <C-b> = :prev-message 100%<Enter> <PgUp> = :prev-message 100%<Enter> g = :select-message 0<Enter> G = :select-message -1<Enter> J = :next-folder<Enter> K = :prev-folder<Enter> l = :next-tab<Enter> <Right> = :next-tab<Enter> h = :prev-tab<Enter> <Left> = :prev-tab<Enter> <Enter> = :view-message<Enter> d = :confirm 'Really delete this message?' ':delete-message<Enter>'<Enter> c = :cf<space> $ = :term<space> [mbinds] # # Any key not bound is passed through to the sub-terminal. <Ctrl+h> = :prev-tab<Enter> <Ctrl+l> = :next-tab<Enter> [colors] # # Colors are configured in one of two ways: # # "foreground" or "background:foreground" # # You can specify colors according to the base 8 names: # default, black, red, green, yellow, blue, magenta, cyan, white # # or you can use numbers for the 256 color palette, # e.g. "127:118" (a particularly ugly combination FYI) # # Add one or more of the following characters to the beginning # of the foreground color to add modifiers: # # * bold # _ underline # ^ reverse # # e.g. "default:_*^default" would reverse the default colors and # with bold and underlined modifiers borders=default:^default loading-indicator=default:default account-unselected=white:black account-selected=default:default account-error=red:black folder-unselected=default:default folder-selected=white:black status-line=white:black status-line-error=red:black ex-line=default:default message-list-selected=white:black message-list-selected-unread=white:_black message-list-unselected=default:default message-list-unselected-unread=default:*default message-list-empty=default:default