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

refact: rust fixes and optimizations #933

Merged
merged 24 commits into from
Nov 17, 2024

Conversation

jeevithakannan2
Copy link
Contributor

@jeevithakannan2 jeevithakannan2 commented Nov 10, 2024

Thanks @lj3954 and @cartercanedy for your reviews and suggestions. Learnt a lot from you guys 😄

Type of Change

  • Bug fix
  • Refactoring
  • UI/UX improvement

Notable changes so for

  • 1aa1dfe Use specified theme color instead of using ratatui::Color for running_command.rs success and fail color + filter.rs preview text color + state.rs min-tui warning color, confirmation.rs add colors for confirmation prompt, theme.rs fix inverted success and fail colors
  • 190c26c Change ConfirmPrompt struct fields to private. Prevent scrolling beyond the list. Fix color bleeding.
  • 0b4f33c Use sort_unstable_by no need of sort_by here, fix word disappearing by recalculating the render x for preview text.
  • 10352c6 Replace anstyle and text-wrap with ratatui inbuilt functions. Prevent processing of text every frame by caching the processed text.
    - 6e5fe07 Adds back the removed clap features from cargo toml. fix: CLI arguments not working #935
  • 3d0f7f4 Reference instead of borrowing commands from state, Refactor draw function variables to immutable, calculate inner size from block instead of manual definition.
  • 79aae9e Move tips to a seperate file for modularity. Pass the whole args to state instead of seperate args. Add the longest_tab_length to appstate struct so that it will not be calculated for each frame rendered. Use function for spawning confirmprompt. Merge command list and task items list rendering a single widget instead of two. Remove redundant keys in handle_key.
  • 1b02fc3 Use const for theme functions.
  • 1044517 Prevent getting locked out when in floating window.
  • 78b7c3f Add more options to the config files

Testing

  • Tested with no issues.

Before

image

After

image

Before

output.mp4

After

2024-11-10.21-38-15.mp4

Impact

Performance improvements and clean code base.

Issues / other PRs related

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.
  • My changes generate no errors/warnings/merge conflicts.

Use theme color instead of using ratatui::Color for running_command success and fail + search preview text color + min tui warning color, add colors for confirmation prompt, fix inverted success and fail colors
Removed redundant match statement with a function
Remove unnecessary usage of pub in ConfirmPropmt struct fields, simplify numbering, prevent scrolling beyond list, fix color bleeding
Use regex for case insesitive finding, implement String instead of char<Vec>, fix word disappearing by recalculating the render x for preview text
@lj3954
Copy link
Contributor

lj3954 commented Nov 10, 2024

  • 0b4f33c Use regex for case insensitive search, implement String instead of char<Vec> for seach_input, fix word disappearing by recalculating the render x for preview text.

Other than the last point, why would we want to do any of these things? Compiling a regex on each change to the search input makes the code less readable & negatively impacts performance compared to just taking the lowercase of the input, which we already do. Vec<char>, over String, is used to fix panics upon inputting a multi-byte unicode character, unicode_width is used to fix incorrect cursor positioning with wider unicode characters. Both are niche issues, but I don't see the purpose of removing these fixes for absolutely no improvement.

3b7e859 Replace redundant match statements with helper function in theme.rs.

Adding a new theme which has different colours for these theme elements could require these match statements be added back. This is the same thing you did when you suggested removing "unnecessary cases" in scripts. This change also does not improve readability.

Sorry, I misunderstood the changes made in that commit. It's even worse an idea than what I thought you were doing. If more themes are added, you'd have to keep adding function parameters, making the code even more difficult to read. A match statement is by far the best choice there.

I oppose these 2 commits. I'll review certain elements of the other changes in a few minutes.

tui/src/confirmation.rs Show resolved Hide resolved
tui/src/confirmation.rs Outdated Show resolved Hide resolved
tui/src/confirmation.rs Outdated Show resolved Hide resolved
@nnyyxxxx
Copy link
Contributor

tab completion was purposefully made to complete lowercase for UX & better visuals on the users end

@nnyyxxxx
Copy link
Contributor

nnyyxxxx commented Nov 11, 2024

i personally think its better to keep it lowercase as it feels more snappier that way imo, tldr: makes the user think they have more control when searching

Use Vec<char> for search_input to prevent panics when using multi-byte characters, use lowercase conversion instead of regex, Added comments for clarity
@jeevithakannan2
Copy link
Contributor Author

jeevithakannan2 commented Nov 11, 2024

  • 0b4f33c Use regex for case insensitive search, implement String instead of char<Vec> for seach_input, fix word disappearing by recalculating the render x for preview text.

Other than the last point, why would we want to do any of these things? Compiling a regex on each change to the search input makes the code less readable & negatively impacts performance compared to just taking the lowercase of the input, which we already do. Vec<char>, over String, is used to fix panics upon inputting a multi-byte unicode character, unicode_width is used to fix incorrect cursor positioning with wider unicode characters. Both are niche issues, but I don't see the purpose of removing these fixes for absolutely no improvement.

Thanks for the quick review. I forgot about the multi-byte characters reverted back to Vec<char> with some comments.

@jeevithakannan2
Copy link
Contributor Author

jeevithakannan2 commented Nov 11, 2024

@cartercanedy @lj3954 Why we are using ansi colors for tree-sitter-highlighting instead of ratatui colors?

@cartercanedy
Copy link
Contributor

cartercanedy commented Nov 11, 2024

treesitter-highlight provides the machinery for interacting with the individual parsers for syntax highlighting, in our case it's the bash parser. This is necessary

Sorry, misunderstood the initial question

Anstlye makes it easier to render the ansi color codes directly to a stream. There's some complication with using the ratatui text constructs since there might be some styling that needs to be applied over a line break, which would make parsing more complicated than necessary

@jeevithakannan2
Copy link
Contributor Author

jeevithakannan2 commented Nov 11, 2024

Since we using custom colors for syntax_highlighting_styles maybe using the ratatui colors reduces the complexity?

What if ratatui colors is used and converted into lines using ratatui spans, lines or text instead of using anstyle and ansi_to_tui to convert them into text ?

@cartercanedy
Copy link
Contributor

Trust me, it's just going to get more complicated...

@jeevithakannan2
Copy link
Contributor Author

Ok I will try my best and create a commit let me know what you think about it

Replaced ansi related code for tree sitter highlight with direct ratatui::text. Cache the processed text in appstate to remove processing of text for every frame render.Create paragraph instead of list so that scroll and wrapping can be done without external crates. Add caps keys for handle_key_event.
tui/src/hint.rs Outdated Show resolved Hide resolved
tui/src/hint.rs Show resolved Hide resolved
@jeevithakannan2
Copy link
Contributor Author

Is it normal for the checkout process to take in 10min in typos workflow 🙄 https://github.com/ChrisTitusTech/linutil/actions/runs/11782804516/job/32818643344?pr=933

@cartercanedy
Copy link
Contributor

The initial checkout can get throttled, I've seen that happen in my own projects

@jeevithakannan2
Copy link
Contributor Author

The initial checkout can get throttled, I've seen that happen in my own projects

Are the changes to the anstyle good ? Did you review the changes?

@jeevithakannan2 jeevithakannan2 marked this pull request as ready for review November 12, 2024 21:02
@jeevithakannan2 jeevithakannan2 changed the title WIP: Rust fixes and optimizations Rust fixes and optimizations Nov 12, 2024
Skip Confirmation, Bypass Size
Revert handling find_command_name in state.rs
Add options for skip_confirmation, size_bypass
@lj3954
Copy link
Contributor

lj3954 commented Nov 16, 2024

Making the theme functions const doesn't accomplish anything useful; they'll still be evaluated at runtime since the theme is not known at compile time.

@lj3954
Copy link
Contributor

lj3954 commented Nov 16, 2024

We also should not be merging PRs like this. I find it unlikely Chris will accept anything with a 1500 line diff.

@jeevithakannan2
Copy link
Contributor Author

Making the theme functions const doesn't accomplish anything useful; they'll still be evaluated at runtime since the theme is not known at compile time.

It may not be now. But if we decide to change how themes work instead of passing the default theme at run time making it as default during compile time will make this more efficient.

@jeevithakannan2
Copy link
Contributor Author

We also should not be merging PRs like this. I find it unlikely Chris will accept anything with a 1500 line diff.

I'm aware of that. What can we do? Do I create 9 separate PRs for each commit?

@cartercanedy
Copy link
Contributor

cartercanedy commented Nov 16, 2024

Making the theme functions const doesn't accomplish anything useful; they'll still be evaluated at runtime since the theme is not known at compile time.

It may not be now. But if we decide to change how themes work instead of passing the default theme at run time making it as default during compile time will make this more efficient.

I don't mind the idea of marking methods const when compatible, but I don't see any way that the theme will ever become a compile-time constant as long as it remains configurable at runtime. The only exception would be if We could make this work if we constructed instances of each theme statically and just passed around references to the one of the compile-time generated themes

@cartercanedy
Copy link
Contributor

We also should not be merging PRs like this. I find it unlikely Chris will accept anything with a 1500 line diff.

I'm aware of that. What can we do? Do I create 9 separate PRs for each commit?

Yes

@adamperkowski adamperkowski changed the title Rust fixes and optimizations refact: rust fixes and optimizations Nov 17, 2024
@adamperkowski adamperkowski added rust Pull requests that update Rust code refactor labels Nov 17, 2024
@adamperkowski
Copy link
Collaborator

man that diff is HUGE
@jeevithakannan2, the conflict-creator

@jeevithakannan2
Copy link
Contributor Author

man that diff is HUGE
@jeevithakannan2, the conflict-creator

I know we have put a lot of time into this. Separating the PRs will do the same. But this makes the program more efficient in many areas. Can't complain.

@ChrisTitusTech ChrisTitusTech merged commit ab7a670 into ChrisTitusTech:main Nov 17, 2024
2 checks passed
@adamperkowski
Copy link
Collaborator

Didn't expect you to actually merge this huge diff but ok.

@jeevithakannan2 jeevithakannan2 deleted the optimization branch November 17, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

main doesnt build Search text disappears if arrow keys are used
6 participants