aboutsummaryrefslogtreecommitdiffstats
path: root/gosrc/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'gosrc/main.go')
-rw-r--r--gosrc/main.go104
1 files changed, 76 insertions, 28 deletions
diff --git a/gosrc/main.go b/gosrc/main.go
index a83189e..496c728 100644
--- a/gosrc/main.go
+++ b/gosrc/main.go
@@ -8,8 +8,9 @@ package main
import (
"encoding/json"
- "io/ioutil"
"fmt"
+ "io"
+ "io/ioutil"
"log"
"os"
"time"
@@ -18,6 +19,12 @@ import (
"github.com/gizak/termui/v3/widgets"
)
+type nodeValue string
+
+func (nv nodeValue) String() string {
+ return string(nv)
+}
+
func main() {
// get user config from json file
config_path := "./config.json"
@@ -37,13 +44,12 @@ func main() {
}
if err != nil {
- log.Fatal("error: request failed %s", "qwe", err)
+ log.Fatalf("error: request failed %s", err)
return
}
- // make a cool ui
- ui_loop(config)
- fmt.Println("qwe")
+ fmt.Println("hello")
+ ui_loop(config)
defer ui.Close()
return
}
@@ -56,27 +62,51 @@ func ui_loop(config Config) error {
// 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("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()
- p3 := widgets.NewParagraph()
- p4 := widgets.NewParagraph()
+ output := widgets.NewParagraph()
p5 := widgets.NewParagraph()
p1.Text = config.Mirror
p2.Text = "1000.0 BTC"
- p3.Text = "hello"
- p4.Text = "cool"
+ output.Text = "hello"
p5.Text = "__MR_SMITH_V001__"
p5.TextStyle.Fg = ui.ColorGreen
p1.Border = true
p2.Border = true
- p3.Border = true
- p4.Border = true
+ output.Border = false
p1.Title = "Active Mirror"
p2.Title = "Balance"
- p3.Title = "public"
- p4.Title = "Key"
+ output.Title = "Output"
p5.Title = "hello"
main_grid := ui.NewGrid()
@@ -88,11 +118,8 @@ func ui_loop(config Config) error {
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.NewRow(1.0/2, l),
+ ui.NewRow(1.0/2, output),
)
// ui update loop
@@ -110,18 +137,39 @@ func ui_loop(config Config) error {
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 "j", "<Down>":
+ l.ScrollDown()
+ case "k", "<Up>":
+ l.ScrollUp()
+ case "e":
+ l.ToggleExpand()
+ case "<Home>":
+ l.ScrollTop()
+ case "G", "<End>":
+ l.ScrollBottom()
+ case "E":
+ l.ExpandAll()
+ case "C":
+ l.CollapseAll()
+ case "<Enter>":
+ if l.SelectedNode().Nodes == nil {
+ body := make_body()
+ signature := sign_request(body, config.Secret_key)
+ rep, err := send_request(body, signature, l.SelectedNode().Value.String(), config)
+ if rep == nil || err != nil {
+ output.Text = "something went wrong :^{"
+ } else {
+ body, _ := io.ReadAll(rep.Body)
+ output.Text = string(body)
+ defer rep.Body.Close()
+ }
+ }
}
- case <-ticker:
- ui.Render(main_grid)
- ticker_count++
+ case <-ticker:
+ ticker_count++
+ default:
+ ui.Render(main_grid)
}
}
}
-// 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)