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

helix-term: ui: Refactor statusline rendering, set configurable #2610

Closed
wants to merge 1 commit into from

Conversation

litchipi
Copy link

In an effort to help bring custom statusline (related issue #708), I created a first refactor that changes almost nothing in the render but would allow future configuration of the statusline:

  • Deleted render_statusline function, created a StatuslineRender struct instead.
  • Created StatuslineElement enum to store every element that can be rendered, with configurable data associated.
    Every new "feature" to add to the statusline will just be a new element in this enum.
  • The render of the statusline is now a rendering of the left part, right part and middle part of the statusline (in this order)
  • A "TODO" has been added where the String (user config) to StatuslineRender will take place
    Still have to decide the format and implement it.
    I was thinking of something like:
    {mode} blah blah {filename} bli blouh {diagnostic W E}
    "blah blah" being static strings added to the statusline, (spaces, dashes, dots, etc ...)
    "W" and "E" being configurable data associated to the statusline element

Changes in the rendered UI:

  • The filename is now rendered in the middle of the available space between the left and right text
  • No leading space in the left text of the bar

Questions I have regarding the implementation:

  • Are the struct well placed in the code ?
  • Should I add more comments ?
  • Are there more arguments that should be passed to the different render functions in order to implement any further features on the bar ?
  • How the EditorView struct can access the user configuration in order to load the StatuslineRender struct from the placeholder string ?

First contribution here, please tell me if there's something wrong :-)

@litchipi
Copy link
Author

My bad, entered directly into the meat of the code and didn't check all the issue before, missed #2434 PR.

Maybe it can bring a thing or 2 to the other PR (I do think the StatuslineElement enum is a good idea) so I let it open, but feel free to close this PR when you want, I'll be more precautious next time 😅

Comment on lines -785 to -797
surface.set_string_truncated(
viewport.x + 8, // 8: 1 space + 3 char mode string + 1 space + 1 spinner + 1 space
viewport.y,
&title,
viewport
.width
.saturating_sub(6)
.saturating_sub(right_side_text.width() as u16 + 1) as usize, // "+ 1": a space between the title and the selection info
|_| base_style,
true,
true,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I am worried if we do a custom statusline we lost the ability to do truncation.

for element in self.statusline_middle.iter() {
element.render(
&mut middle_text,
&self,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you might have to fix the lints.

@archseer
Copy link
Member

#2434 was merged, but thanks for looking into this!

@archseer archseer closed this Jul 22, 2022
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.

3 participants