refac color

pull/10/head
Edouard Paris 5 years ago
parent 5ecac70020
commit 282bce88bc

@ -5,15 +5,89 @@ import "github.com/fatih/color"
type Color color.Color
var (
Yellow = color.New(color.FgYellow).SprintFunc()
Green = color.New(color.FgGreen).SprintFunc()
GreenBg = color.New(color.BgGreen, color.FgBlack).SprintFunc()
Red = color.New(color.FgRed).SprintFunc()
RedBg = color.New(color.BgRed, color.FgBlack).SprintFunc()
Cyan = color.New(color.FgCyan).SprintFunc()
CyanBold = color.New(color.FgCyan, color.Bold).SprintFunc()
CyanBg = color.New(color.BgCyan, color.FgBlack).SprintFunc()
WhiteBg = color.New(color.BgWhite, color.FgBlack).SprintFunc()
BlackBg = color.New(color.BgBlack, color.FgWhite).SprintFunc()
Bold = color.New(color.Bold).SprintFunc()
yellow = color.New(color.FgYellow).SprintFunc()
yellowBold = color.New(color.FgYellow, color.Bold).SprintFunc()
green = color.New(color.FgGreen).SprintFunc()
greenBold = color.New(color.FgGreen, color.Bold).SprintFunc()
red = color.New(color.FgRed).SprintFunc()
redBold = color.New(color.FgRed, color.Bold).SprintFunc()
cyan = color.New(color.FgCyan).SprintFunc()
cyanBold = color.New(color.FgCyan, color.Bold).SprintFunc()
cyanBg = color.New(color.BgCyan, color.FgBlack).SprintFunc()
white = color.New(color.FgWhite).SprintFunc()
whiteBold = color.New(color.FgWhite, color.Bold).SprintFunc()
blackBg = color.New(color.BgBlack, color.FgWhite).SprintFunc()
black = color.New(color.FgBlack).SprintFunc()
)
type Option func(*options)
type options struct {
bold bool
bg bool
}
func newOptions(opts []Option) options {
options := options{}
for i := range opts {
if opts[i] == nil {
continue
}
opts[i](&options)
}
return options
}
func Bold(o *options) { o.bold = true }
func Background(o *options) { o.bg = true }
func Yellow(opts ...Option) func(a ...interface{}) string {
options := newOptions(opts)
if options.bold {
return yellowBold
}
return yellow
}
func Green(opts ...Option) func(a ...interface{}) string {
options := newOptions(opts)
if options.bold {
return greenBold
}
return green
}
func Red(opts ...Option) func(a ...interface{}) string {
options := newOptions(opts)
if options.bold {
return redBold
}
return red
}
func White(opts ...Option) func(a ...interface{}) string {
options := newOptions(opts)
if options.bold {
return whiteBold
}
return white
}
func Cyan(opts ...Option) func(a ...interface{}) string {
options := newOptions(opts)
if options.bold {
return cyanBold
}
if options.bg {
return cyanBg
}
return cyan
}
func Black(opts ...Option) func(a ...interface{}) string {
options := newOptions(opts)
if options.bg {
return blackBg
}
return black
}

@ -84,11 +84,12 @@ func (c *Channel) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
footer.BgColor = gocui.ColorCyan
footer.FgColor = gocui.ColorBlack
footer.Clear()
blackBg := color.Black(color.Background)
fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s %s%s",
color.BlackBg("F1"), "Help",
color.BlackBg("F2"), "Menu",
color.BlackBg("Enter"), "Channels",
color.BlackBg("F10"), "Quit",
blackBg("F1"), "Help",
blackBg("F2"), "Menu",
blackBg("Enter"), "Channels",
blackBg("F10"), "Quit",
))
return nil
}
@ -112,63 +113,66 @@ func (c *Channel) display() {
v := c.view
v.Clear()
channel := c.channel.Item
fmt.Fprintln(v, color.Green(" [ Channel ]"))
green := color.Green()
cyan := color.Cyan()
red := color.Red()
fmt.Fprintln(v, green(" [ Channel ]"))
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" Status:"), status(channel)))
cyan(" Status:"), status(channel)))
fmt.Fprintln(v, fmt.Sprintf("%s %d",
color.Cyan(" ID:"), channel.ID))
cyan(" ID:"), channel.ID))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Capacity:"), channel.Capacity))
cyan(" Capacity:"), channel.Capacity))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Local Balance:"), channel.LocalBalance))
cyan(" Local Balance:"), channel.LocalBalance))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Remote Balance:"), channel.RemoteBalance))
cyan(" Remote Balance:"), channel.RemoteBalance))
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" Channel Point:"), channel.ChannelPoint))
cyan(" Channel Point:"), channel.ChannelPoint))
fmt.Fprintln(v, "")
fmt.Fprintln(v, color.Green(" [ Node ]"))
fmt.Fprintln(v, green(" [ Node ]"))
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" PubKey:"), channel.RemotePubKey))
cyan(" PubKey:"), channel.RemotePubKey))
if channel.Node != nil {
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" Alias:"), channel.Node.Alias))
cyan(" Alias:"), channel.Node.Alias))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Total Capacity:"), channel.Node.TotalCapacity))
cyan(" Total Capacity:"), channel.Node.TotalCapacity))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Total Channels:"), channel.Node.NumChannels))
cyan(" Total Channels:"), channel.Node.NumChannels))
}
if channel.Policy1 != nil {
fmt.Fprintln(v, "")
fmt.Fprintln(v, color.Green(" [ Forward Policy Node1 ]"))
fmt.Fprintln(v, green(" [ Forward Policy Node1 ]"))
if channel.Policy1.Disabled {
fmt.Fprintln(v, color.Red("disabled"))
fmt.Fprintln(v, red("disabled"))
}
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Time lock delta:"), channel.Policy1.TimeLockDelta))
cyan(" Time lock delta:"), channel.Policy1.TimeLockDelta))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Min htlc:"), channel.Policy1.MinHtlc))
cyan(" Min htlc:"), channel.Policy1.MinHtlc))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Fee base msat:"), channel.Policy1.FeeBaseMsat))
cyan(" Fee base msat:"), channel.Policy1.FeeBaseMsat))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan("Fee rate milli msat:"), channel.Policy1.FeeRateMilliMsat))
cyan("Fee rate milli msat:"), channel.Policy1.FeeRateMilliMsat))
}
if channel.Policy2 != nil {
fmt.Fprintln(v, "")
fmt.Fprintln(v, color.Green(" [ Forward Policy Node 2 ]"))
fmt.Fprintln(v, green(" [ Forward Policy Node 2 ]"))
if channel.Policy2.Disabled {
fmt.Fprintln(v, color.Red("disabled"))
fmt.Fprintln(v, red("disabled"))
}
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Time lock delta:"), channel.Policy2.TimeLockDelta))
cyan(" Time lock delta:"), channel.Policy2.TimeLockDelta))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Min htlc:"), channel.Policy2.MinHtlc))
cyan(" Min htlc:"), channel.Policy2.MinHtlc))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Fee base msat:"), channel.Policy2.FeeBaseMsat))
cyan(" Fee base msat:"), channel.Policy2.FeeBaseMsat))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan("Fee rate milli msat:"), channel.Policy2.FeeRateMilliMsat))
cyan("Fee rate milli msat:"), channel.Policy2.FeeRateMilliMsat))
}
}

@ -48,7 +48,7 @@ type Channels struct {
type channelsColumn struct {
name string
width int
display func(*netmodels.Channel) string
display func(*netmodels.Channel, ...color.Option) string
}
func (c Channels) Index() int {
@ -152,11 +152,12 @@ func (c *Channels) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
footer.BgColor = gocui.ColorCyan
footer.FgColor = gocui.ColorBlack
footer.Clear()
blackBg := color.Black(color.Background)
fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s %s%s",
color.BlackBg("F1"), "Help",
color.BlackBg("F2"), "Menu",
color.BlackBg("Enter"), "Channel",
color.BlackBg("F10"), "Quit",
blackBg("F1"), "Help",
blackBg("F2"), "Menu",
blackBg("Enter"), "Channel",
blackBg("F10"), "Quit",
))
return nil
}
@ -166,7 +167,7 @@ func (c *Channels) display() {
var buffer bytes.Buffer
for i := range c.columns {
if c.col == i {
buffer.WriteString(color.Bold(c.columns[i].name))
buffer.WriteString(color.White(color.Bold)(c.columns[i].name))
buffer.WriteString(" ")
continue
}
@ -179,12 +180,11 @@ func (c *Channels) display() {
for _, item := range c.channels.List() {
var buffer bytes.Buffer
for i := range c.columns {
var opt color.Option
if c.col == i {
buffer.WriteString(color.Bold(c.columns[i].display(item)))
buffer.WriteString(" ")
continue
opt = color.Bold
}
buffer.WriteString(c.columns[i].display(item))
buffer.WriteString(c.columns[i].display(item, opt))
buffer.WriteString(" ")
}
fmt.Fprintln(c.view, buffer.String())
@ -218,7 +218,7 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
channels.columns[i] = channelsColumn{
width: 25,
name: fmt.Sprintf("%-25s", columns[i]),
display: func(c *netmodels.Channel) string {
display: func(c *netmodels.Channel, opts ...color.Option) string {
var alias string
if c.Node == nil || c.Node.Alias == "" {
alias = c.RemotePubKey[:24]
@ -227,73 +227,78 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
} else {
alias = c.Node.Alias
}
return fmt.Sprintf("%-25s", alias)
return color.White(opts...)(fmt.Sprintf("%-25s", alias))
},
}
case "GAUGE":
channels.columns[i] = channelsColumn{
width: 21,
name: fmt.Sprintf("%-21s", columns[i]),
display: func(c *netmodels.Channel) string {
display: func(c *netmodels.Channel, opts ...color.Option) string {
index := int(c.LocalBalance * int64(15) / c.Capacity)
var buffer bytes.Buffer
cyan := color.Cyan(opts...)
white := color.White(opts...)
for i := 0; i < 15; i++ {
if i < index {
buffer.WriteString(color.Cyan("|"))
buffer.WriteString(cyan("|"))
continue
}
buffer.WriteString(" ")
}
return fmt.Sprintf("[%s] %2d%%", buffer.String(), c.LocalBalance*100/c.Capacity)
return fmt.Sprintf("%s%s%s",
white("["),
buffer.String(),
white(fmt.Sprintf("] %2d%%", c.LocalBalance*100/c.Capacity)))
},
}
case "LOCAL":
channels.columns[i] = channelsColumn{
width: 12,
name: fmt.Sprintf("%12s", columns[i]),
display: func(c *netmodels.Channel) string {
return color.Cyan(printer.Sprintf("%12d", c.LocalBalance))
display: func(c *netmodels.Channel, opts ...color.Option) string {
return color.Cyan(opts...)(printer.Sprintf("%12d", c.LocalBalance))
},
}
case "CAP":
channels.columns[i] = channelsColumn{
width: 12,
name: fmt.Sprintf("%12s", columns[i]),
display: func(c *netmodels.Channel) string {
return printer.Sprintf("%12d", c.Capacity)
display: func(c *netmodels.Channel, opts ...color.Option) string {
return color.White(opts...)(printer.Sprintf("%12d", c.Capacity))
},
}
case "HTLC":
channels.columns[i] = channelsColumn{
width: 5,
name: fmt.Sprintf("%5s", columns[i]),
display: func(c *netmodels.Channel) string {
return color.Yellow(fmt.Sprintf("%5d", len(c.PendingHTLC)))
display: func(c *netmodels.Channel, opts ...color.Option) string {
return color.Yellow(opts...)(fmt.Sprintf("%5d", len(c.PendingHTLC)))
},
}
case "UNSETTLED":
channels.columns[i] = channelsColumn{
width: 10,
name: fmt.Sprintf("%-10s", columns[i]),
display: func(c *netmodels.Channel) string {
return color.Yellow(printer.Sprintf("%10d", c.UnsettledBalance))
display: func(c *netmodels.Channel, opts ...color.Option) string {
return color.Yellow(opts...)(printer.Sprintf("%10d", c.UnsettledBalance))
},
}
case "CFEE":
channels.columns[i] = channelsColumn{
width: 6,
name: fmt.Sprintf("%-6s", columns[i]),
display: func(c *netmodels.Channel) string {
return printer.Sprintf("%6d", c.CommitFee)
display: func(c *netmodels.Channel, opts ...color.Option) string {
return color.White(opts...)(printer.Sprintf("%6d", c.CommitFee))
},
}
case "LAST UPDATE":
channels.columns[i] = channelsColumn{
width: 15,
name: fmt.Sprintf("%-15s", columns[i]),
display: func(c *netmodels.Channel) string {
display: func(c *netmodels.Channel, opts ...color.Option) string {
if c.LastUpdate != nil {
return color.Cyan(
return color.Cyan(opts...)(
fmt.Sprintf("%15s", c.LastUpdate.Format("15:04:05 Jan _2")),
)
}
@ -304,29 +309,29 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
channels.columns[i] = channelsColumn{
width: 7,
name: fmt.Sprintf("%-7s", columns[i]),
display: func(c *netmodels.Channel) string {
display: func(c *netmodels.Channel, opts ...color.Option) string {
if c.Private {
return color.Red("private")
return color.Red(opts...)("private")
}
return color.Green("public ")
return color.Green(opts...)("public ")
},
}
case "ID":
channels.columns[i] = channelsColumn{
width: 19,
name: fmt.Sprintf("%-19s", columns[i]),
display: func(c *netmodels.Channel) string {
display: func(c *netmodels.Channel, opts ...color.Option) string {
if c.ID == 0 {
return fmt.Sprintf("%-19s", "")
}
return fmt.Sprintf("%d", c.ID)
return color.White(opts...)(fmt.Sprintf("%d", c.ID))
},
}
default:
channels.columns[i] = channelsColumn{
width: 21,
name: fmt.Sprintf("%-21s", columns[i]),
display: func(c *netmodels.Channel) string {
display: func(c *netmodels.Channel, opts ...color.Option) string {
return "column does not exist"
},
}
@ -336,20 +341,20 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
return channels
}
func status(c *netmodels.Channel) string {
func status(c *netmodels.Channel, opts ...color.Option) string {
switch c.Status {
case netmodels.ChannelActive:
return color.Green(fmt.Sprintf("%-13s", "active"))
return color.Green(opts...)(fmt.Sprintf("%-13s", "active"))
case netmodels.ChannelInactive:
return color.Red(fmt.Sprintf("%-13s", "inactive"))
return color.Red(opts...)(fmt.Sprintf("%-13s", "inactive"))
case netmodels.ChannelOpening:
return color.Yellow(fmt.Sprintf("%-13s", "opening"))
return color.Yellow(opts...)(fmt.Sprintf("%-13s", "opening"))
case netmodels.ChannelClosing:
return color.Yellow(fmt.Sprintf("%-13s", "closing"))
return color.Yellow(opts...)(fmt.Sprintf("%-13s", "closing"))
case netmodels.ChannelForceClosing:
return color.Yellow(fmt.Sprintf("%-13s", "force closing"))
return color.Yellow(opts...)(fmt.Sprintf("%-13s", "force closing"))
case netmodels.ChannelWaitingClose:
return color.Yellow(fmt.Sprintf("%-13s", "waiting close"))
return color.Yellow(opts...)(fmt.Sprintf("%-13s", "waiting close"))
}
return ""
}

@ -44,19 +44,20 @@ func (h *Header) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
network = "mainnet"
}
sync := color.Yellow("[syncing]")
sync := color.Yellow()("[syncing]")
if h.Info.Synced {
sync = color.Green("[synced]")
sync = color.Green()("[synced]")
}
v.Clear()
cyan := color.Cyan()
fmt.Fprintln(v, fmt.Sprintf("%s %s %s %s %s %s",
color.CyanBg(h.Info.Alias),
color.Cyan(fmt.Sprintf("%s-v%s", "lnd", version)),
color.Cyan(color.Background)(h.Info.Alias),
cyan(fmt.Sprintf("%s-v%s", "lnd", version)),
fmt.Sprintf("%s %s", chain, network),
sync,
fmt.Sprintf("%s %d", color.Cyan("height:"), h.Info.BlockHeight),
fmt.Sprintf("%s %d", color.Cyan("peers:"), h.Info.NumPeers),
fmt.Sprintf("%s %d", cyan("height:"), h.Info.BlockHeight),
fmt.Sprintf("%s %d", cyan("peers:"), h.Info.NumPeers),
))
return nil
}

@ -55,13 +55,14 @@ func (h Help) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
}
}
h.view.Frame = false
cyan := color.Cyan()
fmt.Fprintln(h.view, fmt.Sprintf("lntop %s - (C) 2019 Edouard Paris", version))
fmt.Fprintln(h.view, "Released under the MIT License")
fmt.Fprintln(h.view, "")
fmt.Fprintln(h.view, fmt.Sprintf("%6s %s",
color.Cyan("F1 h:"), "show/close this help screen"))
cyan("F1 h:"), "show/close this help screen"))
fmt.Fprintln(h.view, fmt.Sprintf("%6s %s",
color.Cyan("F10 q:"), "quit"))
cyan("F10 q:"), "quit"))
_, err = g.SetCurrentView(HELP)
return err
}

@ -53,31 +53,35 @@ func (s *Summary) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
func (s *Summary) display() {
s.left.Clear()
p := message.NewPrinter(language.English)
fmt.Fprintln(s.left, color.Green("[ Channels ]"))
green := color.Green()
yellow := color.Yellow()
cyan := color.Cyan()
red := color.Red()
fmt.Fprintln(s.left, green("[ Channels ]"))
fmt.Fprintln(s.left, p.Sprintf("%s %d (%s|%s)",
color.Cyan("balance:"),
cyan("balance:"),
s.channelsBalance.Balance+s.channelsBalance.PendingOpenBalance,
color.Green(p.Sprintf("%d", s.channelsBalance.Balance)),
color.Yellow(p.Sprintf("%d", s.channelsBalance.PendingOpenBalance)),
green(p.Sprintf("%d", s.channelsBalance.Balance)),
yellow(p.Sprintf("%d", s.channelsBalance.PendingOpenBalance)),
))
fmt.Fprintln(s.left, fmt.Sprintf("%s %d %s %d %s %d %s",
color.Cyan("state :"),
s.info.NumActiveChannels, color.Green("active"),
s.info.NumPendingChannels, color.Yellow("pending"),
s.info.NumInactiveChannels, color.Red("inactive"),
cyan("state :"),
s.info.NumActiveChannels, green("active"),
s.info.NumPendingChannels, yellow("pending"),
s.info.NumInactiveChannels, red("inactive"),
))
fmt.Fprintln(s.left, fmt.Sprintf("%s %s",
color.Cyan("gauge :"),
cyan("gauge :"),
gaugeTotal(s.channelsBalance.Balance, s.channels.List()),
))
s.right.Clear()
fmt.Fprintln(s.right, color.Green("[ Wallet ]"))
fmt.Fprintln(s.right, green("[ Wallet ]"))
fmt.Fprintln(s.right, p.Sprintf("%s %d (%s|%s)",
color.Cyan("balance:"),
cyan("balance:"),
s.walletBalance.TotalBalance,
color.Green(p.Sprintf("%d", s.walletBalance.ConfirmedBalance)),
color.Yellow(p.Sprintf("%d", s.walletBalance.UnconfirmedBalance)),
green(p.Sprintf("%d", s.walletBalance.ConfirmedBalance)),
yellow(p.Sprintf("%d", s.walletBalance.UnconfirmedBalance)),
))
}
@ -93,9 +97,10 @@ func gaugeTotal(balance int64, channels []*netmodels.Channel) string {
index := int(balance * int64(20) / capacity)
var buffer bytes.Buffer
cyan := color.Cyan()
for i := 0; i < 20; i++ {
if i < index {
buffer.WriteString(color.Cyan("|"))
buffer.WriteString(cyan("|"))
continue
}
buffer.WriteString(" ")

@ -84,11 +84,12 @@ func (c *Transaction) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
footer.BgColor = gocui.ColorCyan
footer.FgColor = gocui.ColorBlack
footer.Clear()
blackBg := color.Black(color.Background)
fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s %s%s",
color.BlackBg("F1"), "Help",
color.BlackBg("F2"), "Menu",
color.BlackBg("Enter"), "Transactions",
color.BlackBg("F10"), "Quit",
blackBg("F1"), "Help",
blackBg("F2"), "Menu",
blackBg("Enter"), "Transactions",
blackBg("F10"), "Quit",
))
return nil
}
@ -112,22 +113,24 @@ func (c *Transaction) display() {
v := c.view
v.Clear()
transaction := c.transaction.Item
fmt.Fprintln(v, color.Green(" [ Transaction ]"))
green := color.Green()
cyan := color.Cyan()
fmt.Fprintln(v, green(" [ Transaction ]"))
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" Date:"), transaction.Date.Format("15:04:05 Jan _2")))
cyan(" Date:"), transaction.Date.Format("15:04:05 Jan _2")))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Amount:"), transaction.Amount))
cyan(" Amount:"), transaction.Amount))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" Fee:"), transaction.TotalFees))
cyan(" Fee:"), transaction.TotalFees))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan(" BlockHeight:"), transaction.BlockHeight))
cyan(" BlockHeight:"), transaction.BlockHeight))
fmt.Fprintln(v, p.Sprintf("%s %d",
color.Cyan("NumConfirmations:"), transaction.NumConfirmations))
cyan("NumConfirmations:"), transaction.NumConfirmations))
fmt.Fprintln(v, p.Sprintf("%s %s",
color.Cyan(" BlockHash:"), transaction.BlockHash))
cyan(" BlockHash:"), transaction.BlockHash))
fmt.Fprintln(v, fmt.Sprintf("%s %s",
color.Cyan(" TxHash:"), transaction.TxHash))
fmt.Fprintln(v, "[addresses]")
cyan(" TxHash:"), transaction.TxHash))
fmt.Fprintln(v, green("[ addresses ]"))
}
func NewTransaction(transaction *models.Transaction) *Transaction {

@ -37,7 +37,7 @@ type Transactions struct {
type transactionsColumn struct {
name string
display func(*netmodels.Transaction) string
display func(*netmodels.Transaction, ...color.Option) string
}
func (c Transactions) Index() int {
@ -131,11 +131,12 @@ func (c *Transactions) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
footer.BgColor = gocui.ColorCyan
footer.FgColor = gocui.ColorBlack
footer.Clear()
blackBg := color.Black(color.Background)
fmt.Fprintln(footer, fmt.Sprintf("%s%s %s%s %s%s %s%s",
color.BlackBg("F1"), "Help",
color.BlackBg("F2"), "Menu",
color.BlackBg("Enter"), "Transaction",
color.BlackBg("F10"), "Quit",
blackBg("F1"), "Help",
blackBg("F2"), "Menu",
blackBg("Enter"), "Transaction",
blackBg("F10"), "Quit",
))
return nil
}
@ -175,8 +176,8 @@ func NewTransactions(txs *models.Transactions) *Transactions {
case "TIME":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%-15s", columns[i]),
display: func(tx *netmodels.Transaction) string {
return color.Cyan(
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return color.Cyan(opts...)(
fmt.Sprintf("%15s", tx.Date.Format("15:04:05 Jan _2")),
)
},
@ -184,60 +185,60 @@ func NewTransactions(txs *models.Transactions) *Transactions {
case "HEIGHT":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%8s", columns[i]),
display: func(tx *netmodels.Transaction) string {
return fmt.Sprintf("%8d", tx.BlockHeight)
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return color.White(opts...)(fmt.Sprintf("%8d", tx.BlockHeight))
},
}
case "ADDRESSES":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%10s", columns[i]),
display: func(tx *netmodels.Transaction) string {
return fmt.Sprintf("%10d", len(tx.DestAddresses))
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return color.White(opts...)(fmt.Sprintf("%10d", len(tx.DestAddresses)))
},
}
case "FEE":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%8s", columns[i]),
display: func(tx *netmodels.Transaction) string {
return fmt.Sprintf("%8d", tx.TotalFees)
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return color.White(opts...)(fmt.Sprintf("%8d", tx.TotalFees))
},
}
case "CONFIR":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%8s", columns[i]),
display: func(tx *netmodels.Transaction) string {
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
n := fmt.Sprintf("%8d", tx.NumConfirmations)
if tx.NumConfirmations < 6 {
return color.Yellow(n)
return color.Yellow(opts...)(n)
}
return color.Green(n)
return color.Green(opts...)(n)
},
}
case "TXHASH":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%-64s", columns[i]),
display: func(tx *netmodels.Transaction) string {
return fmt.Sprintf("%13s", tx.TxHash)
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return color.White(opts...)(fmt.Sprintf("%13s", tx.TxHash))
},
}
case "BLOCKHASH":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%-64s", columns[i]),
display: func(tx *netmodels.Transaction) string {
return fmt.Sprintf("%13s", tx.TxHash)
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return color.White(opts...)(fmt.Sprintf("%13s", tx.TxHash))
},
}
case "AMOUNT":
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%13s", columns[i]),
display: func(tx *netmodels.Transaction) string {
return printer.Sprintf("%13d", tx.Amount)
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return color.White(opts...)(printer.Sprintf("%13d", tx.Amount))
},
}
default:
transactions.columns[i] = transactionsColumn{
name: fmt.Sprintf("%-21s", columns[i]),
display: func(tx *netmodels.Transaction) string {
display: func(tx *netmodels.Transaction, opts ...color.Option) string {
return "column does not exist"
},
}

Loading…
Cancel
Save