Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support light background terminal in TUI mode #411

Closed
mcint opened this issue Feb 1, 2023 · 8 comments · Fixed by #413
Closed

Support light background terminal in TUI mode #411

mcint opened this issue Feb 1, 2023 · 8 comments · Fixed by #413
Labels
enhancement New feature or request tui
Milestone

Comments

@mcint
Copy link

mcint commented Feb 1, 2023

It looks like TUI mode is the only one that accepts multiple hosts, and that this tool is mainly built around the TUI. How do I use this with a light terminal background? Can I override the color scheme with something akin to LS_COLORS, or a theme flag?

@fujiapple852 fujiapple852 added enhancement New feature or request tui labels Feb 1, 2023
@fujiapple852
Copy link
Owner

fujiapple852 commented Feb 1, 2023

Thanks for raising this @mcint, customising the theme isn't something trippy supports today but I like the idea.

I think the best way to achieve this may be to have a trippy config file (similar to the one I proposed in #412) that allow specifying the colors for various parts of the TUI, rather than the current hardcoded approach.

What do you think?

@mcint
Copy link
Author

mcint commented Feb 3, 2023

Thanks for the quick reply, and consideration!

bat does this too (search /theme/ in addition to the linked README section).

I'm less a fan of custom configuration, and one more config file. I would love environment variables, for explicit color setting (/overriding) or also a separate one for theme selection. I frequently find that environment variables are quick to override for exploration or adapting to the demands of a task, and can live in my .env file, instead of as another .config/.

It looks like you have other reasons for considering a config file, and given the TUI nature of the primary interface, trippy is more primarily used interactively than in shell pipelines. I think I'd recommend a review of other TUIs to make the decision, htop, wireshark, mtr. Maybe I can write a short blog post in review.

Basically unrelated, I sure wish these theme files could be shared across bat, trippy, *vim, and others, ideally in the same directory, or at least built from shared definitions.

@fujiapple852
Copy link
Owner

I agree that Trippy is primarily a Tui application and therefore being able to configure it via the environment makes sense in the spirit of 12 factors app.

I would like users to be able to specify any Trippy configuration as config file entries, environment variables or command line arguments (in priority order args -> env -> file). There are some good rust crates to help with this, though none that I've seen which support Clap natively. But ultimately this shouldn't be too difficult to piece together manually.

Aside from how it is configured, I've created a PR (#413) which replaces all the hardcoded Tui colors with a TuiTheme. This theme is not yet exposed via config and the colors are hardcoded to match the current Trippy style.

This was a useful exercise as it forced me to think about the specific color theme parameter that will be exposed in the configuration. Currently the theme allows customising the following:

pub struct TuiTheme {
    /// The default background color.
    ///
    /// This may be overridden for specific components.
    bg_color: Color,
    /// The default color of borders.
    ///
    /// This may be overridden for specific components.
    border_color: Color,
    /// The default color of text.
    ///
    /// This may be overridden for specific components.
    text_color: Color,
    /// The color of the text in traces tabs.
    tab_text_color: Color,
    /// The background color of the hops table header.
    hops_table_header_bg_color: Color,
    /// The color of text in the hops table header.
    hops_table_header_text_color: Color,
    /// The color of text of active rows in the hops table.
    hops_table_row_active_text_color: Color,
    /// The color of text of inactive rows in the hops table.
    hops_table_row_inactive_text_color: Color,
    /// The color of the selected series in the hops chart.
    hops_chart_selected_color: Color,
    /// The color of the unselected series in the hops chart.
    hops_chart_unselected_color: Color,
    /// The color of the axis in the hops chart.
    hops_chart_axis_color: Color,
    /// The color of bars in the frequency chart.
    frequency_chart_bar_color: Color,
    /// The color of text in the bars of the frequency chart.
    frequency_chart_text_color: Color,
    /// The color of the samples chart.
    samples_chart_color: Color,
    /// The background color of the help dialog.
    help_dialog_bg_color: Color,
    /// The color of the text in the help dialog.
    help_dialog_text_color: Color,
}

You could imagine, therefore, being able to override the frequency_chart_bar_color via something like (mockup):

Command line argument:

trip --tui-theme-frequency-chart-bar-color Red

Environment variable:

TRIP_TUI_THEME_FREQUENCY_CHART_BAR_COLOR=Blue

Config file:

[theme]
frequency_chart_bar_color=#31c2fc

@fujiapple852
Copy link
Owner

fujiapple852 commented Feb 5, 2023

@mcint I've updated the PR (#413) to expose the above theme configuration options via command line arguments:

--tui-theme-bg-color <TUI_THEME_BG_COLOR>
    The default background color [default: black]
--tui-theme-border-color <TUI_THEME_BORDER_COLOR>
    The default color of borders [default: gray]
--tui-theme-text-color <TUI_THEME_TEXT_COLOR>
    The default color of text [default: gray]
--tui-theme-tab-text-color <TUI_THEME_TAB_TEXT_COLOR>
    The color of the text in traces tabs [default: green]
--tui-theme-hops-table-header-bg-color <TUI_THEME_HOPS_TABLE_HEADER_BG_COLOR>
    The background color of the hops table header [default: white]
--tui-theme-hops-table-header-text-color <TUI_THEME_HOPS_TABLE_HEADER_TEXT_COLOR>
    The color of text in the hops table header [default: black]
--tui-theme-hops-table-row-active-text-color <TUI_THEME_HOPS_TABLE_ROW_ACTIVE_TEXT_COLOR>
    The color of text of active rows in the hops table [default: gray]
--tui-theme-hops-table-row-inactive-text-color <TUI_THEME_HOPS_TABLE_ROW_INACTIVE_TEXT_COLOR>
    The color of text of inactive rows in the hops table [default: dark-gray]
--tui-theme-hops-chart-selected-color <TUI_THEME_HOPS_CHART_SELECTED_COLOR>
    The color of the selected series in the hops chart [default: green]
--tui-theme-hops-chart-unselected-color <TUI_THEME_HOPS_CHART_UNSELECTED_COLOR>
    The color of the unselected series in the hops chart [default: gray]
--tui-theme-hops-chart-axis-color <TUI_THEME_HOPS_CHART_AXIS_COLOR>
    The color of the axis in the hops chart [default: dark-gray]
--tui-theme-frequency-chart-bar-color <TUI_THEME_FREQUENCY_CHART_BAR_COLOR>
    The color of bars in the frequency chart [default: green]
--tui-theme-frequency-chart-text-color <TUI_THEME_FREQUENCY_CHART_TEXT_COLOR>
    The color of text in the bars of the frequency chart [default: gray]
--tui-theme-samples-chart-color <TUI_THEME_SAMPLES_CHART_COLOR>
    The color of the samples chart [default: yellow]
--tui-theme-help-dialog-bg-color <TUI_THEME_HELP_DIALOG_BG_COLOR>
    The background color of the help dialog [default: blue]
--tui-theme-help-dialog-text-color <TUI_THEME_HELP_DIALOG_TEXT_COLOR>
    The color of the text in the help dialog [default: gray]

The supported colors are Black, Red, Green, Yellow, Blue, Magenta, Cyan, Gray, DarkGray, LightRed, LightGreen, LightYellow, LightBlue, LightMagenta, LightCyan, White (case insensitive, dashes allowed) or specify a raw hex value (i.e. ffffff for white).

If would be great if you were able to give that a try and give some feedback on whether it allows you to customise the theme as you would like. If so then I'd look to merge this.

Obviously it is impractical to specify so many theme parameters from the command line, so the next step would be to expose these, and other trippy config, as both config files and environment variable as as described above.

@mcint
Copy link
Author

mcint commented Feb 7, 2023

That does suffice. Thanks for pushing it through so quickly.

@fujiapple852
Copy link
Owner

Reworked the config to avoid having one config option per theme-able item: #443

@fujiapple852
Copy link
Owner

@mcint support for specify theme colors is now also available in the trippy config file, see #412

@fujiapple852
Copy link
Owner

@mcint 0.8.0, which includes a config file for specifying TUI themes, to has been released: https://github.com/fujiapple852/trippy/releases/tag/0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tui
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants