-
Notifications
You must be signed in to change notification settings - Fork 106
Implement item shortcuts #176
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #176 +/- ##
============================================
- Coverage 97.26% 93.99% -3.28%
- Complexity 423 466 +43
============================================
Files 25 26 +1
Lines 1317 1465 +148
============================================
+ Hits 1281 1377 +96
- Misses 36 88 +52
Continue to review full report at Codecov.
|
looks good to me! I like the fact that you don't need to run anything extra to apply the shortcuts. One minor thing I would add to the shortcuts example is change On a side note, did you notice what I said about the newly added method setDefaultControlMappings needing to be re-applied on submenus? I guess that makes sense but it's a bit undesired.. not sure how we could allow the user to set them so they are always applied. If this were a Laravel package project then you could achieve this through a configuration file (ideal) or by using the Cache helper (hacky) but not sure how it could be done otherwise. |
I'll write a better review later but for now I would just like to say that it should be optionnal. Note: we will need to make sure that the custom regexp only returns one character. |
@Lynesth that regex only matches a single character anyway. I think setting the regex is a going a bit far. If that level of customisation is really needed then you could just use the custom control mapping on CliMenu directly. I'll add a method to disable the shortcuts now. |
Docs and feature to disable added. |
@AydinHassan I'm still convinced it should be the other way around (auto-shortcuts disabled by default) to maximize BC. And if adding a function to enable it, why not have it set the regexp on the fly ? public function enableAutoShortcuts($regexp = '/\[(.)\]/') : self
{
$this->autoShortcutsRegexp = $regexp;
$this->autoShortcuts = true;
return $this;
} That way we can easily add items to the menu like those:
without having to manually add custom controls (since automation seems to be the point of this PR) simply by using |
I guess a couple of reasons:
|
Considering your own example for adding keyboard shortcuts makes use of a square bracket:
It would be bad if this push led to a fatal error for anyone that's implemented their key shortcuts in this manner, as I would imagine it's highly likely that people are using shortcuts in exactly this manner. If this doesn't lead to an error though then I think it's good the way it is. I am generally however always in favour of defaults that can be easily overridden. |
@vesper8 that will still work correctly! |
In response to each of your points:
// Added this item
$builder->addItem('Click here to go back or press [X] to quit the application', myFunction() {
echo 'You went back';
});
// Then made this shortcut
$menu->addCustomControlMapping('x', function() {
echo 'You exited';
});
|
Right okay. Feel free to take over the PR. |
Hmmm, I'm sorry if I made you mad or anything, conveying emotions with written words isn't easy (especially in another language). I wasn't angry (and surely didn't want to make you angry), just trying to make my point but i'm really not sure I manage to convince you. That's your project first and foremost so unless you're okay with my proposal I think you should stay true to your beliefs. Or maybe we could simply ask more people their opinion on this so that it isn't just our two point of views "clashing". What do you say ? |
It's fine, I just don't have any more time to spare on this. I thought it would be easier 🙂 |
I'm all for attaching an extra command to the flow in order to activate this automapping.. it makes sense for the user to need to ask for it. Hope this can be re-opened quickly :) Can't wait to have this awesome functionality merged in! Thank you both for your awesome work on this project! |
@Lynesth @AydinHassan Hey guys.. you both worked hard on this awesome PR.. I'm sure everyone that uses this package would love to have this functionality in. If you're worried about backwards compatibility then maybe just push a new major version out to include it? This PR is just about done.. seems like a big waste to let it rot away at this point.. |
@vesper8 maybe I can find some time in the next few days but a lot has happened recently, my partner has been in hospital and life is a bit complicated 😓 |
@AydinHassan so sorry to hear about your partner, i hope they're ok and things are stable. my step-dad has been in and out of the hospital as of late and is on the list for a heart transplant so i know what it's like. of course this is a priority over any code project.. i'm sure you understand how i feel, about a few hours of work having already been spent on this PR and it just needs another little bump to get to the finish line, would be a shame if it never does.. maybe at least re-open the PR for now.. and when you have time, even if that's weeks from now, then you can make those last changes for backwards compatibility and merge it in. I think it will be a fine addition! I've been using my own implementation of automap shortcuts that started off this PR and I've been finding it immensely useful. I'm sure others would to Cheers and good health to you and yours! |
Hey there, sorry I disappeared, I'm having some health issues and will not be able to contribute for some time. This PR looks fine to me. Thank you for taking my opinion in account on this matter I really appreciate it. Kind regards |
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 guess the only thing missing the the explanation about the regex in the docs.
Appart from that it sounds good :)
Great thanks. The regex docs can come later. Sorry about your health. I hope it's not too serious and wish you all the best. It seems like it's been a shitty time for all of us 😔 |
Tagged 3.2.0 :) |
I've implemented shortcuts based on the code from #171 with support for getting the selected item. I've done it a bit different, in the builder. I think that's the better place for something like this. Eg added convenience using the raw methods on
CliMenu
.What do you think?
@Lynesth @vesper8 @mikeymike
Will write some docs if everyone likes :)