refactor: misc restructuring#1015
Conversation
|
I also think we should go through and reduce nesting across the codebase as well, the code isn't very readable right now |
|
@lj3954 @JustLinuxUser @cartercanedy @adamperkowski feel free to review |
JustLinuxUser
left a comment
There was a problem hiding this comment.
I like the changes, but some small tweaks would improve them even more, especially the scroll up, and down thing, I would prefer something like:
fn scroll_down(&mut self) {
let list_len = self.filter.item_list().len() + !self.at_root() as usize;
if let Some(selected) = self.selection.selected() {
if selected == list_len - 1 {
self.selection.select_first();
} else {
self.selection.select_next();
}
}
}
fn scroll_up(&mut self) {
if let Some(selected) = self.selection.selected() {
if selected == 0 {
self.selection.select_last();
} else {
self.selection.select_previous();
}
}
}
to be honest, i like my version better. Maybe its based on style preferences, but i prefer flat, easy to follow, code that has clean separation. I would also like to mention that mine avoids nested conditionals and separates the length calc from the selection calc. |
I dislike the boolean to integer cast. It makes it more difficult to reason about the code. |
It's ok, if you want, you can still use the if, so it would become: let list_len = self.filter.item_list().len() + if self.at_root() { 0 } else { 1 };or even let list_len = if self.at_root {self.filter.item_list().len()} else {self.filter.item_list().len() + 1}like you had before, choose whatever you like best |
|
@JustLinuxUser take a look at f28e085 and see if you like it better |
koibtw
left a comment
There was a problem hiding this comment.
the scope shouldn't be explicitly tui
That does look good, ty |
|
oops |
|
wrong repo 😭 |
Changes: Separate cli flags and put them in their own module. Add a rustfmt configuration file for grouping imports into crates (so we dont have to do this manually, and it seems we were already doing it manually so might as well) Use comments to describe cli flags instead of using ugly syntax (they both work the same but one is less ugly and more readable) Add a --mouse flag to enable mouse interaction (mouse interaction is now off by default) Add a --bypass-root flag to disable the annoying popup when you run the utility as root Fix an issue where you can't reach the bottom of the list in a subdir (i also reduced the nesting in those functions as well for readability) Add help feature to clap dependency to enable --help / -h Add usage feature to clap dependency to enable usage example when running with --help / -h Remove CLI arg examples from readme, and add instructions on how to view them on CLI to prevent it from bloating up the readme
Changes:
Separate cli flags and put them in
their own module.
Add a rustfmt configuration file for
grouping imports into crates (so we
dont have to do this manually, and it
seems we were already doing it manually
so might as well)
Use comments to describe cli flags
instead of using ugly syntax (they both
work the same but one is less ugly and
more readable)
Add a --mouse flag to enable mouse
interaction (mouse interaction is now
off by default)
Add a --bypass-root flag to disable
the annoying popup when you run the
utility as root
Fix an issue where you can't reach the
bottom of the list in a subdir (i also
reduced the nesting in those functions
as well for readability)
Add help feature to clap dependency to
enable --help / -h
Add usage feature to clap dependency
to enable usage example when running
with --help / -h
Remove CLI arg examples from readme,
and add instructions on how to view
them on CLI to prevent it from bloating
up the readme
Explanation:
Some changes in this pull request
duplicate the fixes from #961
while the changes are not
inherently duplicated, I
had refactored the 2 func's
to improve readability and
ended up fixing the same bug.
I had commented under that PR
asking if I should drop the changes
but I have not received a response yet
(at the time of writing)