urbit/main/app/seat/core.hook

523 lines
18 KiB
Plaintext
Raw Normal View History

2015-02-09 00:22:33 +03:00
:: :: ::
:::: /hook/core/seat/app :: ::
:: :: ::
/? 314 :: zuse version
/- *console :: console structures
/+ console :: console library
:: :: ::
:::: :: ::
!: :: ::
=> |% :: data structures
++ house :: all state
$: bin=(map bone source) :: input devices
== ::
++ source :: input device
2015-02-16 23:18:10 +03:00
$: edg=_79 :: terminal columns
off=@ud :: window offset
kil=(unit (list ,@c)) :: kill buffer
2015-02-09 00:22:33 +03:00
apt=(list term) :: application ring
2015-02-16 23:18:10 +03:00
maz=(unit (list ,@c)) :: master window
2015-02-09 00:22:33 +03:00
feg=(map term target) :: live applications
mir=(pair ,@ud (list ,@c)) :: mirrored state
== ::
2015-02-16 23:18:10 +03:00
++ master :: master buffer
$: pos=@ud :: cursor position
buf=(list ,@c) :: text entry
== ::
2015-02-12 05:57:33 +03:00
++ history :: past input
$: pos=@ud :: input position
num=@ud :: number of entries
lay=(map ,@ud (list ,@c)) :: editing overlay
old=(list (list ,@c)) :: entries proper
== ::
++ search :: reverse-i-search
$: pos=@ud :: search position
str=(list ,@c) :: search string
==
2015-02-09 00:22:33 +03:00
++ target :: application target
2015-02-16 23:18:10 +03:00
$: ris=(unit search) :: reverse-i-search
hit=history :: all past input
2015-02-12 05:57:33 +03:00
pom=console-prompt :: static prompt
2015-02-09 00:22:33 +03:00
inp=console-input :: input state
== ::
++ gift :: out result <-$
$% [%mean p=ares] ::
[%nice ~] ::
[%rush %dill-blit dill-blit] ::
== ::
++ sign-gall :: sign from %gall
$% [%mean p=ares] ::
[%nice ~] ::
[%rush %console-effect console-effect] ::
2015-02-09 09:25:00 +03:00
== ::
2015-02-09 00:22:33 +03:00
++ sign :: in result $<-
$% [%g sign-gall] ::
2015-02-09 09:25:00 +03:00
== ::
2015-02-09 00:22:33 +03:00
++ move ,[p=bone q=(mold note gift)] ::
++ note-gall :: note to %gall
2015-02-12 05:57:33 +03:00
$% [%mess p=[p=ship q=path] q=ship r=cage] ::
2015-02-09 00:22:33 +03:00
[%nuke p=[p=ship q=path] q=ship] ::
[%show p=[p=ship q=path] q=ship r=path] ::
[%took p=[p=ship q=path] q=ship] ::
== ::
++ note :: out request $->
$% [%g note-gall] ::
== ::
-- ::
|_ $: hid=hide :: system state
house :: program state
== ::
++ se :: per source
|_ [moz=(list move) [her=ship ost=bone] source]
++ se-abet :: resolve
[(flop moz) %_(+> bin (~(put by bin) ost +<+>))]
::
++ se-belt :: handle input
2015-02-09 09:25:00 +03:00
|= bet=dill-belt
2015-02-09 00:22:33 +03:00
^+ +>
2015-02-09 09:25:00 +03:00
?: ?=(%rez -.bet)
2015-02-16 23:18:10 +03:00
+>(edg (dec p.bet))
2015-02-09 09:25:00 +03:00
?: ?=(%yow -.bet)
2015-02-09 00:22:33 +03:00
(se-link p.bet)
2015-02-16 23:18:10 +03:00
?^ maz
?+ -.bet (se-blit %bel ~)
::
%bac
?: =(0 (lent u.maz))
(se-blit %bel ~)
+>(u.maz (scag (dec (lent u.maz)) u.maz))
::
%ctl
?+ p.bet (se-blit %bel ~)
%d (se-emit ost %give %mean ~)
%v +>.$(maz ~)
%x $(maz ~)
==
::
%ret (se-like(maz ~) u.maz)
%txt +>(u.maz (weld u.maz p.bet))
==
2015-02-09 00:22:33 +03:00
?~ apt
~& %console-no-terminal
(se-blit %bel ~)
=+ nam=i.apt
2015-02-09 09:25:00 +03:00
=+ taz=~(. ta [& nam] (~(got by feg) nam))
2015-02-09 00:22:33 +03:00
=< ta-abet
?- -.bet
%aro (ta-aro:taz p.bet)
%bac ta-bac:taz
2015-02-09 09:25:00 +03:00
%cru (ta-cru:taz p.bet q.bet)
2015-02-09 00:22:33 +03:00
%ctl (ta-ctl:taz p.bet)
2015-02-09 09:25:00 +03:00
%del ta-del:taz
2015-02-09 00:22:33 +03:00
%met (ta-met:taz p.bet)
2015-02-09 09:25:00 +03:00
%ret ta-ret:taz
2015-02-09 00:22:33 +03:00
%txt (ta-txt:taz p.bet)
==
::
++ se-drop :: passive drop
|= nam=term
^+ +>
?> (~(has by feg) nam)
2015-02-16 23:18:10 +03:00
=: feg (~(del by feg) nam)
apt (skip apt |=(a=term =(nam a)))
==
?^ apt +>
?^ maz +>
+>(maz `~)
2015-02-09 00:22:33 +03:00
::
++ se-join :: add connection
|= nam=term
^+ +>
?< (~(has by feg) nam)
2015-02-16 23:18:10 +03:00
+>(maz ~, apt [nam apt], feg (~(put by feg) nam *target))
2015-02-09 00:22:33 +03:00
::
++ se-nuke :: active drop
|= nam=term
2015-02-09 09:25:00 +03:00
^+ +>
(se-drop:(se-send nam %nuke [her ~[nam]] her) nam)
2015-02-09 00:22:33 +03:00
::
2015-02-16 23:18:10 +03:00
++ se-like :: act in master
|= buf=(list ,@c)
(se-link (crip (tufa buf)))
::
2015-02-09 00:22:33 +03:00
++ se-link :: connect to app
|= nam=term
^+ +>
%. nam
=< se-join
(se-send nam %show [her ~[nam]] her /console)
::
++ se-blit :: give output
2015-02-09 09:25:00 +03:00
|= bil=dill-blit
2015-02-09 00:22:33 +03:00
(se-emit ost %give %rush %dill-blit bil)
::
2015-02-16 23:18:10 +03:00
++ se-show :: show buffer, raw
|= lin=(pair ,@ud (list ,@c))
^+ +>
?: =(mir lin) +>
=. +> ?:(=(q.mir q.lin) +> (se-blit %pro q.lin))
=. +> ?:(=(p.mir p.lin) +> (se-blit %hop p.lin))
+>(mir lin)
::
++ se-just :: adjusted buffer
|= lin=(pair ,@ud (list ,@c))
^+ +>
=. off ?:((lth p.lin edg) 0 (sub p.lin edg))
(se-show (sub p.lin off) (scag edg (slag off q.lin)))
::
2015-02-09 00:22:33 +03:00
++ se-view :: flush buffer
2015-02-16 23:18:10 +03:00
%- se-just
?^ maz
=- [(lent zil) zil]
^= zil ^- (list ,@c)
%- welp
:_ u.maz
|- ^- (list ,@c)
?~ apt [`@c`0x23 `@c`0x20 ~]
=+ nex=$(apt t.apt)
%+ welp (tuba (trip i.apt))
?~(t.apt nex `_nex`[`@c`0x2c `@c`0x20 nex])
?~ apt
~&(%se-no-view [0 ~])
~(ta-vew ta [& i.apt] (~(got by feg) i.apt))
2015-02-09 00:22:33 +03:00
::
++ se-kill :: kill a source
2015-02-09 09:25:00 +03:00
=+ tup=apt
|- ^+ +>
?~ tup +>(apt ~)
$(tup +.tup, +> (se-nuke i.tup))
2015-02-09 00:22:33 +03:00
::
++ se-emit :: emit move
|= mov=move
%_(+> moz [mov moz])
::
++ se-send :: send a message
|= [nam=term nog=note-gall]
(se-emit ost %pass [(scot %p her) nam ~] %g nog)
::
++ se-tame
|= nam=term
2015-02-09 09:25:00 +03:00
~(. ta [& nam] (~(got by feg) nam))
2015-02-09 00:22:33 +03:00
::
++ se-pour :: receive results
|= [nam=term sil=sign-gall]
^+ +>
?- -.sil
%mean
~& [%seat-mean sil]
2015-02-09 00:22:33 +03:00
+>.$
::
%nice
+>.$
::
%rush
2015-02-09 09:25:00 +03:00
ta-abet:(ta-fec:(se-tame nam) +>.sil)
2015-02-09 00:22:33 +03:00
==
::
++ ta :: per target
|_ $: $: liv=? :: don't delete
nam=term :: target app
== ::
target :: target state
== ::
++ ta-abet :: resolve
2015-02-09 09:25:00 +03:00
^+ ..ta
2015-02-09 00:22:33 +03:00
?. liv (se-nuke nam)
%_(+> feg (~(put by feg) nam +<+))
::
++ ta-act :: send action
|= act=console-action
2015-02-09 09:25:00 +03:00
^+ +>
2015-02-12 05:57:33 +03:00
%_(+> +> (se-send nam %mess [her ~[nam]] her %console-action !>(act)))
2015-02-09 00:22:33 +03:00
::
++ ta-aro :: hear arrow
|= key=?(%d %l %r %u)
^+ +>
?- key
2015-02-16 23:18:10 +03:00
%d =. ris ~
?. =(num.hit pos.hit)
2015-02-12 05:57:33 +03:00
(ta-mov +(pos.hit))
?: =(0 (lent buf.say.inp))
ta-bel
(ta-hom:ta-nex %set ~)
2015-02-16 23:18:10 +03:00
%l ?^ ris ta-bel
?: =(0 pos.inp) ta-bel
2015-02-09 09:25:00 +03:00
+>(pos.inp (dec pos.inp))
2015-02-16 23:18:10 +03:00
%r ?^ ris ta-bel
?: =((lent buf.say.inp) pos.inp)
2015-02-09 09:25:00 +03:00
ta-bel
+>(pos.inp +(pos.inp))
2015-02-16 23:18:10 +03:00
%u =. ris ~
?:(=(0 pos.hit) ta-bel (ta-mov (dec pos.hit)))
2015-02-09 00:22:33 +03:00
==
::
2015-02-13 01:50:12 +03:00
++ ta-bel .(+> (se-blit %bel ~)) :: beep
++ ta-cat :: mass insert
|= [pos=@ud txt=(list ,@c)]
^- console-edit
:- %mor
|- ^- (list console-edit)
?~ txt ~
[[%ins pos i.txt] $(pos +(pos), txt t.txt)]
::
++ ta-cut :: mass delete
|= [pos=@ud num=@ud]
^- console-edit
:- %mor
|-(?:(=(0 num) ~ [[%del pos] $(num (dec num))]))
::
++ ta-det :: send edit
|= ted=console-edit
^+ +>
(ta-act %det [[his.ven.say.inp own.ven.say.inp] (sham buf.say.inp) ted])
::
2015-02-09 00:22:33 +03:00
++ ta-bac :: hear backspace
^+ .
2015-02-16 23:18:10 +03:00
?^ ris
?: =(~ str.u.ris)
2015-02-12 05:57:33 +03:00
ta-bel
2015-02-16 23:18:10 +03:00
.(str.u.ris (scag (dec (lent str.u.ris)) str.u.ris))
2015-02-09 00:22:33 +03:00
?: =(0 pos.inp)
2015-02-09 09:25:00 +03:00
.(+> (se-blit %bel ~))
2015-02-12 05:57:33 +03:00
=+ pre=(dec pos.inp)
(ta-hom(pos.inp pre) %del pre)
2015-02-09 00:22:33 +03:00
::
++ ta-ctl :: hear control
|= key=@ud
2015-02-12 05:57:33 +03:00
^+ +>
?+ key ta-bel
%a +>(pos.inp 0)
%b (ta-aro %l)
2015-02-16 23:18:10 +03:00
%c ta-bel(ris ~)
2015-02-12 05:57:33 +03:00
%d ?: &(=(0 pos.inp) =(0 (lent buf.say.inp)))
+>(liv |)
ta-del
%e +>(pos.inp (lent buf.say.inp))
%f (ta-aro %r)
2015-02-16 23:18:10 +03:00
%g ta-bel(ris ~)
2015-02-13 01:50:12 +03:00
%k =+ len=(lent buf.say.inp)
?: =(pos.inp len)
ta-bel
%- ta-hom(kil `(slag pos.inp buf.say.inp))
(ta-cut pos.inp (sub len pos.inp))
2015-02-12 05:57:33 +03:00
%l +>(+> (se-blit %clr ~))
%n (ta-aro %d)
%p (ta-aro %u)
2015-02-16 23:18:10 +03:00
%r ?~ ris
+>(ris `[pos.hit ~])
?: =(0 pos.u.ris)
2015-02-13 01:50:12 +03:00
ta-bel
(ta-ser ~)
2015-02-12 05:57:33 +03:00
%t =+ len=(lent buf.say.inp)
?: |(=(0 pos.inp) (lth len 2))
ta-bel
=+ sop=?:(=(len pos.inp) (dec pos.inp) pos.inp)
=. pos.inp +(sop)
%- ta-hom
:~ %mor
[%del sop]
[%ins (dec sop) (snag sop buf.say.inp)]
==
2015-02-13 01:50:12 +03:00
%u ?: =(0 pos.inp)
ta-bel
%- ta-hom(pos.inp 0, kil `(scag pos.inp buf.say.inp))
(ta-cut 0 pos.inp)
2015-02-16 23:18:10 +03:00
%v +>(maz `~)
%x ?: =(~ apt) ta-bel
?^ maz ta-bel
+>(apt (welp (slag 1 apt) [(snag 0 apt) ~]))
2015-02-13 01:50:12 +03:00
%y ?~ kil ta-bel
%- ta-hom(pos.inp (add pos.inp (lent u.kil)))
(ta-cat pos.inp u.kil)
2015-02-12 05:57:33 +03:00
==
2015-02-09 00:22:33 +03:00
::
2015-02-09 09:25:00 +03:00
++ ta-cru :: hear crud
|= [lab=@tas tac=(list tank)]
=. +>+> (se-blit %out (tuba (trip lab)))
(ta-tan tac)
::
2015-02-09 00:22:33 +03:00
++ ta-del :: hear delete
^+ .
?: =((lent buf.say.inp) pos.inp)
2015-02-09 09:25:00 +03:00
.(+> (se-blit %bel ~))
2015-02-09 00:22:33 +03:00
(ta-hom %del pos.inp)
::
2015-02-12 05:57:33 +03:00
++ ta-fec :: apply effect
2015-02-09 00:22:33 +03:00
|= fec=console-effect
^+ +>
?- -.fec
2015-02-09 09:25:00 +03:00
%bel ta-bel
2015-02-09 00:22:33 +03:00
%blk +>
2015-02-09 09:25:00 +03:00
%clr +>(+> (se-blit %clr ~))
%det (ta-got +.fec)
%mor |- ^+ +>.^$
?~ p.fec +>.^$
$(p.fec t.p.fec, +>.^$ ^$(fec i.p.fec))
2015-02-12 05:57:33 +03:00
%nex ta-nex
2015-02-09 09:25:00 +03:00
%pro (ta-pro +.fec)
2015-02-09 00:22:33 +03:00
%tan (ta-tan p.fec)
2015-02-09 09:25:00 +03:00
%txt $(fec [%tan [%leaf p.fec]~])
2015-02-09 00:22:33 +03:00
==
::
2015-02-12 05:57:33 +03:00
++ ta-dog :: correct position
|= ted=console-edit
?. ?=(%set -.ted) +>
+>(pos.inp (lent buf.say.inp))
::
++ ta-got :: apply change
|= cal=console-change
=. +> (ta-dog:+>(say.inp abet:(~(receive cs say.inp) cal)) ted.cal)
+>
2015-02-09 00:22:33 +03:00
::
++ ta-hom :: local edit
|= ted=console-edit
^+ +>
=. +> (ta-det ted)
2015-02-12 05:57:33 +03:00
=. +> (ta-dog:+>(say.inp abet:(~(commit cs say.inp) ted)) ted)
+>
2015-02-09 00:22:33 +03:00
::
++ ta-met :: meta key
|= key=@ud
~& [%ta-met key]
+>
::
2015-02-12 05:57:33 +03:00
++ ta-mov :: move in history
|= sop=@ud
^+ +>
?: =(sop pos.hit) +>
%+ %= ta-hom
pos.hit sop
lay.hit %+ ~(put by lay.hit)
pos.hit
buf.say.inp
==
%set
%- (bond |.((snag (sub num.hit +(sop)) old.hit)))
(~(get by lay.hit) sop)
::
++ ta-nex :: advance history
%_ .
num.hit +(num.hit)
pos.hit +(num.hit)
2015-02-16 23:18:10 +03:00
ris ~
2015-02-12 05:57:33 +03:00
lay.hit ~
old.hit [buf.say.inp old.hit]
==
::
2015-02-09 09:25:00 +03:00
++ ta-pro :: set prompt
|= pom=console-prompt
+>(pom pom)
::
++ ta-ret (ta-act %ret ~) :: hear return
2015-02-12 05:57:33 +03:00
++ ta-ser :: reverse search
|= ext=(list ,@c)
^+ +>
2015-02-16 23:18:10 +03:00
?: |(?=(~ ris) =(0 pos.u.ris)) ta-bel
=+ tot=(weld str.u.ris ext)
=+ dol=(slag (sub num.hit pos.u.ris) old.hit)
=+ sop=pos.u.ris
2015-02-12 05:57:33 +03:00
=+ ^= ser
=+ ^= beg
|= [a=(list ,@c) b=(list ,@c)] ^- ?
?~(a & ?~(b | &(=(i.a i.b) $(a t.a, b t.b))))
|= [a=(list ,@c) b=(list ,@c)] ^- ?
?~(a & ?~(b | |((beg a b) $(b t.b))))
=+ ^= sup
|- ^- (unit ,@ud)
?~ dol ~
?: (ser tot i.dol)
`sop
$(sop (dec sop), dol t.dol)
?~ sup ta-bel
2015-02-16 23:18:10 +03:00
(ta-mov(str.u.ris tot, pos.u.ris (dec u.sup)) (dec u.sup))
2015-02-12 05:57:33 +03:00
::
2015-02-09 00:22:33 +03:00
++ ta-tan :: print tanks
|= tac=(list tank)
2015-02-09 09:25:00 +03:00
=+ wol=`wall`(zing (turn tac |=(a=tank (~(win re a) [0 edg]))))
2015-02-09 00:22:33 +03:00
|- ^+ +>.^$
?~ wol +>.^$
2015-02-09 09:25:00 +03:00
$(wol t.wol, +>+>.^$ (se-blit %out (tuba i.wol)))
2015-02-09 00:22:33 +03:00
::
++ ta-txt :: hear text
|= txt=(list ,@c)
2015-02-12 05:57:33 +03:00
^+ +>
2015-02-16 23:18:10 +03:00
?^ ris
2015-02-12 05:57:33 +03:00
(ta-ser txt)
%- ta-hom(pos.inp (add (lent txt) pos.inp))
2015-02-09 00:22:33 +03:00
:- %mor
|- ^- (list console-edit)
?~ txt ~
[[%ins pos.inp i.txt] $(pos.inp +(pos.inp), txt t.txt)]
::
++ ta-vew :: computed prompt
2015-02-12 05:57:33 +03:00
|- ^- (pair ,@ud (list ,@c))
2015-02-16 23:18:10 +03:00
?^ ris
2015-02-12 05:57:33 +03:00
%= $
2015-02-16 23:18:10 +03:00
ris ~
2015-02-12 05:57:33 +03:00
cap.pom
2015-02-16 23:18:10 +03:00
`(list ,@)`:(welp "(reverse-i-search)'" str.u.ris "': ")
2015-02-12 05:57:33 +03:00
==
=- =. pos.inp (max pos.inp (lent q.vew))
[(add pos.inp (lent p.vew)) (weld p.vew q.vew)]
2015-02-09 00:22:33 +03:00
^= vew ^- (pair (list ,@c) (list ,@c))
?: vis.pom [cap.pom buf.say.inp]
:- ;: welp
cap.pom
2015-02-09 09:25:00 +03:00
?~ buf.say.inp ~
%- tuba
2015-02-09 00:22:33 +03:00
;: welp
2015-02-09 09:25:00 +03:00
"<"
2015-02-09 00:22:33 +03:00
(scow %p (end 4 1 (sham buf.say.inp)))
2015-02-09 09:25:00 +03:00
"> "
2015-02-09 00:22:33 +03:00
==
==
=+ len=(lent buf.say.inp)
|- ^- (list ,@c)
2015-02-09 09:25:00 +03:00
?:(=(0 len) ~ [`@c`'*' $(len (dec len))])
2015-02-09 00:22:33 +03:00
--
--
++ peer
|= [ost=bone her=ship pax=path]
^- [(list move) _+>]
?< (~(has by bin) ost)
2015-02-16 23:18:10 +03:00
:- [ost %give %rush %dill-blit %pro [`@c`0x23 `@c`0x20 ~]]~
%= +>
bin
%+ ~(put by bin) ost
^- source
:* 80
0
~
~
`~
~
[0 ~]
==
==
2015-02-09 00:22:33 +03:00
::
++ poke-dill-belt
|= [ost=bone her=ship bet=dill-belt]
^- [(list move) _+>]
2015-02-09 09:25:00 +03:00
=< se-abet
=< se-view
2015-02-09 23:40:44 +03:00
(~(se-belt se [ost %give %nice ~]~ [her ost] (~(got by bin) ost)) bet)
2015-02-09 00:22:33 +03:00
::
++ pour
|= [ost=bone pax=path sih=*]
^- [(list move) _+>]
=+ sih=((hard sign) sih)
?> ?=([@ @ ~] pax)
=< se-abet
=< se-view
2015-02-09 09:25:00 +03:00
(~(se-pour se ~ [(slav %p i.pax) ost] (~(got by bin) ost)) i.t.pax +.sih)
2015-02-09 00:22:33 +03:00
::
++ pull
|= ost=bone
^- [(list move) _+>]
2015-02-09 09:25:00 +03:00
=^ moz +>
=< se-abet
=< se-view
~(se-kill se ~ [our.hid ost] (~(got by bin) ost))
2015-02-09 00:22:33 +03:00
[moz +>.$(bin (~(del by bin) ost))]
--