File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed
Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,18 @@ type ProfileUI struct {
1717 SiteUrl string
1818}
1919
20+ // Simple Key Value pair used for ordered output
21+ // since map produces unordered kv pairs while iterating
2022type KV struct {
2123 Key string
2224 Value string
2325}
2426
2527func (p * ProfileUI ) Render () error {
28+ // convert minutes to days
2629 daysWatched := float32 (p .MinutesWatched ) / 1440
2730
31+ // populating []KV with data
2832 var dataSlice = []KV {
2933 {"ID" , strconv .Itoa (p .Id )},
3034 {"Name" , p .Name },
@@ -35,16 +39,20 @@ func (p *ProfileUI) Render() error {
3539 {"Site URL" , p .SiteUrl },
3640 }
3741
42+ // finding the max key length for padded output
3843 maxKeyLen := 0
3944 for _ , kv := range dataSlice {
4045 if len (kv .Key ) > maxKeyLen {
4146 maxKeyLen = len (kv .Key )
4247 }
4348 }
4449
50+ // define styles for both key and value string
4551 keyStyle := lipgloss .NewStyle ().Bold (true ).Foreground (lipgloss .Color ("#FF79C6" ))
4652 valueStyle := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#8BE9FD" ))
4753
54+ // iterating over dataSlice and printing the KV pairs
55+ // with appropriate padding
4856 for _ , kv := range dataSlice {
4957 fmt .Printf (
5058 "%s : %s\n " ,
Original file line number Diff line number Diff line change @@ -2,20 +2,23 @@ package ui
22
33import "github.com/charmbracelet/lipgloss"
44
5+ // displays text in green with ✓ on the left
56func SuccessText (msg string ) string {
67 return lipgloss .
78 NewStyle ().
89 Foreground (lipgloss .Color ("#00FF00" )).
910 Render ("✓ " + msg )
1011}
1112
13+ // displays text in red with ✘ on the left
1214func ErrorText (err error ) string {
1315 return lipgloss .
1416 NewStyle ().
1517 Foreground (lipgloss .Color ("#CC0000" )).
1618 Render ("✘ Someting went wrong! Reason: " , err .Error ())
1719}
1820
21+ // displays text in cyan foreground
1922func HighlightedText (msg string ) string {
2023 return lipgloss .
2124 NewStyle ().
Original file line number Diff line number Diff line change @@ -6,11 +6,13 @@ import (
66)
77
88func HandleProfile () error {
9+ // get profile info from API
910 profile , err := api .GetUserProfile ()
1011 if err != nil {
1112 return err
1213 }
1314
15+ // populate ProfileUI struct fields with the data from API
1416 profileUI := ui.ProfileUI {
1517 Id : profile .Data .Viewer .Id ,
1618 Name : profile .Data .Viewer .Name ,
@@ -21,6 +23,7 @@ func HandleProfile() error {
2123 SiteUrl : profile .Data .Viewer .SiteUrl ,
2224 }
2325
26+ // display profile UI
2427 err = profileUI .Render ()
2528 return err
2629}
You can’t perform that action at this time.
0 commit comments