aboutsummaryrefslogtreecommitdiffstats
path: root/gosrc/main.go
blob: a83189eb0d930702fecd40396707c4fc24f53e6c (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//   SMITH            (  //       /
//   main              ( )/       /
//   by salade         )(/        /
//  ________________  ( /)        /
// ()__)____________)))))   :^}   /

package main

import (
	"encoding/json"
	"io/ioutil"
	"fmt"
	"log"
	"os"
	"time"

	ui "github.com/gizak/termui/v3"
	"github.com/gizak/termui/v3/widgets"
)

func main() {
	// get user config from json file
	config_path := "./config.json"
	for i, a := range os.Args[1:] {
		if a == "-c" || a == "--config" {
			config_path = os.Args[i + 2]
		}
	}
	config_content, err := ioutil.ReadFile(config_path)
	if err != nil {
		log.Fatal("error: config file not found", err)
	}
	var config Config
	err = json.Unmarshal(config_content, &config)
	if err != nil {
		log.Fatal("error: marshall() ", err)
	}

	if err != nil {
		log.Fatal("error: request failed %s", "qwe", err)
		return
	}
	// make a cool ui
	ui_loop(config)

	fmt.Println("qwe")
	defer ui.Close()
	return
}

// draw stuff
func ui_loop(config Config) error {
	if err := ui.Init(); err != nil {
		log.Fatal("error: failed to initialize termui", err)
	}

	// set widgets
	p1 := widgets.NewParagraph()
	p2 := widgets.NewParagraph()
	p3 := widgets.NewParagraph()
	p4 := widgets.NewParagraph()
	p5 := widgets.NewParagraph()

	p1.Text = config.Mirror
	p2.Text = "1000.0 BTC"
	p3.Text = "hello"
	p4.Text = "cool"
	p5.Text = "__MR_SMITH_V001__"
	p5.TextStyle.Fg = ui.ColorGreen

	p1.Border = true
	p2.Border = true
	p3.Border = true
	p4.Border = true

	p1.Title = "Active Mirror"
	p2.Title = "Balance"
	p3.Title = "public"
	p4.Title = "Key"
	p5.Title = "hello"

	main_grid := ui.NewGrid()
	termWidth, termHeight := ui.TerminalDimensions()
	main_grid.SetRect(0, 0, termWidth, termHeight)
	main_grid.Border = true

	// add items to grid
	main_grid.Set(
		ui.NewRow(0.1, p5),
		ui.NewRow(1.0/8, p2),
		ui.NewRow(1.0/2, p1),
		ui.NewRow(1.0/2,
			ui.NewCol(1.0/2, p3),
			ui.NewCol(1.0/2, p4),
		),
	)

	// ui update loop
	ui.Render(main_grid)
	ui_events := ui.PollEvents()
	ticker := time.NewTicker(time.Second).C
	ticker_count := 0
	for {
		select {
		case e := <-ui_events:
			switch e.ID {
				case "<C-c>":
					return nil
				case "<Resize>":
					payload := e.Payload.(ui.Resize)
					main_grid.SetRect(0, 0, payload.Width, payload.Height)
					ui.Clear()
					ui.Render(main_grid)
				default:
					p3.Text = e.ID
			}
		case <-ticker:
			ui.Render(main_grid)
			ticker_count++
		}
	}
}

// make request body and sign it
// body := make_body()
// signature := sign_request(body, config.Secret_key)
// res, err := send_request(body, signature, Endpoints.getall, config)