github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/lnutil/color.go (about)

     1  package lnutil
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/fatih/color"
     7  )
     8  
     9  var (
    10  	White  = color.New(color.FgHiWhite).SprintFunc()
    11  	Green  = color.New(color.FgHiGreen).SprintFunc()
    12  	Red    = color.New(color.FgHiRed).SprintFunc()
    13  	Yellow = color.New(color.FgHiYellow).SprintFunc()
    14  
    15  	Header   = color.New(color.FgHiCyan).SprintFunc()
    16  	Prompt   = color.New(color.FgHiYellow).SprintFunc()
    17  	OutPoint = color.New(color.FgYellow).SprintFunc()
    18  	Address  = color.New(color.FgMagenta).SprintFunc()
    19  	BTC      = color.New(color.FgHiWhite).SprintFunc()
    20  	Satoshi  = color.New(color.Faint).SprintFunc()
    21  	MicroBTC = color.New(color.FgYellow, color.Faint).SprintFunc()
    22  )
    23  
    24  func ReqColor(required ...interface{}) string {
    25  	var s string
    26  	for i := 0; i < len(required); i++ {
    27  		s += " <"
    28  		s += White(required[i])
    29  		s += ">"
    30  	}
    31  	return s
    32  }
    33  
    34  func OptColor(optional ...interface{}) string {
    35  	var s string
    36  	var tail string
    37  	for i := 0; i < len(optional); i++ {
    38  		s += " [<"
    39  		s += White(optional[i])
    40  		s += ">"
    41  		tail += "]"
    42  	}
    43  	return s + tail
    44  }
    45  
    46  func SatoshiColor(value int64) string {
    47  
    48  	uBTC := value / 100
    49  	mBTC := uBTC / 1000
    50  	btc := mBTC / 1000
    51  
    52  	sat := value
    53  
    54  	if uBTC < 1 {
    55  		return fmt.Sprintf("%s", Satoshi(sat))
    56  	}
    57  
    58  	uBTC -= (mBTC * 1000)
    59  	sat -= (uBTC * 100)
    60  
    61  	if mBTC < 1 {
    62  		return fmt.Sprintf("%s%s", MicroBTC(uBTC), Satoshi(fmt.Sprintf("%02d", sat)))
    63  	}
    64  
    65  	mBTC -= (btc * 1000)
    66  	sat -= (mBTC * 100000)
    67  
    68  	if btc < 1 {
    69  		return fmt.Sprintf("%d%s%s",
    70  			mBTC,
    71  			MicroBTC(fmt.Sprintf("%03d", uBTC)),
    72  			Satoshi(fmt.Sprintf("%02d", sat)))
    73  	}
    74  
    75  	sat -= btc * 100000000
    76  
    77  	return fmt.Sprintf("%s%03d%s%s",
    78  		BTC(btc),
    79  		mBTC,
    80  		MicroBTC(fmt.Sprintf("%03d", uBTC)),
    81  		Satoshi(fmt.Sprintf("%02d", sat)))
    82  }