From b6ac3001b804e42a1f53a513ae1dfb2f86186389 Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Sun, 17 Sep 2023 17:39:33 +0300 Subject: [PATCH 1/4] add kernal version --- cmds/modules/zui/header.go | 23 ++++++++++++++++++++++- cmds/modules/zui/main.go | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cmds/modules/zui/header.go b/cmds/modules/zui/header.go index 12709b6eb..f8b849cc0 100644 --- a/cmds/modules/zui/header.go +++ b/cmds/modules/zui/header.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strings" + "syscall" "github.com/gizak/termui/v3/widgets" "github.com/pkg/errors" @@ -43,6 +44,7 @@ func headerRenderer(ctx context.Context, c zbus.Client, h *widgets.Paragraph, r "\n" + " This is node %s (farmer %s)\n" + " running Zero-OS version [%s](fg:blue) (mode [%s](fg:cyan))\n" + + " kernal: %s\n" + " cache disk: %s" host := stubs.NewVersionMonitorStub(c) @@ -77,10 +79,29 @@ func headerRenderer(ctx context.Context, c zbus.Client, h *widgets.Paragraph, r cache = red("no ssd disks detected") } - h.Text = fmt.Sprintf(s, nodeID, farm, version.String(), env.RunningMode.String(), cache) + var utsname syscall.Utsname + var uname string + if err := syscall.Uname(&utsname); err != nil { + uname = red(err.Error()) + } else { + uname = green(int8ToStr(utsname.Release[:])) + } + + h.Text = fmt.Sprintf(s, nodeID, farm, version.String(), env.RunningMode.String(), uname, cache) r.Signal() } }() return nil } + +func int8ToStr(arr []int8) string { + b := make([]byte, 0, len(arr)) + for _, v := range arr { + if v == 0x00 { + break + } + b = append(b, byte(v)) + } + return string(b) +} diff --git a/cmds/modules/zui/main.go b/cmds/modules/zui/main.go index ba08b706d..6906bc074 100644 --- a/cmds/modules/zui/main.go +++ b/cmds/modules/zui/main.go @@ -67,11 +67,11 @@ func action(ctx *cli.Context) error { header := widgets.NewParagraph() header.Border = true - header.SetRect(0, 0, width, 7) + header.SetRect(0, 0, width, 8) netgrid := ui.NewGrid() netgrid.Title = "Network" - netgrid.SetRect(0, 7, width, 14) + netgrid.SetRect(0, 8, width, 14) resources := ui.NewGrid() resources.Title = "Provision" From 00e43906621ebf19c9d858d6910fc95e014979e0 Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Sun, 17 Sep 2023 17:43:08 +0300 Subject: [PATCH 2/4] fix typo --- cmds/modules/zui/header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/modules/zui/header.go b/cmds/modules/zui/header.go index f8b849cc0..727b65df6 100644 --- a/cmds/modules/zui/header.go +++ b/cmds/modules/zui/header.go @@ -44,7 +44,7 @@ func headerRenderer(ctx context.Context, c zbus.Client, h *widgets.Paragraph, r "\n" + " This is node %s (farmer %s)\n" + " running Zero-OS version [%s](fg:blue) (mode [%s](fg:cyan))\n" + - " kernal: %s\n" + + " kernel: %s\n" + " cache disk: %s" host := stubs.NewVersionMonitorStub(c) From 85e58a28ce435ff0ab178fd6f1e33ffda549a755 Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Sun, 17 Sep 2023 17:58:11 +0300 Subject: [PATCH 3/4] return empty string if arr is empty --- cmds/modules/zui/header.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmds/modules/zui/header.go b/cmds/modules/zui/header.go index 727b65df6..aef5562bd 100644 --- a/cmds/modules/zui/header.go +++ b/cmds/modules/zui/header.go @@ -96,9 +96,13 @@ func headerRenderer(ctx context.Context, c zbus.Client, h *widgets.Paragraph, r } func int8ToStr(arr []int8) string { + if len(arr) == 0 { + return "" + } + b := make([]byte, 0, len(arr)) for _, v := range arr { - if v == 0x00 { + if v == 0 { break } b = append(b, byte(v)) From 17c0f6ee4ecda9b69973d3ce090b8222a94e07f7 Mon Sep 17 00:00:00 2001 From: rawdaGastan Date: Thu, 21 Sep 2023 12:54:13 +0300 Subject: [PATCH 4/4] use unsafe and slice for int8 slice conversion --- cmds/modules/zui/header.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/cmds/modules/zui/header.go b/cmds/modules/zui/header.go index aef5562bd..c165109e5 100644 --- a/cmds/modules/zui/header.go +++ b/cmds/modules/zui/header.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" "syscall" + "unsafe" "github.com/gizak/termui/v3/widgets" "github.com/pkg/errors" @@ -84,7 +85,7 @@ func headerRenderer(ctx context.Context, c zbus.Client, h *widgets.Paragraph, r if err := syscall.Uname(&utsname); err != nil { uname = red(err.Error()) } else { - uname = green(int8ToStr(utsname.Release[:])) + uname = green(string(unsafe.Slice((*byte)(unsafe.Pointer(&utsname.Release)), len(utsname.Release)))) } h.Text = fmt.Sprintf(s, nodeID, farm, version.String(), env.RunningMode.String(), uname, cache) @@ -94,18 +95,3 @@ func headerRenderer(ctx context.Context, c zbus.Client, h *widgets.Paragraph, r return nil } - -func int8ToStr(arr []int8) string { - if len(arr) == 0 { - return "" - } - - b := make([]byte, 0, len(arr)) - for _, v := range arr { - if v == 0 { - break - } - b = append(b, byte(v)) - } - return string(b) -}