From 6424c502b18ff2f0b263b46729b1d76585e1ad39 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Sat, 30 Apr 2022 20:34:07 +0200 Subject: refactor to to make space for multiple views/workspaces --- gosrc/main.go | 107 +++++++--------------------------------------------------- 1 file changed, 13 insertions(+), 94 deletions(-) (limited to 'gosrc/main.go') diff --git a/gosrc/main.go b/gosrc/main.go index edc3033..8e6417a 100644 --- a/gosrc/main.go +++ b/gosrc/main.go @@ -14,7 +14,6 @@ import ( "time" ui "github.com/gizak/termui/v3" - "github.com/gizak/termui/v3/widgets" ) type nodeValue string @@ -52,81 +51,10 @@ func ui_loop(config Config) error { log.Fatal("error: failed to initialize termui", err) } - // 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, - }, - }, - }, - } - l := widgets.NewTree() - l.WrapText = false - l.SetNodes(requestTree) - l.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, l), - ui.NewCol(0.8, output), - ), - ) - + // create default grid + active_grid := createMainWorkspace(config) // ui update loop - ui.Render(main_grid) + ui.Render(active_grid.grid) ui_events := ui.PollEvents() ticker := time.NewTicker(time.Second).C ticker_count := 0 @@ -138,38 +66,29 @@ func ui_loop(config Config) error { return nil case "": payload := e.Payload.(ui.Resize) - main_grid.SetRect(0, 0, payload.Width, payload.Height) + active_grid.grid.SetRect(0, 0, payload.Width, payload.Height) ui.Clear() case "j", "": - l.ScrollDown() + active_grid.tree.ScrollDown() case "k", "": - l.ScrollUp() + active_grid.tree.ScrollUp() case "e": - l.ToggleExpand() + active_grid.tree.ToggleExpand() case "": - l.ScrollTop() + active_grid.tree.ScrollTop() case "G", "": - l.ScrollBottom() + active_grid.tree.ScrollBottom() case "E": - l.ExpandAll() + active_grid.tree.ExpandAll() case "C": - l.CollapseAll() + active_grid.tree.CollapseAll() case "": - if l.SelectedNode().Nodes == nil { - rep, err := sendRequest(l.SelectedNode().Value.String(), config) - if rep == nil || err != nil { - output.Text = "something went wrong :^{" - } else { - displayResponse(l.SelectedNode().Value.String(), rep, &output.Text) - defer rep.Body.Close() - } - } + active_grid.handleEnter(config) } case <-ticker: ticker_count++ default: - ui.Render(main_grid) + ui.Render(active_grid.grid) } } } - -- cgit v1.2.3