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: implement syntax highlighting for preview text #568

Merged

Conversation

cartercanedy
Copy link
Contributor

@cartercanedy cartercanedy commented Sep 20, 2024

image

Tree-sitter is a permissively-licensed, open-source parser framework, well known for its integrations in many popular editors (i use nvim, btw). Luckily, they provide Rust bindings that are reasonably straightforward to use. This PR implements syntax highlighting for the source preview, making it much easier to read for people wanting to understand the code behind commands that they are running.

Type of Change

  • New feature
  • Bug fix
  • Documentation update
  • Refactoring
  • Hotfix
  • Security patch
  • UI/UX improvement

Description

  • Implement tree-sitter-based syntax highlighting

Testing

Manual testing by perusing the previews of various commands

Impact

This should make it much easier to understand the source while being presented in the preview

Checklist

  • My code adheres to the coding and style guidelines of the project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no errors/warnings/merge conflicts.

@cartercanedy cartercanedy force-pushed the syntax-highlighting-in-preview branch 2 times, most recently from a87dcf2 to 58388b5 Compare September 20, 2024 17:59
Copy link
Collaborator

@adamperkowski adamperkowski left a comment

Choose a reason for hiding this comment

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

Awesome.
Just remember to run cargo fmt --all.

tui/src/floating_text.rs Outdated Show resolved Hide resolved
tui/src/floating_text.rs Outdated Show resolved Hide resolved
@cartercanedy cartercanedy force-pushed the syntax-highlighting-in-preview branch from 58388b5 to cf5dedd Compare September 20, 2024 18:03
cartercanedy and others added 2 commits September 20, 2024 11:04
Co-authored-by: Adam Perkowski <[email protected]>
Co-authored-by: Adam Perkowski <[email protected]>
@cartercanedy
Copy link
Contributor Author

cartercanedy commented Sep 20, 2024

Just remember to run cargo fmt --all.

and remove Cargo.lock
:))

@adamperkowski
Copy link
Collaborator

and remove Cargo.lock

Don't remove it if you're adding deps.
If it doesn't conflict, then it's fine.

@cartercanedy
Copy link
Contributor Author

and remove Cargo.lock

Don't remove it if you're adding deps.
If it doesn't conflict, then it's fine.

Did the Cargo.lock ci check get removed?

@adamperkowski
Copy link
Collaborator

adamperkowski commented Sep 20, 2024

Did the Cargo.lock ci check get removed?

It did because Cargo.lock exists for some reason.
Just don't push a deleated and re-cleanbuilded Cargo.lock if not neccessary. - That's the idea here.

@cartercanedy
Copy link
Contributor Author

Just don't push a deleated and re-cleanbuilded Cargo.lock if not neccessary

makes sense

@Real-MullaC
Copy link
Contributor

Please take a look at the check.

@cartercanedy cartercanedy force-pushed the syntax-highlighting-in-preview branch from 2b583d8 to 6726338 Compare September 20, 2024 21:41
@cartercanedy
Copy link
Contributor Author

Please take a look at the check.

already on it

@lj3954
Copy link
Contributor

lj3954 commented Sep 20, 2024

This causes a reversion by removing functionality added in #202.

@cartercanedy
Copy link
Contributor Author

Yeah, that'll have to get sorted out. I'll have to take a deeper look into breaking up the lines on overflow, since it gets a little complicated with the unrendered ansi sequences in the raw strings

@cartercanedy
Copy link
Contributor Author

Just perusing the docs a bit, this shouldn't be too hard. I'd probably still use a flat map, just over the constructed lines rather than the raw text to preserve the styling and accurately determine the width of the actually rendered text

@cartercanedy
Copy link
Contributor Author

@lj3954 why are we looking at wrapping rather than side scrolling?

@ChrisTitusTech
Copy link
Owner

@lj3954 why are we looking at wrapping rather than side scrolling?

Oh I like side scrolling a lot better.

@cartercanedy
Copy link
Contributor Author

cartercanedy commented Sep 21, 2024

Oh I like side scrolling a lot better.

Me 2, but there's also the issue of altered semantics of a mid line break without also inserting a trailing* backslash, and even then I'm not sure that backslashes are valid at any arbitrary location*

@cartercanedy cartercanedy force-pushed the syntax-highlighting-in-preview branch from 2298001 to e570f30 Compare September 21, 2024 21:34
@cartercanedy
Copy link
Contributor Author

@ChrisTitusTech @lj3954 just implemented side scrolling to fix regression

Copy link
Collaborator

@adamperkowski adamperkowski left a comment

Choose a reason for hiding this comment

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

v_scroll and h_scroll could be renamed to scroll_v and scroll_h but it's not that big.

@lj3954
Copy link
Contributor

lj3954 commented Sep 21, 2024

get_lines should not take in an owned String, the split method is implemented for str instead. The lines() method also is more idiomatic than split("\n").

@cartercanedy cartercanedy force-pushed the syntax-highlighting-in-preview branch from e570f30 to 0aa035d Compare September 21, 2024 22:43
@cartercanedy cartercanedy force-pushed the syntax-highlighting-in-preview branch from 0aa035d to a70a6bb Compare September 21, 2024 22:45
@cartercanedy
Copy link
Contributor Author

get_lines should not take in an owned String, the split method is implemented for str instead. The lines() method also is more idiomatic than split("\n").

good catch, that was pretty sloppy

This was accidentally left in from benching
@ChrisTitusTech ChrisTitusTech merged commit 76a4ffc into ChrisTitusTech:main Sep 22, 2024
1 check passed
@ChrisTitusTech ChrisTitusTech added the enhancement New feature or request label Sep 22, 2024
@cartercanedy cartercanedy deleted the syntax-highlighting-in-preview branch September 24, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants