-
-
Notifications
You must be signed in to change notification settings - Fork 651
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
get_mode_info
based on keybinds
#319
Conversation
get_mode_info
according to keybindsget_mode_info
based on keybinds
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.
This is excellent to have! Another thing that's been on my todo list!
I've left a couple of comments for consideration and might like to get some second opinions about the Display
implementation, but things are looking great so far 😄
The status bar plugin might also need the mode removed where it does this:
The <p>ane
thing won't really work once that key is remapped. Try shrinking your terminal to see it switch to this mode :)
|
I'm also working on status bar improvement, but it may take a while horasal@18ff3a7 |
Hey @horasal ! Thanks for doing all of this! Is this ready for a review or are you looking to finish your status-bar improvements first? |
@TheLostLambda Status-bar improvements needs many extra works so I decide to file another pr for that |
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.
Overall looking great! I would personally simplify the const fn
into a HashMap
stored in State
and would merge the actions
module into the data
module, but aside from that, this looks ready to merge!
If you want to sort out the merge conflicts and address those two points, I'm happy to press the button for you!
use std::collections::HashMap; | ||
|
||
// const fn now does not support PartialEq/Eq, we have to implement our own compare fn | ||
const fn compare_key(l: &Key, r: &Key) -> bool { |
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.
These are really cool (and I also realize I told you to try using these when this code was still in Zellij 😅 ), but if you'd like, the State
struct here is secretly stored in a lazy_static!
already! You could go back to your shorter first solution and pop the HashMap in there and implement either Default
or populate it during the call to load()
.
Sorry again to do the 180 on you here, but that would probably clean things back up a little!
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.
I tried to put key_order
in State. However, it's necessary to pass Hashmap
everywhere and it's really annoying. I prefer a lazy_static
in mode_info.rs
or just use current const. How do you think about it? or is there any better way to pass Hashmap
around?
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.
I'll give this a more thorough review today, but I think this vastly simplifies these two const fn
s into one! (Let me know if this actually is not doing the right thing 😅)
const fn get_key_order(key: &Key) -> Option<i32> {
match key {
Key::Left | Key::Right => Some(0),
Key::Up | Key::Down => Some(1),
Key::PageUp | Key::PageDown => Some(2),
Key::Char(_) => Some(3),
_ => None,
}
}
Match doesn't actually need Eq
to function in this basic manner :)
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.
you're right. this looks awesome!
zellij-tile/src/lib.rs
Outdated
@@ -1,3 +1,4 @@ | |||
pub mod actions; |
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.
I'd personally merge this file in with the data
module, but if you disagree, I'm happy to chat about it!
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.
Merged into data 9c0767a
} | ||
} | ||
|
||
impl Display for Key { |
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.
Looks great!
@@ -71,8 +105,7 @@ impl Default for InputMode { | |||
#[derive(Default, Debug, Clone, Serialize, Deserialize)] | |||
pub struct ModeInfo { | |||
pub mode: InputMode, | |||
// FIXME: This should probably return Keys and Actions, then sort out strings plugin-side | |||
pub keybinds: Vec<(String, String)>, // <shortcut> => <shortcut description> | |||
pub keybinds: Vec<(Key, Vec<Action>)>, |
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.
This looks awesome! You said the HashMap had some issues with JSON, right?
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.
Yes, Json can not serialize HashMap<Key, ..>
because Key will be serialized as a map but a map can not be a key in json.
rebased |
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.
This is coming along well! I think there is a bit of behavior that we need to fix though. Currently, the first part of the status bar will always show the defaults and never custom keybinds (as far as I can tell).
Also, this mode:
Still needs removing I think!
Sorry this is taking so long, it's a quite complex change, but certainly an important one!
use std::collections::HashMap; | ||
|
||
// const fn now does not support PartialEq/Eq, we have to implement our own compare fn | ||
const fn compare_key(l: &Key, r: &Key) -> bool { |
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.
I'll give this a more thorough review today, but I think this vastly simplifies these two const fn
s into one! (Let me know if this actually is not doing the right thing 😅)
const fn get_key_order(key: &Key) -> Option<i32> {
match key {
Key::Left | Key::Right => Some(0),
Key::Up | Key::Down => Some(1),
Key::PageUp | Key::PageDown => Some(2),
Key::Char(_) => Some(3),
_ => None,
}
}
Match doesn't actually need Eq
to function in this basic manner :)
Thanks for all of your continued hard work on this! I think it might be a little confusing if we had a half-functional rebinding UI like this in main, so I'd personally like to combine this PR with the status-bar fixes, but I know that might make for a big diff. Let me know if you'd be up for that! |
|
@TheLostLambda status bar now correctly show new keybinds: |
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.
This is great! I really like the new status bar behavior! It does seem like we've lost a little bit of spacing though if you'd like to add that back in. It may be hard to see without the proper fonts installed.
The spacing before Ctrl
and around each item of the first line seems to have gone missing.
Additionally, were there some complications with including the []
keybindings in the tip?
Thanks again for all of your hard work! This is incredible stuff!
rebased |
@TheLostLambda |
Unfortunately our tests are a little flaky at times, especially on the CI :( It's on my TODO. I re-ran them and they pass now. |
@TheLostLambda I'm wondering if anyone (maybe @denismaxim0v can provide some hints?) can resolve these conflicts. p.s. I'm pretty sure that we can just change the color of impl ShortCutTextElement {
fn to_styled_text(&self, style: CtrlKeyMode) -> ANSIGenericString<str> { // all colors are defined in this function
match (style, self) {
(CtrlKeyMode::Unselected, ShortCutTextElement::Prefix) => {
Style::new().fg(GRAY).on(BRIGHT_GRAY) // just change things here
} |
Hey @horasal - I'm afraid I now had to change things even further in regards to color themes and the api of the plugins! |
This pr changes the default static
get_mode_info
to dynamically strings generated from keybinds.Now
get_mode_info
acceptsKeybind
and will searchKey
for eachAction
.key
is handled by the following rules: