Use tcell.Style.Reverse instead of black on white

This commit is contained in:
Drew DeVault 2019-03-30 12:59:18 -04:00
parent 700dea23fa
commit 84965d680c
7 changed files with 25 additions and 22 deletions

View file

@ -49,7 +49,7 @@ func (bordered *Bordered) Draw(ctx *Context) {
y := 0 y := 0
width := ctx.Width() width := ctx.Width()
height := ctx.Height() height := ctx.Height()
style := tcell.StyleDefault.Background(tcell.ColorWhite).Foreground(tcell.ColorBlack) style := tcell.StyleDefault.Reverse(true)
if bordered.borders&BORDER_LEFT != 0 { if bordered.borders&BORDER_LEFT != 0 {
ctx.Fill(0, 0, 1, ctx.Height(), ' ', style) ctx.Fill(0, 0, 1, ctx.Height(), ' ', style)
x += 1 x += 1

View file

@ -83,19 +83,13 @@ func (tabs *Tabs) Select(index int) {
func (strip *TabStrip) Draw(ctx *Context) { func (strip *TabStrip) Draw(ctx *Context) {
x := 0 x := 0
for i, tab := range strip.Tabs { for i, tab := range strip.Tabs {
style := tcell.StyleDefault. style := tcell.StyleDefault.Reverse(true)
Background(tcell.ColorWhite).
Foreground(tcell.ColorBlack)
if strip.Selected == i { if strip.Selected == i {
style = tcell.StyleDefault. style = tcell.StyleDefault
Background(tcell.ColorDefault).
Foreground(tcell.ColorDefault)
} }
x += ctx.Printf(x, 0, style, " %s ", tab.Name) x += ctx.Printf(x, 0, style, " %s ", tab.Name)
} }
style := tcell.StyleDefault. style := tcell.StyleDefault.Reverse(true)
Background(tcell.ColorWhite).
Foreground(tcell.ColorBlack)
ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style) ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style)
} }

View file

@ -16,6 +16,7 @@ type Text struct {
strategy uint strategy uint
fg tcell.Color fg tcell.Color
bg tcell.Color bg tcell.Color
reverse bool
onInvalidate func(d Drawable) onInvalidate func(d Drawable)
} }
@ -46,6 +47,12 @@ func (t *Text) Color(fg tcell.Color, bg tcell.Color) *Text {
return t return t
} }
func (t *Text) Reverse(reverse bool) *Text {
t.reverse = reverse
t.Invalidate()
return t
}
func (t *Text) Draw(ctx *Context) { func (t *Text) Draw(ctx *Context) {
size := runewidth.StringWidth(t.text) size := runewidth.StringWidth(t.text)
x := 0 x := 0
@ -56,6 +63,9 @@ func (t *Text) Draw(ctx *Context) {
x = ctx.Width() - size x = ctx.Width() - size
} }
style := tcell.StyleDefault.Background(t.bg).Foreground(t.fg) style := tcell.StyleDefault.Background(t.bg).Foreground(t.fg)
if t.reverse {
style = style.Reverse(true)
}
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style) ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
ctx.Printf(x, 0, style, t.text) ctx.Printf(x, 0, style, t.text)
} }

View file

@ -49,7 +49,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
grid.AddChild(libui.NewText("aerc"). grid.AddChild(libui.NewText("aerc").
Strategy(libui.TEXT_CENTER). Strategy(libui.TEXT_CENTER).
Color(tcell.ColorBlack, tcell.ColorWhite)) Reverse(true))
grid.AddChild(tabs.TabStrip).At(0, 1) grid.AddChild(tabs.TabStrip).At(0, 1)
grid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2) grid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)

View file

@ -109,8 +109,7 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
} }
style := tcell.StyleDefault style := tcell.StyleDefault
if name == dirlist.selected { if name == dirlist.selected {
style = style.Background(tcell.ColorWhite). style = style.Reverse(true)
Foreground(tcell.ColorBlack)
} }
ctx.Fill(0, row, ctx.Width(), 1, ' ', style) ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
ctx.Printf(0, row, style, "%s", name) ctx.Printf(0, row, style, "%s", name)

View file

@ -78,8 +78,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
style := tcell.StyleDefault style := tcell.StyleDefault
if row == ml.selected-ml.scroll { if row == ml.selected-ml.scroll {
style = style.Background(tcell.ColorWhite). style = style.Reverse(true)
Foreground(tcell.ColorBlack)
} }
if _, ok := ml.store.Deleted[msg.Uid]; ok { if _, ok := ml.store.Deleted[msg.Uid]; ok {
style = style.Foreground(tcell.ColorGray) style = style.Foreground(tcell.ColorGray)

View file

@ -24,8 +24,8 @@ type StatusMessage struct {
func NewStatusLine() *StatusLine { func NewStatusLine() *StatusLine {
return &StatusLine{ return &StatusLine{
fallback: StatusMessage{ fallback: StatusMessage{
bg: tcell.ColorWhite, bg: tcell.ColorDefault,
fg: tcell.ColorBlack, fg: tcell.ColorDefault,
message: "Idle", message: "Idle",
}, },
} }
@ -46,15 +46,16 @@ func (status *StatusLine) Draw(ctx *ui.Context) {
if len(status.stack) != 0 { if len(status.stack) != 0 {
line = status.stack[len(status.stack)-1] line = status.stack[len(status.stack)-1]
} }
style := tcell.StyleDefault.Background(line.bg).Foreground(line.fg) 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(), ' ', style)
ctx.Printf(0, 0, style, "%s", line.message) ctx.Printf(0, 0, style, "%s", line.message)
} }
func (status *StatusLine) Set(text string) *StatusMessage { func (status *StatusLine) Set(text string) *StatusMessage {
status.fallback = StatusMessage{ status.fallback = StatusMessage{
bg: tcell.ColorWhite, bg: tcell.ColorDefault,
fg: tcell.ColorBlack, fg: tcell.ColorDefault,
message: text, message: text,
} }
status.Invalidate() status.Invalidate()
@ -63,8 +64,8 @@ func (status *StatusLine) Set(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{
bg: tcell.ColorWhite, bg: tcell.ColorDefault,
fg: tcell.ColorBlack, fg: tcell.ColorDefault,
message: text, message: text,
} }
status.stack = append(status.stack, msg) status.stack = append(status.stack, msg)