shrub/main/app/shell/core.hook

462 lines
15 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
::
|% ::
2014-10-31 04:54:54 +03:00
++ axle ::
2014-11-01 03:53:11 +03:00
$: pid=@u :: next process id
pax=_`path`/=try= :: working directory
act=(unit span) :: active child
pip=(map span span) :: pipe out->in
pop=(map span span) :: pipe in->out
2014-11-06 01:40:18 +03:00
pot=(map span ,[cord prom]) :: prompts
2014-11-01 03:53:11 +03:00
var=(map term vase) :: variables
2014-10-31 04:54:54 +03:00
== ::
2014-09-12 06:11:03 +04:00
++ 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-22 06:59:05 +04:00
[%sage p=path q=*] ::
2014-10-24 02:56:06 +04:00
[%verb ~] ::
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-10-31 04:54:54 +03:00
++ glas $|(%out [%in 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
2014-10-31 00:57:47 +03:00
[%comt ~] :: comment
2014-10-10 02:57:24 +04:00
[%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-22 06:59:05 +04:00
[%sage p=path q=*] ::
2014-10-24 02:56:06 +04:00
[%verb ~] ::
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-24 00:22:01 +04:00
%+ ifix [(star ace) gaw]
;~ pose
2014-10-10 02:57:24 +04:00
(stag %run ;~(plug (star ;~(sfix (task(tol %0) bar) ace)) (task col)))
2014-10-31 00:57:47 +03:00
(stag %end ;~(pfix col sem ;~(pose (stag %& dem) (stag %| sym))))
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))))
2014-10-22 06:04:27 +04:00
(stag %path (full ;~(sfix loca(pax paf) (star ace))))
2014-10-14 05:27:54 +04:00
(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-31 00:57:47 +03:00
(stag %comt ;~(pfix col col (cold ~ (star prn))))
2014-11-12 03:50:49 +03:00
(stag %comt (easy ~))
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-10-31 04:54:54 +03:00
:::: per event
::
|%
++ ve
|= [hid=hide ost=bone axle]
=* vat +<+>
=| mow=(list move)
|%
++ abet
^- [(list move) axle]
[(flop mow) vat]
::
++ blab
|= mof=(list move)
+>.$(mow (welp mof mow))
::
++ chew-file
|= [paf=path msg=tape tor=(unit toro)]
^- (list move)
%+ welp
(print palm/[" " ~ ~ ~]^~[leaf/msg (dank:ut paf)])
%+ turn (drop tor)
|=(a=toro [ost %pass writ/paf %c %info our.hid a])
::
++ cubs :: tasks with open /in
%- 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)
==
~
(some i.t.a)
::
++ eat
|= [you=ship com=coma]
?- -.com
%comt +>.$
%del (eat-del +.com)
%end (eat-end +.com)
%hoon (eat-hoon +.com)
2014-10-31 04:54:54 +03:00
%ins (eat-ins +.com)
%mut (eat-mut +.com)
%path (eat-path +.com)
2014-10-31 04:54:54 +03:00
%run (eat-run you +.com)
%rvar (eat-rvar +.com)
%var (eat-var +.com)
2014-10-01 01:53:37 +04:00
==
2014-10-31 04:54:54 +03:00
::
++ eat-del
|= paf=path
^+ +>
=. &3.paf '='
%- blab
%+ chew-file paf
?^ (file paf) ["! none" ~]
["deleted" `(fray paf)]
::
2014-11-01 03:53:11 +03:00
++ eat-end :: XX clean up state
2014-10-31 04:54:54 +03:00
|= poc=(each ,@u cord)
^+ +>
?- -.poc
%&
=+ cil=(scot %ud p.poc)
=+ cin=(trip (~(got by cub.hid) cil))
%+ blab
[ost %pass /child/[cil]/fork %g %cide cil]
(print leaf/"- :{cin}({(trip cil)})")
::
%|
=+ ^- moz=(list move)
%+ murn (~(tap by cub.hid))
|= [a=span b=term]
?. =(b p.poc) ~
%- some
[ost %pass /child/[a]/fork %g %cide a]
%- blab %+ welp moz
(print leaf/"-{<(lent moz)>} :{(trip p.poc)}")
2014-10-14 05:27:54 +04:00
==
2014-09-23 02:20:47 +04:00
::
2014-10-31 04:54:54 +03:00
++ eat-hoon
|= gen=twig
^+ +>
(blab (print (sell (exec gen))))
::
++ eat-ins
|= [paf=path gen=(unit twig)]
^+ +>
=. &3.paf '='
%- blab
%+ chew-file paf
?^ (file paf) ["! exists" ~]
:- "written"
`(foal paf q:(exec (fall gen [%bczp atom/%t])))
::
++ eat-mut
|= [paf=path gen=twig]
^+ +>
=. &3.paf '='
%- blab
%+ chew-file paf
?^ (file paf) ["! none" ~]
["changed" `(foal paf q:(exec gen))]
::
++ eat-path
|= paf=path
^+ +>
=. pax paf
(blab (print leaf/"=% {(spud paf)}"))
::
++ eat-run
|= [you=ship mud=(list mand) mad=mand]
^+ +>
2014-11-05 23:35:36 +03:00
:: =. +>.$ (blab (print leaf/"+ :{(trip p.mad)}"))
=| inp=(unit span)
2014-10-31 04:54:54 +03:00
=< +>.$
2014-10-10 00:05:21 +04:00
%+ reel
2014-10-31 04:54:54 +03:00
`(list mand)`(welp mud mad ~)
=+ a=[app=*mand .]
|.
=> a
2014-09-26 04:10:17 +04:00
=+ cil=(scot %ud pid)
2014-10-31 04:54:54 +03:00
%_ +>
2014-10-10 00:05:21 +04:00
pid +(pid)
pip ?~ inp pip (~(put by pip) cil u.inp)
pop ?~ inp pop (~(put by pop) u.inp cil)
inp `cil
2014-10-31 04:54:54 +03:00
mow
=+ yon=[our.hid cil imp.hid]
=+ mez=[(cat 3 p.app '-args') (exec [%clsg q.app])]
2014-10-31 04:54:54 +03:00
%- welp :_ mow
^- (list move)
2014-10-31 04:54:54 +03:00
:~ [ost %pass /child/[cil]/fork %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
==
::
2014-10-31 04:54:54 +03:00
++ eat-rvar
|= vor=term
^+ +>
=+ mod=(~(has by var) vor)
=. var (~(del by var) vor)
(blab (print leaf/"{?:(mod "var gone" "no var")} {<vor>}"))
::
++ eat-var
|= [vor=term gen=twig]
^+ +>
=+ old=(~(get by var) vor)
=+ new=(exec gen)
2014-10-10 02:33:00 +04:00
=+ mod=?~(old "new var" ?:(=(new u.old) "same var" "changed"))
2014-10-31 04:54:54 +03:00
=. var (~(put by var) vor new)
(blab (print leaf/"{mod} {<vor>}"))
2014-10-02 04:46:24 +04:00
::
2014-10-31 04:54:54 +03:00
++ exec
|= gen=twig
%- slap :_ gen
%+ roll (~(tap by var))
=< .(q pit)
|= [[n=term v=vase] q=vase]
(slop [[%face n p.v] q.v] q)
2014-09-25 04:37:29 +04:00
::
2014-10-31 04:54:54 +03: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)
::
++ peer
|= [you=ship gal=glas]
^+ +>
?@ gal
%_ +>.$
mow :_(mow [ost %give %rush %term-line prompt ~ ~])
==
?. (~(has by cub.hid) p.gal) +>.$
?: (~(has by pop) p.gal) +>.$
=. act `p.gal
(blab ping)
::
++ ping (print-vase !>(*(list tank)))
++ poke-kyev
|= [you=ship key=kyev]
^+ +>
?: ?=([~ @] key) (poke-txt you q.key) :: simple keypress ?
?> ?=([[%ctrl ~ ~] @t] key)
?+ q.key
%+ blab
[ost %give %nice ~]
(print leaf/"no command \\{(trip q.key)}")
%x =. act next-act
(blab [ost %give %nice ~] ping)
%l =+ =- tak=rose/[" " "[" "]"]^(turn cubs -)
|= a=span
leaf/(trip (rap 3 (~(got by cub.hid) a) '(' a ')' ~))
(blab [ost give/nice/~] (print tak))
==
::
++ poke-txt :: handle command
|= [you=ship txt=cord]
^+ +>
?^ act :: pipe to child
%+ blab
[ost %give %nice ~]
(spam /in/[u.act] %rush %txt txt)
=+ pas=((full ~(parse from pax lat.hid)) [1 1] (trip txt))
?~ q.pas
(blab (print leaf/"<syntax error at {<`[@ @]`p.pas>}>"))
=+ com=(wonk pas)
=> .(+>.$ (eat you com))
=. +>.$ (blab (stash txt))
+>.$(mow :_(mow [ost %give %nice ~]))
2014-09-23 03:06:55 +04:00
::
2014-10-31 04:54:54 +03:00
++ print |=(a=tank (print-vase !>(`(list tank)`[a ~])))
++ print-vase
|= tan=vase :: [p=p:!>(*(list tank)) q=*]
^- (list move)
%^ spam /out %meta
:(slop !>(%rush) !>(%term-line) !>(prompt) !>(~) tan)
::
++ prompt
2014-11-06 01:40:18 +03:00
^- [cord prom]
2014-10-31 04:54:54 +03:00
?^ act
2014-11-01 03:53:11 +03:00
=+ por=(~(get by pot) u.act)
?^ por u.por
2014-11-06 01:40:18 +03:00
[(rap 3 (~(got by cub.hid) u.act) '(' u.act ') ' ~) %text]
:_ %text
2014-10-31 04:54:54 +03:00
?. &(?=([@ @ @ *] pax) =('0' &3.pax))
(rsh 3 1 (spat pax))
2014-11-05 23:35:36 +03:00
(rap 3 &1.pax '/' &2.pax '=' ?~(|3.pax ~['> '] ~[(spat |3.pax) '> ']))
2014-10-31 04:54:54 +03:00
::
++ purr
|= [cil=span fom=?(%fork %out %main) typ=type sih=sign]
^+ +>
?< ?=(?(%sage %verb %veer %vega) +<.sih)
?- fom
%fork
2014-09-23 02:20:47 +04:00
?> ?=(%gone +<.sih)
2014-10-31 04:54:54 +03:00
%_ +>.$
mow :_(mow [ost %give %nice ~])
act ?:(=(act [~ cil]) ~ act)
==
::
2014-09-23 05:00:25 +04:00
%main
?> ?=(?(%nice %mean) +<.sih)
2014-10-31 04:54:54 +03:00
(blab [ost %give +.sih] ping)
::
2014-09-27 05:01:17 +04:00
%out
2014-10-31 04:54:54 +03:00
?. ?=(?(%rust %rush) +<.sih) +>.$
2014-11-05 23:35:36 +03:00
?: ?=(%prompt p.sih)
?: (~(has by pip) cil) +>.$
2014-11-06 01:40:18 +03:00
=. pot (~(put by pot) cil (,[cord prom] q.sih))
2014-11-05 23:35:36 +03:00
(blab ping)
2014-10-31 04:54:54 +03:00
%- blab
?: (~(has by pip) cil)
(spam /in/(~(got by pip) cil) %meta (slot 3 typ sih))
%- print-vase
2014-09-26 04:54:51 +04:00
?+ p.sih
2014-10-01 01:07:40 +04:00
!>([(sell (slot 15 [typ sih]))]~)
2014-11-01 03:53:11 +03:00
%tang (slot 15 [typ sih])
%txt
?^ q.sih !! :: move to vase space?
!>([leaf/(trip q.sih)]~)
2014-10-31 04:54:54 +03:00
==
2014-09-23 02:20:47 +04:00
==
2014-10-31 04:54:54 +03:00
::
++ spam
|= [pax=path gip=gift]
^- (list move)
%+ turn
(~(tap in (~(get ju pus.hid) pax)))
|=(a=bone [a %give gip])
::
++ stash
|= a=cord
%^ spam /out %meta
!>([%rush %term-line `term-line`[prompt [a]~ ~]])
--
--
!:
:::: formal interface
::
|_ [hid=hide vat=axle]
2014-09-23 02:20:47 +04:00
::
2014-10-31 04:54:54 +03:00
++ peer :: handle subscription
|= [ost=bone you=ship pax=path]
^- [(list move) _+>]
?~ pax `+>.$
?. ?=(?(%in %out) i.pax) `+>.$
=+ ^= gal
?: ?=(%out i.pax) %out
2014-11-05 23:35:36 +03:00
[%in ?<(?=(~ t.pax) i.t.pax)]
2014-10-31 04:54:54 +03:00
=+ abet:(peer:(ve hid ost vat) you gal)
[-< +>.$(vat ->)]
2014-10-03 03:00:57 +04:00
::
2014-10-31 04:54:54 +03:00
++ poke-kyev :: handle key event
|= [ost=bone you=ship key=kyev]
^- [(list move) _+>]
=+ abet:(poke-kyev:(ve hid ost vat) you key)
[-< +>.$(vat ->)]
2014-10-01 01:53:37 +04:00
::
2014-10-31 04:54:54 +03:00
++ poke-txt :: handle command
|= [ost=bone you=ship txt=cord]
^- [(list move) _+>]
=+ abet:(poke-txt:(ve hid ost vat) you txt)
[-< +>.$(vat ->)]
2014-10-02 04:42:59 +04:00
::
2014-10-31 04:54:54 +03:00
++ purr
|= [ost=bone pax=path typ=type sih=sign]
^- [(list move) _+>]
?: ?=(%sage +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
?: ?=(%verb +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
?: ?=(%veer +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
?: ?=(%vega +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
?~ pax ~& %no-path !!
?> ?=([%child span ?(%fork %out %main) ~] pax)
=+ abet:(purr:(ve hid ost vat) i.t.pax i.t.t.pax typ sih)
[-< +>.$(vat ->)]
2014-09-12 06:11:03 +04:00
--