Skip to content

Commit

Permalink
accessibility color overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
sambukowski committed Aug 19, 2024
1 parent d385707 commit 9122f87
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 6 deletions.
8 changes: 8 additions & 0 deletions modules/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<instance>/config/base-config.toml` to add or change settings:
Expand Down
2 changes: 2 additions & 0 deletions modules/cli/cmd/devrunner/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions modules/cli/cmd/devrunner/config/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand All @@ -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,
}
}

Expand All @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions modules/cli/cmd/devrunner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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:
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions modules/cli/internal/processrunner/processrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -56,6 +58,8 @@ type NewProcessRunnerOpts struct {
LogPath string
ExportLogs bool
StartMinimized bool
HighlightColor string
BorderColor string
}

// NewProcessRunner creates a new ProcessRunner.
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions modules/cli/internal/testutils/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
25 changes: 21 additions & 4 deletions modules/cli/internal/ui/processpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 9122f87

Please sign in to comment.