Support markup in menu command
This commit is contained in:
parent
69b16d814b
commit
db2fa6f5cb
|
@ -1386,7 +1386,8 @@ const CommandDesc menu_cmd = {
|
||||||
"menu and execute commands for the selected item",
|
"menu and execute commands for the selected item",
|
||||||
ParameterDesc{
|
ParameterDesc{
|
||||||
{ { "auto-single", { false, "instantly validate if only one item is available" } },
|
{ { "auto-single", { false, "instantly validate if only one item is available" } },
|
||||||
{ "select-cmds", { false, "each item specify an additional command to run when selected" } } }
|
{ "select-cmds", { false, "each item specify an additional command to run when selected" } },
|
||||||
|
{ "markup", { false, "parse menu entries as markup text" } } }
|
||||||
},
|
},
|
||||||
CommandFlags::None,
|
CommandFlags::None,
|
||||||
CommandHelper{},
|
CommandHelper{},
|
||||||
|
@ -1394,6 +1395,7 @@ const CommandDesc menu_cmd = {
|
||||||
[](const ParametersParser& parser, Context& context)
|
[](const ParametersParser& parser, Context& context)
|
||||||
{
|
{
|
||||||
const bool with_select_cmds = (bool)parser.get_switch("select-cmds");
|
const bool with_select_cmds = (bool)parser.get_switch("select-cmds");
|
||||||
|
const bool markup = (bool)parser.get_switch("markup");
|
||||||
const size_t modulo = with_select_cmds ? 3 : 2;
|
const size_t modulo = with_select_cmds ? 3 : 2;
|
||||||
|
|
||||||
const size_t count = parser.positional_count();
|
const size_t count = parser.positional_count();
|
||||||
|
@ -1411,7 +1413,8 @@ const CommandDesc menu_cmd = {
|
||||||
Vector<String> select_cmds;
|
Vector<String> select_cmds;
|
||||||
for (int i = 0; i < count; i += modulo)
|
for (int i = 0; i < count; i += modulo)
|
||||||
{
|
{
|
||||||
choices.push_back({ parser[i], {} });
|
choices.push_back(markup ? parse_display_line(parser[i])
|
||||||
|
: DisplayLine{ parser[i], {} });
|
||||||
commands.push_back(parser[i+1]);
|
commands.push_back(parser[i+1]);
|
||||||
if (with_select_cmds)
|
if (with_select_cmds)
|
||||||
select_cmds.push_back(parser[i+2]);
|
select_cmds.push_back(parser[i+2]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user