status: use contextual ui styleset for statusline

Use contextual ui styleset for statusline widget.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-04-17 01:03:50 +02:00 committed by Robin Jarry
parent 6edfbfa8ce
commit a34be9eb36

View file

@ -16,7 +16,6 @@ type StatusLine struct {
stack []*StatusMessage stack []*StatusMessage
fallback StatusMessage fallback StatusMessage
aerc *Aerc aerc *Aerc
uiConfig config.UIConfig
} }
type StatusMessage struct { type StatusMessage struct {
@ -30,7 +29,6 @@ func NewStatusLine(uiConfig config.UIConfig) *StatusLine {
style: uiConfig.GetStyle(config.STYLE_STATUSLINE_DEFAULT), style: uiConfig.GetStyle(config.STYLE_STATUSLINE_DEFAULT),
message: "Idle", message: "Idle",
}, },
uiConfig: uiConfig,
} }
} }
@ -56,7 +54,7 @@ func (status *StatusLine) Draw(ctx *ui.Context) {
func (status *StatusLine) Set(text string) *StatusMessage { func (status *StatusLine) Set(text string) *StatusMessage {
status.fallback = StatusMessage{ status.fallback = StatusMessage{
style: status.uiConfig.GetStyle(config.STYLE_STATUSLINE_DEFAULT), style: status.uiConfig().GetStyle(config.STYLE_STATUSLINE_DEFAULT),
message: text, message: text,
} }
status.Invalidate() status.Invalidate()
@ -65,7 +63,7 @@ func (status *StatusLine) Set(text string) *StatusMessage {
func (status *StatusLine) SetError(text string) *StatusMessage { func (status *StatusLine) SetError(text string) *StatusMessage {
status.fallback = StatusMessage{ status.fallback = StatusMessage{
style: status.uiConfig.GetStyle(config.STYLE_STATUSLINE_ERROR), style: status.uiConfig().GetStyle(config.STYLE_STATUSLINE_ERROR),
message: text, message: text,
} }
status.Invalidate() status.Invalidate()
@ -74,7 +72,7 @@ func (status *StatusLine) SetError(text string) *StatusMessage {
func (status *StatusLine) Push(text string, expiry time.Duration) *StatusMessage { func (status *StatusLine) Push(text string, expiry time.Duration) *StatusMessage {
msg := &StatusMessage{ msg := &StatusMessage{
style: status.uiConfig.GetStyle(config.STYLE_STATUSLINE_DEFAULT), style: status.uiConfig().GetStyle(config.STYLE_STATUSLINE_DEFAULT),
message: text, message: text,
} }
status.stack = append(status.stack, msg) status.stack = append(status.stack, msg)
@ -96,13 +94,13 @@ func (status *StatusLine) Push(text string, expiry time.Duration) *StatusMessage
func (status *StatusLine) PushError(text string) *StatusMessage { func (status *StatusLine) PushError(text string) *StatusMessage {
msg := status.Push(text, 10*time.Second) msg := status.Push(text, 10*time.Second)
msg.Color(status.uiConfig.GetStyle(config.STYLE_STATUSLINE_ERROR)) msg.Color(status.uiConfig().GetStyle(config.STYLE_STATUSLINE_ERROR))
return msg return msg
} }
func (status *StatusLine) PushSuccess(text string) *StatusMessage { func (status *StatusLine) PushSuccess(text string) *StatusMessage {
msg := status.Push(text, 10*time.Second) msg := status.Push(text, 10*time.Second)
msg.Color(status.uiConfig.GetStyle(config.STYLE_STATUSLINE_SUCCESS)) msg.Color(status.uiConfig().GetStyle(config.STYLE_STATUSLINE_SUCCESS))
return msg return msg
} }
@ -110,6 +108,10 @@ func (status *StatusLine) Expire() {
status.stack = nil status.stack = nil
} }
func (status *StatusLine) uiConfig() config.UIConfig {
return status.aerc.SelectedAccountUiConfig()
}
func (status *StatusLine) SetAerc(aerc *Aerc) { func (status *StatusLine) SetAerc(aerc *Aerc) {
status.aerc = aerc status.aerc = aerc
} }