aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/status.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/status.go
parent548a5fff68a648a5e0b6fd909e3c21463addc8af (diff)
downloadaerc-905cb9dfd3ef197bb4b59039a1be76ce2c8e3099.tar.gz
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/status.go')
-rw-r--r--widgets/status.go49
1 files changed, 33 insertions, 16 deletions
diff --git a/widgets/status.go b/widgets/status.go
index 6bdeb4f7..122ca5f1 100644
--- a/widgets/status.go
+++ b/widgets/status.go
@@ -6,6 +6,7 @@ import (
"github.com/gdamore/tcell"
"github.com/mattn/go-runewidth"
+ "git.sr.ht/~sircmpwn/aerc/config"
"git.sr.ht/~sircmpwn/aerc/lib/ui"
)
@@ -14,21 +15,21 @@ type StatusLine struct {
stack []*StatusMessage
fallback StatusMessage
aerc *Aerc
+ uiConfig config.UIConfig
}
type StatusMessage struct {
- bg tcell.Color
- fg tcell.Color
+ style tcell.Style
message string
}
-func NewStatusLine() *StatusLine {
+func NewStatusLine(uiConfig config.UIConfig) *StatusLine {
return &StatusLine{
fallback: StatusMessage{
- bg: tcell.ColorDefault,
- fg: tcell.ColorDefault,
+ style: uiConfig.GetStyle(config.STYLE_STATUSLINE_DEFAULT),
message: "Idle",
},
+ uiConfig: uiConfig,
}
}
@@ -41,9 +42,7 @@ func (status *StatusLine) Draw(ctx *ui.Context) {
if len(status.stack) != 0 {
line = status.stack[len(status.stack)-1]
}
- style := tcell.StyleDefault.
- Background(line.bg).Foreground(line.fg).Reverse(true)
- ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', line.style)
pendingKeys := ""
if status.aerc != nil {
for _, pendingKey := range status.aerc.pendingKeys {
@@ -51,13 +50,21 @@ func (status *StatusLine) Draw(ctx *ui.Context) {
}
}
message := runewidth.FillRight(line.message, ctx.Width()-len(pendingKeys)-5)
- ctx.Printf(0, 0, style, "%s%s", message, pendingKeys)
+ ctx.Printf(0, 0, line.style, "%s%s", message, pendingKeys)
}
func (status *StatusLine) Set(text string) *StatusMessage {
status.fallback = StatusMessage{
- bg: tcell.ColorDefault,
- fg: tcell.ColorDefault,
+ style: status.uiConfig.GetStyle(config.STYLE_STATUSLINE_DEFAULT),
+ message: text,
+ }
+ status.Invalidate()
+ return &status.fallback
+}
+
+func (status *StatusLine) SetError(text string) *StatusMessage {
+ status.fallback = StatusMessage{
+ style: status.uiConfig.GetStyle(config.STYLE_STATUSLINE_ERROR),
message: text,
}
status.Invalidate()
@@ -66,8 +73,7 @@ func (status *StatusLine) Set(text string) *StatusMessage {
func (status *StatusLine) Push(text string, expiry time.Duration) *StatusMessage {
msg := &StatusMessage{
- bg: tcell.ColorDefault,
- fg: tcell.ColorDefault,
+ style: status.uiConfig.GetStyle(config.STYLE_STATUSLINE_DEFAULT),
message: text,
}
status.stack = append(status.stack, msg)
@@ -85,6 +91,18 @@ func (status *StatusLine) Push(text string, expiry time.Duration) *StatusMessage
return msg
}
+func (status *StatusLine) PushError(text string) *StatusMessage {
+ msg := status.Push(text, 10*time.Second)
+ msg.Color(status.uiConfig.GetStyle(config.STYLE_STATUSLINE_ERROR))
+ return msg
+}
+
+func (status *StatusLine) PushSuccess(text string) *StatusMessage {
+ msg := status.Push(text, 10*time.Second)
+ msg.Color(status.uiConfig.GetStyle(config.STYLE_STATUSLINE_SUCCESS))
+ return msg
+}
+
func (status *StatusLine) Expire() {
status.stack = nil
}
@@ -93,7 +111,6 @@ func (status *StatusLine) SetAerc(aerc *Aerc) {
status.aerc = aerc
}
-func (msg *StatusMessage) Color(bg tcell.Color, fg tcell.Color) {
- msg.bg = bg
- msg.fg = fg
+func (msg *StatusMessage) Color(style tcell.Style) {
+ msg.style = style
}