diff --git a/pkg/display/table.go b/pkg/display/table.go index 59cc441..d3d6e13 100644 --- a/pkg/display/table.go +++ b/pkg/display/table.go @@ -21,6 +21,10 @@ func NewTableData(columnsCount int) *TableData { } } +func (d *TableData) SetColumnsCount(count int) { + d.ColumnsCount = count +} + func (d *TableData) GetCell(row, column int) *tview.TableCell { index := row*d.ColumnsCount + column text := "" @@ -32,7 +36,7 @@ func (d *TableData) GetCell(row, column int) *tview.TableCell { cell := tview.NewTableCell(text) if index < len(d.Validators) && d.Validators[index].Validator.IsProposer { - cell.SetBackgroundColor(tcell.ColorPeachPuff) + cell.SetBackgroundColor(tcell.ColorForestGreen) } return cell diff --git a/pkg/display/wrapper.go b/pkg/display/wrapper.go index 5a05afe..549a368 100644 --- a/pkg/display/wrapper.go +++ b/pkg/display/wrapper.go @@ -12,9 +12,9 @@ import ( ) const ( - ColumnsAmount = 3 - RowsAmount = 10 - DebugBlockHeight = 2 + DefaultColumnsCount = 3 + RowsAmount = 10 + DebugBlockHeight = 2 ) type Wrapper struct { @@ -30,6 +30,7 @@ type Wrapper struct { HelpModal *tview.Modal InfoBlockWidth int + ColumnsCount int DebugEnabled bool @@ -42,7 +43,7 @@ type Wrapper struct { } func NewWrapper(logger zerolog.Logger, pauseChannel chan bool, appVersion string) *Wrapper { - tableData := NewTableData(ColumnsAmount) + tableData := NewTableData(DefaultColumnsCount) helpTextBytes, _ := static.TemplatesFs.ReadFile("help.txt") helpText := strings.ReplaceAll(string(helpTextBytes), "{{ Version }}", appVersion) @@ -93,6 +94,7 @@ func NewWrapper(logger zerolog.Logger, pauseChannel chan bool, appVersion string Logger: logger.With().Str("component", "display_wrapper").Logger(), DebugEnabled: false, InfoBlockWidth: 2, + ColumnsCount: DefaultColumnsCount, PauseChannel: pauseChannel, IsPaused: false, IsHelpDisplayed: false, @@ -121,6 +123,14 @@ func (w *Wrapper) Start() { w.ToggleHelp() } + if event.Rune() == 'm' { + w.ChangeColumnsCount(true) + } + + if event.Rune() == 'l' { + w.ChangeColumnsCount(false) + } + if event.Rune() == 'p' { w.IsPaused = !w.IsPaused w.PauseChannel <- w.IsPaused @@ -177,7 +187,6 @@ func (w *Wrapper) SetState(state *types.State) { fmt.Fprint(w.ProgressTextView, state.SerializePrevotesProgressbar(width, height/2)) fmt.Fprint(w.ProgressTextView, "\n") fmt.Fprint(w.ProgressTextView, state.SerializePrecommitsProgressbar(width, height/2)) - w.ProgressTextView.Highlight("progress") w.App.Draw() } @@ -197,6 +206,18 @@ func (w *Wrapper) ChangeInfoBlockHeight(increase bool) { w.Redraw() } +func (w *Wrapper) ChangeColumnsCount(increase bool) { + if increase { + w.ColumnsCount++ + } else if !increase && w.ColumnsCount-1 >= 1 { + w.ColumnsCount-- + } + + w.TableData.SetColumnsCount(w.ColumnsCount) + + w.Redraw() +} + func (w *Wrapper) Redraw() { w.Grid.RemoveItem(w.ConsensusInfoTextView) w.Grid.RemoveItem(w.ChainInfoTextView) diff --git a/pkg/types/progressbar.go b/pkg/types/progressbar.go index d807c84..4b97773 100644 --- a/pkg/types/progressbar.go +++ b/pkg/types/progressbar.go @@ -19,16 +19,27 @@ func (p ProgressBar) Serialize() string { percentTextStart := (p.Width - len(percentText)) / 2 percentTextLine := (p.Height+1)/2 - 1 + isColored := func(value bool) string { + if value { + return "green" + } + + return "-" + } + for lineIndex := 0; lineIndex < p.Height; lineIndex++ { - line := "[\"progress\"]" - terminated := false + line := "" + format := "" for index := 0; index < p.Width; index++ { percent := int(float64(index) / float64(p.Width) * 100) - if percent > p.Progress && !terminated { - terminated = true - line += "[\"\"]" + isBackgroundColored := percent <= p.Progress + + newFormat := fmt.Sprintf("[white:%s]", isColored(isBackgroundColored)) + if format != newFormat { + format = newFormat + line += format } if lineIndex == percentTextLine && (index >= percentTextStart && index < percentTextStart+len(percentText)) { @@ -38,10 +49,6 @@ func (p ProgressBar) Serialize() string { } } - if !terminated { - line += "[\"\"]" - } - sb.WriteString(line + "\n") } diff --git a/pkg/types/state.go b/pkg/types/state.go index 464a2f8..540e051 100644 --- a/pkg/types/state.go +++ b/pkg/types/state.go @@ -90,6 +90,26 @@ func (s *State) SerializeConsensus() string { s.Validators.GetTotalVotingPowerPrecommittedPercent(true), s.Validators.GetTotalVotingPowerPrecommittedPercent(false), )) + + prevoted := 0 + precommitted := 0 + + for _, validator := range *s.Validators { + if validator.Prevote != VotedNil { + prevoted += 1 + } + if validator.Precommit != VotedNil { + precommitted += 1 + } + } + + sb.WriteString(fmt.Sprintf( + " prevoted/precommitted: %d/%d (out of %d)\n", + prevoted, + precommitted, + len(*s.Validators), + )) + sb.WriteString(fmt.Sprintf(" last updated at: %s\n", utils.SerializeTime(time.Now()))) return sb.String() @@ -147,7 +167,7 @@ func (s *State) SerializePrevotesProgressbar(width int, height int) string { return "" } - prevotePercent := s.Validators.GetTotalVotingPowerPrevotedPercent(false) + prevotePercent := s.Validators.GetTotalVotingPowerPrevotedPercent(true) prevotePercentFloat, _ := prevotePercent.Float64() prevotePercentInt := int(prevotePercentFloat) @@ -159,7 +179,7 @@ func (s *State) SerializePrecommitsProgressbar(width int, height int) string { return "" } - precommitPercent := s.Validators.GetTotalVotingPowerPrecommittedPercent(false) + precommitPercent := s.Validators.GetTotalVotingPowerPrecommittedPercent(true) precommitPercentFloat, _ := precommitPercent.Float64() precommitPercentInt := int(precommitPercentFloat) diff --git a/static/help.txt b/static/help.txt index 3bdbaa7..949dcf5 100644 --- a/static/help.txt +++ b/static/help.txt @@ -7,6 +7,7 @@ Created by 🐹 Quokka Stake with ❤️. You can use the following shortcuts: - enable [d[]ebug panel - make the info blocks above [b[]igger or [s[]maller +- display [m[]more or [l[]ess columns in validators table - display or hide this [h[]elp message - [p[]ause new updates - [q[]uit the app (or Ctrl+C) \ No newline at end of file