shrub/main/app/shell/core.hook

372 lines
12 KiB
Plaintext
Raw Normal View History

2014-09-26 04:10:17 +04:00
:: Shell
2014-09-12 06:11:03 +04:00
::
2014-09-26 04:10:17 +04:00
:::: /hook/core/shell/app
2014-09-12 06:11:03 +04:00
::
/? 314
2014-10-10 01:58:47 +04:00
/- term-line, kyev
/= pit /~ !>(.) :: kernel vase
2014-09-12 06:11:03 +04:00
::
:::: structures
::
|% ::
++ gift ::
$% [%rush p=gilt] ::
2014-09-27 05:01:17 +04:00
[%mean p=ares] ::
2014-09-12 06:11:03 +04:00
[%nice ~] ::
2014-10-01 01:53:37 +04:00
[%meta p=vase] ::
2014-10-04 02:31:16 +04:00
[%veer p=@ta q=path r=@t] ::
[%vega p=path] ::
2014-09-12 06:11:03 +04:00
== ::
++ gilt ::
$% [%term-line p=term-line] ::
[%txt p=cord] ::
== ::
2014-09-12 06:11:03 +04:00
++ hapt ,[p=ship q=path] ::
++ move ,[p=bone q=(mold note gift)] ::
++ note ::
2014-10-14 05:27:54 +04:00
$% $: %c ::
$% [%info p=@p q=toro] ::
== == ::
$: %g ::
2014-09-23 02:20:47 +04:00
$% [%cide p=span] ::
[%show p=hapt q=ship r=path] ::
[%sire p=term q=span] ::
2014-09-23 05:00:25 +04:00
[%mess p=hapt q=ship r=cage] ::
2014-09-25 04:37:29 +04:00
[%meta p=vase] ::
2014-09-12 06:11:03 +04:00
== == == ::
2014-10-10 02:57:24 +04:00
++ mand ,[p=term q=(list twig)] :: name and arguments
2014-09-23 05:00:25 +04:00
++ coma ::
$% [%run p=(list mand) q=mand] :: pipe into
2014-10-10 02:57:24 +04:00
[%end p=(each ,@u cord)] :: kill pid/name
[%path p=path] :: chdir
2014-10-14 05:27:54 +04:00
[%del p=path] :: rm file
[%ins p=path q=(unit twig)] :: add file
[%mut p=path q=twig] :: change file
2014-10-10 02:57:24 +04:00
[%hoon p=twig] :: eval expression
[%var p=term q=twig] :: set variable
[%rvar p=term] :: unset variable
2014-09-23 05:00:25 +04:00
== ::
2014-09-12 06:11:03 +04:00
++ sign ::
$% $: %g ::
2014-09-23 02:20:47 +04:00
$% [%gone p=hapt] ::
2014-09-12 06:11:03 +04:00
[%mean p=ares] ::
2014-09-23 02:20:47 +04:00
[%nice ~] ::
2014-09-26 04:54:51 +04:00
[%rush p=mark q=*] ::
[%rust p=mark q=*] ::
2014-10-04 02:31:16 +04:00
[%veer p=@ta q=path r=@t] ::
[%vega p=path] ::
2014-09-12 06:11:03 +04:00
== == == ::
--
!:
:::: parsers
::
|%
++ maybe |*(fel=_rule (cook |*(a=(unit) (fall a ~)) (opts fel)))
2014-10-10 02:57:24 +04:00
++ opts :: parse unit
|* fel=_rule
;~ pose
(cook some fel)
(easy ~)
==
::
2014-10-10 02:57:24 +04:00
++ from :: parse door
=+ tol=`?(0 1 2)`%2 :: wide, tallish, tall
|_ [pax=path lat=time]
2014-10-10 02:57:24 +04:00
++ rail :: build from wide/tall
|* [wid=_rule wif=_rule tal=_rule]
?~ tol wid
2014-10-17 02:12:34 +04:00
=- ;~(pose wif wid)
^= wif
?: ?=(1 tol) wif
;~(pose tal wif)
::
2014-10-14 05:27:54 +04:00
++ rais |*([wid=_rule tal=_rule] (rail wid wid tal))
::
2014-10-10 02:57:24 +04:00
++ parse :: top level
^- $+(nail (like coma))
=+ paf=pax
2014-10-10 01:58:47 +04:00
=. pax ?.(&(?=([@ @ @ *] pax) =('0' &3.pax)) pax pax(&3 (scot da/lat)))
2014-10-17 03:42:40 +04:00
%+ ifix [(star ace) (star ace)]
;~ pose
2014-10-10 02:57:24 +04:00
(stag %run ;~(plug (star ;~(sfix (task(tol %0) bar) ace)) (task col)))
(stag %end ;~(pfix sem ;~(pose (stag %& dem) (stag %| sym))))
2014-10-17 03:48:57 +04:00
(stag %path (full ;~(sfix loca(pax paf) (star ace))))
2014-10-14 05:27:54 +04:00
(stag %del ;~(pfix hep ace loca))
(stag %mut ;~(pfix col ace ;~(plug loca expg)))
(stag %ins ;~(pfix lus ace ;~(plug loca (opts expg))))
(stag %var ;~(plug ;~(pfix tis sym) expg))
(stag %rvar ;~(pfix ;~(plug tis tis) sym))
2014-10-14 05:27:54 +04:00
(stag %hoon expr)
2014-10-10 02:57:24 +04:00
==
::
2014-10-14 05:27:54 +04:00
++ expg (rais ;~(pfix ace expr(tol %1)) ;~(pfix gap expr))
++ expr (rais [wide tall]:(vang & pax))
++ loca %+ sear ;~(biff plex:(vang & pax) vabe) :: path in %clay
[;~(pose rood ;~(simu cen scat))]:(vang & pax)
++ vabe |=(a=path ?~((tome a) ~ (some a))) :: check valid beam
2014-10-10 02:57:24 +04:00
++ args :: task arguments
%^ rail
2014-10-14 05:27:54 +04:00
(ifix sel^ser (most ace expr))
(plus ;~(pfix ace expr))
;~(sfix (plus ;~(pfix gap expr)) ;~(plug gap duz))
::
2014-10-10 02:57:24 +04:00
++ task |*(fel=_rule ;~(pfix fel ;~(plug sym (maybe args))))
::
--
--
!:
2014-09-12 06:11:03 +04:00
:::: program
::
2014-10-01 01:53:37 +04:00
|_ $: hid=hide
pid=@u
pax=_`path`/=try=
act=(unit span)
pip=(map span span)
pop=(map span span)
2014-10-02 04:42:59 +04:00
var=(map term vase)
2014-10-01 01:53:37 +04:00
==
2014-09-23 02:20:47 +04:00
::
2014-10-10 02:57:24 +04:00
++ peer :: handle subscription
2014-09-27 05:01:17 +04:00
|= [ost=bone you=ship pax=path]
^- [(list move) _+>]
?~ pax `+>.$
?+ i.pax `+>.$
2014-10-03 02:21:23 +04:00
%in :: to app
2014-09-27 05:01:17 +04:00
?~ t.pax `+>.$
?. (~(has by cub.hid) i.t.pax) `+>.$
2014-10-01 01:53:37 +04:00
?: (~(has by pop) i.t.pax) `+>.$
2014-09-27 05:01:17 +04:00
:_ +>.$(act `i.t.pax)
2014-10-03 02:21:23 +04:00
(print ost you ~)
%out :: to terminal
?> ?=(~ t.pax)
2014-10-08 02:38:15 +04:00
:_ +>.$
[ost %give %rush %term-line `term-line`[prompt ~ ~]]~
2014-09-27 05:01:17 +04:00
==
::
2014-10-10 02:57:24 +04:00
++ cubs :: tasks with open /in
2014-10-01 04:29:32 +04:00
%- sort :_ |=([a=span b=span] (lth (slav %ud a) (slav %ud b)))
^- (list span)
%+ murn (~(tap by sup.hid))
|= [@ @ a=path]
?. ?& ?=([%in cord ~] a)
(~(has by cub.hid) i.t.a)
!(~(has by pop) i.t.a)
==
~
2014-10-01 04:29:32 +04:00
(some i.t.a)
::
2014-10-10 02:57:24 +04:00
++ next-act :: rotate active task
=+ opt=[i=`(unit span)`~ t=(turn cubs |=(a=span `(unit span)`[~ a]))]
|-
?~ t.opt ~
?: =(act i.opt)
i.t.opt
$(opt t.opt)
::
++ poke-kyev :: handle key event
2014-10-10 01:58:47 +04:00
|= [ost=bone you=ship key=kyev]
2014-10-10 02:57:24 +04:00
^- [(list move) _+>]
?: ?=([~ @] key) (poke-txt ost you q.key) :: simple keypress
2014-10-10 01:58:47 +04:00
?> ?=([[%ctrl ~ ~] @t] key)
2014-10-10 02:57:24 +04:00
?+ q.key
:_ +>.$
:- [ost %give %nice ~]
(print ost you leaf/"no command \\{(trip q.key)}" ~)
%x =. act next-act
:_ +>.$
:- [ost %give %nice ~]
(print ost you ~)
%l =+ =- tak=rose/[" " "[" "]"]^(turn cubs -)
|= a=span
leaf/(trip (rap 3 (~(got by cub.hid) a) '(' a ')' ~))
[[[ost give/nice/~] (print ost you tak ~)] +>.$]
==
2014-10-10 01:58:47 +04:00
::
2014-10-10 02:57:24 +04:00
++ poke-txt :: handle command
2014-09-12 06:11:03 +04:00
|= [ost=bone you=ship txt=cord]
^- [(list move) _+>]
2014-10-10 02:57:24 +04:00
?: =('\\' (end 3 1 txt)) :: escaped ctrl-key
(poke-kyev ost you [%ctrl ~ ~] (rsh 3 1 txt))
?^ act :: pipe to child
2014-09-27 05:01:17 +04:00
:_ +>.$
:- [ost %give %nice ~]
(spam /in/[u.act] %rush %txt txt)
2014-10-03 03:00:57 +04:00
::
=- :_ con
2014-10-08 23:29:21 +04:00
%+ welp (stash:con ost you txt)
2014-10-03 03:00:57 +04:00
?~ tak
mof
%+ welp
2014-10-08 23:29:21 +04:00
(print:con ost you tak ~)
2014-10-03 03:00:57 +04:00
[[ost %give %nice ~] mof]
^- [con=_+>.$ tak=$|(~ tank) mof=(list move)]
=+ pas=((full ~(parse from pax lat.hid)) [1 1] (trip txt))
?~ q.pas
[+>.$ leaf/"<syntax error at {<`[@ @]`p.pas>}>" ~]
=+ com=(wonk pas)
^- [con=_+>.$ tak=$|(~ tank) mof=(list move)]
?- -.com
2014-09-23 02:20:47 +04:00
%path
=. pax p.com
[+>.$ leaf/"=% {(spud p.com)}" ~]
2014-10-14 05:27:54 +04:00
::
?(%ins %mut %del)
:- +>.$
=+ paf=[.(&3 '=')]:?+(-.com p.com %del p.com)
=- :- palm/[" " ~ ~ ~]^~[leaf/msg (dank:ut paf)]
(turn (drop tor) |=(a=toro [ost %pass writ/paf %c %info our.hid a]))
2014-10-14 05:27:54 +04:00
^- [msg=tape tor=(unit toro)]
|-
?- -.com
%ins
?^ (file p.com) ["! exists" ~]
["written" `(foal p.com q:(exec (fall q.com [%bczp atom/%t])))]
%mut
?~ (file p.com) $(com [%del p.com])
["changed" `(foal p.com q:(exec q.com))]
%del
?~ (file p.com) ["! none" ~]
["written" `(fray p.com)]
==
2014-09-23 02:20:47 +04:00
::
%run
=+ mof=(print ost you leaf/"+ :{(trip p.q.com)}" ~)
=| inp=(unit span)
=< [+>.$ ~ mof]
2014-10-10 00:05:21 +04:00
%+ reel
`(list mand)`(welp p.com q.com ~)
=+ a=[app=*mand .]
|.
=> a
2014-09-26 04:10:17 +04:00
=+ cil=(scot %ud pid)
2014-10-10 00:05:21 +04:00
::~& [%pipsqueak <inp> <app>]
%_ +>
pid +(pid)
pip ?~ inp pip (~(put by pip) cil u.inp)
pop ?~ inp pop (~(put by pop) u.inp cil)
inp `cil
mof
=+ yon=[our.hid cil imp.hid]
=+ mez=[(cat 3 p.app '-args') (exec [%clsg q.app])]
=- (weld (flop -) mof) :: XX strange order
^- (list move)
:~ [ost %pass /child/[cil] %g %sire p.app cil]
[ost %pass /child/[cil]/out %g %show yon you /out]
[ost %pass /child/[cil]/main %g %meta !>([%mess yon you mez])]
==
2014-09-23 02:20:47 +04:00
==
::
%end
?: ?=(%& -.p.com)
=+ cil=(scot %ud p.p.com)
2014-10-01 04:29:32 +04:00
=+ cin=(trip (~(got by cub.hid) cil))
:- +>.$ :- ~
:_ (print ost you leaf/"- :{cin}({(trip cil)})" ~)
[ost %pass /child/[cil] %g %cide cil]
=* cil p.p.com
=- [+>.$ leaf/"-{<(lent moz)>} :{(trip cil)}" moz]
2014-10-03 03:00:57 +04:00
^= moz
%+ murn (~(tap by cub.hid)) |= [a=span b=term]
?. =(b cil) ~
%- some
[ost %pass /child/[a] %g %cide a]
2014-10-02 04:42:59 +04:00
::
%var
2014-10-10 02:33:00 +04:00
=+ old=(~(get by var) p.com)
=+ new=(exec q.com)
=+ mod=?~(old "new var" ?:(=(new u.old) "same var" "changed"))
=. var (~(put by var) p.com new)
[+>.$ leaf/"{mod} {<p.com>}" ~]
2014-10-02 04:46:24 +04:00
::
%rvar
2014-10-10 02:33:00 +04:00
=+ mod=(~(has by var) p.com)
=. var (~(del by var) p.com)
2014-10-10 02:33:00 +04:00
[+>.$ leaf/"{?:(mod "var gone" "no var")} {<p.com>}" ~]
2014-09-25 04:37:29 +04:00
::
%hoon
[+>.$ (sell (exec p.com)) ~]
2014-09-12 06:11:03 +04:00
==
::
2014-09-26 04:54:51 +04:00
++ purr
|= [ost=bone pax=path typ=type sih=sign]
2014-09-12 06:11:03 +04:00
^- [(list move) _+>]
2014-10-08 02:38:15 +04:00
::~& shel-purr/pax
2014-09-25 04:37:29 +04:00
:: ~& [%shell-pour -.sih (,@ta +<.sih)]
2014-09-26 04:54:51 +04:00
::=+ sih=((hard sign) sih)
2014-10-04 02:31:16 +04:00
?: ?=(%veer +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
?: ?=(%vega +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
2014-09-23 03:06:55 +04:00
?~ pax ~& %no-path !!
2014-09-23 02:20:47 +04:00
?+ &1.pax ~& %strange-path !!
2014-09-23 03:06:55 +04:00
%print
2014-09-27 05:01:17 +04:00
`+>.$
2014-09-23 03:06:55 +04:00
::
2014-09-23 02:20:47 +04:00
%child
2014-09-23 03:06:55 +04:00
?~ |1.pax ~& %no-child !!
?~ |2.pax
2014-09-23 02:20:47 +04:00
?> ?=(%gone +<.sih)
2014-09-27 05:01:17 +04:00
:- [ost %give %nice ~]~
+>.$(act ?:(=(act [~ &2.pax]) ~ act))
:_ +>.$
2014-09-23 03:06:55 +04:00
?+ &3.pax ~& %strange-child-path !!
2014-09-23 05:00:25 +04:00
%main
?> ?=(?(%nice %mean) +<.sih)
2014-10-08 02:38:15 +04:00
:- [ost %give +.sih]
::~& act
(print ost our.hid ~)
2014-09-27 05:01:17 +04:00
%out
2014-09-23 03:06:55 +04:00
?. ?=(?(%rust %rush) +<.sih) ~
2014-10-01 01:53:37 +04:00
?: (~(has by pip) &2.pax)
2014-10-16 02:05:48 +04:00
:: ~& [%yay &2.pax <pip> <pop>]
:: ~& [%spamming-to /in/(~(got by pip) &2.pax) (~(get ju pus.hid) /in/(~(got by pip) &2.pax))]
2014-10-01 01:53:37 +04:00
(spam /in/(~(got by pip) &2.pax) %meta (slot 3 typ sih))
2014-10-16 02:05:48 +04:00
:: ~& [%nay &2.pax <pip> <pop>]
2014-10-01 01:07:40 +04:00
%^ print-vase ost our.hid
2014-09-26 04:54:51 +04:00
?+ p.sih
2014-10-01 01:07:40 +04:00
!>([(sell (slot 15 [typ sih]))]~)
2014-09-26 04:54:51 +04:00
%tang
2014-10-01 01:07:40 +04:00
(slot 15 [typ sih])
%txt
?^ q.sih !! :: move to vase space?
!>([leaf/(trip q.sih)]~)
2014-09-23 02:20:47 +04:00
==
2014-09-26 04:54:51 +04:00
== ==
2014-09-23 02:20:47 +04:00
::
2014-10-03 03:00:57 +04:00
++ stash
|= [a=bone b=ship c=cord]
2014-10-08 23:29:21 +04:00
::~& shel-stash/[prompt c]
%^ spam /out %meta
2014-10-08 02:38:15 +04:00
!>([%rush %term-line `term-line`[prompt [c]~ ~]])
2014-10-03 03:00:57 +04:00
::
2014-10-01 01:07:40 +04:00
++ print |=([a=bone b=ship c=(list tank)] (print-vase a b !>(c)))
++ print-vase
|= [ost=bone you=ship tan=vase] :: [p=p:!>(*(list tank)) q=*]
2014-10-03 02:21:23 +04:00
^- (list move)
2014-10-08 02:38:15 +04:00
::~& shel-print/prompt
%^ spam /out %meta
:(slop !>(%rush) !>(%term-line) !>(prompt) !>(~) tan)
2014-10-01 01:53:37 +04:00
::
2014-10-03 03:00:57 +04:00
++ prompt
2014-10-08 02:38:15 +04:00
^- @t
2014-10-03 03:00:57 +04:00
?^ act
(rap 3 (~(got by cub.hid) u.act) '(' u.act ') ' ~)
2014-10-10 01:58:47 +04:00
?. &(?=([@ @ @ *] pax) =('0' &3.pax))
2014-10-03 03:00:57 +04:00
(spat pax)
(rap 3 '/' &1.pax '/' &2.pax '=' ?~(|3.pax ~ [(spat |3.pax)]~))
++ exec
2014-10-02 04:42:59 +04:00
|= gen=twig
%- slap :_ gen
%+ roll (~(tap by var))
=< .(q pit)
2014-10-02 21:24:17 +04:00
|= [[n=term v=vase] q=vase]
(slop [[%face n p.v] q.v] q)
2014-10-02 04:42:59 +04:00
::
2014-09-27 05:01:17 +04:00
++ spam
|= [pax=path gip=gift]
^- (list move)
%+ turn
(~(tap in (~(get ju pus.hid) pax)))
|=(a=bone [a %give gip])
2014-09-12 06:11:03 +04:00
--