abstract color

Former-commit-id: d8b0cffdf8f1e462dfe0f3ab6397184b3de09b2e [formerly 187f30f5c7]
Former-commit-id: 649cfa1af7c048413ac2b284b0e29e041b2609b7
pull/15/head
Miguel Mota 6 years ago
parent fa89b4d0ad
commit 3b31a8478b

14
.gitignore vendored

@ -0,0 +1,14 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.DS_Store

@ -0,0 +1,21 @@
MIT license
Copyright (C) 2015 Miguel Mota
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.

@ -14,6 +14,65 @@ Make sure to have [golang](https://golang.org/) installed, then do:
go get -u github.com/miguelmota/cointop
```
## Usage
### Table commands
List of shortcuts:
|Key|Action|
|----|------|
|`<up>`|navigate up|
|`<down>`|navigate down|
|`<ctrl-u>`|page up|
|`<ctrl-d>`|page down|
|`<enter>`|visit highlighted coin on CoinMarketCap|
|`<space>`|alias to `<enter>`
|`j`|alias to `<down>`|
|`k`|alias to `<up>`|
|`r`|sort by *[r]ank*|
|`n`|sort by *[n]ame*|
|`s`|sort by *[s]ymbol*|
|`p`|sort by *[p]rice*|
|`m`|sort by *[m]arket cap*|
|`v`|sort by *24 hour [v]olume*|
|`1`|sort by *[1] hour change*|
|`2`|sort by *[2]4 hour change*|
|`7`|sort by *[7] day change*|
|`t`|sort by *[t]otal supply*|
|`a`|sort by *[a]vailable supply*|
|`l`|sort by *[l]ast updated*|
|`q`|[q]uit|
|`<esc>`|alias to quit|
|`<ctrl-c>`|alias to quit|
<!--
|`h`|toggle [h]elp|
|`?`|alias to help|
-->
## FAQ
- Q: Where is the data from?
- A: The data is from [Coin Market Cap](https://coinmarketcap.com/).
- Q: What coins does this support?
- A: This supports any coin listed on [Coin Market Cap](https://coinmarketcap.com/).
- Q: How often is the data polled?
- A: Data gets polled once every minute by default.
- Q: I installed cointop without errors but the command is not found.
- A: Make sure your `GOPATH` and `PATH` is set correctly.
```bash
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
```
## License
MIT

@ -0,0 +1,10 @@
package apis
import (
cmc "github.com/miguelmota/cointop/apis/cmc"
)
// NewCMC new CoinMarketCap api
func NewCMC() Interface {
return cmc.New()
}

@ -8,21 +8,13 @@ import (
"github.com/bradfitz/slice"
humanize "github.com/dustin/go-humanize"
"github.com/fatih/color"
"github.com/gizak/termui"
"github.com/jroimartin/gocui"
"github.com/miguelmota/cointop/apis"
cmc "github.com/miguelmota/cointop/apis/cmc"
apitypes "github.com/miguelmota/cointop/apis/types"
"github.com/miguelmota/cointop/color"
"github.com/miguelmota/cointop/pad"
"github.com/miguelmota/cointop/table"
"github.com/willf/pad"
)
var (
white = color.New(color.FgWhite).SprintFunc()
green = color.New(color.FgGreen).SprintFunc()
red = color.New(color.FgRed).SprintFunc()
cyan = color.New(color.FgCyan).SprintFunc()
)
var (
@ -60,7 +52,7 @@ func main() {
ct := Cointop{
g: g,
api: cmc.New(),
api: apis.NewCMC(),
}
g.SetManagerFunc(ct.layout)
@ -463,27 +455,27 @@ func (ct *Cointop) setTable() error {
for _, coin := range ct.coins {
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
colorprice := cyan
color1h := white
color24h := white
color7d := white
colorprice := color.Cyan
color1h := color.White
color24h := color.White
color7d := color.White
if coin.PercentChange1H > 0 {
color1h = green
color1h = color.Green
}
if coin.PercentChange1H < 0 {
color1h = red
color1h = color.Red
}
if coin.PercentChange24H > 0 {
color24h = green
color24h = color.Green
}
if coin.PercentChange24H < 0 {
color24h = red
color24h = color.Red
}
if coin.PercentChange7D > 0 {
color7d = green
color7d = color.Green
}
if coin.PercentChange7D < 0 {
color7d = red
color7d = color.Red
}
ct.table.AddRow(
pad.Left(fmt.Sprint(coin.Rank), 4, " "),

@ -0,0 +1,10 @@
package color
import "github.com/fatih/color"
var (
White = color.New(color.FgWhite).SprintFunc()
Green = color.New(color.FgGreen).SprintFunc()
Red = color.New(color.FgRed).SprintFunc()
Cyan = color.New(color.FgCyan).SprintFunc()
)

@ -0,0 +1,19 @@
package pad
func times(str string, n int) (out string) {
for i := 0; i < n; i++ {
out += str
}
return
}
// Left left-pads the string with pad up to len runes
// len may be exceeded if
func Left(str string, length int, pad string) string {
return times(pad, length-len(str)) + str
}
// Right right-pads the string with pad up to len runes
func Right(str string, length int, pad string) string {
return str + times(pad, length-len(str))
}
Loading…
Cancel
Save