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

Add keybinding config file #112

Merged
merged 6 commits into from
Oct 31, 2019
Merged

Add keybinding config file #112

merged 6 commits into from
Oct 31, 2019

Conversation

zacklukem
Copy link
Contributor

This will add a config.yml file along side the client.yml file which
will allow the user to configure custom keybindings. Currently this
commit only covers global keybindings and not per-screen keybindings but
this could be added in the future. This commit also doesn't currently
allow for overriding default navigation keys (hjkl etc.) but that could
also be added later.

Resolves: #46

This will add a `config.yml` file along side the `client.yml` file which
will allow the user to configure custom keybindings.  Currently this
commit only covers global keybindings and not per-screen keybindings but
this could be added in the future. This commit also doesn't currently
allow for overriding default navigation keys (hjkl etc.) but that could
also be added later.

Resolves: Rigellute#46
Fixes clippy and rustfmt errors for 2c7884e
Copy link
Owner

@Rigellute Rigellute left a comment

Choose a reason for hiding this comment

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

This looks really good @zacklukem.

I have only one concern - now that the user can control global key presses, the user could add a global key press that clashes with block specific events or add duplicate global events, which might lead to confusion for the user.

For example, as it stands the user would not be able to create a global event using enter, hjkl, arrow keys or backspace since this would break the block level behaviour.

I suppose this is a tradeoff for providing customisation, and to help with this we could add some more user facing validation in user_config.

Thoughts?

repeat: 'r'
search: '/'
```

Copy link
Owner

Choose a reason for hiding this comment

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

Good explanation 👍

let config_string = fs::read_to_string(&paths.config_file_path)?;
let config_yml: UserConfigString = serde_yaml::from_str(&config_string)?;

macro_rules! to_keys {
Copy link
Owner

Choose a reason for hiding this comment

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

Nice macro 👍

Reserves the keys, hjkl up down left right, backspace and return and
prevents them from being used in user keybinding config.
@zacklukem
Copy link
Contributor Author

I added code to check hjkl, return and arrow keys

}

fn check_reserved_keys(key: Key) -> Result<(), failure::Error> {
let reserved = [
Copy link
Contributor Author

@zacklukem zacklukem Oct 29, 2019

Choose a reason for hiding this comment

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

We can add more keys to check here, but if we want to add checks for keys that the user can re-bind, we would need to use a vec or maybe a hashmap in order to not prevent the user from doing something like this:

decrease_volume: '+'
increase_volume: '-'

Because with current code, if we add + and - to the reserved keys, the User wouldn't be able to do something like this, even if it is valid.

I think it isn't too important to block keys that are configurable from being reused by the user at all, as those keys are documented in the README.

Thoughts?

@zacklukem zacklukem requested a review from Rigellute October 29, 2019 14:33
@jfaltis
Copy link
Contributor

jfaltis commented Oct 29, 2019

This looks very nice @zacklukem. I would suggest to move all the keybindings into one section in the config file to get a nicer structure into the config (because there are probably more settings sections than only keybindings in the future). This needs to be added asap so there is no need to transform existing configuration files into the new configuration file structure. I submitted a pull request with these changes to your branch.

zacklukem#1

Move keybindings into its own section in config file
@Rigellute
Copy link
Owner

Sorry for late response - I intend to review this again tomorrow (not able to look at the moment)

Copy link
Owner

@Rigellute Rigellute left a comment

Choose a reason for hiding this comment

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

Apologies again for the delay.

This looks great, thank you for working on it.

One more piece we could add would be to read the custom keybindings in the help menu with spotify-tui - right now it shows the hardcoded global keypresses

@Rigellute Rigellute merged commit 06d7b91 into Rigellute:master Oct 31, 2019
@Rigellute
Copy link
Owner

@all-contributors please add @zacklukem for code

@allcontributors
Copy link
Contributor

@Rigellute

I've put up a pull request to add @zacklukem! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a configuration file (e.g. for keybindings, etc.)
3 participants