about summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ui')
-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, 48 insertions, 60 deletions
diff --git a/lib/ui/borders.go b/lib/ui/borders.go
index 7a75759..99d6880 100644
--- a/lib/ui/borders.go
+++ b/lib/ui/borders.go
@@ -2,6 +2,8 @@ package ui
 
 import (
 	"github.com/gdamore/tcell"
+
+	"git.sr.ht/~sircmpwn/aerc/config"
 )
 
 const (
@@ -16,12 +18,15 @@ type Bordered struct {
 	borders      uint
 	content      Drawable
 	onInvalidate func(d Drawable)
+	uiConfig     config.UIConfig
 }
 
-func NewBordered(content Drawable, borders uint) *Bordered {
+func NewBordered(
+	content Drawable, borders uint, uiConfig config.UIConfig) *Bordered {
 	b := &Bordered{
-		borders: borders,
-		content: content,
+		borders:  borders,
+		content:  content,
+		uiConfig: uiConfig,
 	}
 	content.OnInvalidate(b.contentInvalidated)
 	return b
@@ -44,7 +49,7 @@ func (bordered *Bordered) Draw(ctx *Context) {
 	y := 0
 	width := ctx.Width()
 	height := ctx.Height()
-	style := tcell.StyleDefault.Reverse(true)
+	style := bordered.uiConfig.GetStyle(config.STYLE_BORDER)
 	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 690a869..c9004a0 100644
--- a/lib/ui/stack.go
+++ b/lib/ui/stack.go
@@ -3,16 +3,19 @@ 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() *Stack {
-	return &Stack{}
+func NewStack(uiConfig config.UIConfig) *Stack {
+	return &Stack{uiConfig: uiConfig}
 }
 
 func (stack *Stack) Children() []Drawable {
@@ -33,7 +36,8 @@ func (stack *Stack) Draw(ctx *Context) {
 	if len(stack.children) > 0 {
 		stack.Peek().Draw(ctx)
 	} else {
-		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+		ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ',
+			stack.uiConfig.GetStyle(config.STYLE_STACK))
 	}
 }
 
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 4b99e4b..cd5f448 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 := tcell.StyleDefault.Reverse(true)
+		style := strip.uiConfig.GetStyle(config.STYLE_TAB)
 		if strip.Selected == i {
-			style = tcell.StyleDefault
+			style = strip.uiConfig.GetStyleSelected(config.STYLE_TAB)
 		}
 		tabWidth := 32
 		if ctx.Width()-x < tabWidth {
@@ -301,8 +301,8 @@ func (strip *TabStrip) Draw(ctx *Context) {
 			break
 		}
 	}
-	style := tcell.StyleDefault.Reverse(true)
-	ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style)
+	ctx.Fill(x, 0, ctx.Width()-x, 1, ' ',
+		strip.uiConfig.GetStyle(config.STYLE_TAB))
 }
 
 func (strip *TabStrip) Invalidate() {
@@ -386,7 +386,8 @@ func (content *TabContent) Draw(ctx *Context) {
 	if content.Selected >= len(content.Tabs) {
 		width := ctx.Width()
 		height := ctx.Height()
-		ctx.Fill(0, 0, width, height, ' ', tcell.StyleDefault)
+		ctx.Fill(0, 0, width, height, ' ',
+			content.uiConfig.GetStyle(config.STYLE_TAB))
 	}
 
 	tab := content.Tabs[content.Selected]
diff --git a/lib/ui/text.go b/lib/ui/text.go
index 2b82598..455c2eb 100644
--- a/lib/ui/text.go
+++ b/lib/ui/text.go
@@ -15,17 +15,13 @@ type Text struct {
 	Invalidatable
 	text     string
 	strategy uint
-	fg       tcell.Color
-	bg       tcell.Color
-	bold     bool
-	reverse  bool
+	style    tcell.Style
 }
 
-func NewText(text string) *Text {
+func NewText(text string, style tcell.Style) *Text {
 	return &Text{
-		bg:   tcell.ColorDefault,
-		fg:   tcell.ColorDefault,
-		text: text,
+		text:  text,
+		style: style,
 	}
 }
 
@@ -41,25 +37,6 @@ 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
@@ -69,15 +46,8 @@ func (t *Text) Draw(ctx *Context) {
 	if t.strategy == TEXT_RIGHT {
 		x = ctx.Width() - size
 	}
-	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)
+	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', t.style)
+	ctx.Printf(x, 0, t.style, "%s", t.text)
 }
 
 func (t *Text) Invalidate() {
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index f6b0c72..2445065 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -6,6 +6,8 @@ import (
 
 	"github.com/gdamore/tcell"
 	"github.com/mattn/go-runewidth"
+
+	"git.sr.ht/~sircmpwn/aerc/config"
 )
 
 // TODO: Attach history providers
@@ -27,16 +29,18 @@ 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) *TextInput {
+func NewTextInput(text string, ui config.UIConfig) *TextInput {
 	return &TextInput{
-		cells: -1,
-		text:  []rune(text),
-		index: len([]rune(text)),
+		cells:    -1,
+		text:     []rune(text),
+		index:    len([]rune(text)),
+		uiConfig: ui,
 	}
 }
 
@@ -87,16 +91,18 @@ func (ti *TextInput) Draw(ctx *Context) {
 		ti.ensureScroll()
 	}
 	ti.ctx = ctx // gross
-	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+
+	defaultStyle := ti.uiConfig.GetStyle(config.STYLE_DEFAULT)
+	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', defaultStyle)
 
 	text := ti.text[scroll:]
 	sindex := ti.index - scroll
 	if ti.password {
-		x := ctx.Printf(0, 0, tcell.StyleDefault, "%s", ti.prompt)
+		x := ctx.Printf(0, 0, defaultStyle, "%s", ti.prompt)
 		cells := runewidth.StringWidth(string(text))
-		ctx.Fill(x, 0, cells, 1, '*', tcell.StyleDefault)
+		ctx.Fill(x, 0, cells, 1, '*', defaultStyle)
 	} else {
-		ctx.Printf(0, 0, tcell.StyleDefault, "%s%s", ti.prompt, string(text))
+		ctx.Printf(0, 0, defaultStyle, "%s%s", ti.prompt, string(text))
 	}
 	cells := runewidth.StringWidth(string(text[:sindex]) + ti.prompt)
 	if ti.focus {
@@ -126,6 +132,7 @@ 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)
@@ -353,6 +360,7 @@ type completions struct {
 	onSelect   func(int)
 	onExec     func()
 	onStem     func(string)
+	uiConfig   config.UIConfig
 }
 
 func maxLen(ss []string) int {
@@ -367,10 +375,10 @@ func maxLen(ss []string) int {
 }
 
 func (c *completions) Draw(ctx *Context) {
-	bg := tcell.StyleDefault
-	sel := tcell.StyleDefault.Reverse(true)
-	gutter := tcell.StyleDefault
-	pill := tcell.StyleDefault.Reverse(true)
+	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)
 
 	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', bg)
 
an>="100%"><dl> <dt><font face="helvetica, arial"><a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a>(<a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>) </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="ranger.gui.widgets.browserview.html#BrowserView">BrowserView</a>(<a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>, <a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a>) </font></dt></dl> </dd> <dt><font face="helvetica, arial"><a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>(<a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>) </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="ranger.gui.widgets.browserview.html#BrowserView">BrowserView</a>(<a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>, <a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a>) </font></dt></dl> </dd> </dl> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#000000" face="helvetica, arial"><a name="BrowserView">class <strong>BrowserView</strong></a>(<a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>, <a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a>)</font></td></tr> <tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="ranger.gui.widgets.browserview.html#BrowserView">BrowserView</a></dd> <dd><a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a></dd> <dd><a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a></dd> <dd><a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a></dd> <dd><a href="ranger.shared.html#EnvironmentAware">ranger.shared.EnvironmentAware</a></dd> <dd><a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a></dd> <dd><a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a></dd> <dd><a href="ranger.gui.curses_shortcuts.html#CursesShortcuts">ranger.gui.curses_shortcuts.CursesShortcuts</a></dd> <dd><a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a></dd> <dd><a href="builtins.html#object">builtins.object</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="BrowserView-__init__"><strong>__init__</strong></a>(self, win, ratios, preview<font color="#909090">=True</font>)</dt></dl> <dl><dt><a name="BrowserView-click"><strong>click</strong></a>(self, event)</dt></dl> <dl><dt><a name="BrowserView-close_pager"><strong>close_pager</strong></a>(self)</dt></dl> <dl><dt><a name="BrowserView-draw"><strong>draw</strong></a>(self)</dt></dl> <dl><dt><a name="BrowserView-open_pager"><strong>open_pager</strong></a>(self)</dt></dl> <dl><dt><a name="BrowserView-poke"><strong>poke</strong></a>(self)</dt></dl> <dl><dt><a name="BrowserView-resize"><strong>resize</strong></a>(self, y, x, hei, wid)</dt><dd><tt>Resize&nbsp;all&nbsp;the&nbsp;columns&nbsp;according&nbsp;to&nbsp;the&nbsp;given&nbsp;ratio</tt></dd></dl> <hr> Data and other attributes defined here:<br> <dl><dt><strong>need_clear</strong> = False</dl> <dl><dt><strong>preview</strong> = True</dl> <dl><dt><strong>preview_available</strong> = True</dl> <dl><dt><strong>ratios</strong> = None</dl> <dl><dt><strong>stretch_ratios</strong> = None</dl> <hr> Methods inherited from <a href="ranger.gui.displayable.html#DisplayableContainer">ranger.gui.displayable.DisplayableContainer</a>:<br> <dl><dt><a name="BrowserView-add_child"><strong>add_child</strong></a>(self, obj)</dt><dd><tt>Add&nbsp;the&nbsp;objects&nbsp;to&nbsp;the&nbsp;container.</tt></dd></dl> <dl><dt><a name="BrowserView-destroy"><strong>destroy</strong></a>(self)</dt><dd><tt>Recursively&nbsp;called&nbsp;on&nbsp;objects&nbsp;in&nbsp;container</tt></dd></dl> <dl><dt><a name="BrowserView-finalize"><strong>finalize</strong></a>(self)</dt><dd><tt>Recursively&nbsp;called&nbsp;on&nbsp;visible&nbsp;objects&nbsp;in&nbsp;container</tt></dd></dl> <dl><dt><a name="BrowserView-press"><strong>press</strong></a>(self, key)</dt><dd><tt>Recursively&nbsp;called&nbsp;on&nbsp;objects&nbsp;in&nbsp;container</tt></dd></dl> <dl><dt><a name="BrowserView-remove_child"><strong>remove_child</strong></a>(self, obj)</dt><dd><tt>Remove&nbsp;the&nbsp;object&nbsp;from&nbsp;the&nbsp;container.</tt></dd></dl> <hr> Methods inherited from <a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>:<br> <dl><dt><a name="BrowserView-__contains__"><strong>__contains__</strong></a>(self, item)</dt><dd><tt>Is&nbsp;item&nbsp;inside&nbsp;the&nbsp;boundaries?<br> item&nbsp;can&nbsp;be&nbsp;an&nbsp;iterable&nbsp;like&nbsp;[y,&nbsp;x]&nbsp;or&nbsp;an&nbsp;object&nbsp;with&nbsp;x&nbsp;and&nbsp;y&nbsp;methods.</tt></dd></dl> <dl><dt><a name="BrowserView-__nonzero__"><strong>__nonzero__</strong></a>(self)</dt><dd><tt>Always&nbsp;True</tt></dd></dl> <dl><dt><a name="BrowserView-__str__"><strong>__str__</strong></a>(self)</dt></dl> <dl><dt><a name="BrowserView-contains_point"><strong>contains_point</strong></a>(self, y, x)</dt><dd><tt>Test&nbsp;whether&nbsp;the&nbsp;point&nbsp;(with&nbsp;absolute&nbsp;coordinates)&nbsp;lies<br> within&nbsp;the&nbsp;boundaries&nbsp;of&nbsp;this&nbsp;object.</tt></dd></dl> <hr> Data and other attributes inherited from <a href="ranger.shared.html#EnvironmentAware">ranger.shared.EnvironmentAware</a>:<br> <dl><dt><strong>env</strong> = None</dl> <hr> Data and other attributes inherited from <a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a>:<br> <dl><dt><strong>fm</strong> = None</dl> <hr> Data descriptors inherited from <a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a>:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd> </dl> <hr> Methods inherited from <a href="ranger.gui.curses_shortcuts.html#CursesShortcuts">ranger.gui.curses_shortcuts.CursesShortcuts</a>:<br> <dl><dt><a name="BrowserView-addnstr"><strong>addnstr</strong></a>(self, *args)</dt></dl> <dl><dt><a name="BrowserView-addstr"><strong>addstr</strong></a>(self, *args)</dt></dl> <dl><dt><a name="BrowserView-color"><strong>color</strong></a>(self, keylist<font color="#909090">=None</font>, *keys)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;from&nbsp;now&nbsp;on.</tt></dd></dl> <dl><dt><a name="BrowserView-color_at"><strong>color_at</strong></a>(self, y, x, wid, keylist<font color="#909090">=None</font>, *keys)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;at&nbsp;the&nbsp;specified&nbsp;position</tt></dd></dl> <dl><dt><a name="BrowserView-color_reset"><strong>color_reset</strong></a>(self)</dt><dd><tt>Change&nbsp;the&nbsp;colors&nbsp;to&nbsp;the&nbsp;default&nbsp;colors</tt></dd></dl> <hr> Data and other attributes inherited from <a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a>:<br> <dl><dt><strong>settings</strong> = &lt;ranger.ext.openstruct.OpenStruct object at 0x7f6a9067fbd0&gt;</dl> </td></tr></table></td></tr></table> </body></html>