Merge pull request #4 from lyricnz/feature/tcell-events-vuong

Lots of good work with 24-bit color, styling cleanups, etc. Thanks @vuon9 !
pull/232/head
Simon Roberts 3 years ago committed by GitHub
commit 4319e00dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -57,6 +57,7 @@ wasm
.appimage_workspace
todo.txt
.vscode
docs/public
deploy_docs.sh

@ -490,8 +490,7 @@ func (ct *Cointop) Run() error {
return err
}
ui.SetFgColor(ct.colorscheme.BaseFg())
ui.SetBgColor(ct.colorscheme.BaseBg())
ui.SetStyle(ct.colorscheme.BaseStyle())
ct.ui = ui
ct.g = ui.GetGocui()
defer ui.Close()

@ -3,10 +3,11 @@ package cointop
import (
"fmt"
"strconv"
"strings"
"sync"
"github.com/cointop-sh/cointop/pkg/termbox"
fcolor "github.com/fatih/color"
"github.com/gdamore/tcell/v2"
"github.com/tomnomnom/xtermcolor"
)
@ -50,19 +51,38 @@ var BgColorschemeColorsMap = map[string]fcolor.Attribute{
"yellow": fcolor.BgYellow,
}
var GocuiColorschemeColorsMap = map[string]termbox.Attribute{
"black": termbox.ColorBlack,
"blue": termbox.ColorBlue,
"cyan": termbox.ColorCyan,
"green": termbox.ColorGreen,
"magenta": termbox.ColorMagenta,
"red": termbox.ColorRed,
"white": termbox.ColorWhite,
"yellow": termbox.ColorYellow,
// See more: vendor/github.com/mattn/go-colorable/colorable_windows.go:905
// any new color for the below mapping should be compatible with this above list
var TcellColorschemeColorsMap = map[string]tcell.Color{
"black": tcell.ColorBlack,
"blue": tcell.ColorNavy,
"cyan": tcell.ColorTeal,
"green": tcell.ColorGreen,
"magenta": tcell.ColorPurple,
"red": tcell.ColorMaroon,
"white": tcell.ColorSilver,
"yellow": tcell.ColorOlive,
}
// NewColorscheme ...
func NewColorscheme(colors ColorschemeColors) *Colorscheme {
// Build lookup table for defined values, then replace references to these
const prefix = "define_"
const reference = "&"
defines := ColorschemeColors{}
for k, v := range colors {
if strings.HasPrefix(k, prefix) {
defines[k[len(prefix):]] = v
}
}
for k, v := range colors {
if vs, ok := v.(string); ok {
if strings.HasPrefix(vs, reference) {
colors[k] = defines[vs[len(reference):]]
}
}
}
return &Colorscheme{
colors: colors,
cache: make(ColorCache),
@ -70,14 +90,8 @@ func NewColorscheme(colors ColorschemeColors) *Colorscheme {
}
}
// BaseFg ...
func (c *Colorscheme) BaseFg() termbox.Attribute {
return c.GocuiFgColor("base")
}
// BaseBg ...
func (c *Colorscheme) BaseBg() termbox.Attribute {
return c.GocuiBgColor("base")
func (c *Colorscheme) BaseStyle() tcell.Style {
return c.Style("base")
}
// Chart ...
@ -245,17 +259,44 @@ func (c *Colorscheme) ToSprintf(name string) ISprintf {
return cached
}
// TODO: use c.Style(name)?
var attrs []fcolor.Attribute
if v, ok := c.colors[name+"_fg"].(string); ok {
if fg, ok := c.ToFgAttr(v); ok {
attrs = append(attrs, fg)
} else {
color := tcell.GetColor(v)
if color != tcell.ColorDefault {
// 24-bit foreground 38;2;⟨r⟩;⟨g⟩;⟨b⟩
r, g, b := color.RGB()
attrs = append(attrs, 38)
attrs = append(attrs, 2)
attrs = append(attrs, fcolor.Attribute(r))
attrs = append(attrs, fcolor.Attribute(g))
attrs = append(attrs, fcolor.Attribute(b))
// log.Debugf("XXX added FG color %s", attrs)
}
}
}
if v, ok := c.colors[name+"_bg"].(string); ok {
if bg, ok := c.ToBgAttr(v); ok {
attrs = append(attrs, bg)
} else {
color := tcell.GetColor(v)
if color != tcell.ColorDefault {
// 24-bit background 48;2;⟨r⟩;⟨g⟩;⟨b⟩
r, g, b := color.RGB()
attrs = append(attrs, 48)
attrs = append(attrs, 2)
attrs = append(attrs, fcolor.Attribute(r))
attrs = append(attrs, fcolor.Attribute(g))
attrs = append(attrs, fcolor.Attribute(b))
// log.Debugf("XXX added BG color %s", attrs)
}
}
}
if v, ok := c.colors[name+"_bold"].(bool); ok {
if bold, ok := c.ToBoldAttr(v); ok {
attrs = append(attrs, bold)
@ -275,43 +316,47 @@ func (c *Colorscheme) Color(name string, a ...interface{}) string {
return c.ToSprintf(name)(a...)
}
func (c *Colorscheme) GocuiFgColor(name string) termbox.Attribute {
var attrs []termbox.Attribute
if v, ok := c.colors[name+"_fg"].(string); ok {
if fg, ok := c.ToGocuiAttr(v); ok {
attrs = append(attrs, fg)
}
func (c *Colorscheme) Style(name string) tcell.Style {
st := tcell.StyleDefault
st = st.Foreground(c.tcellColor(name + "_fg"))
st = st.Background(c.tcellColor(name + "_bg"))
if v, ok := c.colors[name+"_bold"].(bool); ok {
st = st.Bold(v)
}
// TODO: fixme
// if v, ok := c.colors[name+"_bold"].(bool); ok {
// if v {
// attrs = append(attrs, gocui.AttrBold)
// }
// }
// if v, ok := c.colors[name+"_underline"].(bool); ok {
// if v {
// attrs = append(attrs, gocui.AttrUnderline)
// }
// }
if len(attrs) > 0 {
var combined termbox.Attribute
for _, v := range attrs {
combined = combined ^ v
}
return combined
if v, ok := c.colors[name+"_underline"].(bool); ok {
st = st.Underline(v)
}
return termbox.ColorDefault
// TODO: Blink Dim Italic Reverse Strikethrough
return st
}
func (c *Colorscheme) GocuiBgColor(name string) termbox.Attribute {
if v, ok := c.colors[name+"_bg"].(string); ok {
if bg, ok := c.ToGocuiAttr(v); ok {
return bg
}
// tcellColor can supply for types of color name: specific mapped name, tcell color name, hex
// Examples: black, honeydew, #000000
func (c *Colorscheme) tcellColor(name string) tcell.Color {
v, ok := c.colors[name].(string)
if !ok {
// log.Debugf("XXX tcellColor(%s) could not be found!", name)
return tcell.ColorDefault
}
if color, found := TcellColorschemeColorsMap[v]; found {
// log.Debugf("XXX tcellColor(%s => %s) FOUND %s", name, v, color)
return color
}
color := tcell.GetColor(v)
if color != tcell.ColorDefault {
// log.Debugf("XXX tcellColor(%s => %s) GET %s", name, v, color)
return color
}
return termbox.ColorDefault
// find closest X11 color to RGB
// if code, ok := HexToAnsi(v); ok {
// // log.Debugf("XXX tcellColor(%s => %s) HEX %s", name, v, code)
// return tcell.PaletteColor(int(code) & 0xff)
// }
// log.Debugf("XXX tcellColor(%s => %s) FALLTHROUGH %s", name, v, color)
return color
}
func (c *Colorscheme) ToFgAttr(v string) (fcolor.Attribute, bool) {
@ -319,9 +364,10 @@ func (c *Colorscheme) ToFgAttr(v string) (fcolor.Attribute, bool) {
return attr, true
}
if code, ok := HexToAnsi(v); ok {
return fcolor.Attribute(code), true
}
// find closest X11 color to RGB
// if code, ok := HexToAnsi(v); ok {
// return fcolor.Attribute(code), true
// }
return 0, false
}
@ -331,9 +377,10 @@ func (c *Colorscheme) ToBgAttr(v string) (fcolor.Attribute, bool) {
return attr, true
}
if code, ok := HexToAnsi(v); ok {
return fcolor.Attribute(code), true
}
// find closest X11 color to RGB
// if code, ok := HexToAnsi(v); ok {
// return fcolor.Attribute(code), true
// }
return 0, false
}
@ -348,19 +395,6 @@ func (c *Colorscheme) ToUnderlineAttr(v bool) (fcolor.Attribute, bool) {
return fcolor.Underline, v
}
// ToGocuiAttr converts a color string name to a gocui Attribute type
func (c *Colorscheme) ToGocuiAttr(v string) (termbox.Attribute, bool) {
if attr, ok := GocuiColorschemeColorsMap[v]; ok {
return attr, true
}
if code, ok := HexToAnsi(v); ok {
return termbox.Attribute(code), true
}
return 0, false
}
// HexToAnsi converts a hex color string to a uint8 ansi code
func HexToAnsi(h string) (uint8, bool) {
if h == "" {
@ -374,6 +408,7 @@ func HexToAnsi(h string) (uint8, bool) {
}
}
// TODO: only use if exact, otherwise use 24-bit version
code, err := xtermcolor.FromHexStr(h)
if err != nil {
return 0, false
@ -381,5 +416,3 @@ func HexToAnsi(h string) (uint8, bool) {
return code, true
}
// gocui can use xterm colors

@ -58,8 +58,7 @@ func (ct *Cointop) layout() error {
} else {
if err := ct.ui.SetView(ct.Views.Marketbar, 0, topOffset-1, maxX, marketbarHeight+1); err != nil {
ct.Views.Marketbar.SetFrame(false)
ct.Views.Marketbar.SetFgColor(ct.colorscheme.GocuiFgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetBgColor(ct.colorscheme.GocuiBgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetStyle(ct.colorscheme.Style(ct.Views.Marketbar.Name()))
go func() {
ct.UpdateMarketbar()
_, found := ct.cache.Get(ct.Views.Marketbar.Name())
@ -92,8 +91,7 @@ func (ct *Cointop) layout() error {
if err := ct.ui.SetView(ct.Views.Chart, 0, chartTopOffset, maxX, topOffset+chartHeight); err != nil {
ct.Views.Chart.Clear()
ct.Views.Chart.SetFrame(false)
ct.Views.Chart.SetFgColor(ct.colorscheme.GocuiFgColor(ct.Views.Chart.Name()))
ct.Views.Chart.SetBgColor(ct.colorscheme.GocuiBgColor(ct.Views.Chart.Name()))
ct.Views.Chart.SetStyle(ct.colorscheme.Style(ct.Views.Chart.Name()))
go func() {
ct.UpdateChart()
cachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
@ -124,8 +122,7 @@ func (ct *Cointop) layout() error {
topOffset = topOffset + chartHeight
if err := ct.ui.SetView(ct.Views.TableHeader, tableOffsetX, topOffset-1, maxX, topOffset+1); err != nil {
ct.Views.TableHeader.SetFrame(false)
ct.Views.TableHeader.SetFgColor(ct.colorscheme.GocuiFgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetBgColor(ct.colorscheme.GocuiBgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetStyle(ct.colorscheme.Style(ct.Views.TableHeader.Name()))
go ct.UpdateTableHeader()
}
@ -133,8 +130,7 @@ func (ct *Cointop) layout() error {
if err := ct.ui.SetView(ct.Views.Table, tableOffsetX, topOffset-1, maxX, maxY-statusbarHeight); err != nil {
ct.Views.Table.SetFrame(false)
ct.Views.Table.SetHighlight(true)
ct.Views.Table.SetSelFgColor(ct.colorscheme.GocuiFgColor("table_row_active"))
ct.Views.Table.SetSelBgColor(ct.colorscheme.GocuiBgColor("table_row_active"))
ct.Views.Table.SetSelStyle(ct.colorscheme.Style("table_row_active"))
_, found := ct.cache.Get("allCoinsSlugMap")
if found {
ct.cache.Delete("allCoinsSlugMap")
@ -149,8 +145,7 @@ func (ct *Cointop) layout() error {
if !ct.State.hideStatusbar {
if err := ct.ui.SetView(ct.Views.Statusbar, 0, maxY-statusbarHeight-1, maxX, maxY); err != nil {
ct.Views.Statusbar.SetFrame(false)
ct.Views.Statusbar.SetFgColor(ct.colorscheme.GocuiFgColor(ct.Views.Statusbar.Name()))
ct.Views.Statusbar.SetBgColor(ct.colorscheme.GocuiBgColor(ct.Views.Statusbar.Name()))
ct.Views.Statusbar.SetStyle(ct.colorscheme.Style(ct.Views.Statusbar.Name()))
go ct.UpdateStatusbar("")
}
} else {
@ -166,22 +161,19 @@ func (ct *Cointop) layout() error {
ct.Views.SearchField.SetEditable(true)
ct.Views.SearchField.SetWrap(true)
ct.Views.SearchField.SetFrame(false)
ct.Views.SearchField.SetFgColor(ct.colorscheme.GocuiFgColor("searchbar"))
ct.Views.SearchField.SetBgColor(ct.colorscheme.GocuiBgColor("searchbar"))
ct.Views.SearchField.SetStyle(ct.colorscheme.Style("searchbar"))
}
if err := ct.ui.SetView(ct.Views.Menu, 1, 1, maxX-1, maxY-1); err != nil {
ct.Views.Menu.SetFrame(false)
ct.Views.Menu.SetFgColor(ct.colorscheme.GocuiFgColor("menu"))
ct.Views.Menu.SetBgColor(ct.colorscheme.GocuiBgColor("menu"))
ct.Views.Menu.SetStyle(ct.colorscheme.Style("menu"))
}
if err := ct.ui.SetView(ct.Views.Input, 3, 6, 30, 8); err != nil {
ct.Views.Input.SetFrame(true)
ct.Views.Input.SetEditable(true)
ct.Views.Input.SetWrap(true)
ct.Views.Input.SetFgColor(ct.colorscheme.GocuiFgColor("menu"))
ct.Views.Input.SetBgColor(ct.colorscheme.GocuiBgColor("menu"))
ct.Views.Input.SetStyle(ct.colorscheme.Style("menu"))
// run only once on init.
// this bit of code should be at the bottom

@ -42,13 +42,18 @@ draft: false
Copy an existing [colorscheme](https://github.com/cointop-sh/colors/blob/master/cointop.toml) to `~/.config/cointop/colors/` and customize the colors. Then run cointop with `--colorscheme <colorscheme>` to use the colorscheme.
## How do I make the background color transparent?
You can use any of the 250-odd X11 colors by name. See https://en.wikipedia.org/wiki/X11_color_names (use lower-case and without spaces). You can also include 24-bit colors by using the #rrggbb hex code.
Change the background color options in the colorscheme file to `default` to use the system default color, eg. `base_bg = "default"`
You can also define values in the colorscheme file, and reference them from throughout the file, using the following syntax:
## Why don't colorschemes support RGB or hex colors?
```toml
define_base03 = "#002b36"
menu_header_fg = "&base03"
```
Some of the cointop underlying rendering libraries don't support true colors. See [issue](https://github.com/nsf/termbox/issues/37).
## How do I make the background color transparent?
Change the background color options in the colorscheme file to `default` to use the system default color, eg. `base_bg = "default"`
## Where is the config file located?

@ -120,7 +120,7 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) {
return true, nil
case ch == 'm':
var err error
err = ei.output256()
err = ei.parseEscapeParams()
// switch ei.mode {
// case OutputNormal:
// err = ei.outputNormal()
@ -141,17 +141,34 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) {
return false, nil
}
// outputNormal provides 8 different colors:
// black, red, green, yellow, blue, magenta, cyan, white
func (ei *escapeInterpreter) outputNormal() error {
for _, param := range ei.csiParam {
p, err := strconv.Atoi(param)
if err != nil {
// parseEscapeParams interprets an escape sequence as a style modifier
// allows you to leverage the 256-colors terminal mode:
// 0x01 - 0x08: the 8 colors as in OutputNormal (black, red, green, yellow, blue, magenta, cyan, white)
// 0x09 - 0x10: Color* | AttrBold
// 0x11 - 0xe8: 216 different colors
// 0xe9 - 0x1ff: 24 different shades of grey
// see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
// see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
// 256-colors: ESC[ 38;5;${ID}m # foreground
// 256-colors: ESC[ 48;5;${ID}m # background
// 24-bit ESC[ 38;2;⟨r⟩;⟨g⟩;⟨b⟩ m Select RGB foreground color
// 24-bit ESC[ 48;2;⟨r⟩;⟨g⟩;⟨b⟩ m Select RGB background color
func (ei *escapeInterpreter) parseEscapeParams() error {
// TODO: cache escape -> Style
// convert params to int
params := make([]int, len(ei.csiParam))
for i, param := range ei.csiParam {
if p, err := strconv.Atoi(param); err == nil {
params[i] = p
} else {
return errCSIParseError
}
}
// see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
// see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
// consume elements of params until done
pos := 0
for ok := true; ok; ok = pos < len(params) {
p := params[pos]
switch {
case p >= 30 && p <= 37:
ei.curStyle = ei.curStyle.Foreground(tcell.PaletteColor(p - 30))
@ -169,63 +186,27 @@ func (ei *escapeInterpreter) outputNormal() error {
ei.curStyle = ei.curStyle.Reverse(true)
case p == 0:
ei.curStyle = tcell.StyleDefault
}
}
return nil
}
// output256 allows you to leverage the 256-colors terminal mode:
// 0x01 - 0x08: the 8 colors as in OutputNormal
// 0x09 - 0x10: Color* | AttrBold
// 0x11 - 0xe8: 216 different colors
// 0xe9 - 0x1ff: 24 different shades of grey
func (ei *escapeInterpreter) output256() error {
if len(ei.csiParam) < 3 {
return ei.outputNormal()
}
mode, err := strconv.Atoi(ei.csiParam[1])
if err != nil {
return errCSIParseError
}
if mode != 5 {
return ei.outputNormal()
}
fgbg, err := strconv.Atoi(ei.csiParam[0])
if err != nil {
return errCSIParseError
}
color, err := strconv.Atoi(ei.csiParam[2])
if err != nil {
return errCSIParseError
}
switch fgbg {
case 38:
ei.curStyle = ei.curStyle.Foreground(tcell.PaletteColor(color + 1))
for _, param := range ei.csiParam[3:] {
p, err := strconv.Atoi(param)
if err != nil {
return errCSIParseError
case p == 38 || p == 48: // 256-color or 24-bit
// parse mode and additional params to generate a color
mode := params[pos+1] // second param - 2 or 5
var x tcell.Color
if mode == 5 { // 256 color
x = tcell.PaletteColor(params[pos+2] + 1)
pos += 2 // two additional (5+index)
} else if mode == 2 { // 24-bit
x = tcell.NewRGBColor(int32(params[pos+2]), int32(params[pos+3]), int32(params[pos+4]))
pos += 4 // four additional (2+r/g/b)
} else {
return errCSIParseError // invalid mode
}
switch {
case p == 1:
ei.curStyle = ei.curStyle.Bold(true)
case p == 4:
ei.curStyle = ei.curStyle.Underline(true)
case p == 7:
ei.curStyle = ei.curStyle.Reverse(true)
if p == 38 {
ei.curStyle = ei.curStyle.Foreground(x)
} else {
ei.curStyle = ei.curStyle.Background(x)
}
}
case 48:
ei.curStyle = ei.curStyle.Background(tcell.PaletteColor(color + 1))
default:
return errCSIParseError
}
pos += 1 // move along 1 by default
}
return nil
}

@ -75,17 +75,15 @@ type Gui struct {
// NewGui returns a new Gui object with a given output mode.
// func NewGui(mode OutputMode) (*Gui, error) {
func NewGui() (*Gui, error) {
g := &Gui{}
//outMode = OutputNormal
// outMode = OutputNormal
if s, e := tcell.NewScreen(); e != nil {
return nil, e
} else if e = s.Init(); e != nil {
return nil, e
} else {
g.screen = s
}
// g.outputMode = mode
@ -283,7 +281,7 @@ func (g *Gui) CurrentView() *View {
// be a rune or a Key.
// TODO: split into key/mouse bindings?
func (g *Gui) SetKeybinding(viewname string, key tcell.Key, ch rune, mod tcell.ModMask, handler func(*Gui, *View) error) error {
//var kb *eventBinding
// var kb *eventBinding
// k, ch, err := getKey(key)
// if err != nil {
@ -675,7 +673,6 @@ func (g *Gui) onEvent(ev tcell.Event) error {
// GetViewRelativeMousePosition returns the View and relative x/y for the provided mouse event.
func (g *Gui) GetViewRelativeMousePosition(ev tcell.Event) (*View, int, int, error) {
if kbe, ok := ev.(*tcell.EventMouse); ok {
mx, my := kbe.Position()
v, err := g.ViewByPosition(mx, my)

@ -341,15 +341,6 @@ func (v *View) draw() error {
break
}
// fgColor := c.fgColor
// if fgColor == ColorDefault {
// fgColor = v.FgColor
// }
// bgColor := c.bgColor
// if bgColor == ColorDefault {
// bgColor = v.BgColor
// }
st := c.style
fgColor, bgColor, _ := c.style.Decompose()
vfgColor, vbgColor, _ := v.Style.Decompose()

@ -1,93 +0,0 @@
// Copyright 2020 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
// You may obtain a copy of the license at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package termbox is a compatibility layer to allow tcell to emulate
// the github.com/nsf/termbox package.
package termbox
import (
"github.com/gdamore/tcell/v2"
)
// Attribute affects the presentation of characters, such as color, boldness,
// and so forth.
type Attribute uint16
// Colors first. The order here is significant.
const (
ColorDefault Attribute = iota
ColorBlack
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorMagenta
ColorCyan
ColorWhite
)
// TODO: remove compatability layer
func FixColor(c tcell.Color) tcell.Color {
if c == tcell.ColorDefault {
return c
}
c = tcell.PaletteColor(int(c) & 0xff)
// switch g.outputMode {
// case OutputNormal:
// c = tcell.PaletteColor(int(c) & 0xf)
// case Output256:
// c = tcell.PaletteColor(int(c) & 0xff)
// case Output216:
// c = tcell.PaletteColor(int(c)%216 + 16)
// case OutputGrayscale:
// c %= tcell.PaletteColor(int(c)%24 + 232)
// default:
// c = tcell.ColorDefault
// }
return c
}
// TODO: remove compatability layer
func MkColor(color Attribute) tcell.Color {
if color == ColorDefault {
return tcell.ColorDefault
} else {
return FixColor(tcell.PaletteColor(int(color)&0x1ff - 1))
}
}
func MkStyle(fg, bg Attribute) tcell.Style {
st := tcell.StyleDefault
if fg != ColorDefault {
// f := tcell.PaletteColor(int(fg)&0x1ff - 1)
// f = g.fixColor(f)
st = st.Foreground(MkColor(fg))
}
if bg != ColorDefault {
// b := tcell.PaletteColor(int(bg)&0x1ff - 1)
// b = g.fixColor(b)
st = st.Background(MkColor(bg))
}
// TODO: fixme
// if (fg|bg)&AttrBold != 0 {
// st = st.Bold(true)
// }
// if (fg|bg)&AttrUnderline != 0 {
// st = st.Underline(true)
// }
// if (fg|bg)&AttrReverse != 0 {
// st = st.Reverse(true)
// }
return st
}

@ -2,7 +2,7 @@ package ui
import (
"github.com/cointop-sh/cointop/pkg/gocui"
"github.com/cointop-sh/cointop/pkg/termbox"
"github.com/gdamore/tcell/v2"
)
// UI is the UI view struct
@ -27,14 +27,9 @@ func (ui *UI) GetGocui() *gocui.Gui {
return ui.g
}
// SetFgColor sets the foreground color
func (ui *UI) SetFgColor(fgColor termbox.Attribute) {
ui.g.Style = ui.g.Style.Foreground(termbox.MkColor(fgColor))
}
// SetBgColor sets the background color
func (ui *UI) SetBgColor(bgColor termbox.Attribute) {
ui.g.Style = ui.g.Style.Background(termbox.MkColor(bgColor))
// SetFgColor sets the default style
func (ui *UI) SetStyle(st tcell.Style) {
ui.g.Style = st
}
// SetInputEsc enables the escape key

@ -4,7 +4,7 @@ import (
"fmt"
"github.com/cointop-sh/cointop/pkg/gocui"
"github.com/cointop-sh/cointop/pkg/termbox"
"github.com/gdamore/tcell/v2"
)
// IView is the view interface
@ -214,33 +214,14 @@ func (view *View) SetWrap(enabled bool) error {
return nil
}
// SetFgColor sets the foreground color
func (view *View) SetFgColor(color termbox.Attribute) {
if view.HasBacking() {
view.backing.Style = view.backing.Style.Foreground(termbox.MkColor(color))
}
}
// SetBgColor sets the background color
func (view *View) SetBgColor(color termbox.Attribute) {
if view.HasBacking() {
// view.backing.BgColor = color
view.backing.Style = view.backing.Style.Background(termbox.MkColor(color))
}
// SetStyle sets the text style for the view
func (view *View) SetStyle(st tcell.Style) {
view.backing.Style = st
}
// SetSelFgColor sets the foreground color for selection
func (view *View) SetSelFgColor(color termbox.Attribute) {
if view.HasBacking() {
view.backing.SelStyle = view.backing.SelStyle.Foreground(termbox.MkColor(color))
}
}
// SetSelBgColor sets the background color for selection
func (view *View) SetSelBgColor(color termbox.Attribute) {
if view.HasBacking() {
view.backing.SelStyle = view.backing.SelStyle.Background(termbox.MkColor(color))
}
// SetStyle sets the selection text style for the view
func (view *View) SetSelStyle(st tcell.Style) {
view.backing.SelStyle = st
}
// Read reads data in bytes buffer

Loading…
Cancel
Save