From 752f14ae8f64e22890c7ab3ffef0a8b9e751f4b2 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Sun, 1 May 2022 22:35:20 +0200 Subject: workspaces --- gosrc/main.go | 13 ++++---- gosrc/workspace.go | 88 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 83 insertions(+), 18 deletions(-) diff --git a/gosrc/main.go b/gosrc/main.go index 8e6417a..4239322 100644 --- a/gosrc/main.go +++ b/gosrc/main.go @@ -16,12 +16,6 @@ import ( ui "github.com/gizak/termui/v3" ) -type nodeValue string - -func (nv nodeValue) String() string { - return string(nv) -} - func main() { // get user config from json file config_path := "./config.json" @@ -45,7 +39,7 @@ func main() { return } -// draw stuff +// draw stuff and get input func ui_loop(config Config) error { if err := ui.Init(); err != nil { log.Fatal("error: failed to initialize termui", err) @@ -84,6 +78,11 @@ func ui_loop(config Config) error { active_grid.tree.CollapseAll() case "": active_grid.handleEnter(config) + case "2": + active_grid = createTradeWorkspace(config) + ui.Clear() + ui.Render(active_grid.grid) + ui_events = ui.PollEvents() } case <-ticker: ticker_count++ diff --git a/gosrc/workspace.go b/gosrc/workspace.go index 84bea64..7b1d3ce 100644 --- a/gosrc/workspace.go +++ b/gosrc/workspace.go @@ -5,6 +5,14 @@ import ( "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": @@ -20,8 +28,8 @@ func (d DisplayGrid) handleEnter(config Config) { } } - -func createMainWorkspace(config Config) DisplayGrid { +// create workspace one, where general information is displayed and fetched +func createMainWorkspace(config Config) *DisplayGrid { // set widgets p1 := widgets.NewParagraph() requestTree := []*widgets.TreeNode{ @@ -35,8 +43,7 @@ func createMainWorkspace(config Config) DisplayGrid { { Value: nodeValue("Available Coins"), Nodes: nil, - }, - { + }, { Value: nodeValue("Deposit Address"), Nodes: nil, }, @@ -56,10 +63,10 @@ func createMainWorkspace(config Config) DisplayGrid { }, }, } - l := widgets.NewTree() - l.WrapText = false - l.SetNodes(requestTree) - l.TextStyle = ui.NewStyle(ui.ColorYellow) + tree := widgets.NewTree() + tree.WrapText = false + tree.SetNodes(requestTree) + tree.TextStyle = ui.NewStyle(ui.ColorYellow) p2 := widgets.NewParagraph() output := widgets.NewParagraph() @@ -91,14 +98,73 @@ func createMainWorkspace(config Config) DisplayGrid { ui.NewRow(0.1, p5), ui.NewRow(0.1, p2), ui.NewRow(0.8, - ui.NewCol(0.2, l), + ui.NewCol(0.2, tree), ui.NewCol(0.8, output), ), ) - return DisplayGrid{ + + grid := DisplayGrid{ output: output, - tree: l, + 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 = "" + strategy.Title = "strategy" + strategy.Text = "" + + 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 } -- cgit v1.2.3