about summary refs log tree commit diff stats
path: root/widgets/msgviewer.go
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r--widgets/msgviewer.go63
1 files changed, 24 insertions, 39 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 30c83f7..107ff59 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -33,7 +33,6 @@ type MessageViewer struct {
 	grid     *ui.Grid
 	switcher *PartSwitcher
 	msg      lib.MessageView
-	uiConfig config.UIConfig
 }
 
 type PartSwitcher struct {
@@ -63,11 +62,9 @@ func NewMessageViewer(acct *AccountView,
 	header, headerHeight := layout.grid(
 		func(header string) ui.Drawable {
 			return &HeaderView{
-				conf: conf,
 				Name: header,
 				Value: fmtHeader(msg.MessageInfo(), header,
 					acct.UiConfig().TimestampFormat),
-				uiConfig: acct.UiConfig(),
 			}
 		},
 	)
@@ -97,16 +94,15 @@ func NewMessageViewer(acct *AccountView,
 	err := createSwitcher(acct, switcher, conf, msg)
 	if err != nil {
 		return &MessageViewer{
-			err:      err,
-			grid:     grid,
-			msg:      msg,
-			uiConfig: acct.UiConfig(),
+			err:  err,
+			grid: grid,
+			msg:  msg,
 		}
 	}
 
 	grid.AddChild(header).At(0, 0)
 	if msg.PGPDetails() != nil {
-		grid.AddChild(NewPGPInfo(msg.PGPDetails(), acct.UiConfig())).At(1, 0)
+		grid.AddChild(NewPGPInfo(msg.PGPDetails())).At(1, 0)
 		grid.AddChild(ui.NewFill(' ')).At(2, 0)
 		grid.AddChild(switcher).At(3, 0)
 	} else {
@@ -120,7 +116,6 @@ func NewMessageViewer(acct *AccountView,
 		grid:     grid,
 		msg:      msg,
 		switcher: switcher,
-		uiConfig: acct.UiConfig(),
 	}
 	switcher.mv = mv
 
@@ -229,9 +224,8 @@ func createSwitcher(acct *AccountView, switcher *PartSwitcher,
 
 func (mv *MessageViewer) Draw(ctx *ui.Context) {
 	if mv.err != nil {
-		style := mv.acct.UiConfig().GetStyle(config.STYLE_DEFAULT)
-		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
-		ctx.Printf(0, 0, style, "%s", mv.err.Error())
+		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+		ctx.Printf(0, 0, tcell.StyleDefault, "%s", mv.err.Error())
 		return
 	}
 	mv.grid.Draw(ctx)
@@ -353,10 +347,7 @@ func (ps *PartSwitcher) Draw(ctx *ui.Context) {
 	ps.height = ctx.Height()
 	y := ctx.Height() - height
 	for i, part := range ps.parts {
-		style := ps.mv.uiConfig.GetStyle(config.STYLE_DEFAULT)
-		if ps.selected == i {
-			style = ps.mv.uiConfig.GetStyleSelected(config.STYLE_DEFAULT)
-		}
+		style := tcell.StyleDefault.Reverse(ps.selected == i)
 		ctx.Fill(0, y+i, ctx.Width(), 1, ' ', style)
 		name := fmt.Sprintf("%s/%s",
 			strings.ToLower(part.part.MIMEType),
@@ -445,7 +436,6 @@ func (mv *MessageViewer) Focus(focus bool) {
 
 type PartViewer struct {
 	ui.Invalidatable
-	conf        *config.AercConfig
 	err         error
 	fetched     bool
 	filter      *exec.Cmd
@@ -460,7 +450,6 @@ type PartViewer struct {
 	term        *Terminal
 	selecter    *Selecter
 	grid        *ui.Grid
-	uiConfig    config.UIConfig
 }
 
 func NewPartViewer(acct *AccountView, conf *config.AercConfig,
@@ -530,8 +519,7 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
 		{ui.SIZE_WEIGHT, ui.Const(1)},
 	})
 
-	selecter := NewSelecter([]string{"Save message", "Pipe to command"},
-		0, acct.UiConfig()).
+	selecter := NewSelecter([]string{"Save message", "Pipe to command"}, 0).
 		OnChoose(func(option string) {
 			switch option {
 			case "Save message":
@@ -544,7 +532,6 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
 	grid.AddChild(selecter).At(2, 0)
 
 	pv := &PartViewer{
-		conf:        conf,
 		filter:      filter,
 		index:       index,
 		msg:         msg,
@@ -556,7 +543,6 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
 		term:        term,
 		selecter:    selecter,
 		grid:        grid,
-		uiConfig:    acct.UiConfig(),
 	}
 
 	if term != nil {
@@ -675,16 +661,14 @@ func (pv *PartViewer) Invalidate() {
 }
 
 func (pv *PartViewer) Draw(ctx *ui.Context) {
-	style := pv.uiConfig.GetStyle(config.STYLE_DEFAULT)
-	styleError := pv.uiConfig.GetStyle(config.STYLE_ERROR)
 	if pv.filter == nil {
 		// TODO: Let them download it directly or something
-		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
-		ctx.Printf(0, 0, styleError,
+		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+		ctx.Printf(0, 0, tcell.StyleDefault.Foreground(tcell.ColorRed),
 			"No filter configured for this mimetype ('%s/%s')",
 			pv.part.MIMEType, pv.part.MIMESubType,
 		)
-		ctx.Printf(0, 2, style,
+		ctx.Printf(0, 2, tcell.StyleDefault,
 			"You can still :save the message or :pipe it to an external command")
 		pv.selecter.Focus(true)
 		pv.grid.Draw(ctx)
@@ -695,8 +679,8 @@ func (pv *PartViewer) Draw(ctx *ui.Context) {
 		pv.fetched = true
 	}
 	if pv.err != nil {
-		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
-		ctx.Printf(0, 0, style, "%s", pv.err.Error())
+		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+		ctx.Printf(0, 0, tcell.StyleDefault, "%s", pv.err.Error())
 		return
 	}
 	pv.term.Draw(ctx)
@@ -718,10 +702,8 @@ func (pv *PartViewer) Event(event tcell.Event) bool {
 
 type HeaderView struct {
 	ui.Invalidatable
-	conf     *config.AercConfig
-	Name     string
-	Value    string
-	uiConfig config.UIConfig
+	Name  string
+	Value string
 }
 
 func (hv *HeaderView) Draw(ctx *ui.Context) {
@@ -729,15 +711,18 @@ func (hv *HeaderView) Draw(ctx *ui.Context) {
 	size := runewidth.StringWidth(name)
 	lim := ctx.Width() - size - 1
 	value := runewidth.Truncate(" "+hv.Value, lim, "…")
-
-	vstyle := hv.uiConfig.GetStyle(config.STYLE_DEFAULT)
-	hstyle := hv.uiConfig.GetStyle(config.STYLE_HEADER)
-
+	var (
+		hstyle tcell.Style
+		vstyle tcell.Style
+	)
 	// TODO: Make this more robust and less dumb
 	if hv.Name == "PGP" {
-		vstyle = hv.uiConfig.GetStyle(config.STYLE_SUCCESS)
+		vstyle = tcell.StyleDefault.Foreground(tcell.ColorGreen)
+		hstyle = tcell.StyleDefault.Bold(true)
+	} else {
+		vstyle = tcell.StyleDefault
+		hstyle = tcell.StyleDefault.Bold(true)
 	}
-
 	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', vstyle)
 	ctx.Printf(0, 0, hstyle, "%s", name)
 	ctx.Printf(size, 0, vstyle, "%s", value)