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

Add option to invert selection colors #2488

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tarkah
Copy link
Contributor

@tarkah tarkah commented May 27, 2023

Resolves #2395

This adds a new option that inverts the fg / bg colors of the selection instead of coloring w/ palette.black.

I've just passed along a bool with chunk_selection_and_colors but I can refactor into a better defined enum type if desired.

Edit: 9e140a2 I've removed the magic boolean and refactored to an enum for strongly typed variants.

@tarkah tarkah temporarily deployed to cachix May 27, 2023 18:46 — with GitHub Actions Inactive
@@ -168,6 +168,7 @@ pub fn start_client(
colors: palette,
rounded_corners: config.ui.pane_frames.rounded_corners,
hide_session_name: config.ui.pane_frames.hide_session_name,
invert_selection_colors: config_options.invert_selection_colors.unwrap_or_default(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was initially confusing for me... why do we pass in config and config_options separately? I originally accessed this via config.options but apparently the CLI options flags aren't sync'd to this. I spent quite a bit of time scratching my head. Maybe some newtype safety can help here if this separation is intentional.

@tarkah tarkah temporarily deployed to cachix May 28, 2023 15:19 — with GitHub Actions Inactive
@tarkah tarkah temporarily deployed to cachix May 28, 2023 17:20 — with GitHub Actions Inactive
let background_color = match style.colors.bg {
PaletteColor::Rgb(rgb) => AnsiCode::RgbCode(rgb),
PaletteColor::EightBit(col) => AnsiCode::ColorIndex(col),
let selection = self.selection.offset(content_x, content_y);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the selection offsetting here as depending on offset_* in add_selection_and_colors or now SelectionColors::invert / discrete seems like a layer violation. Those methods expect a Selection for determining which color styles to apply, but we shouldn't leak another implementation detail into them.

However, this doesn't eliminate the risk of forgetting to call Selection::offset. Maybe returning an OffsetSelection newtype from Selection::offset and depending on that in SelectionColors would ensure this guarantee.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this guarantee in 54c107a. Now the compiler will complain if you try to pass a Selection to SelectionColors, so we must call offset first.

@tarkah tarkah temporarily deployed to cachix May 28, 2023 17:36 — with GitHub Actions Inactive
@jgayfer
Copy link

jgayfer commented Oct 16, 2023

Thanks for taking this on. Hopefully gets some traction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: invert selection bg and fg colors
2 participants