-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #144: Support for color schemes
- Loading branch information
Showing
24 changed files
with
1,087 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
) | ||
|
||
const ( | ||
// DefaultColor represents a default color. | ||
DefaultColor Color = "default" | ||
|
||
// TransparentColor represents the terminal bg color. | ||
TransparentColor Color = "-" | ||
) | ||
|
||
// Colors tracks multiple colors. | ||
type Colors []Color | ||
|
||
// Colors converts series string colors to colors. | ||
func (c Colors) Colors() []tcell.Color { | ||
cc := make([]tcell.Color, 0, len(c)) | ||
for _, color := range c { | ||
cc = append(cc, color.Color()) | ||
} | ||
|
||
return cc | ||
} | ||
|
||
// Color represents a color. | ||
type Color string | ||
|
||
// NewColor returns a new color. | ||
func NewColor(c string) Color { | ||
return Color(c) | ||
} | ||
|
||
// String returns color as string. | ||
func (c Color) String() string { | ||
if c.isHex() { | ||
return string(c) | ||
} | ||
if c == DefaultColor { | ||
return "-" | ||
} | ||
col := c.Color().TrueColor().Hex() | ||
if col < 0 { | ||
return "-" | ||
} | ||
|
||
return fmt.Sprintf("#%06x", col) | ||
} | ||
|
||
func (c Color) isHex() bool { | ||
return len(c) == 7 && c[0] == '#' | ||
} | ||
|
||
// Color returns a view color. | ||
func (c Color) Color() tcell.Color { | ||
if c == DefaultColor { | ||
return tcell.ColorDefault | ||
} | ||
if c.isHex() { | ||
return tcell.GetColor(string(c)).TrueColor() | ||
} else { | ||
return tcell.GetColor(string(c)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
var ( | ||
|
||
////go:embed templates/hotkeys.yaml | ||
// hotkeysTpl tracks hotkeys default config template | ||
//hotkeysTpl []byte | ||
|
||
//go:embed themes/*-theme.yaml | ||
themesFolder embed.FS | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
"gopkg.in/yaml.v3" | ||
"io" | ||
"os" | ||
) | ||
|
||
// StyleListener represents a skin's listener. | ||
type StyleListener interface { | ||
// StylesChanged notifies listener the skin changed. | ||
StylesChanged(*Styles) | ||
} | ||
|
||
type ( | ||
|
||
// Styles tracks process compose styling options. | ||
Styles struct { | ||
Style Style `yaml:"style"` | ||
} | ||
|
||
// Style tracks PC styles. | ||
Style struct { | ||
Name string `yaml:"name"` | ||
Body Body `yaml:"body"` | ||
StatTable StatTable `yaml:"stat_table"` | ||
ProcTable ProcTable `yaml:"proc_table"` | ||
Help Help `yaml:"help"` | ||
Dialog Dialog `yaml:"dialog"` | ||
} | ||
|
||
// Body tracks body styles. | ||
Body struct { | ||
FgColor Color `yaml:"fgColor"` | ||
BgColor Color `yaml:"bgColor"` | ||
SecondaryTextColor Color `yaml:"secondaryTextColor"` | ||
TertiaryTextColor Color `yaml:"tertiaryTextColor"` | ||
BorderColor Color `yaml:"borderColor"` | ||
} | ||
|
||
// StatTable tracks stats table styles. | ||
StatTable struct { | ||
KeyFgColor Color `yaml:"keyFgColor"` | ||
ValueFgColor Color `yaml:"valueFgColor"` | ||
BgColor Color `yaml:"bgColor"` | ||
LogoColor Color `yaml:"logoColor"` | ||
} | ||
|
||
// ProcTable tracks processes table styles. | ||
ProcTable struct { | ||
FgColor Color `yaml:"fgColor"` | ||
FgWarning Color `yaml:"fgWarning"` | ||
FgPending Color `yaml:"fgPending"` | ||
FgCompleted Color `yaml:"fgCompleted"` | ||
FgError Color `yaml:"fgError"` | ||
BgColor Color `yaml:"bgColor"` | ||
HeaderFgColor Color `yaml:"headerFgColor"` | ||
} | ||
|
||
// Help tracks help styles. | ||
Help struct { | ||
KeyColor Color `yaml:"keyColor"` | ||
FgColor Color `yaml:"fgColor"` | ||
HlColor Color `yaml:"hlColor"` | ||
FgCategoryColor Color `yaml:"categoryFgColor"` | ||
} | ||
|
||
// Dialog tracks dialog styles. | ||
Dialog struct { | ||
FgColor Color `yaml:"fgColor"` | ||
BgColor Color `yaml:"bgColor"` | ||
ButtonFgColor Color `yaml:"buttonFgColor"` | ||
ButtonBgColor Color `yaml:"buttonBgColor"` | ||
ButtonFocusFgColor Color `yaml:"buttonFocusFgColor"` | ||
ButtonFocusBgColor Color `yaml:"buttonFocusBgColor"` | ||
LabelFgColor Color `yaml:"labelFgColor"` | ||
FieldFgColor Color `yaml:"fieldFgColor"` | ||
FieldBgColor Color `yaml:"fieldBgColor"` | ||
} | ||
) | ||
|
||
func newStyle() Style { | ||
return Style{ | ||
Name: "Default", | ||
Body: newBody(), | ||
StatTable: newStatTable(), | ||
ProcTable: newProcTable(), | ||
Help: newHelp(), | ||
Dialog: newDialog(), | ||
} | ||
} | ||
|
||
func newBody() Body { | ||
return Body{ | ||
FgColor: "white", | ||
BgColor: "black", | ||
SecondaryTextColor: "yellow", | ||
TertiaryTextColor: "green", | ||
BorderColor: "white", | ||
} | ||
} | ||
|
||
func newStatTable() StatTable { | ||
return StatTable{ | ||
KeyFgColor: "yellow", | ||
ValueFgColor: "white", | ||
BgColor: "black", | ||
LogoColor: "yellow", | ||
} | ||
} | ||
|
||
func newProcTable() ProcTable { | ||
return ProcTable{ | ||
HeaderFgColor: "white", | ||
FgColor: "lightskyblue", | ||
BgColor: "black", | ||
FgWarning: "yellow", | ||
FgPending: "grey", | ||
FgCompleted: "lightgreen", | ||
FgError: "red", | ||
} | ||
} | ||
|
||
func newHelp() Help { | ||
return Help{ | ||
FgColor: "black", | ||
KeyColor: "white", | ||
HlColor: "green", | ||
FgCategoryColor: "lightskyblue", | ||
} | ||
} | ||
|
||
func newDialog() Dialog { | ||
return Dialog{ | ||
FgColor: "cadetblue", | ||
BgColor: "black", | ||
ButtonBgColor: "lightskyblue", | ||
ButtonFgColor: "black", | ||
ButtonFocusBgColor: "dodgerblue", | ||
ButtonFocusFgColor: "black", | ||
LabelFgColor: "yellow", | ||
FieldFgColor: "black", | ||
FieldBgColor: "lightskyblue", | ||
} | ||
} | ||
|
||
// NewStyles creates a new default config. | ||
func NewStyles() *Styles { | ||
//var s Styles | ||
//if err := yaml.Unmarshal(stockThemeTpl, &s); err == nil { | ||
// return &s | ||
//} | ||
|
||
return &Styles{ | ||
Style: newStyle(), | ||
} | ||
} | ||
|
||
// Load process compose styles from file. | ||
func (s *Styles) Load(path string) error { | ||
b, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
if err := yaml.Unmarshal(b, s); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// FgColor returns the foreground color. | ||
func (s *Styles) FgColor() tcell.Color { | ||
return s.Body().FgColor.Color() | ||
} | ||
|
||
// BgColor returns the background color. | ||
func (s *Styles) BgColor() tcell.Color { | ||
return s.Body().BgColor.Color() | ||
} | ||
|
||
// BorderColor returns the border color. | ||
func (s *Styles) BorderColor() tcell.Color { | ||
return s.Body().BorderColor.Color() | ||
} | ||
|
||
// Body returns body styles. | ||
func (s *Styles) Body() Body { | ||
return s.Style.Body | ||
} | ||
|
||
// StatTable returns stat table styles. | ||
func (s *Styles) StatTable() StatTable { | ||
return s.Style.StatTable | ||
} | ||
|
||
// ProcTable returns process table styles. | ||
func (s *Styles) ProcTable() ProcTable { | ||
return s.Style.ProcTable | ||
} | ||
|
||
// Help returns help styles. | ||
func (s *Styles) Help() Help { | ||
return s.Style.Help | ||
} | ||
|
||
// Dialog returns dialog styles. | ||
func (s *Styles) Dialog() Dialog { | ||
return s.Style.Dialog | ||
} | ||
|
||
// Update apply terminal colors based on styles. | ||
func (s *Styles) Update() { | ||
tview.Styles.PrimitiveBackgroundColor = s.BgColor() | ||
//tview.Styles.ContrastBackgroundColor = s.BgColor() | ||
tview.Styles.MoreContrastBackgroundColor = s.BgColor() | ||
tview.Styles.PrimaryTextColor = s.FgColor() | ||
tview.Styles.BorderColor = s.BorderColor() | ||
tview.Styles.TitleColor = s.FgColor() | ||
tview.Styles.GraphicsColor = s.FgColor() | ||
tview.Styles.SecondaryTextColor = s.Body().SecondaryTextColor.Color() | ||
tview.Styles.TertiaryTextColor = s.Body().TertiaryTextColor.Color() | ||
tview.Styles.InverseTextColor = s.FgColor() | ||
tview.Styles.ContrastSecondaryTextColor = s.FgColor() | ||
} | ||
|
||
// GetStyleName returns the style name | ||
func (s *Styles) GetStyleName() string { | ||
return s.Style.Name | ||
} | ||
|
||
// Dump for debug. | ||
func (s *Styles) Dump(w io.Writer) { | ||
b, _ := yaml.Marshal(s) | ||
_, _ = fmt.Fprintf(w, "%s", b) | ||
} |
Oops, something went wrong.