~chrisppy/titan

17021ce9af427a5abc0c22eb490324b3b383a007 — Chris Palmer 2 months ago 723d8c7
add theming for tabs and scroll bar
5 files changed, 105 insertions(+), 9 deletions(-)

M browser.go
M config.go
M defaultConfig.go
M doc/titan-config.5.scd
M ui.go
M browser.go => browser.go +4 -4
@@ 28,10 28,10 @@ func (a *app) loadBrowserPanel(links []string) {
	a.UI.BrowserPanel.TabNames = make([]string, 0)

	a.UI.BrowserPanel.TabbedPanels = cview.NewTabbedPanels()
	a.UI.BrowserPanel.TabbedPanels.SetTabBackgroundColor(a.Config.Theme.ContentBGColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabTextColor(a.Config.Theme.ContentTextColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabBackgroundColorFocused(a.Config.Theme.TitleBGColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabTextColorFocused(a.Config.Theme.TitleFGColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabBackgroundColor(a.Config.Theme.TabBGColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabTextColor(a.Config.Theme.TabTextColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabBackgroundColorFocused(a.Config.Theme.TabActiveBGColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabTextColorFocused(a.Config.Theme.TabActiveTextColor)
	a.UI.BrowserPanel.TabbedPanels.SetTabSwitcherDivider("", "", "")

	a.UI.BrowserPanel.View = cview.NewFlex()

M config.go => config.go +55 -1
@@ 80,12 80,18 @@ type command struct {

type theme struct {
	ErrColor            tcell.Color
	ScrollBarColor      tcell.Color
	TabBarColor         tcell.Color
	CMDBGColor          tcell.Color
	CMDFGColor          tcell.Color
	StatusBGColor       tcell.Color
	StatusFGColor       tcell.Color
	TitleBGColor        tcell.Color
	TitleFGColor        tcell.Color
	TabBGColor          tcell.Color
	TabTextColor        tcell.Color
	TabActiveBGColor    tcell.Color
	TabActiveTextColor  tcell.Color
	ContentBGColor      tcell.Color
	ContentTextColor    tcell.Color
	ContentH1Color      string


@@ 457,7 463,7 @@ func (a *app) parseTheme(dir *scfg.Directive) map[error]bool {
	errors := make(map[error]bool)

	var bg, fg string
	var ferr, ftitle, fstat, fcmd, fcnt bool
	var ferr, ftitle, fstat, fcmd, fcnt, ftab, ftaba, fsb, ftb bool
	for _, d := range dir.Children {
		switch n := d.Name; n {
		case "background-color":


@@ 505,6 511,13 @@ func (a *app) parseTheme(dir *scfg.Directive) map[error]bool {
			} else {
				fg = d.Params[0]
			}
		case "scroll-bar-color":
			fsb = true
			if err := validateDirective(n, d, one); err != nil {
				errors[err] = false
			} else {
				a.Config.Theme.ScrollBarColor = tcell.GetColor(d.Params[0])
			}
		case "status-bar":
			fstat = true
			if bga, fga, err := parseChildTheme(n, d); len(err) > 0 {


@@ 515,6 528,33 @@ func (a *app) parseTheme(dir *scfg.Directive) map[error]bool {
				a.Config.Theme.StatusBGColor = tcell.GetColor(bga)
				a.Config.Theme.StatusFGColor = tcell.GetColor(fga)
			}
		case "tab":
			ftab = true
			if bga, fga, err := parseChildTheme(n, d); len(err) > 0 {
				for k, v := range err {
					errors[k] = v
				}
			} else {
				a.Config.Theme.TabBGColor = tcell.GetColor(bga)
				a.Config.Theme.TabTextColor = tcell.GetColor(fga)
			}
		case "tab-active":
			ftaba = true
			if bga, fga, err := parseChildTheme(n, d); len(err) > 0 {
				for k, v := range err {
					errors[k] = v
				}
			} else {
				a.Config.Theme.TabActiveBGColor = tcell.GetColor(bga)
				a.Config.Theme.TabActiveTextColor = tcell.GetColor(fga)
			}
		case "tab-bar-color":
			ftb = true
			if err := validateDirective(n, d, one); err != nil {
				errors[err] = false
			} else {
				a.Config.Theme.TabBarColor = tcell.GetColor(d.Params[0])
			}
		case "title-bar":
			ftitle = true
			if bga, fga, err := parseChildTheme(n, d); len(err) > 0 {


@@ 539,6 579,12 @@ func (a *app) parseTheme(dir *scfg.Directive) map[error]bool {
	if !ferr {
		errors[fmt.Errorf("error-color is a required directive for theme")] = false
	}
	if !fsb {
		errors[fmt.Errorf("scroll-bar-color is a required directive for theme")] = false
	}
	if !ftb {
		errors[fmt.Errorf("tab-bar-color is a required directive for theme")] = false
	}

	if !fcmd && bg != "" && fg != "" {
		a.Config.Theme.CMDBGColor = tcell.GetColor(bg)


@@ 562,6 608,14 @@ func (a *app) parseTheme(dir *scfg.Directive) map[error]bool {
		a.Config.Theme.TitleBGColor = tcell.GetColor(bg)
		a.Config.Theme.TitleFGColor = tcell.GetColor(fg)
	}
	if !ftab && bg != "" && fg != "" {
		a.Config.Theme.TabBGColor = tcell.GetColor(bg)
		a.Config.Theme.TabTextColor = tcell.GetColor(fg)
	}
	if !ftaba && bg != "" && fg != "" {
		a.Config.Theme.TabActiveBGColor = tcell.GetColor(fg)
		a.Config.Theme.TabActiveTextColor = tcell.GetColor(bg)
	}

	return errors
}

M defaultConfig.go => defaultConfig.go +18 -0
@@ 71,6 71,12 @@ theme {
	# error text color
	error-color "#bf616a"

	# scroll bar color
	scroll-bar-color "#b48ead"

	# tab bar color
	tab-bar-color "#3b4252"

	# Theming the command line bar
	command-line {
		background-color "#2e3440"


@@ 94,6 100,18 @@ theme {
#		background-color "#88c0d0"
#		foreground-color "#2e3440"
# 	}	

	# Theming a tab
	tab {
		background-color "#3b4252"
		foreground-color "#d8dee9"
	}
	
	# Theming an active tab
	tab-active {
		background-color "#2e3440"
		foreground-color "#e5e9f0"
	}
	
	# Theming the title bar
# 	title-bar {

M doc/titan-config.5.scd => doc/titan-config.5.scd +26 -1
@@ 37,6 37,12 @@ defined, it will inherit the colors from *background-color* and++
*error-color* <color>
	Text color of error messages.

*scroll-bar-color* <color>
	Color of the scroll bar.

*tab-bar-color* <color>
	Background color of tab bar.

*COMMAND LINE*
	Command line is defined within a _command-line_ _{_ _}_ block inside a++
_theme_ _{_ _}_ block.


@@ 47,7 53,6 @@ _theme_ _{_ _}_ block.
	*foreground-color* <color>
		Foreground color of the command line.


*STATUS LINE*
	Status line is defined within a _status-line_ _{_ _}_ block inside a++
_theme_ _{_ _}_ block.


@@ 58,6 63,26 @@ _theme_ _{_ _}_ block.
	*foreground-color* <color>
		Foreground color of the status line.

*TAB*
	Tab is defined within a _tab_ _{_ _}_ block inside a++
_theme_ _{_ _}_ block.

	*background-color* <color>
		Background color of the tab.

	*foreground-color* <color>
		Foreground color of the tab.

*TAB ACTIVE*
	Tab Active  is defined within a _tab-active_ _{_ _}_ block inside a++
_theme_ _{_ _}_ block.

	*background-color* <color>
		Background color of the active tab.

	*foreground-color* <color>
		Foreground color of the active tab.

*TITLE BAR*
	Title bar is defined within a _title-bar_ _{_ _}_ block inside a++
_theme_ _{_ _}_ block.

M ui.go => ui.go +2 -3
@@ 100,9 100,8 @@ func (a *app) loadUI(links []string) {
		Panels:      cview.NewPanels(),
	}

	cview.Styles.ScrollBarColor = a.Config.Theme.TitleBGColor
	cview.Styles.PrimaryTextColor = a.Config.Theme.ContentTextColor
	cview.Styles.PrimitiveBackgroundColor = a.Config.Theme.ContentBGColor
	cview.Styles.ScrollBarColor = a.Config.Theme.ScrollBarColor
	cview.Styles.PrimitiveBackgroundColor = a.Config.Theme.TabBarColor

	a.addBindings()
	a.UI.Application.SetInputCapture(a.UI.Bindings.Capture)