Minor code style/comment cleanups; remove redundant code (#257)

* Fix comments
* Fix bug with localization param
* Remove unused modules, fix a few minor code style issues
pull/274/head
Simon Roberts 3 years ago committed by GitHub
parent b8a3672ea9
commit 8b8db3bd13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -219,9 +219,6 @@ var DefaultConfigFilepath = pathutil.NormalizePath(":PREFERRED_CONFIG_HOME:/coin
// DefaultCacheDir ...
var DefaultCacheDir = filecache.DefaultCacheDir
// DefaultColorsDir ...
var DefaultColorsDir = fmt.Sprintf("%s/colors", DefaultConfigFilepath)
// DefaultFavoriteChar ...
var DefaultFavoriteChar = "*"

@ -2,13 +2,11 @@ package cointop
import (
"fmt"
"strconv"
"strings"
"sync"
fcolor "github.com/fatih/color"
"github.com/gdamore/tcell/v2"
"github.com/tomnomnom/xtermcolor"
)
// TODO: fix hex color support
@ -53,6 +51,8 @@ var BgColorschemeColorsMap = map[string]fcolor.Attribute{
// 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
// TcellColorschemeColorsMap map colorscheme names to tcell colors
var TcellColorschemeColorsMap = map[string]tcell.Color{
"black": tcell.ColorBlack,
"blue": tcell.ColorNavy,
@ -387,25 +387,3 @@ func (c *Colorscheme) ToBoldAttr(v bool) (fcolor.Attribute, bool) {
func (c *Colorscheme) ToUnderlineAttr(v bool) (fcolor.Attribute, bool) {
return fcolor.Underline, v
}
// HexToAnsi converts a hex color string to a uint8 ansi code
func HexToAnsi(h string) (uint8, bool) {
if h == "" {
return 0, false
}
n, err := strconv.Atoi(h)
if err == nil {
if n <= 255 {
return uint8(n), true
}
}
// TODO: only use if exact, otherwise use 24-bit version
code, err := xtermcolor.FromHexStr(h)
if err != nil {
return 0, false
}
return code, true
}

@ -336,8 +336,7 @@ func (ct *Cointop) SetKeybindings() error {
return nil
}
// MouseLeftClickDebug emit a debug message about which View and coordinates are in MouseClick
// TODO: delete before merge
// MouseDebug emit a debug message about which View and coordinates are in MouseClick
func (ct *Cointop) MouseDebug() error {
v, x, y, err := ct.g.GetViewRelativeMousePosition(ct.g.CurrentEvent)
if err != nil {

@ -179,7 +179,7 @@ func (ct *Cointop) GetActiveTableHeaders() []string {
return cols
}
// GetActiveTableHeaders returns the list of active table headers
// IsActiveTableCompactNotation returns whether the current view is using compact-notation
func (ct *Cointop) IsActiveTableCompactNotation() bool {
var compact bool
switch ct.State.selectedView {
@ -276,7 +276,7 @@ func (ct *Cointop) UpdateTableHeader() error {
return nil
}
// MouseLeftClick is called on mouse left click event
// TableHeaderMouseLeftClick is called on mouse left click event
func (ct *Cointop) TableHeaderMouseLeftClick() error {
_, x, _, err := ct.g.GetViewRelativeMousePosition(ct.g.CurrentEvent)
if err != nil {

@ -20,7 +20,6 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/text v0.3.7
)
@ -35,6 +34,7 @@ require (
github.com/gopherjs/gopherwasm v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/maruel/panicparse v1.6.1 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect

@ -312,8 +312,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e h1:Ee+VZw13r9NTOMnwTPs6O5KZ0MJU54hsxu9FpZ4pQ10=
github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e/go.mod h1:fSIW/szJHsRts/4U8wlMPhs+YqJC+7NYR+Qqb1uJVpA=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

@ -148,7 +148,7 @@ func (s *Service) GetCoinGraphData(convert, symbol, name string, start, end int6
return ret, nil
}
// GetCachedExchangeRates returns an indefinitely cached set of exchange rates
// GetExchangeRates returns the exchange rates from the backend, or a cached copy if requested and available
func (s *Service) GetExchangeRates(cached bool) (*types.ExchangeRatesItem, error) {
if s.cachedRates == nil || !cached {
rates, err := s.client.ExchangeRates()

@ -210,7 +210,7 @@ func (c *Client) CoinsID(id string, localization bool, tickers bool, marketData
return nil, fmt.Errorf("id is required")
}
params := url.Values{}
params.Add("localization", format.Bool2String(sparkline))
params.Add("localization", format.Bool2String(localization))
params.Add("tickers", format.Bool2String(tickers))
params.Add("market_data", format.Bool2String(marketData))
params.Add("community_data", format.Bool2String(communityData))

@ -492,7 +492,7 @@ func (v *View) Word(x, y int) (string, error) {
} else {
nr = nr + x
}
return string(str[nl:nr]), nil
return str[nl:nr], nil
}
// indexFunc allows to split lines by words taking into account spaces

@ -229,7 +229,7 @@ func findMatch(mux map[string]func(Event), path string) string {
// ResetHandlers Remove all existing defined Handlers from the map
func (es *EvtStream) ResetHandlers() {
for Path, _ := range es.Handlers {
for Path := range es.Handlers {
delete(es.Handlers, Path)
}
return

@ -111,7 +111,7 @@ func lookUpAttr(clrmap map[string]Attribute, name string) Attribute {
ns := strings.Split(name, ".")
for i := range ns {
nn := strings.Join(ns[i:len(ns)], ".")
nn := strings.Join(ns[i:], ".")
a, ok = ColorMap[nn]
if ok {
break

@ -27,7 +27,7 @@ func (ui *UI) GetGocui() *gocui.Gui {
return ui.g
}
// SetFgColor sets the default style
// SetStyle sets the default style
func (ui *UI) SetStyle(style tcell.Style) {
ui.g.Style = style
}

@ -221,7 +221,7 @@ func (view *View) SetStyle(style tcell.Style) {
}
}
// SetStyle sets the selection text style for the view
// SetSelStyle sets the selection text style for the view
func (view *View) SetSelStyle(style tcell.Style) {
if view.HasBacking() {
view.backing.SelStyle = style

@ -1,4 +0,0 @@
*.swp
examples/examples
cmd/xtermcolor/xtermcolor
xtermcolor

@ -1,11 +0,0 @@
language: go
go:
- 1.0
- 1.1
- 1.2
- 1.3
- 1.4
- 1.5
- 1.6
- tip

@ -1,13 +0,0 @@
# Changelog
## 0.1.1
- Adds `xtermcolor` command
## 0.1.0
- Now uses a `color.Palette` and its `.Index` method
- Support for convering hex strings (e.g. #CC66FF)
## 0.0.0
- Conversion using map lookup
- Conversion from discrete RGB integers
- Conversion from single integer

@ -1,10 +0,0 @@
# Contributing
* Raise an issue if appropriate
* Fork the repo
* Bootstrap the dev dependencies (run `./script/bootstrap`)
* Make your changes
* Use [gofmt](https://golang.org/cmd/gofmt/)
* Make sure the tests pass (run `./script/test`)
* Make sure the linters pass (run `./script/lint`)
* Issue a pull request

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2016 Tom Hudson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,70 +0,0 @@
# XtermColor
Find the closest xterm color to anything implementing [color.Color](https://golang.org/pkg/image/color/#Color).
Provides a [color.Palette](https://golang.org/pkg/image/color/#Palette) as `xtermcolor.Colors` so you can use `.Convert` and `.Index`,
but also provides convenience functions to get the index as a `uint8` from a `color.Color`, a 32 bit integer, or a 24 bit hex string.
[![Build Status](https://travis-ci.org/tomnomnom/xtermcolor.svg?branch=master)](https://travis-ci.org/tomnomnom/xtermcolor)
Full documentation can be found on [GoDoc](https://godoc.org/github.com/tomnomnom/xtermcolor).
Basic usage (examples/basic.go):
```go
package main
import (
"fmt"
"image/color"
"github.com/tomnomnom/xtermcolor"
)
func main() {
fmt.Println(xtermcolor.Colors.Convert(color.RGBA{128, 64, 32, 255}))
fmt.Println(xtermcolor.FromColor(color.RGBA{120, 210, 120, 255}))
fmt.Println(xtermcolor.FromInt(0xCC66FFFF))
code, err := xtermcolor.FromHexStr("#FEFEFE")
if err != nil {
fmt.Println(err)
}
fmt.Println(code)
}
```
```
▶ go run examples/basic.go
{135 95 0 255}
114
171
15
```
## xtermcolor command
There's also an `xtermcolor` command you can install by running:
```
▶ go get github.com/tomnomnom/xtermcolor/cmd/xtermcolor
```
Or you can download a binary from the [releases page](https://github.com/tomnomnom/xtermcolor/releases).
The command returns the color code for a 24 bit hex number:
```
▶ xtermcolor cc66ff
171
```
...or for seperate 8 bit red, green and blue components:
```
▶ xtermcolor 210 128 0
172
```

@ -1,319 +0,0 @@
// Package xtermcolor provides a palette for xterm colors, and conversion to that palette from anything implementing color.Color
package xtermcolor
import (
"errors"
"image/color"
"strconv"
)
// Colors lists Xterm color codes vs. RGBA; values taken from https://gist.github.com/jasonm23/2868981
// color.Palette is really []color.Color and provides .Convert() and .Index()
var Colors = color.Palette{
// Basic block
0: color.RGBA{0x00, 0x00, 0x00, 0xff},
1: color.RGBA{0x80, 0x00, 0x00, 0xff},
2: color.RGBA{0x00, 0x80, 0x00, 0xff},
3: color.RGBA{0x80, 0x80, 0x00, 0xff},
4: color.RGBA{0x00, 0x00, 0x80, 0xff},
5: color.RGBA{0x80, 0x00, 0x80, 0xff},
6: color.RGBA{0x00, 0x80, 0x80, 0xff},
7: color.RGBA{0xc0, 0xc0, 0xc0, 0xff},
8: color.RGBA{0x80, 0x80, 0x80, 0xff},
9: color.RGBA{0xff, 0x00, 0x00, 0xff},
10: color.RGBA{0x00, 0xff, 0x00, 0xff},
11: color.RGBA{0xff, 0xff, 0x00, 0xff},
12: color.RGBA{0x00, 0x00, 0xff, 0xff},
13: color.RGBA{0xff, 0x00, 0xff, 0xff},
14: color.RGBA{0x00, 0xff, 0xff, 0xff},
15: color.RGBA{0xff, 0xff, 0xff, 0xff},
// 6x6x6 cube block
16: color.RGBA{0x00, 0x00, 0x00, 0xff},
17: color.RGBA{0x00, 0x00, 0x5f, 0xff},
18: color.RGBA{0x00, 0x00, 0x87, 0xff},
19: color.RGBA{0x00, 0x00, 0xaf, 0xff},
20: color.RGBA{0x00, 0x00, 0xd7, 0xff},
21: color.RGBA{0x00, 0x00, 0xff, 0xff},
22: color.RGBA{0x00, 0x5f, 0x00, 0xff},
23: color.RGBA{0x00, 0x5f, 0x5f, 0xff},
24: color.RGBA{0x00, 0x5f, 0x87, 0xff},
25: color.RGBA{0x00, 0x5f, 0xaf, 0xff},
26: color.RGBA{0x00, 0x5f, 0xd7, 0xff},
27: color.RGBA{0x00, 0x5f, 0xff, 0xff},
28: color.RGBA{0x00, 0x87, 0x00, 0xff},
29: color.RGBA{0x00, 0x87, 0x5f, 0xff},
30: color.RGBA{0x00, 0x87, 0x87, 0xff},
31: color.RGBA{0x00, 0x87, 0xaf, 0xff},
32: color.RGBA{0x00, 0x87, 0xd7, 0xff},
33: color.RGBA{0x00, 0x87, 0xff, 0xff},
34: color.RGBA{0x00, 0xaf, 0x00, 0xff},
35: color.RGBA{0x00, 0xaf, 0x5f, 0xff},
36: color.RGBA{0x00, 0xaf, 0x87, 0xff},
37: color.RGBA{0x00, 0xaf, 0xaf, 0xff},
38: color.RGBA{0x00, 0xaf, 0xd7, 0xff},
39: color.RGBA{0x00, 0xaf, 0xff, 0xff},
40: color.RGBA{0x00, 0xd7, 0x00, 0xff},
41: color.RGBA{0x00, 0xd7, 0x5f, 0xff},
42: color.RGBA{0x00, 0xd7, 0x87, 0xff},
43: color.RGBA{0x00, 0xd7, 0xaf, 0xff},
44: color.RGBA{0x00, 0xd7, 0xd7, 0xff},
45: color.RGBA{0x00, 0xd7, 0xff, 0xff},
46: color.RGBA{0x00, 0xff, 0x00, 0xff},
47: color.RGBA{0x00, 0xff, 0x5f, 0xff},
48: color.RGBA{0x00, 0xff, 0x87, 0xff},
49: color.RGBA{0x00, 0xff, 0xaf, 0xff},
50: color.RGBA{0x00, 0xff, 0xd7, 0xff},
51: color.RGBA{0x00, 0xff, 0xff, 0xff},
82: color.RGBA{0x5f, 0xff, 0x00, 0xff},
83: color.RGBA{0x5f, 0xff, 0x5f, 0xff},
84: color.RGBA{0x5f, 0xff, 0x87, 0xff},
85: color.RGBA{0x5f, 0xff, 0xaf, 0xff},
86: color.RGBA{0x5f, 0xff, 0xd7, 0xff},
87: color.RGBA{0x5f, 0xff, 0xff, 0xff},
76: color.RGBA{0x5f, 0xd7, 0x00, 0xff},
77: color.RGBA{0x5f, 0xd7, 0x5f, 0xff},
78: color.RGBA{0x5f, 0xd7, 0x87, 0xff},
79: color.RGBA{0x5f, 0xd7, 0xaf, 0xff},
80: color.RGBA{0x5f, 0xd7, 0xd7, 0xff},
81: color.RGBA{0x5f, 0xd7, 0xff, 0xff},
70: color.RGBA{0x5f, 0xaf, 0x00, 0xff},
71: color.RGBA{0x5f, 0xaf, 0x5f, 0xff},
72: color.RGBA{0x5f, 0xaf, 0x87, 0xff},
73: color.RGBA{0x5f, 0xaf, 0xaf, 0xff},
74: color.RGBA{0x5f, 0xaf, 0xd7, 0xff},
75: color.RGBA{0x5f, 0xaf, 0xff, 0xff},
64: color.RGBA{0x5f, 0x87, 0x00, 0xff},
65: color.RGBA{0x5f, 0x87, 0x5f, 0xff},
66: color.RGBA{0x5f, 0x87, 0x87, 0xff},
67: color.RGBA{0x5f, 0x87, 0xaf, 0xff},
68: color.RGBA{0x5f, 0x87, 0xd7, 0xff},
69: color.RGBA{0x5f, 0x87, 0xff, 0xff},
58: color.RGBA{0x5f, 0x5f, 0x00, 0xff},
59: color.RGBA{0x5f, 0x5f, 0x5f, 0xff},
60: color.RGBA{0x5f, 0x5f, 0x87, 0xff},
61: color.RGBA{0x5f, 0x5f, 0xaf, 0xff},
62: color.RGBA{0x5f, 0x5f, 0xd7, 0xff},
63: color.RGBA{0x5f, 0x5f, 0xff, 0xff},
52: color.RGBA{0x5f, 0x00, 0x00, 0xff},
53: color.RGBA{0x5f, 0x00, 0x5f, 0xff},
54: color.RGBA{0x5f, 0x00, 0x87, 0xff},
55: color.RGBA{0x5f, 0x00, 0xaf, 0xff},
56: color.RGBA{0x5f, 0x00, 0xd7, 0xff},
57: color.RGBA{0x5f, 0x00, 0xff, 0xff},
93: color.RGBA{0x87, 0x00, 0xff, 0xff},
92: color.RGBA{0x87, 0x00, 0xd7, 0xff},
91: color.RGBA{0x87, 0x00, 0xaf, 0xff},
90: color.RGBA{0x87, 0x00, 0x87, 0xff},
89: color.RGBA{0x87, 0x00, 0x5f, 0xff},
88: color.RGBA{0x87, 0x00, 0x00, 0xff},
99: color.RGBA{0x87, 0x5f, 0xff, 0xff},
98: color.RGBA{0x87, 0x5f, 0xd7, 0xff},
97: color.RGBA{0x87, 0x5f, 0xaf, 0xff},
96: color.RGBA{0x87, 0x5f, 0x87, 0xff},
95: color.RGBA{0x87, 0x5f, 0x5f, 0xff},
94: color.RGBA{0x87, 0x5f, 0x00, 0xff},
105: color.RGBA{0x87, 0x87, 0xff, 0xff},
104: color.RGBA{0x87, 0x87, 0xd7, 0xff},
103: color.RGBA{0x87, 0x87, 0xaf, 0xff},
102: color.RGBA{0x87, 0x87, 0x87, 0xff},
101: color.RGBA{0x87, 0x87, 0x5f, 0xff},
100: color.RGBA{0x87, 0x87, 0x00, 0xff},
111: color.RGBA{0x87, 0xaf, 0xff, 0xff},
110: color.RGBA{0x87, 0xaf, 0xd7, 0xff},
109: color.RGBA{0x87, 0xaf, 0xaf, 0xff},
108: color.RGBA{0x87, 0xaf, 0x87, 0xff},
107: color.RGBA{0x87, 0xaf, 0x5f, 0xff},
106: color.RGBA{0x87, 0xaf, 0x00, 0xff},
117: color.RGBA{0x87, 0xd7, 0xff, 0xff},
116: color.RGBA{0x87, 0xd7, 0xd7, 0xff},
115: color.RGBA{0x87, 0xd7, 0xaf, 0xff},
114: color.RGBA{0x87, 0xd7, 0x87, 0xff},
113: color.RGBA{0x87, 0xd7, 0x5f, 0xff},
112: color.RGBA{0x87, 0xd7, 0x00, 0xff},
123: color.RGBA{0x87, 0xff, 0xff, 0xff},
122: color.RGBA{0x87, 0xff, 0xd7, 0xff},
121: color.RGBA{0x87, 0xff, 0xaf, 0xff},
120: color.RGBA{0x87, 0xff, 0x87, 0xff},
119: color.RGBA{0x87, 0xff, 0x5f, 0xff},
118: color.RGBA{0x87, 0xff, 0x00, 0xff},
159: color.RGBA{0xaf, 0xff, 0xff, 0xff},
158: color.RGBA{0xaf, 0xff, 0xd7, 0xff},
157: color.RGBA{0xaf, 0xff, 0xaf, 0xff},
156: color.RGBA{0xaf, 0xff, 0x87, 0xff},
155: color.RGBA{0xaf, 0xff, 0x5f, 0xff},
154: color.RGBA{0xaf, 0xff, 0x00, 0xff},
153: color.RGBA{0xaf, 0xd7, 0xff, 0xff},
152: color.RGBA{0xaf, 0xd7, 0xd7, 0xff},
151: color.RGBA{0xaf, 0xd7, 0xaf, 0xff},
150: color.RGBA{0xaf, 0xd7, 0x87, 0xff},
149: color.RGBA{0xaf, 0xd7, 0x5f, 0xff},
148: color.RGBA{0xaf, 0xd7, 0x00, 0xff},
147: color.RGBA{0xaf, 0xaf, 0xff, 0xff},
146: color.RGBA{0xaf, 0xaf, 0xd7, 0xff},
145: color.RGBA{0xaf, 0xaf, 0xaf, 0xff},
144: color.RGBA{0xaf, 0xaf, 0x87, 0xff},
143: color.RGBA{0xaf, 0xaf, 0x5f, 0xff},
142: color.RGBA{0xaf, 0xaf, 0x00, 0xff},
141: color.RGBA{0xaf, 0x87, 0xff, 0xff},
140: color.RGBA{0xaf, 0x87, 0xd7, 0xff},
139: color.RGBA{0xaf, 0x87, 0xaf, 0xff},
138: color.RGBA{0xaf, 0x87, 0x87, 0xff},
137: color.RGBA{0xaf, 0x87, 0x5f, 0xff},
136: color.RGBA{0xaf, 0x87, 0x00, 0xff},
135: color.RGBA{0xaf, 0x5f, 0xff, 0xff},
134: color.RGBA{0xaf, 0x5f, 0xd7, 0xff},
133: color.RGBA{0xaf, 0x5f, 0xaf, 0xff},
132: color.RGBA{0xaf, 0x5f, 0x87, 0xff},
131: color.RGBA{0xaf, 0x5f, 0x5f, 0xff},
130: color.RGBA{0xaf, 0x5f, 0x00, 0xff},
129: color.RGBA{0xaf, 0x00, 0xff, 0xff},
128: color.RGBA{0xaf, 0x00, 0xd7, 0xff},
127: color.RGBA{0xaf, 0x00, 0xaf, 0xff},
126: color.RGBA{0xaf, 0x00, 0x87, 0xff},
125: color.RGBA{0xaf, 0x00, 0x5f, 0xff},
124: color.RGBA{0xaf, 0x00, 0x00, 0xff},
160: color.RGBA{0xd7, 0x00, 0x00, 0xff},
161: color.RGBA{0xd7, 0x00, 0x5f, 0xff},
162: color.RGBA{0xd7, 0x00, 0x87, 0xff},
163: color.RGBA{0xd7, 0x00, 0xaf, 0xff},
164: color.RGBA{0xd7, 0x00, 0xd7, 0xff},
165: color.RGBA{0xd7, 0x00, 0xff, 0xff},
166: color.RGBA{0xd7, 0x5f, 0x00, 0xff},
167: color.RGBA{0xd7, 0x5f, 0x5f, 0xff},
168: color.RGBA{0xd7, 0x5f, 0x87, 0xff},
169: color.RGBA{0xd7, 0x5f, 0xaf, 0xff},
170: color.RGBA{0xd7, 0x5f, 0xd7, 0xff},
171: color.RGBA{0xd7, 0x5f, 0xff, 0xff},
172: color.RGBA{0xd7, 0x87, 0x00, 0xff},
173: color.RGBA{0xd7, 0x87, 0x5f, 0xff},
174: color.RGBA{0xd7, 0x87, 0x87, 0xff},
175: color.RGBA{0xd7, 0x87, 0xaf, 0xff},
176: color.RGBA{0xd7, 0x87, 0xd7, 0xff},
177: color.RGBA{0xd7, 0x87, 0xff, 0xff},
178: color.RGBA{0xdf, 0xaf, 0x00, 0xff},
179: color.RGBA{0xdf, 0xaf, 0x5f, 0xff},
180: color.RGBA{0xdf, 0xaf, 0x87, 0xff},
181: color.RGBA{0xdf, 0xaf, 0xaf, 0xff},
182: color.RGBA{0xdf, 0xaf, 0xdf, 0xff},
183: color.RGBA{0xdf, 0xaf, 0xff, 0xff},
184: color.RGBA{0xdf, 0xdf, 0x00, 0xff},
185: color.RGBA{0xdf, 0xdf, 0x5f, 0xff},
186: color.RGBA{0xdf, 0xdf, 0x87, 0xff},
187: color.RGBA{0xdf, 0xdf, 0xaf, 0xff},
188: color.RGBA{0xdf, 0xdf, 0xdf, 0xff},
189: color.RGBA{0xdf, 0xdf, 0xff, 0xff},
190: color.RGBA{0xdf, 0xff, 0x00, 0xff},
191: color.RGBA{0xdf, 0xff, 0x5f, 0xff},
192: color.RGBA{0xdf, 0xff, 0x87, 0xff},
193: color.RGBA{0xdf, 0xff, 0xaf, 0xff},
194: color.RGBA{0xdf, 0xff, 0xdf, 0xff},
195: color.RGBA{0xdf, 0xff, 0xff, 0xff},
226: color.RGBA{0xff, 0xff, 0x00, 0xff},
227: color.RGBA{0xff, 0xff, 0x5f, 0xff},
228: color.RGBA{0xff, 0xff, 0x87, 0xff},
229: color.RGBA{0xff, 0xff, 0xaf, 0xff},
230: color.RGBA{0xff, 0xff, 0xdf, 0xff},
231: color.RGBA{0xff, 0xff, 0xff, 0xff},
220: color.RGBA{0xff, 0xdf, 0x00, 0xff},
221: color.RGBA{0xff, 0xdf, 0x5f, 0xff},
222: color.RGBA{0xff, 0xdf, 0x87, 0xff},
223: color.RGBA{0xff, 0xdf, 0xaf, 0xff},
224: color.RGBA{0xff, 0xdf, 0xdf, 0xff},
225: color.RGBA{0xff, 0xdf, 0xff, 0xff},
214: color.RGBA{0xff, 0xaf, 0x00, 0xff},
215: color.RGBA{0xff, 0xaf, 0x5f, 0xff},
216: color.RGBA{0xff, 0xaf, 0x87, 0xff},
217: color.RGBA{0xff, 0xaf, 0xaf, 0xff},
218: color.RGBA{0xff, 0xaf, 0xdf, 0xff},
219: color.RGBA{0xff, 0xaf, 0xff, 0xff},
208: color.RGBA{0xff, 0x87, 0x00, 0xff},
209: color.RGBA{0xff, 0x87, 0x5f, 0xff},
210: color.RGBA{0xff, 0x87, 0x87, 0xff},
211: color.RGBA{0xff, 0x87, 0xaf, 0xff},
212: color.RGBA{0xff, 0x87, 0xdf, 0xff},
213: color.RGBA{0xff, 0x87, 0xff, 0xff},
202: color.RGBA{0xff, 0x5f, 0x00, 0xff},
203: color.RGBA{0xff, 0x5f, 0x5f, 0xff},
204: color.RGBA{0xff, 0x5f, 0x87, 0xff},
205: color.RGBA{0xff, 0x5f, 0xaf, 0xff},
206: color.RGBA{0xff, 0x5f, 0xdf, 0xff},
207: color.RGBA{0xff, 0x5f, 0xff, 0xff},
196: color.RGBA{0xff, 0x00, 0x00, 0xff},
197: color.RGBA{0xff, 0x00, 0x5f, 0xff},
198: color.RGBA{0xff, 0x00, 0x87, 0xff},
199: color.RGBA{0xff, 0x00, 0xaf, 0xff},
200: color.RGBA{0xff, 0x00, 0xdf, 0xff},
201: color.RGBA{0xff, 0x00, 0xff, 0xff},
// Grayscale block
232: color.RGBA{0x08, 0x08, 0x08, 0xff},
233: color.RGBA{0x12, 0x12, 0x12, 0xff},
234: color.RGBA{0x1c, 0x1c, 0x1c, 0xff},
235: color.RGBA{0x26, 0x26, 0x26, 0xff},
236: color.RGBA{0x30, 0x30, 0x30, 0xff},
237: color.RGBA{0x3a, 0x3a, 0x3a, 0xff},
238: color.RGBA{0x44, 0x44, 0x44, 0xff},
239: color.RGBA{0x4e, 0x4e, 0x4e, 0xff},
240: color.RGBA{0x58, 0x58, 0x58, 0xff},
241: color.RGBA{0x62, 0x62, 0x62, 0xff},
242: color.RGBA{0x6c, 0x6c, 0x6c, 0xff},
243: color.RGBA{0x76, 0x76, 0x76, 0xff},
255: color.RGBA{0xee, 0xee, 0xee, 0xff},
254: color.RGBA{0xe4, 0xe4, 0xe4, 0xff},
253: color.RGBA{0xda, 0xda, 0xda, 0xff},
252: color.RGBA{0xd0, 0xd0, 0xd0, 0xff},
251: color.RGBA{0xc6, 0xc6, 0xc6, 0xff},
250: color.RGBA{0xbc, 0xbc, 0xbc, 0xff},
249: color.RGBA{0xb2, 0xb2, 0xb2, 0xff},
248: color.RGBA{0xa8, 0xa8, 0xa8, 0xff},
247: color.RGBA{0x9e, 0x9e, 0x9e, 0xff},
246: color.RGBA{0x94, 0x94, 0x94, 0xff},
245: color.RGBA{0x8a, 0x8a, 0x8a, 0xff},
244: color.RGBA{0x80, 0x80, 0x80, 0xff},
}
var (
// ErrorEmptyHexStr is returned by FromHexStr when an empty hex string is provided
ErrorEmptyHexStr = errors.New("Empty hex string provided")
// ErrorHexParse is returned by FromHexStr when an invalid hex string is provided
ErrorHexParse = errors.New("Failed to parse string as hex; try something like #CC66FF")
)
// Convert a 32 bit color to a color.RGBA
func intToRGBA(c uint32) color.RGBA {
r := uint8((c >> 24) & 0xff)
g := uint8((c >> 16) & 0xff)
b := uint8((c >> 8) & 0xff)
a := uint8(c & 0xff)
return color.RGBA{r, g, b, a}
}
// FromColor finds the closest xterm colour to a given color.Color
func FromColor(target color.Color) uint8 {
return uint8(Colors.Index(target))
}
// FromInt finds the closest xterm color to a given 32 bit RGBA color (e.g. 0xff00ff00).
func FromInt(target uint32) uint8 {
return FromColor(intToRGBA(target))
}
// FromHexStr finds the closest xterm color to a given 24 bit hex string, e.g. "#CC66FF" or "FEFEFE"
// It's mostly useful if you're used to specifying colours as hex in CSS etc
func FromHexStr(str string) (uint8, error) {
if len(str) == 0 {
return 0, ErrorEmptyHexStr
}
if str[0] == '#' {
str = str[1:]
}
v, err := strconv.ParseUint(str, 16, 24)
if err != nil {
return 0, ErrorHexParse
}
return FromInt(uint32((v << 8) + 0xFF)), nil
}

@ -146,9 +146,6 @@ github.com/spf13/pflag
# github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af
## explicit
github.com/tadvi/systray
# github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e
## explicit
github.com/tomnomnom/xtermcolor
# golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
## explicit; go 1.17
golang.org/x/crypto/blowfish

Loading…
Cancel
Save