diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-30 15:55:21 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-30 15:55:21 -0400 |
commit | 337dd18c9ca5ad5c01ef46f9b6f7ac40cd0f2fc5 (patch) | |
tree | 0d5988419cf5d8b11d464d1f7016ab9ed4d40028 | |
parent | ab632d4e976187a561b2bd1ffb0448904a3d106a (diff) |
Add multipart selector mockup to msgviewer
-rw-r--r-- | widgets/msgviewer.go | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index e94ece4..9d80c74 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -109,7 +109,7 @@ index 0000000..1c55bfe func NewMessageViewer() *MessageViewer { grid := ui.NewGrid().Rows([]ui.GridSpec{ - {ui.SIZE_EXACT, 3}, + {ui.SIZE_EXACT, 4}, {ui.SIZE_WEIGHT, 1}, }).Columns([]ui.GridSpec{ {ui.SIZE_WEIGHT, 1}, @@ -119,6 +119,7 @@ func NewMessageViewer() *MessageViewer { {ui.SIZE_EXACT, 1}, {ui.SIZE_EXACT, 1}, {ui.SIZE_EXACT, 1}, + {ui.SIZE_EXACT, 1}, }).Columns([]ui.GridSpec{ {ui.SIZE_WEIGHT, 1}, {ui.SIZE_WEIGHT, 1}, @@ -139,7 +140,19 @@ func NewMessageViewer() *MessageViewer { Value: "[PATCH todo.sr.ht v2 1/3 Alter Event fields " + "and migrate data]", }).At(1, 0).Span(1, 2) - headers.AddChild(ui.NewFill(' ')).At(2, 0).Span(1, 2) + headers.AddChild( + &HeaderView{ + Name: "PGP", + Value: "✓ Valid PGP signature from Ivan Habunek", + }).At(2, 0).Span(1, 2) + headers.AddChild(ui.NewFill(' ')).At(3, 0).Span(1, 2) + + body := ui.NewGrid().Rows([]ui.GridSpec{ + {ui.SIZE_WEIGHT, 1}, + }).Columns([]ui.GridSpec{ + {ui.SIZE_WEIGHT, 1}, + {ui.SIZE_EXACT, 20}, + }) cmd := exec.Command("sh", "-c", "./contrib/hldiff.py | less -R") pipe, _ := cmd.StdinPipe() @@ -152,9 +165,13 @@ func NewMessageViewer() *MessageViewer { }() } term.Focus(true) + body.AddChild(term).At(0, 0) + + body.AddChild(ui.NewBordered( + &MultipartView{}, ui.BORDER_LEFT)).At(0, 1) grid.AddChild(headers).At(0, 0) - grid.AddChild(term).At(1, 0) + grid.AddChild(body).At(1, 0) return &MessageViewer{grid, term} } @@ -189,10 +206,14 @@ type HeaderView struct { func (hv *HeaderView) Draw(ctx *ui.Context) { size := runewidth.StringWidth(" " + hv.Name + " ") - ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault) - style := tcell.StyleDefault.Reverse(true) - ctx.Printf(0, 0, style, " "+hv.Name+" ") - style = tcell.StyleDefault + var style tcell.Style + if hv.Name == "PGP" { + style = tcell.StyleDefault.Foreground(tcell.ColorGreen) + } else { + style = tcell.StyleDefault + } + ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style) + ctx.Printf(0, 0, tcell.StyleDefault.Reverse(true), " "+hv.Name+" ") ctx.Printf(size, 0, style, " "+hv.Value) } @@ -205,3 +226,25 @@ func (hv *HeaderView) Invalidate() { func (hv *HeaderView) OnInvalidate(fn func(d ui.Drawable)) { hv.onInvalidate = fn } + +type MultipartView struct { + onInvalidate func(d ui.Drawable) +} + +func (mpv *MultipartView) 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(0, 0, tcell.StyleDefault.Reverse(true), "text/plain") + ctx.Printf(0, 1, tcell.StyleDefault, "text/html") + ctx.Printf(0, 2, tcell.StyleDefault, "application/pgp-si…") +} + +func (mpv *MultipartView) Invalidate() { + if mpv.onInvalidate != nil { + mpv.onInvalidate(mpv) + } +} + +func (mpv *MultipartView) OnInvalidate(fn func(d ui.Drawable)) { + mpv.onInvalidate = fn +} |