diff --git a/modules/cli/README.md b/modules/cli/README.md index 582062a..d0ef1e8 100644 --- a/modules/cli/README.md +++ b/modules/cli/README.md @@ -201,6 +201,14 @@ The CLI uses four configuration files: Once `astria-go dev init` has been run, edit `~/.astria/tui-config.toml` to control the starting settings of the TUI app. +The `highlight_color` and `border_color` accept both named colors and +hexadecimal notation: + +```toml +highlight_color = "blue" +border_color = "#808080" +``` + ### Set Service Environment Variables Edit `~/.astria//config/base-config.toml` to add or change settings: diff --git a/modules/cli/cmd/devrunner/config/constants.go b/modules/cli/cmd/devrunner/config/constants.go index 66038af..a708e42 100644 --- a/modules/cli/cmd/devrunner/config/constants.go +++ b/modules/cli/cmd/devrunner/config/constants.go @@ -17,6 +17,8 @@ const ( DefaultTargetNetwork = "local" LocalNativeDenom = "nria" DefaultTUIConfigName = "tui-config.toml" + DefaultHighlightColor = "blue" + DefaultBorderColor = "gray" // NOTE - do not include the 'v' at the beginning of the version number CometbftVersion = "0.38.8" diff --git a/modules/cli/cmd/devrunner/config/tui.go b/modules/cli/cmd/devrunner/config/tui.go index 4222787..7cf2e8c 100644 --- a/modules/cli/cmd/devrunner/config/tui.go +++ b/modules/cli/cmd/devrunner/config/tui.go @@ -12,7 +12,7 @@ import ( // TUIConfig is the struct that holds the configuration and start state for the // TUI. type TUIConfig struct { - // Service settings + // Log viewer settings for services AutoScroll bool `mapstructure:"auto_scroll" toml:"auto_scroll"` WrapLines bool `mapstructure:"wrap_lines" toml:"wrap_lines"` Borderless bool `mapstructure:"borderless" toml:"borderless"` @@ -27,6 +27,10 @@ type TUIConfig struct { SequencerStartsMinimized bool `mapstructure:"sequencer_starts_minimized" toml:"sequencer_starts_minimized"` // Generic services start minimized GenericStartsMinimized bool `mapstructure:"generic_starts_minimized" toml:"generic_starts_minimized"` + + // Accessibility settings + HighlightColor string `mapstructure:"highlight_color" toml:"highlight_color"` + BorderColor string `mapstructure:"border_color" toml:"border_color"` } // DefaultTUIConfig returns a TUIConfig struct populated with all default @@ -36,12 +40,14 @@ func DefaultTUIConfig() TUIConfig { AutoScroll: true, WrapLines: false, Borderless: false, - OverrideInstanceName: "default", + OverrideInstanceName: DefaultInstanceName, CometBFTStartsMinimized: false, ConductorStartsMinimized: false, ComposerStartsMinimized: false, SequencerStartsMinimized: false, GenericStartsMinimized: true, + HighlightColor: DefaultHighlightColor, + BorderColor: DefaultBorderColor, } } @@ -57,6 +63,8 @@ func (c TUIConfig) String() string { output += fmt.Sprintf("ComposerStartsMinimized: %v, ", c.ComposerStartsMinimized) output += fmt.Sprintf("SequencerStartsMinimized: %v, ", c.SequencerStartsMinimized) output += fmt.Sprintf("GenericStartsMinimized: %v", c.GenericStartsMinimized) + output += fmt.Sprintf("HighlightColor: %s, ", c.HighlightColor) + output += fmt.Sprintf("BorderColor: %s", c.BorderColor) output += "}" return output } diff --git a/modules/cli/cmd/devrunner/run.go b/modules/cli/cmd/devrunner/run.go index 8d1fe40..b97ddd2 100644 --- a/modules/cli/cmd/devrunner/run.go +++ b/modules/cli/cmd/devrunner/run.go @@ -133,6 +133,8 @@ func runCmdHandler(c *cobra.Command, _ []string) { LogPath: filepath.Join(logsDir, appStartTime+"-astria-sequencer.log"), ExportLogs: exportLogs, StartMinimized: tuiConfig.SequencerStartsMinimized, + HighlightColor: tuiConfig.HighlightColor, + BorderColor: tuiConfig.BorderColor, } seqRunner = processrunner.NewProcessRunner(ctx, seqOpts) case "composer": @@ -147,6 +149,8 @@ func runCmdHandler(c *cobra.Command, _ []string) { LogPath: filepath.Join(logsDir, appStartTime+"-astria-composer.log"), ExportLogs: exportLogs, StartMinimized: tuiConfig.ComposerStartsMinimized, + HighlightColor: tuiConfig.HighlightColor, + BorderColor: tuiConfig.BorderColor, } compRunner = processrunner.NewProcessRunner(ctx, composerOpts) case "conductor": @@ -161,6 +165,8 @@ func runCmdHandler(c *cobra.Command, _ []string) { LogPath: filepath.Join(logsDir, appStartTime+"-astria-conductor.log"), ExportLogs: exportLogs, StartMinimized: tuiConfig.ConductorStartsMinimized, + HighlightColor: tuiConfig.HighlightColor, + BorderColor: tuiConfig.BorderColor, } condRunner = processrunner.NewProcessRunner(ctx, conductorOpts) case "cometbft": @@ -186,6 +192,8 @@ func runCmdHandler(c *cobra.Command, _ []string) { LogPath: filepath.Join(logsDir, appStartTime+"-cometbft.log"), ExportLogs: exportLogs, StartMinimized: tuiConfig.CometBFTStartsMinimized, + HighlightColor: tuiConfig.HighlightColor, + BorderColor: tuiConfig.BorderColor, } cometRunner = processrunner.NewProcessRunner(ctx, cometOpts) default: @@ -199,6 +207,8 @@ func runCmdHandler(c *cobra.Command, _ []string) { LogPath: filepath.Join(logsDir, appStartTime+"-"+service.Name+".log"), ExportLogs: exportLogs, StartMinimized: tuiConfig.GenericStartsMinimized, + HighlightColor: tuiConfig.HighlightColor, + BorderColor: tuiConfig.BorderColor, } genericRunner := processrunner.NewProcessRunner(ctx, genericOpts) genericRunners = append(genericRunners, genericRunner) diff --git a/modules/cli/internal/processrunner/processrunner.go b/modules/cli/internal/processrunner/processrunner.go index 578f082..39db687 100644 --- a/modules/cli/internal/processrunner/processrunner.go +++ b/modules/cli/internal/processrunner/processrunner.go @@ -24,6 +24,8 @@ type ProcessRunner interface { CanWriteToLog() bool WriteToLog(data string) error GetStartMinimized() bool + GetHighlightColor() string + GetBorderColor() string } // ProcessRunner is a struct that represents a process to be run. @@ -56,6 +58,8 @@ type NewProcessRunnerOpts struct { LogPath string ExportLogs bool StartMinimized bool + HighlightColor string + BorderColor string } // NewProcessRunner creates a new ProcessRunner. @@ -260,3 +264,11 @@ func (pr *processRunner) WriteToLog(data string) error { func (pr *processRunner) GetStartMinimized() bool { return pr.opts.StartMinimized } + +func (pr *processRunner) GetHighlightColor() string { + return pr.opts.HighlightColor +} + +func (pr *processRunner) GetBorderColor() string { + return pr.opts.BorderColor +} diff --git a/modules/cli/internal/testutils/mocks.go b/modules/cli/internal/testutils/mocks.go index 56c1a43..dceb5a6 100644 --- a/modules/cli/internal/testutils/mocks.go +++ b/modules/cli/internal/testutils/mocks.go @@ -72,3 +72,11 @@ func (m *MockProcessRunner) WriteToLog(data string) error { func (m *MockProcessRunner) GetStartMinimized() bool { return false } + +func (m *MockProcessRunner) GetHighlightColor() string { + return "blue" +} + +func (m *MockProcessRunner) GetBorderColor() string { + return "gray" +} diff --git a/modules/cli/internal/ui/processpane.go b/modules/cli/internal/ui/processpane.go index f0c4fd6..6941194 100644 --- a/modules/cli/internal/ui/processpane.go +++ b/modules/cli/internal/ui/processpane.go @@ -23,6 +23,9 @@ type ProcessPane struct { Title string isMinimized bool + + HighlightColor tcell.Color + BorderColor tcell.Color } // NewProcessPane creates a new ProcessPane with a textView and processrunner.ProcessRunner @@ -34,11 +37,22 @@ func NewProcessPane(tApp *tview.Application, pr processrunner.ProcessRunner) *Pr tApp.Draw() }) tv.SetBorder(true). - SetBorderColor(tcell.ColorGray). SetTitle(pr.GetTitle()) ansiWriter := tview.ANSIWriter(tv) + highlightColor := tcell.GetColor(pr.GetHighlightColor()) + if highlightColor == 0 { + log.Debugf("Highlight color %s could not be parsed, using default %s", pr.GetHighlightColor(), tcell.ColorBlue.Name()) + highlightColor = tcell.ColorBlue + } + + borderColor := tcell.GetColor(pr.GetBorderColor()) + if borderColor == 0 { + log.Debugf("Border color %s could not be parsed, using default %s", pr.GetBorderColor(), tcell.ColorGray.Name()) + borderColor = tcell.ColorGray + } + return &ProcessPane{ tApp: tApp, textView: tv, @@ -47,6 +61,8 @@ func NewProcessPane(tApp *tview.Application, pr processrunner.ProcessRunner) *Pr Title: pr.GetTitle(), TickerInterval: 250, isMinimized: pr.GetStartMinimized(), + HighlightColor: highlightColor, + BorderColor: borderColor, } } @@ -116,11 +132,12 @@ func (pp *ProcessPane) GetTextView() *tview.TextView { // Highlight highlights or unhighlights the ProcessPane's textView. func (pp *ProcessPane) Highlight(highlight bool) { + highlightTitleFormat := "[black:" + pp.HighlightColor.Name() + "]" if highlight { - title := "[black:blue]" + pp.Title + "[::-]" - pp.textView.SetBorderColor(tcell.ColorBlue).SetTitle(title) + title := highlightTitleFormat + pp.Title + "[::-]" + pp.textView.SetBorderColor(pp.HighlightColor).SetTitle(title) } else { - pp.textView.SetBorderColor(tcell.ColorGray).SetTitle(pp.Title) + pp.textView.SetBorderColor(pp.BorderColor).SetTitle(pp.Title) } }