From 066c3995addba3aa96a02db8594c0e23f371cbab Mon Sep 17 00:00:00 2001 From: Joshua Blanch Date: Tue, 24 Dec 2024 12:08:51 +0000 Subject: [PATCH 1/2] scan: sample tview increment count Signed-off-by: Joshua Blanch --- cmd/scan.go | 30 +++++++++++++++++++++++++++--- go.mod | 4 +++- go.sum | 5 +++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cmd/scan.go b/cmd/scan.go index 5d1f100..06bba14 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" // "github.com/gdamore/tcell/v2" + "time" "github.com/rivo/tview" // "github.com/shirou/gopsutil/v4/cpu" // "github.com/shirou/gopsutil/v4/mem" @@ -26,9 +27,32 @@ $ goup scan } func scanResource(ctx *cli.Context) error { - box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") - if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { - return fmt.Errorf("application error: %w", err) + + // Create a new TextView + textView := tview.NewTextView(). + SetTextAlign(tview.AlignCenter). + SetDynamicColors(true) // Enable color tags if needed + + // Create a new application + app := tview.NewApplication() + + // Update the TextView in a goroutine + go func() { + number := 0 + for { + time.Sleep(1 * time.Second) // Wait for 1 second + number++ + + // Update the TextView's text + app.QueueUpdateDraw(func() { + textView.SetText(fmt.Sprintf("Incrementing Number: %d", number)) + }) + } + }() + + // Set the root and run the application + if err := app.SetRoot(textView, true).Run(); err != nil { + fmt.Println("ooga"); } return nil } diff --git a/go.mod b/go.mod index a415b71..0baaafd 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,9 @@ require ( github.com/charmbracelet/bubbles v0.20.0 github.com/charmbracelet/bubbletea v1.2.4 github.com/charmbracelet/lipgloss v1.0.0 + github.com/gdamore/tcell/v2 v2.7.4 github.com/rivo/tview v0.0.0-20241103174730-c76f7879f592 + github.com/shirou/gopsutil/v3 v3.24.5 github.com/shirou/gopsutil/v4 v4.24.11 github.com/urfave/cli/v2 v2.27.5 ) @@ -19,7 +21,6 @@ require ( github.com/ebitengine/purego v0.8.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/gdamore/encoding v1.0.0 // indirect - github.com/gdamore/tcell/v2 v2.7.4 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect @@ -32,6 +33,7 @@ require ( github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/numcpus v0.8.0 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect diff --git a/go.sum b/go.sum index b5d18e1..2b85469 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,13 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI= +github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk= github.com/shirou/gopsutil/v4 v4.24.11 h1:WaU9xqGFKvFfsUv94SXcUPD7rCkU0vr/asVdQOBZNj8= github.com/shirou/gopsutil/v4 v4.24.11/go.mod h1:s4D/wg+ag4rG0WO7AiTj2BeYCRhym0vM7DHbZRxnIT8= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= From 79f87cb9010512443996208b07ff2895e5e98b60 Mon Sep 17 00:00:00 2001 From: Joshua Blanch Date: Tue, 24 Dec 2024 12:12:05 +0000 Subject: [PATCH 2/2] scan: go fmt Signed-off-by: Joshua Blanch --- cmd/scan.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/scan.go b/cmd/scan.go index 06bba14..9b5cd39 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -3,8 +3,8 @@ package cmd import ( "fmt" // "github.com/gdamore/tcell/v2" - "time" "github.com/rivo/tview" + "time" // "github.com/shirou/gopsutil/v4/cpu" // "github.com/shirou/gopsutil/v4/mem" "github.com/urfave/cli/v2" @@ -52,7 +52,7 @@ func scanResource(ctx *cli.Context) error { // Set the root and run the application if err := app.SetRoot(textView, true).Run(); err != nil { - fmt.Println("ooga"); + fmt.Println("ooga") } return nil }