From 8341d99ce0d9daa1b10186feec2bf16e0773b8b8 Mon Sep 17 00:00:00 2001 From: Fang Date: Sat, 6 Jun 2020 18:58:57 +0200 Subject: [PATCH] shoe: optionally auto-run commands on entry The +command-parser must now produce both a flag and a command noun. If the flag is true, instantly runs the command from the noun. If false, maintains standard behavior and only runs it on-return. --- pkg/arvo/app/chat-cli.hoon | 1 + pkg/arvo/app/shoe.hoon | 4 ++-- pkg/arvo/lib/shoe.hoon | 38 ++++++++++++++++++++++++++------------ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/pkg/arvo/app/chat-cli.hoon b/pkg/arvo/app/chat-cli.hoon index 20065b4843..959a1f2707 100644 --- a/pkg/arvo/app/chat-cli.hoon +++ b/pkg/arvo/app/chat-cli.hoon @@ -451,6 +451,7 @@ :: ++ parser |^ + %+ stag | %+ knee *command |. ~+ =- ;~(pose ;~(pfix mic -) message) ;~ pose diff --git a/pkg/arvo/app/shoe.hoon b/pkg/arvo/app/shoe.hoon index 504365c591..83f24b9d6b 100644 --- a/pkg/arvo/app/shoe.hoon +++ b/pkg/arvo/app/shoe.hoon @@ -40,8 +40,8 @@ :: ++ command-parser |= sole-id=@ta - ^+ |~(nail *(like command)) - (cold ~ (jest 'demo')) + ^+ |~(nail *(like [? command])) + (cold [& ~] (jest 'demo')) :: ++ tab-list |= sole-id=@ta diff --git a/pkg/arvo/lib/shoe.hoon b/pkg/arvo/lib/shoe.hoon index 3727c4624b..67ab744044 100644 --- a/pkg/arvo/lib/shoe.hoon +++ b/pkg/arvo/lib/shoe.hoon @@ -35,14 +35,20 @@ |* command-type=mold $_ ^| |_ bowl:gall + :: +command-parser: input parser for a specific session + :: + :: if the head of the result is true, instantly run the command + :: ++ command-parser |~ sole-id=@ta - |~(nail *(like command-type)) + |~(nail *(like [? command-type])) + :: +tab-list: autocomplete options for the session (to match +command-parser) :: ++ tab-list |~ sole-id=@ta :: (list [@t tank]) *(list (option:auto tank)) + :: +on-command: called when a valid command is run :: ++ on-command |~ [sole-id=@ta command=command-type] @@ -106,7 +112,8 @@ |* [shoe=* command-type=mold] |_ =bowl:gall ++ command-parser - (easy *command-type) + |= sole-id=@ta + (easy *[? command-type]) :: ++ tab-list ~ @@ -193,9 +200,9 @@ (~(gut by soles) sole-id *sole-share) |^ =^ [cards=(list card) =_cli-state] shoe ?- -.dat.act - %det [(apply-edit +.dat.act) shoe] + %det (apply-edit +.dat.act) %clr [[~ cli-state] shoe] - %ret run-command + %ret try-command %tab [(tab +.dat.act) shoe] == :- (deal cards) @@ -208,15 +215,18 @@ :: ++ apply-edit |= =sole-change - ^- (quip card _cli-state) + ^+ [[*(list card) cli-state] shoe] =^ inverse cli-state (~(transceive sole cli-state) sole-change) :: res: & for fully parsed, | for parsing failure at location :: - =/ res=(each (unit) @ud) + =/ res=(each (unit [run=? cmd=command-type]) @ud) %+ rose (tufa buf.cli-state) (command-parser:og sole-id) - ?: ?=(%& -.res) [~ cli-state] + ?: ?=(%& -.res) + ?~ p.res [[~ cli-state] shoe] + (run-command cmd.u.p.res) + :_ shoe :: parsing failed :: ?. &(?=(%del -.inverse) =(+(p.inverse) (lent buf.cli-state))) @@ -234,14 +244,18 @@ [%err p.res] :: cursor to error location == :: - ++ run-command + ++ try-command ^+ [[*(list card) cli-state] shoe] - =/ cmd=(unit command-type) + =/ res=(unit [? cmd=command-type]) %+ rust (tufa buf.cli-state) (command-parser:og sole-id) - ?~ cmd - [[[(effect %bel ~)]~ cli-state] shoe] - =^ cards shoe (on-command:og sole-id u.cmd) + ?^ res (run-command cmd.u.res) + [[[(effect %bel ~)]~ cli-state] shoe] + :: + ++ run-command + |= cmd=command-type + ^+ [[*(list card) cli-state] shoe] + =^ cards shoe (on-command:og sole-id cmd) :: clear buffer :: =^ clear cli-state (~(transmit sole cli-state) [%set ~])