summaryrefslogtreecommitdiff
path: root/widgets/msgviewer.go
diff options
context:
space:
mode:
authorKalyan Sriram <coder.kalyan@gmail.com>2020-07-27 01:03:55 -0700
committerReto Brunner <reto@labrat.space>2020-08-06 21:42:06 +0200
commit905cb9dfd3ef197bb4b59039a1be76ce2c8e3099 (patch)
tree2d923c42ec224b1d525d942a7bb17416f4a62dd5 /widgets/msgviewer.go
parent548a5fff68a648a5e0b6fd909e3c21463addc8af (diff)
downloadaerc-905cb9dfd3ef197bb4b59039a1be76ce2c8e3099.zip
Implement style configuration.
Introduce the ability to configure stylesets, allowing customization of aerc's look (color scheme, font weight, etc). Default styleset is installed to /path/to/aerc/stylesets/default.
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r--widgets/msgviewer.go63
1 files changed, 39 insertions, 24 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 107ff59..30c83f7 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -33,6 +33,7 @@ type MessageViewer struct {
grid *ui.Grid
switcher *PartSwitcher
msg lib.MessageView
+ uiConfig config.UIConfig
}
type PartSwitcher struct {
@@ -62,9 +63,11 @@ 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(),
}
},
)
@@ -94,15 +97,16 @@ func NewMessageViewer(acct *AccountView,
err := createSwitcher(acct, switcher, conf, msg)
if err != nil {
return &MessageViewer{
- err: err,
- grid: grid,
- msg: msg,
+ err: err,
+ grid: grid,
+ msg: msg,
+ uiConfig: acct.UiConfig(),
}
}
grid.AddChild(header).At(0, 0)
if msg.PGPDetails() != nil {
- grid.AddChild(NewPGPInfo(msg.PGPDetails())).At(1, 0)
+ grid.AddChild(NewPGPInfo(msg.PGPDetails(), acct.UiConfig())).At(1, 0)
grid.AddChild(ui.NewFill(' ')).At(2, 0)
grid.AddChild(switcher).At(3, 0)
} else {
@@ -116,6 +120,7 @@ func NewMessageViewer(acct *AccountView,
grid: grid,
msg: msg,
switcher: switcher,
+ uiConfig: acct.UiConfig(),
}
switcher.mv = mv
@@ -224,8 +229,9 @@ func createSwitcher(acct *AccountView, switcher *PartSwitcher,
func (mv *MessageViewer) Draw(ctx *ui.Context) {
if mv.err != nil {
- ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
- ctx.Printf(0, 0, tcell.StyleDefault, "%s", mv.err.Error())
+ 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())
return
}
mv.grid.Draw(ctx)
@@ -347,7 +353,10 @@ func (ps *PartSwitcher) Draw(ctx *ui.Context) {
ps.height = ctx.Height()
y := ctx.Height() - height
for i, part := range ps.parts {
- style := tcell.StyleDefault.Reverse(ps.selected == i)
+ style := ps.mv.uiConfig.GetStyle(config.STYLE_DEFAULT)
+ if ps.selected == i {
+ style = ps.mv.uiConfig.GetStyleSelected(config.STYLE_DEFAULT)
+ }
ctx.Fill(0, y+i, ctx.Width(), 1, ' ', style)
name := fmt.Sprintf("%s/%s",
strings.ToLower(part.part.MIMEType),
@@ -436,6 +445,7 @@ func (mv *MessageViewer) Focus(focus bool) {
type PartViewer struct {
ui.Invalidatable
+ conf *config.AercConfig
err error
fetched bool
filter *exec.Cmd
@@ -450,6 +460,7 @@ type PartViewer struct {
term *Terminal
selecter *Selecter
grid *ui.Grid
+ uiConfig config.UIConfig
}
func NewPartViewer(acct *AccountView, conf *config.AercConfig,
@@ -519,7 +530,8 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
{ui.SIZE_WEIGHT, ui.Const(1)},
})
- selecter := NewSelecter([]string{"Save message", "Pipe to command"}, 0).
+ selecter := NewSelecter([]string{"Save message", "Pipe to command"},
+ 0, acct.UiConfig()).
OnChoose(func(option string) {
switch option {
case "Save message":
@@ -532,6 +544,7 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
grid.AddChild(selecter).At(2, 0)
pv := &PartViewer{
+ conf: conf,
filter: filter,
index: index,
msg: msg,
@@ -543,6 +556,7 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
term: term,
selecter: selecter,
grid: grid,
+ uiConfig: acct.UiConfig(),
}
if term != nil {
@@ -661,14 +675,16 @@ 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(), ' ', tcell.StyleDefault)
- ctx.Printf(0, 0, tcell.StyleDefault.Foreground(tcell.ColorRed),
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
+ ctx.Printf(0, 0, styleError,
"No filter configured for this mimetype ('%s/%s')",
pv.part.MIMEType, pv.part.MIMESubType,
)
- ctx.Printf(0, 2, tcell.StyleDefault,
+ ctx.Printf(0, 2, style,
"You can still :save the message or :pipe it to an external command")
pv.selecter.Focus(true)
pv.grid.Draw(ctx)
@@ -679,8 +695,8 @@ func (pv *PartViewer) Draw(ctx *ui.Context) {
pv.fetched = true
}
if pv.err != nil {
- ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
- ctx.Printf(0, 0, tcell.StyleDefault, "%s", pv.err.Error())
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
+ ctx.Printf(0, 0, style, "%s", pv.err.Error())
return
}
pv.term.Draw(ctx)
@@ -702,8 +718,10 @@ func (pv *PartViewer) Event(event tcell.Event) bool {
type HeaderView struct {
ui.Invalidatable
- Name string
- Value string
+ conf *config.AercConfig
+ Name string
+ Value string
+ uiConfig config.UIConfig
}
func (hv *HeaderView) Draw(ctx *ui.Context) {
@@ -711,18 +729,15 @@ func (hv *HeaderView) Draw(ctx *ui.Context) {
size := runewidth.StringWidth(name)
lim := ctx.Width() - size - 1
value := runewidth.Truncate(" "+hv.Value, lim, "…")
- var (
- hstyle tcell.Style
- vstyle tcell.Style
- )
+
+ vstyle := hv.uiConfig.GetStyle(config.STYLE_DEFAULT)
+ hstyle := hv.uiConfig.GetStyle(config.STYLE_HEADER)
+
// TODO: Make this more robust and less dumb
if hv.Name == "PGP" {
- vstyle = tcell.StyleDefault.Foreground(tcell.ColorGreen)
- hstyle = tcell.StyleDefault.Bold(true)
- } else {
- vstyle = tcell.StyleDefault
- hstyle = tcell.StyleDefault.Bold(true)
+ vstyle = hv.uiConfig.GetStyle(config.STYLE_SUCCESS)
}
+
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', vstyle)
ctx.Printf(0, 0, hstyle, "%s", name)
ctx.Printf(size, 0, vstyle, "%s", value)