-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Resolving #16 - Feature: add an "Are you sure you want to quit?" modal #44
Conversation
add keyEvent handler function for exiting mode add Exiting variant to UiMode enum | add prompt_exit method implement ExitingMode widget rendering fix mixed UiState issue
should fix #16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mhdmhsni, great work! I really liked your solution with the enum struct. I think it saved a lot of code, good call.
In addition to some comments I left, there's also one more thing we need to do:
If you notice, right now on this branch if you quit the app, it hangs a little. You'll have to press another ctrl-c (or any other key really) to get back to your prompt.
The reason for this is that there's a bit of a hack in main.rs, and we need to update it.
Essentially, you need to change this line: /~https://github.com/imsnif/diskonaut/blob/main/src/main.rs#L115-L116
To just check for the y
key. This adds a bit of a delay before we keep listening for user input, so that the app has time to quit and we know we need to exit the loop. I know it's not the most elegant thing, but I could not think of a better solution - sorry for that. :)
src/input/controls.rs
Outdated
| Event::Key(Key::Esc) | ||
| Event::Key(Key::Backspace) | ||
| Event::Key(Key::Char('n')) => { | ||
if app.loaded { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an app.reset_ui_mode()
method that does this. You can use it in both of these conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry! I missed the method.
Thanks for the tip!
src/ui/modals/confirm_box.rs
Outdated
.modifier(Modifier::BOLD); | ||
|
||
let text_max_length = confirm_rect.width - 4; | ||
let confirm_text = truncate_middle(confirm_msg, text_max_length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, what happens with this line is that the "Are you sure you want to quit?" line gets truncated on a small window to something like "Are you su[...] to quit?"
Do you think we can have a few options here and make it "shorten" itself if the window is not wide enough?
eg. "Are you sure you want to quit?" ==> "Sure you want to quit?" ==> "Really quit?" ==> "Quit?"
There are a few examples of this in the code, like here: /~https://github.com/imsnif/diskonaut/blob/main/src/ui/term_too_small.rs#L16-L33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. i think i can handle that with the explanation you just did.
I'll inform you in case of any problem.
src/ui/modals/confirm_box.rs
Outdated
); | ||
buf.set_string( | ||
y_n_line_start_position, | ||
confirm_rect.y + confirm_rect.height / 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we lower the y/n line a little so the message is more spread out on the window? I think it'll look a little better. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course! thanks for the remark. To be honest, it wasn't a good idea in the first place now that i think of it.
I think it might be good if i add a "+ 3" at the end of the line:
confirm_rect.y + confirm_rect.height / 2 + 3,
(this is the exact position of the y/n line in deletion_prompt.)
Also, about merging from main: we changed controls.rs in a different PR to now have a macro called |
Thanks! Getting this kind of feedback is very heartwarming and encouraging. :)
Thank you. fixed that. Also, i think i have to thank you for your patience and your useful descriptive explanations. ❤️ |
Hi, @imsnif, i made the changes. but there are 2 things i have to mention:
|
Hey @mhdmhsni, thanks for all the changes. Looks like this is a bigger issue than I initially thought. :) There are a few more things we need to do before we can merge this. I'll list them here, but let me know if you want a hand with them:
About snapshot testing with insta: we use insta (/~https://github.com/mitsuhiko/insta) for snapshot testing. It gives us the I plan on writing all of this up in a CONTRIBUTING.md file, so please let me know if anything is unclear. Thanks again for your work on this and for sticking by. I hope this is not more than you hoped for :) |
Hey @imsnif, it seems that i had only one job and i failed it successfully! :) (sorry for the dad joke!) about the issues you mentioned, I'll work on them as soon as i can. i do not see anything unclear about the things you said. it's clear enough by me. but if i faced any problem resolving these ones i'll let you know. |
Sounds great, @mhdmhsni - take your time, I'm here if you need anything. |
Hey @imsnif, there are a few things i have to say:
|
Oi, that's not good. Thanks for finding this! Yes, please change them all. :)
Hmm... I think the best solution in this case would be to skip the ConfirmModal. Because ScreenTooSmall can also mean that the terminal is 2 columns wide, and then we can't render anything no matter how hard we try. :) In this case, I don't want to force the user to go to another terminal and
That's what I would do too... I would imagine now they fail because we need to update both the amount of snapshots we're expecting (because we added one with the confirm modal) and that the expected_terminal_events also needs to be updated. Let me know if you want a hand looking deeper into these. |
fix panic in modals when terminal-width=50 listen for all possible keys when user tries to exit exit without confirmation in ScreenTooSmall mode fix tests to be compatible with ConfirmModal Changes
…snif#45) * Make enter select largest folder if nothing is selected * Rename method * Renamed and changed method to do what it originally said * Efficiency improvements * Added test for the feature * Run cargo insta review * Fixed len for assert_eq! * Fixed asserts at end of test * Run cargo insta review again
* Add <q> shortcut in the legend * Fix typo for description * Use <arrows> instead of <hjkl> or <arrow keys> * Apply fmt * Merge main
…imsnif#53) * Keep a stack up visited items and make go_up use it This will allow us to keep track of where our previous selections were so can can automatically select the parents when we go up in the hierarchy. Closes imsnif#48. Signed-off-by: Daniel Egger <daniel@eggers-club.de> * Redo snapshot tests to fix failures Signed-off-by: Daniel Egger <daniel@eggers-club.de> * style(naming): minor naming change for clarity Co-authored-by: Aram Drevekenin <aram@poor.dev>
…msnif#51) * Fix crash when truncating to middle of a character * Fix alignment of file names with wide characters * Respect use ::formatting convention
Hi @imsnif, there's a little conflict inside of CHANGELOG.md. and i'm sorry because i forgot to squash the commits after merging main branch into this one! -- nothing fancy has changed, just fixed the tests, snapshots, fixed that terminal_width=50 panic issue, a little change in test_utils that i thought it might be better than defining an extra function which does the the same job. (added an extra parameter to thanks again for all your helps. and if anything needs to change, please feel free to let me know. UPDATE: fixed the conflict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks great.
Thank you for your meticulous work and attention to detail! I'm very happy about this feature. :)
I'm hoping to see more contributions from you in the future.
Thank you! :) |
this commit will add an ability to the app which asks user for confirmation just before exit, both in normal and loading mode. please feel free to comment or ask for any changes.
squashed commits: