diff --git a/cmd/tmtop.go b/cmd/tmtop.go index e50a5be..ff68145 100644 --- a/cmd/tmtop.go +++ b/cmd/tmtop.go @@ -38,6 +38,7 @@ func main() { rootCmd.PersistentFlags().StringVar(&config.ConsumerChainID, "consumer-chain-id", "", "Consumer chain ID") rootCmd.PersistentFlags().DurationVar(&config.RefreshRate, "refresh-rate", time.Second, "Refresh rate") rootCmd.PersistentFlags().BoolVar(&config.Verbose, "verbose", false, "Display more debug logs") + rootCmd.PersistentFlags().BoolVar(&config.DisableEmojis, "disable-emojis", false, "Disable emojis in output") rootCmd.PersistentFlags().StringVar(&config.ChainType, "chain-type", "cosmos", "Chain type. Allowed values are: 'cosmos', 'tendermint'") rootCmd.PersistentFlags().DurationVar(&config.ValidatorsRefreshRate, "validators-refresh-rate", time.Minute, "Validators refresh rate") rootCmd.PersistentFlags().DurationVar(&config.ChainInfoRefreshRate, "chain-info-refresh-rate", 5*time.Minute, "Chain info refresh rate") diff --git a/pkg/app.go b/pkg/app.go index 2ca850d..0d98eb7 100644 --- a/pkg/app.go +++ b/pkg/app.go @@ -38,7 +38,7 @@ func NewApp(config configPkg.Config, version string) *App { Version: version, Config: config, Aggregator: aggregator.NewAggregator(config, logger), - DisplayWrapper: display.NewWrapper(logger, pauseChannel, version), + DisplayWrapper: display.NewWrapper(config, logger, pauseChannel, version), State: types.NewState(), LogChannel: logChannel, PauseChannel: pauseChannel, diff --git a/pkg/config/config.go b/pkg/config/config.go index 314416b..9832ea9 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -18,6 +18,7 @@ type Config struct { BlockTimeRefreshRate time.Duration ChainType string Verbose bool + DisableEmojis bool } func (c Config) GetProviderOrConsumerHost() string { diff --git a/pkg/display/all_rounds_table.go b/pkg/display/all_rounds_table.go index 016cd49..feef20d 100644 --- a/pkg/display/all_rounds_table.go +++ b/pkg/display/all_rounds_table.go @@ -12,12 +12,14 @@ import ( type AllRoundsTableData struct { tview.TableContentReadOnly - Validators types.ValidatorsWithInfoAndAllRoundVotes + Validators types.ValidatorsWithInfoAndAllRoundVotes + DisableEmojis bool } -func NewAllRoundsTableData() *AllRoundsTableData { +func NewAllRoundsTableData(disableEmojis bool) *AllRoundsTableData { return &AllRoundsTableData{ - Validators: types.ValidatorsWithInfoAndAllRoundVotes{}, + Validators: types.ValidatorsWithInfoAndAllRoundVotes{}, + DisableEmojis: disableEmojis, } } @@ -44,7 +46,7 @@ func (d *AllRoundsTableData) GetCell(row, column int) *tview.TableCell { roundVotes := d.Validators.RoundsVotes[column-1] roundVote := roundVotes[row-1] - text := roundVote.Serialize() + text := roundVote.Serialize(d.DisableEmojis) cell := tview.NewTableCell(text) diff --git a/pkg/display/last_round_table.go b/pkg/display/last_round_table.go index f53830d..fe55c6d 100644 --- a/pkg/display/last_round_table.go +++ b/pkg/display/last_round_table.go @@ -10,14 +10,16 @@ import ( type LastRoundTableData struct { tview.TableContentReadOnly - Validators types.ValidatorsWithInfo - ColumnsCount int + Validators types.ValidatorsWithInfo + ColumnsCount int + DisableEmojis bool } -func NewLastRoundTableData(columnsCount int) *LastRoundTableData { +func NewLastRoundTableData(columnsCount int, disableEmojis bool) *LastRoundTableData { return &LastRoundTableData{ - ColumnsCount: columnsCount, - Validators: make(types.ValidatorsWithInfo, 0), + ColumnsCount: columnsCount, + Validators: make(types.ValidatorsWithInfo, 0), + DisableEmojis: disableEmojis, } } @@ -30,7 +32,7 @@ func (d *LastRoundTableData) GetCell(row, column int) *tview.TableCell { text := "" if index < len(d.Validators) { - text = d.Validators[index].Serialize() + text = d.Validators[index].Serialize(d.DisableEmojis) } cell := tview.NewTableCell(text) diff --git a/pkg/display/wrapper.go b/pkg/display/wrapper.go index 94896b4..f01df44 100644 --- a/pkg/display/wrapper.go +++ b/pkg/display/wrapper.go @@ -2,6 +2,7 @@ package display import ( "fmt" + configPkg "main/pkg/config" "main/pkg/types" "main/static" "strings" @@ -49,11 +50,18 @@ type Wrapper struct { IsPaused bool IsHelpDisplayed bool + + DisableEmojis bool } -func NewWrapper(logger zerolog.Logger, pauseChannel chan bool, appVersion string) *Wrapper { - lastRoundTableData := NewLastRoundTableData(DefaultColumnsCount) - allRoundsTableData := NewAllRoundsTableData() +func NewWrapper( + config configPkg.Config, + logger zerolog.Logger, + pauseChannel chan bool, + appVersion string, +) *Wrapper { + lastRoundTableData := NewLastRoundTableData(DefaultColumnsCount, config.DisableEmojis) + allRoundsTableData := NewAllRoundsTableData(config.DisableEmojis) helpTextBytes, _ := static.TemplatesFs.ReadFile("help.txt") helpText := strings.ReplaceAll(string(helpTextBytes), "{{ Version }}", appVersion) @@ -116,6 +124,7 @@ func NewWrapper(logger zerolog.Logger, pauseChannel chan bool, appVersion string PauseChannel: pauseChannel, IsPaused: false, IsHelpDisplayed: false, + DisableEmojis: config.DisableEmojis, } } @@ -171,9 +180,9 @@ func (w *Wrapper) Start() { w.Redraw() - fmt.Fprint(w.ChainInfoTextView, "Loading...") - fmt.Fprint(w.ConsensusInfoTextView, "Loading...") - fmt.Fprint(w.ProgressTextView, "Loading...") + _, _ = fmt.Fprint(w.ChainInfoTextView, "Loading...") + _, _ = fmt.Fprint(w.ConsensusInfoTextView, "Loading...") + _, _ = fmt.Fprint(w.ProgressTextView, "Loading...") w.App.SetBeforeDrawFunc(func(screen tcell.Screen) bool { screen.Clear() @@ -204,19 +213,19 @@ func (w *Wrapper) SetState(state *types.State) { w.ConsensusInfoTextView.Clear() w.ChainInfoTextView.Clear() w.ProgressTextView.Clear() - fmt.Fprint(w.ConsensusInfoTextView, state.SerializeConsensus()) - fmt.Fprint(w.ChainInfoTextView, state.SerializeChainInfo()) + _, _ = fmt.Fprint(w.ConsensusInfoTextView, state.SerializeConsensus()) + _, _ = fmt.Fprint(w.ChainInfoTextView, state.SerializeChainInfo()) _, _, width, height := w.ConsensusInfoTextView.GetInnerRect() - fmt.Fprint(w.ProgressTextView, state.SerializePrevotesProgressbar(width, height/2)) - fmt.Fprint(w.ProgressTextView, "\n") - fmt.Fprint(w.ProgressTextView, state.SerializePrecommitsProgressbar(width, height/2)) + _, _ = fmt.Fprint(w.ProgressTextView, state.SerializePrevotesProgressbar(width, height/2)) + _, _ = fmt.Fprint(w.ProgressTextView, "\n") + _, _ = fmt.Fprint(w.ProgressTextView, state.SerializePrecommitsProgressbar(width, height/2)) w.App.Draw() } func (w *Wrapper) DebugText(text string) { - fmt.Fprint(w.DebugTextView, text) + _, _ = fmt.Fprint(w.DebugTextView, text) w.DebugTextView.ScrollToEnd() } diff --git a/pkg/types/validator.go b/pkg/types/validator.go index 1b0ef7d..6944064 100644 --- a/pkg/types/validator.go +++ b/pkg/types/validator.go @@ -23,11 +23,11 @@ type RoundVote struct { IsProposer bool } -func (v RoundVote) Serialize() string { +func (v RoundVote) Serialize(disableEmojis bool) string { return fmt.Sprintf( " %s %s", - v.Prevote.Serialize(), - v.Precommit.Serialize(), + v.Prevote.Serialize(disableEmojis), + v.Precommit.Serialize(disableEmojis), ) } @@ -106,19 +106,23 @@ type ValidatorWithInfo struct { ChainValidator *ChainValidator } -func (v ValidatorWithInfo) Serialize() string { +func (v ValidatorWithInfo) Serialize(disableEmojis bool) string { name := v.Validator.Address if v.ChainValidator != nil { name = v.ChainValidator.Moniker if v.ChainValidator.AssignedAddress != "" { - name = "🔑 " + name + emoji := "🔑" + if disableEmojis { + emoji = "[k[]" + } + name = emoji + " " + name } } return fmt.Sprintf( " %s %s %s %s%% %s ", - v.RoundVote.Prevote.Serialize(), - v.RoundVote.Precommit.Serialize(), + v.RoundVote.Prevote.Serialize(disableEmojis), + v.RoundVote.Precommit.Serialize(disableEmojis), utils.RightPadAndTrim(strconv.Itoa(v.Validator.Index+1), 3), utils.RightPadAndTrim(fmt.Sprintf("%.2f", v.Validator.VotingPowerPercent), 6), utils.LeftPadAndTrim(name, 25), diff --git a/pkg/types/vote.go b/pkg/types/vote.go index 7a69e72..cd3d5f8 100644 --- a/pkg/types/vote.go +++ b/pkg/types/vote.go @@ -1,7 +1,5 @@ package types -import loggerPkg "main/pkg/logger" - type Vote int const ( @@ -10,7 +8,20 @@ const ( VotedZero ) -func (v Vote) Serialize() string { +func (v Vote) Serialize(disableEmojis bool) string { + if disableEmojis { + switch v { + case Voted: + return "[X[]" + case VotedZero: + return "[0[]" + case VotedNil: + return "[ []" + default: + return "" + } + } + switch v { case Voted: return "✅" @@ -18,8 +29,7 @@ func (v Vote) Serialize() string { return "🤷" case VotedNil: return "❌" + default: + return "" } - - loggerPkg.GetDefaultLogger().Fatal().Str("value", string(rune(v))).Msg("Error parsing vote") - return "" }