Skip to content

Commit

Permalink
Merge pull request #4976 from multiversx/fix-termui-logs
Browse files Browse the repository at this point in the history
Small termui fixes
  • Loading branch information
iulianpascalau committed Feb 9, 2023
2 parents cf213fd + e641ade commit eb39125
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
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))
})
}

0 comments on commit eb39125

Please sign in to comment.