Comments (6)
Hello, unfortunately that is not currently possible. You would have to customise a lot of the components to make that work.
I'd probably start with creating a new menu item and customise the select action:
cli-menu/src/MenuItem/MenuMenuItem.php
Line 79 in 7ba829f
This is what is triggered when you "select" the item. Note that you will need to manually construct the CliMenu
instance. You might also need to replicate some of the code in this method too:
cli-menu/src/Builder/CliMenuBuilder.php
Line 207 in 92dd003
from cli-menu.
Thank you for the help! Sounds a bit daunting but at least you think it is possible? It would be a nice addition to cli-menu IMO. I may give it a crack
from cli-menu.
@AydinHassan Could you perhaps say a few more words though about why this isn't currently possible, and what would need to change (what I would need to add) in order to make it possible?
Is it not possible only because I am dealing with a sub-menu?
from cli-menu.
@vesper8 each menu type (https://github.com/php-school/cli-menu/tree/master/src/MenuItem) has a method getSelectAction
- in the case of normal selectable items, you provide the callable to be executed. In the case of submenu's the action is not customisable - it is closure which opens the menu, see my first link in the previous comment.
We could allow to specify a custom callback for when a submenu is selected but we would need to flesh out the order in which this should happen, should the user function be executed before or after the sub menu is opened? Should the user function just be passed the default action and they can just run that as and when they want?
Overall I'm not entirely sure we need this as a feature, I'd like to see an implementation before I decide if the complexity is worth it. I appreciate it might not be worth your effort in that case, so that's your call 😃
from cli-menu.
Ok thanks for the clarification @AydinHassan
Before I decide whether I want to give this a shot, can you see an alternative way of achieving what I want to do with another type of menu item?
For me it really doesn't have to be a sub-menu.. The desired outcome is that upon clicking a menu item, I am given a list of freshly-generated options, and upon clicking any of those options, an action is immediately executed.
Is there a way to achieve this right now?
from cli-menu.
@vesper8 no there is no other way
from cli-menu.
Related Issues (20)
- Custom and auto mappings can't override default HOT 18
- Menu Dialog HOT 12
- Menu blink because deprecated warning. HOT 4
- Terminal overflow and menu size HOT 2
- Checked checkbox HOT 3
- Windows compatibility: replace posix_isatty() with stream_isatty() HOT 5
- Menu items and cp1251 HOT 3
- setPromptText - multiline support HOT 5
- PHPStorm - How to debug HOT 3
- PHPUnit problem if first item is not a SelectableItem which calls ->close() HOT 2
- Don't work setWidth() for MenuStyle HOT 4
- askText() requires two presses of enter and cuts the line (during copy/paste) HOT 1
- Pressing backspace in an empty text input crashes the menu system HOT 8
- Missing import HOT 3
- Replace ctype_digit with is_numeric ? HOT 2
- Feature request - ability to add sub-menu from addItem's callable HOT 9
- How do I capture CTRL+C event? HOT 2
- preserving selection index as you move up/down
- Feature: present menu "inline"; without clearing terminal screen HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli-menu.