Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small termui fixes #4976

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmd/termui/view/termuic/termuiRenders/widgetsRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (wr *WidgetsRender) prepareInstanceInfo() {
rows[5] = []string{computeRedundancyStr(wr.presenter.GetRedundancyLevel(), wr.presenter.GetRedundancyIsMainActive())}
rows[6] = []string{fmt.Sprintf("Chain ID: %s", chainID)}

wr.instanceInfo.Title = "MultiversX instance info"
wr.instanceInfo.Title = "MultiversX instance info:"
wr.instanceInfo.RowSeparator = false
wr.instanceInfo.Rows = rows
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (wr *WidgetsRender) prepareChainInfo(numMillisecondsRefreshTime int) {
numConnectedPeers, numIntraShardValidators, numConnectedNodes)}
rows[9] = []string{fmt.Sprintf("All known validators: %d", numLiveValidators)}

wr.chainInfo.Title = "Chain info"
wr.chainInfo.Title = "Chain info:"
wr.chainInfo.RowSeparator = false
wr.chainInfo.Rows = rows
}
Expand Down Expand Up @@ -323,18 +323,18 @@ func (wr *WidgetsRender) prepareBlockInfo() {
currentRoundTimestamp := wr.presenter.GetCurrentRoundTimestamp()
rows[7] = []string{fmt.Sprintf("Current round timestamp: %d", currentRoundTimestamp)}

wr.blockInfo.Title = "Block info"
wr.blockInfo.Title = "Block info:"
wr.blockInfo.RowSeparator = false
wr.blockInfo.Rows = rows
}

func (wr *WidgetsRender) prepareListWithLogsForDisplay() {
wr.lLog.Title = "Log info"
wr.lLog.Title = "Log info:"
wr.lLog.TextStyle = ui.NewStyle(ui.ColorWhite)

logData := wr.presenter.GetLogLines()
wr.lLog.Rows = wr.prepareLogLines(logData, wr.lLog.Size().Y)
wr.lLog.WrapText = true
wr.lLog.WrapText = false
}

func (wr *WidgetsRender) prepareLogLines(logData []string, size int) []string {
Expand Down Expand Up @@ -370,13 +370,13 @@ func fitStringToWidth(original string, maxWidth int) string {

func (wr *WidgetsRender) prepareLoads() {
cpuLoadPercent := wr.presenter.GetCpuLoadPercent()
wr.cpuLoad.Title = "CPU load"
wr.cpuLoad.Title = "CPU load:"
wr.cpuLoad.Percent = int(cpuLoadPercent)

memLoadPercent := wr.presenter.GetMemLoadPercent()
memTotalMemoryBytes := wr.presenter.GetTotalMem()
memUsed := wr.presenter.GetMemUsedByNode()
wr.memoryLoad.Title = "Memory load"
wr.memoryLoad.Title = "Memory load:"
wr.memoryLoad.Percent = int(memLoadPercent)
str := fmt.Sprintf("%d%% / used: %s / total: %s", memLoadPercent, core.ConvertBytes(memUsed), core.ConvertBytes(memTotalMemoryBytes))
wr.memoryLoad.Label = fitStringToWidth(str, wr.memoryLoad.Size().X)
Expand Down
45 changes: 45 additions & 0 deletions cmd/termui/view/termuic/termuiRenders/widgetsRender_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package termuiRenders

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestWidgetsRender_prepareLogLines(t *testing.T) {
t.Parallel()

wr := &WidgetsRender{}
numLogLines := 25
testLogLines25 := make([]string, 0, numLogLines)
for i := 0; i < numLogLines; i++ {
testLogLines25 = append(testLogLines25, fmt.Sprintf("test line %d", i))
}

t.Run("small size should return empty", func(t *testing.T) {
t.Parallel()

for i := 0; i <= 2; i++ {
result := wr.prepareLogLines(testLogLines25, i)
assert.Empty(t, result)
}
})
t.Run("equal size should return the same slice", func(t *testing.T) {
t.Parallel()

result := wr.prepareLogLines(testLogLines25, numLogLines+2)
assert.Equal(t, testLogLines25, result)
})
t.Run("should trim", func(t *testing.T) {
t.Parallel()

result := wr.prepareLogLines(testLogLines25, numLogLines)
assert.Equal(t, testLogLines25[2:], result)
assert.Equal(t, 23, len(result))

result = wr.prepareLogLines(testLogLines25, 10)
assert.Equal(t, testLogLines25[17:], result)
assert.Equal(t, 8, len(result))
})
}