aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/borders.go13
-rw-r--r--lib/ui/stack.go10
-rw-r--r--lib/ui/tab.go11
-rw-r--r--lib/ui/text.go42
-rw-r--r--lib/ui/textinput.go32
5 files changed, 60 insertions, 48 deletions
diff --git a/lib/ui/borders.go b/lib/ui/borders.go
index 99d6880d..7a757595 100644
--- a/lib/ui/borders.go
+++ b/lib/ui/borders.go
@@ -2,8 +2,6 @@ package ui
import (
"github.com/gdamore/tcell"
-
- "git.sr.ht/~sircmpwn/aerc/config"
)
const (
@@ -18,15 +16,12 @@ type Bordered struct {
borders uint
content Drawable
onInvalidate func(d Drawable)
- uiConfig config.UIConfig
}
-func NewBordered(
- content Drawable, borders uint, uiConfig config.UIConfig) *Bordered {
+func NewBordered(content Drawable, borders uint) *Bordered {
b := &Bordered{
- borders: borders,
- content: content,
- uiConfig: uiConfig,
+ borders: borders,
+ content: content,
}
content.OnInvalidate(b.contentInvalidated)
return b
@@ -49,7 +44,7 @@ func (bordered *Bordered) Draw(ctx *Context) {
y := 0
width := ctx.Width()
height := ctx.Height()
- style := bordered.uiConfig.GetStyle(config.STYLE_BORDER)
+ style := tcell.StyleDefault.Reverse(true)
if bordered.borders&BORDER_LEFT != 0 {
ctx.Fill(0, 0, 1, ctx.Height(), ' ', style)
x += 1
diff --git a/lib/ui/stack.go b/lib/ui/stack.go
index c9004a0d..690a8699 100644
--- a/lib/ui/stack.go
+++ b/lib/ui/stack.go
@@ -3,19 +3,16 @@ package ui
import (
"fmt"
- "git.sr.ht/~sircmpwn/aerc/config"
-
"github.com/gdamore/tcell"
)
type Stack struct {
children []Drawable
onInvalidate []func(d Drawable)
- uiConfig config.UIConfig
}
-func NewStack(uiConfig config.UIConfig) *Stack {
- return &Stack{uiConfig: uiConfig}
+func NewStack() *Stack {
+ return &Stack{}
}
func (stack *Stack) Children() []Drawable {
@@ -36,8 +33,7 @@ func (stack *Stack) Draw(ctx *Context) {
if len(stack.children) > 0 {
stack.Peek().Draw(ctx)
} else {
- ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ',
- stack.uiConfig.GetStyle(config.STYLE_STACK))
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
}
}
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index cd5f4485..4b99e4b7 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -283,9 +283,9 @@ func (tabs *Tabs) removeHistory(index int) {
func (strip *TabStrip) Draw(ctx *Context) {
x := 0
for i, tab := range strip.Tabs {
- style := strip.uiConfig.GetStyle(config.STYLE_TAB)
+ style := tcell.StyleDefault.Reverse(true)
if strip.Selected == i {
- style = strip.uiConfig.GetStyleSelected(config.STYLE_TAB)
+ style = tcell.StyleDefault
}
tabWidth := 32
if ctx.Width()-x < tabWidth {
@@ -301,8 +301,8 @@ func (strip *TabStrip) Draw(ctx *Context) {
break
}
}
- ctx.Fill(x, 0, ctx.Width()-x, 1, ' ',
- strip.uiConfig.GetStyle(config.STYLE_TAB))
+ style := tcell.StyleDefault.Reverse(true)
+ ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style)
}
func (strip *TabStrip) Invalidate() {
@@ -386,8 +386,7 @@ func (content *TabContent) Draw(ctx *Context) {
if content.Selected >= len(content.Tabs) {
width := ctx.Width()
height := ctx.Height()
- ctx.Fill(0, 0, width, height, ' ',
- content.uiConfig.GetStyle(config.STYLE_TAB))
+ ctx.Fill(0, 0, width, height, ' ', tcell.StyleDefault)
}
tab := content.Tabs[content.Selected]
diff --git a/lib/ui/text.go b/lib/ui/text.go
index 455c2eb6..2b825985 100644
--- a/lib/ui/text.go
+++ b/lib/ui/text.go
@@ -15,13 +15,17 @@ type Text struct {
Invalidatable
text string
strategy uint
- style tcell.Style
+ fg tcell.Color
+ bg tcell.Color
+ bold bool
+ reverse bool
}
-func NewText(text string, style tcell.Style) *Text {
+func NewText(text string) *Text {
return &Text{
- text: text,
- style: style,
+ bg: tcell.ColorDefault,
+ fg: tcell.ColorDefault,
+ text: text,
}
}
@@ -37,6 +41,25 @@ func (t *Text) Strategy(strategy uint) *Text {
return t
}
+func (t *Text) Bold(bold bool) *Text {
+ t.bold = bold
+ t.Invalidate()
+ return t
+}
+
+func (t *Text) Color(fg tcell.Color, bg tcell.Color) *Text {
+ t.fg = fg
+ t.bg = bg
+ t.Invalidate()
+ return t
+}
+
+func (t *Text) Reverse(reverse bool) *Text {
+ t.reverse = reverse
+ t.Invalidate()
+ return t
+}
+
func (t *Text) Draw(ctx *Context) {
size := runewidth.StringWidth(t.text)
x := 0
@@ -46,8 +69,15 @@ func (t *Text) Draw(ctx *Context) {
if t.strategy == TEXT_RIGHT {
x = ctx.Width() - size
}
- ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', t.style)
- ctx.Printf(x, 0, t.style, "%s", t.text)
+ style := tcell.StyleDefault.Background(t.bg).Foreground(t.fg)
+ if t.bold {
+ style = style.Bold(true)
+ }
+ if t.reverse {
+ style = style.Reverse(true)
+ }
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
+ ctx.Printf(x, 0, style, "%s", t.text)
}
func (t *Text) Invalidate() {
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 24450658..f6b0c725 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -6,8 +6,6 @@ import (
"github.com/gdamore/tcell"
"github.com/mattn/go-runewidth"
-
- "git.sr.ht/~sircmpwn/aerc/config"
)
// TODO: Attach history providers
@@ -29,18 +27,16 @@ type TextInput struct {
completeIndex int
completeDelay time.Duration
completeDebouncer *time.Timer
- uiConfig config.UIConfig
}
// Creates a new TextInput. TextInputs will render a "textbox" in the entire
// context they're given, and process keypresses to build a string from user
// input.
-func NewTextInput(text string, ui config.UIConfig) *TextInput {
+func NewTextInput(text string) *TextInput {
return &TextInput{
- cells: -1,
- text: []rune(text),
- index: len([]rune(text)),
- uiConfig: ui,
+ cells: -1,
+ text: []rune(text),
+ index: len([]rune(text)),
}
}
@@ -91,18 +87,16 @@ func (ti *TextInput) Draw(ctx *Context) {
ti.ensureScroll()
}
ti.ctx = ctx // gross
-
- defaultStyle := ti.uiConfig.GetStyle(config.STYLE_DEFAULT)
- ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', defaultStyle)
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
text := ti.text[scroll:]
sindex := ti.index - scroll
if ti.password {
- x := ctx.Printf(0, 0, defaultStyle, "%s", ti.prompt)
+ x := ctx.Printf(0, 0, tcell.StyleDefault, "%s", ti.prompt)
cells := runewidth.StringWidth(string(text))
- ctx.Fill(x, 0, cells, 1, '*', defaultStyle)
+ ctx.Fill(x, 0, cells, 1, '*', tcell.StyleDefault)
} else {
- ctx.Printf(0, 0, defaultStyle, "%s%s", ti.prompt, string(text))
+ ctx.Printf(0, 0, tcell.StyleDefault, "%s%s", ti.prompt, string(text))
}
cells := runewidth.StringWidth(string(text[:sindex]) + ti.prompt)
if ti.focus {
@@ -132,7 +126,6 @@ func (ti *TextInput) drawPopover(ctx *Context) {
ti.Set(stem + ti.StringRight())
ti.Invalidate()
},
- uiConfig: ti.uiConfig,
}
width := maxLen(ti.completions) + 3
height := len(ti.completions)
@@ -360,7 +353,6 @@ type completions struct {
onSelect func(int)
onExec func()
onStem func(string)
- uiConfig config.UIConfig
}
func maxLen(ss []string) int {
@@ -375,10 +367,10 @@ func maxLen(ss []string) int {
}
func (c *completions) Draw(ctx *Context) {
- bg := c.uiConfig.GetStyle(config.STYLE_COMPLETION_DEFAULT)
- gutter := c.uiConfig.GetStyle(config.STYLE_COMPLETION_GUTTER)
- pill := c.uiConfig.GetStyle(config.STYLE_COMPLETION_PILL)
- sel := c.uiConfig.GetStyleSelected(config.STYLE_COMPLETION_DEFAULT)
+ bg := tcell.StyleDefault
+ sel := tcell.StyleDefault.Reverse(true)
+ gutter := tcell.StyleDefault
+ pill := tcell.StyleDefault.Reverse(true)
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', bg)