Table alignment fixes

pull/94/head
Miguel Mota 3 years ago
parent 68ff8ecfb7
commit ea93f6b5ca

@ -186,7 +186,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
rowCells = append(rowCells,
&table.RowCell{
LeftMargin: 1,
Width: 19,
Width: 20,
LeftAlign: false,
Color: ct.colorscheme.TableRow,
Text: humanize.Commaf(coin.AvailableSupply),

@ -160,7 +160,7 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
rowCells = append(rowCells,
&table.RowCell{
LeftMargin: 1,
Width: 10,
Width: 11,
LeftAlign: false,
Color: color1h,
Text: fmt.Sprintf("%.2f%%", coin.PercentChange1H),
@ -238,6 +238,9 @@ func (ct *Cointop) ToggleShowPortfolio() error {
// TogglePortfolioUpdateMenu toggles the portfolio update menu
func (ct *Cointop) TogglePortfolioUpdateMenu() error {
ct.debuglog("togglePortfolioUpdateMenu()")
if ct.IsPriceAlertsVisible() {
return ct.ShowPriceAlertsUpdateMenu()
}
ct.State.portfolioUpdateMenuVisible = !ct.State.portfolioUpdateMenuVisible
if ct.State.portfolioUpdateMenuVisible {
return ct.ShowPortfolioUpdateMenu()

@ -3,7 +3,6 @@ package cointop
import (
"errors"
"fmt"
"log"
"regexp"
"strconv"
"strings"
@ -86,7 +85,7 @@ func (ct *Cointop) GetPriceAlertsTable() *table.Table {
},
&table.RowCell{
LeftMargin: 1,
Width: 16,
Width: 14,
LeftAlign: false,
Color: ct.colorscheme.TableColumnPrice,
Text: targetPrice,
@ -99,8 +98,8 @@ func (ct *Cointop) GetPriceAlertsTable() *table.Table {
Text: humanize.Commaf(coin.Price),
},
&table.RowCell{
LeftMargin: 2,
Width: 11,
LeftMargin: 4,
Width: 10,
LeftAlign: true,
Color: ct.colorscheme.TableRow,
Text: frequency,
@ -126,21 +125,19 @@ func (ct *Cointop) IsPriceAlertsVisible() bool {
}
// PriceAlertWatcher starts the price alert watcher
func (ct *Cointop) PriceAlertWatcher() {
func (ct *Cointop) PriceAlertWatcher() error {
ct.debuglog("priceAlertWatcher()")
alerts := ct.State.priceAlerts.Entries
ticker := time.NewTicker(2 * time.Second)
for {
select {
case <-ticker.C:
for _, alert := range alerts {
err := ct.CheckPriceAlert(alert)
if err != nil {
log.Fatal(err)
}
ticker := time.NewTicker(5 * time.Second)
for range ticker.C {
for _, alert := range alerts {
err := ct.CheckPriceAlert(alert)
if err != nil {
return err
}
}
}
return nil
}
// CheckPriceAlert checks the price alert
@ -256,7 +253,7 @@ func (ct *Cointop) UpdatePriceAlertsUpdateMenu(isNew bool) error {
// ShowPriceAlertsAddMenu shows the alert add menu
func (ct *Cointop) ShowPriceAlertsAddMenu() error {
ct.debuglog("showPriceAlertsAddMenu()")
ct.ToggleSelectedView(PriceAlertsView)
ct.SetSelectedView(PriceAlertsView)
ct.State.lastSelectedRowIndex = ct.HighlightedPageRowIndex()
ct.UpdatePriceAlertsUpdateMenu(true)
ct.ui.SetCursor(true)
@ -268,8 +265,8 @@ func (ct *Cointop) ShowPriceAlertsAddMenu() error {
// ShowPriceAlertsUpdateMenu shows the alerts update menu
func (ct *Cointop) ShowPriceAlertsUpdateMenu() error {
ct.ToggleSelectedView(PriceAlertsView)
ct.debuglog("showPriceAlertsUpdateMenu()")
ct.SetSelectedView(PriceAlertsView)
ct.State.lastSelectedRowIndex = ct.HighlightedPageRowIndex()
ct.UpdatePriceAlertsUpdateMenu(false)
ct.ui.SetCursor(true)
@ -311,7 +308,8 @@ func (ct *Cointop) CreatePriceAlert() error {
defer ct.HidePriceAlertsUpdateMenu()
var coinName string
if ct.State.priceAlertEditID == "" {
isNew := ct.State.priceAlertEditID == ""
if isNew {
coin := ct.HighlightedRowCoin()
coinName = coin.Name
} else {
@ -332,7 +330,9 @@ func (ct *Cointop) CreatePriceAlert() error {
}
ct.UpdateTable()
ct.GoToPageRowIndex(ct.State.lastSelectedRowIndex)
if isNew {
ct.GoToPageRowIndex(0)
}
return nil
}

@ -44,7 +44,11 @@ func (ct *Cointop) UpdateStatusbar(s string) error {
helpStr := fmt.Sprintf("%s%s %sHelp", "[Q]", quitText, "[?]")
var content string
if ct.IsPriceAlertsVisible() {
content = fmt.Sprintf("%s [E]Edit [+]Add", helpStr)
var editStr string
if ct.ActivePriceAlertsLen() > 0 {
editStr = "[E]Edit "
}
content = fmt.Sprintf("%s %s[+]Add", helpStr, editStr)
} else {
base := fmt.Sprintf("%s %sChart %sRange %sSearch %sConvert %s %s", helpStr, "[Enter]", "[[ ]]", "[/]", "[C]", favoritesText, portfolioText)
str := pad.Right(fmt.Sprintf("%v %sPage %v/%v %s", base, "[← →]", currpage, totalpages, s), ct.width(), " ")

@ -29,24 +29,33 @@ func (ct *Cointop) UpdateTableHeader() error {
}
baseColor := ct.colorscheme.TableHeaderSprintf()
offset := 0
lb := "["
rb := "]"
noSort := ct.IsPriceAlertsVisible()
if noSort {
offset = 2
lb = ""
rb = ""
}
possibleHeaders := map[string]*t{
"rank": {baseColor, "[r]ank", 0, 1, " "},
"name": {baseColor, "[n]ame", 0, 11, " "},
"symbol": {baseColor, "[s]ymbol", 4, 0, " "},
"target_price": {baseColor, "[t]arget price", 2, 0, " "},
"price": {baseColor, "[p]rice", 2, 0, " "},
"rank": {baseColor, fmt.Sprintf("%sr%sank", lb, rb), 0, 1 + offset, " "},
"name": {baseColor, fmt.Sprintf("%sn%same", lb, rb), 0, 11 + offset, " "},
"symbol": {baseColor, fmt.Sprintf("%ss%symbol", lb, rb), 4, 0 + offset, " "},
"target_price": {baseColor, fmt.Sprintf("%st%sarget price", lb, rb), 2, 0 + offset, " "},
"price": {baseColor, fmt.Sprintf("%sp%srice", lb, rb), 2, 0 + offset, " "},
"frequency": {baseColor, "frequency", 1, 0, " "},
"holdings": {baseColor, "[h]oldings", 5, 0, " "},
"balance": {baseColor, "[b]alance", 5, 0, " "},
"marketcap": {baseColor, "[m]arket cap", 5, 0, " "},
"24h_volume": {baseColor, "24H [v]olume", 3, 0, " "},
"1h_change": {baseColor, "[1]H%", 5, 0, " "},
"24h_change": {baseColor, "[2]4H%", 3, 0, " "},
"7d_change": {baseColor, "[7]D%", 4, 0, " "},
"total_supply": {baseColor, "[t]otal supply", 7, 0, " "},
"available_supply": {baseColor, "[a]vailable supply", 0, 0, " "},
"percent_holdings": {baseColor, "[%]holdings", 2, 0, " "},
"last_updated": {baseColor, "last [u]pdated", 3, 0, " "},
"holdings": {baseColor, fmt.Sprintf("%sh%soldings", lb, rb), 5, 0 + offset, " "},
"balance": {baseColor, fmt.Sprintf("%sb%salance", lb, rb), 5, 0, " "},
"marketcap": {baseColor, fmt.Sprintf("%sm%sarket cap", lb, rb), 5, 0 + offset, " "},
"24h_volume": {baseColor, fmt.Sprintf("24H %sv%solume", lb, rb), 3, 0 + offset, " "},
"1h_change": {baseColor, fmt.Sprintf("%s1%sH%%", lb, rb), 5, 0 + offset, " "},
"24h_change": {baseColor, fmt.Sprintf("%s2%s4H%%", lb, rb), 3, 0 + offset, " "},
"7d_change": {baseColor, fmt.Sprintf("%s7%sD%%", lb, rb), 4, 0 + offset, " "},
"total_supply": {baseColor, fmt.Sprintf("%st%sotal supply", lb, rb), 7, 0 + offset, " "},
"available_supply": {baseColor, fmt.Sprintf("%sa%svailable supply", lb, rb), 1, 0 + offset, " "},
"percent_holdings": {baseColor, fmt.Sprintf("%s%%%sholdings", lb, rb), 2, 0 + offset, " "},
"last_updated": {baseColor, fmt.Sprintf("last %su%spdated", lb, rb), 3, 0, " "},
}
for k := range possibleHeaders {

Loading…
Cancel
Save