aboutsummaryrefslogtreecommitdiffstats
path: root/gosrc/workspace.go
blob: 7b1d3ce88316d7ff6bc81d7139697a56a7a3659d (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package main

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

type nodeValue string

func (nv nodeValue) String() string {
	return string(nv)
}

//
//
func (d DisplayGrid) handleEnter(config Config) {
	switch d.name {
	case "main":
		if d.tree.SelectedNode().Nodes == nil {
			rep, err := sendRequest(d.tree.SelectedNode().Value.String(), config)
			if rep == nil || err != nil {
				d.output.Text = "something went wrong :^{"
			} else {
				displayResponse(d.tree.SelectedNode().Value.String(), rep, &d.output.Text)
				defer rep.Body.Close()
			}
		}
	}
}

// create workspace one, where general information is displayed and fetched
func createMainWorkspace(config Config) *DisplayGrid {
	// set widgets
	p1 := widgets.NewParagraph()
	requestTree := []*widgets.TreeNode{
		{
			Value: nodeValue("Information"),
			Nodes:[]*widgets.TreeNode{
				{
					Value: nodeValue("Account Status"),
					Nodes:nil,
				},
				{
					Value: nodeValue("Available Coins"),
					Nodes: nil,
				}, {
					Value: nodeValue("Deposit Address"),
					Nodes: nil,
				},
				{
					Value: nodeValue("Daily Snapshot"),
					Nodes: nil,
				},
			},
		},
		{
			Value: nodeValue("Actions"),
			Nodes:[]*widgets.TreeNode{
				{
					Value: nodeValue("Buy x coin"),
					Nodes:nil,
				},
			},
		},
	}
	tree := widgets.NewTree()
	tree.WrapText = false
	tree.SetNodes(requestTree)
	tree.TextStyle = ui.NewStyle(ui.ColorYellow)

	p2 := widgets.NewParagraph()
	output := widgets.NewParagraph()
	p5 := widgets.NewParagraph()

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

	p1.Border = true
	p2.Border = true
	output.Border = true
	output.TextStyle.Fg = ui.ColorGreen

	p1.Title = "Active Mirror"
	p2.Title = "Balance"
	output.Title = "Output"
	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(0.1, p2),
		ui.NewRow(0.8,
			ui.NewCol(0.2, tree),
			ui.NewCol(0.8, output),
		),
	)

	grid := DisplayGrid{
		output: output,
		tree: tree,
		grid: main_grid,
		name: "main",
	}
	return &grid
}

// create workspace two, where the user can trade symbols
func createTradeWorkspace(config Config) *DisplayGrid {
	output    := widgets.NewParagraph()
	ticker    := widgets.NewParagraph()
	strategy  := widgets.NewParagraph()
	tree      := widgets.NewTree()
	main_grid := ui.NewGrid()

	ticker.Title   = "symbol"
	ticker.Text   = "<pick a symbol>"
	strategy.Title   = "strategy"
	strategy.Text = "<then, pick a strategy>"

	requestTree := []*widgets.TreeNode{
		{
			Value: nodeValue("Available Symbols"),
			Nodes:[]*widgets.TreeNode{
				{
					Value: nodeValue("BTCETH"),
					Nodes:nil,
				},
			},
		},
		{
			Value: nodeValue("Available Strategies"),
			Nodes:[]*widgets.TreeNode{
				{
					Value: nodeValue("FizzBozzNacci(TM)"),
					Nodes:nil,
				},
			},
		},
	}
	tree.WrapText = false
	tree.SetNodes(requestTree)
	tree.TextStyle = ui.NewStyle(ui.ColorYellow)

	termWidth, termHeight := ui.TerminalDimensions()
	main_grid.SetRect(0, 0, termWidth, termHeight)
	main_grid.Border = true
	main_grid.Set(
		ui.NewRow(0.1, ticker),
		ui.NewRow(0.1, strategy),
		ui.NewRow(0.8,
			ui.NewCol(0.2, tree),
			ui.NewCol(0.8, output),
		),
	)
	grid := DisplayGrid{
		output: output,
		tree: tree,
		grid: main_grid,
		name: "trading",
	}
	return &grid
}