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

feat: Use custom character to draw editor rulers #11798

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

codingjerk
Copy link

This PR allows selecting custom character to draw editor rulers and it contains fixes and improvements on PR #9256

Differences from previous PR

  1. No unnecessary formatting changes
  2. No unnecessary string allocation for every character drawn
  3. Separate theme key (ui.virtual.ruler.char) if editor.ruler-char is set to allow using different styles for "background ruler" and "character ruler"
  4. Ruler character is drawn under the text

Screenshot

Default theme with config

[editor]
  rulers = [ 40, 60 ]
  ruler-char = "¦"

image

@codingjerk
Copy link
Author

codingjerk commented Sep 30, 2024

I believe I also need to add theme key ui.virtual.ruler.char to every theme in helix.

I believe reasonable value for it is the same as ui.virtual.indent-guide. Using bg from ui.virtual.ruler as fg doesn't work well — in some themes it's pretty hard to see "character rulers" since they're thinner.

I'll wait for reviewers to approve this approach, before adding new key to every theme.

@baldwindavid
Copy link

baldwindavid commented Sep 30, 2024

@codingjerk Thanks for this; a real big win here is fixing the issue of the disappearing cursor over a ruler.

I read about some of the constraints and complications in #9256 and see that it's not completely straightforward how to approach.

Not a reviewer at all, but I do wonder if an option might be to introduce a couple settings:

Settings

| `ruler-style` | `bg` displays the ruler as a background color, while `char` displays the configured `ruler-char` | `bg` |
| `ruler-char`  | Specifies the character used to display the rulers when `ruler-style` is `char` | `|` |

The default style would be background so as not to break current settings. The default ruler character is set to |, but will only display if the ruler-style is set to char.

Theme Changes

Perhaps an additional theme key is then not necessary. Instead, the bg dictates the bg ruler-style just as it does now and fg dictates the char ruler-style.

"ui.virtual.ruler" = { bg = "cursorline", fg = "cursorline" }

@codingjerk
Copy link
Author

Hi @baldwindavid, I’m glad you found it useful! Regarding your thoughts:

"ui.virtual.ruler" = { bg = "cursorline", fg = "cursorline" }

I like this idea and originally considered it, but it would break the current behavior where both background and foreground colors can be set for the ruler. For example, you can highlight characters under the ruler in red:

image

It would also slightly complicate the code, as this PR just selects the corresponding theme key, whereas your solution requires extracting the style from within the style value. While it’s not a huge issue, it’s still something to note.

That said, I think it could be worth it, as it simplifies configuration and theming a bit. Thanks for bringing it up.

I hope the maintainers can comment which solution is better, and I’d be happy to either keep the current approach or implement yours.

ruler-style

This is an interesting idea — it would make switching the ruler style easier since the user wouldn't need to select a character manually if they’re fine with the default. It’s also more explicit, and I like it. This solution also doesn't have any significant tradeoffs, I believe. Introducing two more options is okay, since it will simplify ruler-char making it char instead of Option<char>.

Both ideas are independent, so I will update my PR to include the second idea (the ruler-style option) while waiting for the maintainers' feedback on the first (using single theme key).

@codingjerk
Copy link
Author

I added commit 4acdbe3 with separate ruler-style option. LGTM now.

Waiting for maintainers to comment on themes

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.

2 participants