-
Notifications
You must be signed in to change notification settings - Fork 9
/
format.go
56 lines (48 loc) · 1.52 KB
/
format.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"log"
"github.com/fatih/color"
)
var (
faintWhiteColor = color.New(color.FgWhite, color.Faint).SprintFunc()
hiWhiteColor = color.New(color.FgHiWhite, color.Bold).SprintFunc()
hiWhiteColorF = color.New(color.FgHiWhite, color.Bold).SprintfFunc()
cyanColor = color.New(color.FgBlue, color.Bold).SprintFunc()
errColor = color.New(color.FgHiRed, color.Bold).SprintFunc()
errColorF = color.New(color.FgHiRed, color.Bold).SprintfFunc()
infoColor = color.New(color.FgHiYellow, color.Bold).SprintFunc()
infoColorF = color.New(color.FgHiYellow, color.Bold).SprintfFunc()
)
func formatAmt(amt int64) string {
btc := amt / COIN
ms := amt % COIN / 1e6
ts := amt % 1e6 / 1e3
s := amt % 1e3
if btc > 0 {
return fmt.Sprintf("%s.%s,%s,%s", infoColorF("%d", btc), infoColorF("%02d", ms),
infoColorF("%03d", ts), infoColorF("%03d", s))
}
if ms > 0 {
return fmt.Sprintf("%s,%s,%s", infoColorF("%d", ms), infoColorF("%03d", ts), infoColorF("%03d", s))
}
if ts > 0 {
return fmt.Sprintf("%s,%s", infoColorF("%d", ts), infoColorF("%03d", s))
}
if s >= 0 {
return infoColorF("%d", s)
}
return errColor("error: ", amt)
}
func formatFee(amtMsat int64) string {
if amtMsat < 1000 {
return hiWhiteColorF("0.%03d", amtMsat)
}
return hiWhiteColor(amtMsat / 1000)
}
func formatFeePPM(amtMsat int64, feeMsat int64) string {
return hiWhiteColor(int64(float64(feeMsat) / float64(amtMsat) * 1e6))
}
func logErrorF(fmt string, args ...any) {
log.Print(errColorF(fmt, args...))
}