diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9193b32 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/LICENSE.md b/LICENSE.md new file mode 100755 index 0000000..eb0736f --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md index 7f6ba5f..b2b0f4b 100644 --- a/README.md +++ b/README.md @@ -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| +|----|------| +|``|navigate up| +|``|navigate down| +|``|page up| +|``|page down| +|``|visit highlighted coin on CoinMarketCap| +|``|alias to `` +|`j`|alias to ``| +|`k`|alias to ``| +|`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| +|``|alias to quit| +|``|alias to quit| + + + +## 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 diff --git a/apis/apis.go b/apis/apis.go new file mode 100644 index 0000000..8a52002 --- /dev/null +++ b/apis/apis.go @@ -0,0 +1,10 @@ +package apis + +import ( + cmc "github.com/miguelmota/cointop/apis/cmc" +) + +// NewCMC new CoinMarketCap api +func NewCMC() Interface { + return cmc.New() +} diff --git a/cointop.go b/cointop.go index 98d6dc7..57fc705 100644 --- a/cointop.go +++ b/cointop.go @@ -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, " "), diff --git a/color/color.go b/color/color.go new file mode 100644 index 0000000..8ee5ff8 --- /dev/null +++ b/color/color.go @@ -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() +) diff --git a/pad/pad.go b/pad/pad.go new file mode 100644 index 0000000..69a89ab --- /dev/null +++ b/pad/pad.go @@ -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)) +}