shrub/lib/drum.hoon

1025 lines
34 KiB
Plaintext
Raw Normal View History

2015-05-17 04:05:56 +03:00
:: :: ::
2015-06-08 22:48:35 +03:00
:::: /hoon/drum/lib :: ::
2015-05-17 04:05:56 +03:00
:: :: ::
/? 310 :: version
2015-09-02 03:24:18 +03:00
/- sole
2015-09-02 01:20:17 +03:00
/+ sole
2015-09-02 03:24:18 +03:00
[. ^sole]
2016-11-17 04:42:58 +03:00
:: :: ::
2015-05-17 04:05:56 +03:00
:::: :: ::
:: :: ::
|% :: ::
++ drum-part {$drum $2 drum-pith-2} ::
++ drum-part-old {$drum $1 drum-pith-1} ::
:: ::
++ drum-pith-1 :: pre-style
%+ cork drum-pith-2 ::
|=(drum-pith-2 +<(bin *(map bone source-1))) ::
:: ::
++ source-1 ::
%+ cork source ::
|=(source +<(mir *(pair @ud (list @c)))) :: style-less mir
:: ::
++ drum-pith-2 ::
2016-05-02 21:56:00 +03:00
$: sys/(unit bone) :: local console
eel/(set gill:gall) :: connect to
ray/(set well:gall) ::
fur/(map dude:gall (unit server)) :: servers
2015-12-20 23:50:45 +03:00
bin/(map bone source) :: terminals
2015-05-17 04:05:56 +03:00
== ::
:: :: ::
:::: :: ::
:: :: ::
++ server :: running server
2015-12-20 23:50:45 +03:00
$: syd/desk :: app identity
cas/case :: boot case
2015-05-17 04:05:56 +03:00
== ::
++ kill :: kill ring
$: pos/@ud :: ring position
num/@ud :: number of entries
max/_60 :: max entries
old/(list (list @c)) :: entries proper
== ::
2015-05-17 04:05:56 +03:00
++ source :: input device
$: edg/_80 :: terminal columns
2015-12-20 23:50:45 +03:00
off/@ud :: window offset
kil/kill :: kill buffer
2015-12-20 23:50:45 +03:00
inx/@ud :: ring index
fug/(map gill:gall (unit target)) :: connections
mir/(pair @ud stub:dill) :: mirrored terminal
2015-05-17 04:05:56 +03:00
== ::
++ history :: past input
2015-12-20 23:50:45 +03:00
$: pos/@ud :: input position
num/@ud :: number of entries
lay/(map @ud (list @c)) :: editing overlay
old/(list (list @c)) :: entries proper
2015-05-17 04:05:56 +03:00
== ::
++ search :: reverse-i-search
2015-12-20 23:50:45 +03:00
$: pos/@ud :: search position
str/(list @c) :: search string
2015-05-17 04:05:56 +03:00
== ::
++ target :: application target
2016-11-08 04:40:00 +03:00
$: $= blt :: curr & prev belts
%+ pair
(unit dill-belt:dill)
(unit dill-belt:dill)
ris/(unit search) :: reverse-i-search
2015-12-20 23:50:45 +03:00
hit/history :: all past input
pom/sole-prompt :: static prompt
inp/sole-command :: input state
2015-05-17 04:05:56 +03:00
== ::
2015-09-02 01:20:17 +03:00
--
:: :: ::
2015-05-17 04:05:56 +03:00
:::: :: ::
:: :: ::
2015-09-02 01:20:17 +03:00
|%
2015-05-17 04:05:56 +03:00
++ deft-apes :: default servers
2015-12-20 23:50:45 +03:00
|= our/ship
%- ~(gas in *(set well:gall))
^- (list well:gall)
=+ myr=(clan:title our)
2016-09-02 05:37:58 +03:00
?: ?=($pawn myr)
2015-07-14 03:46:37 +03:00
[[%base %talk] [%base %dojo] ~]
2016-09-02 05:37:58 +03:00
?: ?=($earl myr)
2015-10-08 01:42:19 +03:00
[[%home %dojo] ~]
2015-06-09 18:23:40 +03:00
[[%home %talk] [%home %dojo] ~]
2015-05-17 04:05:56 +03:00
::
++ deft-fish :: default connects
2015-12-20 23:50:45 +03:00
|= our/ship
%- ~(gas in *(set gill:gall))
^- (list gill:gall)
?: ?=($earl (clan:title our))
[[(sein:title our) %talk] [our %dojo] ~]
2015-06-09 18:23:40 +03:00
[[our %talk] [our %dojo] ~]
2015-05-17 04:05:56 +03:00
::
++ drum-make :: initial part
2015-12-20 23:50:45 +03:00
|= our/ship
2016-07-04 09:27:08 +03:00
^- drum-part
2015-05-17 04:05:56 +03:00
:* %drum
%2
2016-05-02 21:56:00 +03:00
~ :: sys
2015-05-17 04:05:56 +03:00
(deft-fish our) :: eel
(deft-apes our) :: ray
~ :: fur
~ :: bin
== ::
2016-09-07 07:54:25 +03:00
::
2015-05-17 04:05:56 +03:00
++ drum-path :: encode path
|= gyl/gill:gall
2016-11-12 04:26:19 +03:00
^- wire
[%drum %phat (scot %p p.gyl) q.gyl ~]
2015-05-17 04:05:56 +03:00
::
++ drum-phat :: decode path
|= way/wire ^- gill:gall
2015-12-09 04:54:26 +03:00
?>(?=({@ @ $~} way) [(slav %p i.way) i.t.way])
2015-09-02 01:20:17 +03:00
--
2016-11-17 04:42:58 +03:00
::
2015-09-02 01:20:17 +03:00
::::
::
|= {hid/bowl:gall drum-part} :: main drum work
2016-09-08 08:42:40 +03:00
=+ (fall (~(get by bin) ost.hid) *source)
2015-10-23 01:45:48 +03:00
=* dev -
2015-09-02 01:20:17 +03:00
=> |% :: arvo structures
++ pear :: request
2015-12-20 23:50:45 +03:00
$% {$sole-action p/sole-action} ::
2015-12-09 04:54:26 +03:00
{$talk-command command:talk} ::
2015-09-02 01:20:17 +03:00
== ::
++ lime :: update
$% {$dill-blit dill-blit:dill} ::
2015-09-02 01:20:17 +03:00
== ::
++ card :: general card
2015-12-14 10:58:14 +03:00
$% {$conf wire dock $load ship term} ::
2015-12-09 04:54:26 +03:00
{$diff lime} ::
{$peer wire dock path} ::
{$poke wire dock pear} ::
{$pull wire dock $~} ::
2015-09-02 01:20:17 +03:00
== ::
++ move (pair bone card) :: user-level move
--
|_ {moz/(list move) biz/(list dill-blit:dill)}
2016-09-07 07:54:25 +03:00
++ diff-sole-effect-phat :: app event
2016-07-04 09:27:08 +03:00
|= {way/wire fec/sole-effect}
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
=+ gyl=(drum-phat way)
?: (se-aint gyl) +>.$
(se-diff gyl fec)
::
++ peer ::
2016-09-08 08:30:47 +03:00
|= pax/path
2016-09-08 08:42:40 +03:00
~| [%drum-unauthorized our+our.hid src+src.hid] :: ourself
?> (team:title our.hid src.hid) :: or our own moon
2016-09-08 08:30:47 +03:00
=< se-abet =< se-view
2016-09-08 08:42:40 +03:00
(se-text "[{<src.hid>}, driving {<our.hid>}]")
2015-09-02 01:20:17 +03:00
::
2016-09-07 07:54:25 +03:00
++ poke-dill-belt :: terminal event
|= bet/dill-belt:dill
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
(se-belt bet)
::
2016-09-07 07:54:25 +03:00
++ poke-start :: start app
|= wel/well:gall
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
(se-born wel)
::
2016-09-07 07:54:25 +03:00
++ poke-link :: connect app
|= gyl/gill:gall
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
(se-link gyl)
::
2016-09-07 07:54:25 +03:00
++ poke-unlink :: disconnect app
|= gyl/gill:gall
2015-10-20 23:48:11 +03:00
=< se-abet =< se-view
(se-klin gyl)
::
2016-09-07 07:54:25 +03:00
++ poke-exit :: shutdown
2016-11-08 04:40:00 +03:00
|= $~
se-abet:(se-blit-sys `dill-blit:dill`[%qit ~])
::
2016-09-07 07:54:25 +03:00
++ poke-put :: write file
2016-04-30 02:18:59 +03:00
|= {pax/path txt/@}
2016-05-02 21:56:00 +03:00
se-abet:(se-blit-sys [%sav pax txt]) ::
2016-04-30 02:18:59 +03:00
::
2016-09-07 07:54:25 +03:00
++ reap-phat :: ack connect
2016-07-04 09:27:08 +03:00
|= {way/wire saw/(unit tang)}
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
=+ gyl=(drum-phat way)
?~ saw
(se-join gyl)
(se-dump:(se-drop & gyl) u.saw)
::
2016-09-07 07:54:25 +03:00
++ take-coup-phat :: ack poke
2016-07-04 09:27:08 +03:00
|= {way/wire saw/(unit tang)}
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
?~ saw +>
=+ gyl=(drum-phat way)
?: (se-aint gyl) +>.$
2016-09-08 08:30:47 +03:00
%- se-dump:(se-drop & gyl)
:_ u.saw
2016-09-08 08:42:40 +03:00
>[%drum-coup-fail src.hid ost.hid gyl]<
2015-09-02 01:20:17 +03:00
::
2016-09-07 07:54:25 +03:00
++ take-onto :: ack start
|= {way/wire saw/(each suss:gall tang)}
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
2015-12-09 04:54:26 +03:00
?> ?=({@ @ $~} way)
2015-09-02 01:20:17 +03:00
?> (~(has by fur) i.t.way)
=/ wel/well:gall [i.way i.t.way]
?- saw
{$| *} (se-dump p.saw)
{$& *} ?> =(q.wel p.p.saw)
:: =. +>.$ (se-text "live {<p.saw>}")
+>.$(fur (~(put by fur) q.wel `[p.wel %da r.p.saw]))
2016-07-04 09:27:08 +03:00
==
2015-09-02 01:20:17 +03:00
::
++ quit-phat ::
2016-07-04 09:27:08 +03:00
|= way/wire
2015-09-02 01:20:17 +03:00
=< se-abet =< se-view
=+ gyl=(drum-phat way)
2016-09-08 08:42:40 +03:00
~& [%drum-quit src.hid ost.hid gyl]
2015-09-02 01:20:17 +03:00
(se-drop %| gyl)
:: :: ::
:::: :: ::
:: :: ::
++ se-abet :: resolve
^- (quip move *drum-part)
2016-09-02 05:42:59 +03:00
=* pith +>+>+<+
2015-09-02 01:20:17 +03:00
?. se-ably
=. . se-adit
2016-09-02 05:42:59 +03:00
[(flop moz) pith]
2016-09-08 08:42:40 +03:00
=. sys ?^(sys sys `ost.hid)
2015-10-23 01:45:48 +03:00
=. . se-subze:se-adze:se-adit
2016-09-08 08:42:40 +03:00
:_ pith(bin (~(put by bin) ost.hid dev))
2016-09-02 05:42:59 +03:00
%- flop
2015-09-02 01:20:17 +03:00
^- (list move)
2016-09-02 05:42:59 +03:00
?~ biz moz
:_ moz
2016-09-08 08:42:40 +03:00
[ost.hid %diff %dill-blit ?~(t.biz i.biz [%mor (flop biz)])]
2015-09-02 01:20:17 +03:00
::
2016-09-08 08:42:40 +03:00
++ se-ably (~(has by sup.hid) ost.hid) :: caused by console
2016-09-07 07:54:25 +03:00
::
2015-09-02 01:20:17 +03:00
++ se-adit :: update servers
2015-10-23 01:45:48 +03:00
^+ .
%+ roll (~(tap in ray))
=< .(con +>)
|= {wel/well:gall con/_..se-adit} ^+ con
2015-10-23 01:45:48 +03:00
=. +>.$ con
2016-07-04 09:27:08 +03:00
=+ hig=(~(get by fur) q.wel)
2015-12-10 12:17:19 +03:00
?: &(?=(^ hig) |(?=($~ u.hig) =(p.wel syd.u.u.hig))) +>.$
2015-10-23 01:45:48 +03:00
=. +>.$ (se-text "activated app {(trip p.wel)}/{(trip q.wel)}")
%- se-emit(fur (~(put by fur) q.wel ~))
2016-09-08 08:42:40 +03:00
[ost.hid %conf [%drum p.wel q.wel ~] [our.hid q.wel] %load our.hid p.wel]
2015-09-02 01:20:17 +03:00
::
++ se-adze :: update connections
2015-10-23 01:45:48 +03:00
^+ .
%+ roll (~(tap in eel))
=< .(con +>)
|= {gil/gill:gall con/_.} ^+ con
2015-10-23 01:45:48 +03:00
=. +>.$ con
?: (~(has by fug) gil)
+>.$
(se-peer gil)
::
++ se-subze :: downdate connections
2016-09-08 08:42:40 +03:00
=< .(dev (~(got by bin) ost.hid))
=. bin (~(put by bin) ost.hid dev)
2015-10-23 01:45:48 +03:00
^+ .
%- ~(rep by bin)
=< .(con +>)
2015-12-20 23:50:45 +03:00
|= {{ost/bone dev/source} con/_.} ^+ con
2016-09-08 08:42:40 +03:00
=+ xeno=se-subze-local:%_(con ost.hid ost, dev dev)
xeno(ost.hid ost.hid.con, dev dev.con, bin (~(put by bin) ost dev.xeno))
2015-10-23 01:45:48 +03:00
::
++ se-subze-local
^+ .
%- ~(rep by fug)
=< .(con +>)
|= {{gil/gill:gall *} con/_.} ^+ con
2015-10-23 01:45:48 +03:00
=. +>.$ con
?: (~(has in eel) gil)
+>.$
(se-nuke gil)
2015-09-02 01:20:17 +03:00
::
++ se-aint :: ignore result
|= gyl/gill:gall
2015-09-02 01:20:17 +03:00
^- ?
2016-09-08 08:42:40 +03:00
?. (~(has by bin) ost.hid) &
2015-09-02 01:20:17 +03:00
=+ gyr=(~(get by fug) gyl)
2016-09-02 05:37:58 +03:00
|(?=($~ gyr) ?=($~ u.gyr))
2015-09-02 01:20:17 +03:00
::
++ se-alas :: recalculate index
|= gyl/gill:gall
2015-09-02 01:20:17 +03:00
=+ [xin=0 wag=se-amor]
|- ^+ +>.^$
?~ wag +>.^$(inx 0)
?: =(i.wag gyl) +>.^$(inx xin)
$(wag t.wag, xin +(xin))
::
++ se-amor :: live targets
^- (list gill:gall)
%+ skim (~(tap in eel))
|=(a/gill:gall ?=({$~ $~ *} (~(get by fug) a)))
2015-09-02 01:20:17 +03:00
::
++ se-anon :: rotate index
=+ wag=se-amor
?~ wag +
2015-12-21 00:16:39 +03:00
:: ~& [%se-anon inx+inx wag+wag nex+(mod +(inx) (lent se-amor))]
2017-03-02 00:03:41 +03:00
+(off 0, inx (mod +(inx) (lent wag)))
2015-09-02 01:20:17 +03:00
::
++ se-agon :: current gill
^- (unit gill:gall)
2015-09-02 01:20:17 +03:00
=+ wag=se-amor
?~ wag ~
`(snag inx `(list gill:gall)`wag)
2015-09-02 01:20:17 +03:00
::
++ se-belt :: handle input
|= bet/dill-belt:dill
2015-09-02 01:20:17 +03:00
^+ +>
2016-09-06 22:55:50 +03:00
?: ?=({?($cru $hey $rez $yow) *} bet) :: target-agnostic
2016-09-09 03:57:05 +03:00
?- bet
2016-09-06 22:55:50 +03:00
{$cru *} (se-dump:(se-text (trip p.bet)) q.bet)
2016-09-09 03:57:05 +03:00
{$hey *} +>(mir [0 ~]) :: refresh
{$rez *} +>(edg (dec p.bet)) :: resize window
{$yow *} ~&([%no-yow -.bet] +>)
==
2015-09-02 01:20:17 +03:00
=+ gul=se-agon
?: |(?=($~ gul) (se-aint u.gul))
2016-09-02 05:37:58 +03:00
(se-blit %bel ~)
ta-abet:(ta-belt:(se-tame u.gul) bet)
2015-09-02 01:20:17 +03:00
::
++ se-born :: new server
|= wel/well:gall
2015-09-02 01:20:17 +03:00
^+ +>
?: (~(has in ray) wel)
(se-text "[already running {<p.wel>}/{<q.wel>}]")
2016-09-08 08:31:42 +03:00
%= +>
ray (~(put in ray) wel)
2016-09-08 08:42:40 +03:00
eel (~(put in eel) [our.hid q.wel])
2016-09-08 08:31:42 +03:00
==
2015-09-02 01:20:17 +03:00
::
++ se-drop :: disconnect
|= {pej/? gyl/gill:gall}
2015-09-02 01:20:17 +03:00
^+ +>
=+ lag=se-agon
?. (~(has by fug) gyl) +>.$
=. fug (~(del by fug) gyl)
=. eel ?.(pej eel (~(del in eel) gyl))
2016-07-04 09:27:08 +03:00
=. +>.$ ?. &(?=(^ lag) !=(gyl u.lag))
2015-09-02 01:20:17 +03:00
+>.$(inx 0)
(se-alas u.lag)
=. +>.$ (se-text "[unlinked from {<gyl>}]")
2016-09-08 08:42:40 +03:00
?: =(gyl [our.hid %dojo]) :: undead dojo
2015-06-02 21:36:56 +03:00
(se-link gyl)
2015-10-08 01:42:19 +03:00
+>.$
2015-09-02 01:20:17 +03:00
::
++ se-dump :: print tanks
2015-12-20 23:50:45 +03:00
|= tac/(list tank)
2015-09-02 01:20:17 +03:00
^+ +>
?. se-ably (se-talk tac)
=/ wol/wall
(zing (turn (flop tac) |=(a/tank (~(win re a) [0 edg]))))
2015-09-02 01:20:17 +03:00
|- ^+ +>.^$
?~ wol +>.^$
?. ((sane %t) (crip i.wol)) :: XX upstream validation
2016-10-14 04:18:55 +03:00
~& bad-text+<`*`i.wol>
$(wol t.wol)
2015-09-02 01:20:17 +03:00
$(wol t.wol, +>.^$ (se-blit %out (tuba i.wol)))
::
++ se-join :: confirm connection
|= gyl/gill:gall
2015-09-02 01:20:17 +03:00
^+ +>
=. +> (se-text "[linked to {<gyl>}]")
2016-09-02 05:37:58 +03:00
?> ?=($~ (~(got by fug) gyl))
2015-10-08 01:42:19 +03:00
(se-alas(fug (~(put by fug) gyl `*target)) gyl)
2015-09-02 01:20:17 +03:00
::
2016-09-07 07:54:25 +03:00
++ se-nuke :: teardown connection
|= gyl/gill:gall
2015-09-02 01:20:17 +03:00
^+ +>
2015-10-08 01:42:19 +03:00
(se-drop:(se-pull gyl) & gyl)
2015-09-02 01:20:17 +03:00
::
2015-10-20 23:48:11 +03:00
++ se-klin :: disconnect app
|= gyl/gill:gall
2015-10-20 23:48:11 +03:00
+>(eel (~(del in eel) gyl))
::
2015-09-02 01:20:17 +03:00
++ se-link :: connect to app
|= gyl/gill:gall
2015-09-02 01:20:17 +03:00
+>(eel (~(put in eel) gyl))
::
++ se-blit :: give output
|= bil/dill-blit:dill
2015-09-02 01:20:17 +03:00
+>(biz [bil biz])
::
++ se-blit-sys :: output to system
|= bil/dill-blit:dill ^+ +>
2016-05-02 21:56:00 +03:00
?~ sys ~&(%se-blit-no-sys +>)
(se-emit [u.sys %diff %dill-blit bil])
::
2015-09-02 01:20:17 +03:00
++ se-show :: show buffer, raw
|= lin/(pair @ud stub:dill)
2015-09-02 01:20:17 +03:00
^+ +>
?: =(mir lin) +>
=. +> ?:(=(p.mir p.lin) +> (se-blit %hop (add p.lin (lent-stye:klr q.lin))))
=. +> ?:(=(q.mir q.lin) +> (se-blit %pom q.lin))
2015-09-02 01:20:17 +03:00
+>(mir lin)
::
2016-07-04 09:27:08 +03:00
++ se-just :: adjusted buffer
|= {pom/stub:dill lin/(pair @ud (list @c))}
2015-09-02 01:20:17 +03:00
^+ +>
=/ pol (lent-char:klr pom)
=/ end (sub edg pol)
=/ pos (add pol p.lin)
?: (gte (div (mul pol 100) edg) 35) :: old style (long prompt)
=/ off ?:((lte p.lin end) 0 (sub p.lin end))
%+ se-show
(sub pos off)
(swag:klr [off edg] (welp pom [*stye:dill q.lin]~))
=. off ?: (gth p.lin (add end off))
(sub p.lin end)
?: (lth p.lin off)
(min p.lin (dec off))
off
%+ se-show
(sub pos off)
(welp pom [*stye:dill (swag [off end] q.lin)]~)
2015-09-02 01:20:17 +03:00
::
++ se-view :: flush buffer
2016-09-07 17:21:41 +03:00
^+ .
2015-09-02 01:20:17 +03:00
=+ gul=se-agon
?: |(?=($~ gul) (se-aint u.gul)) +
2016-09-07 17:21:41 +03:00
(se-just ta-vew:(se-tame u.gul))
2015-09-02 01:20:17 +03:00
::
++ se-emit :: emit move
2015-12-20 23:50:45 +03:00
|= mov/move
2015-09-02 01:20:17 +03:00
%_(+> moz [mov moz])
::
2016-09-08 18:12:17 +03:00
++ se-talk
2016-07-04 09:27:08 +03:00
|= tac/(list tank)
2015-09-02 01:20:17 +03:00
^+ +>
:: XX talk should be usable for stack traces, see urbit#584 which this change
:: closed for the problems there
((slog (flop tac)) +>)
2016-09-08 08:42:40 +03:00
::(se-emit 0 %poke /drum/talk [our.hid %talk] (said:talk our.hid %drum now.hid eny.hid tac))
2015-09-02 01:20:17 +03:00
::
++ se-text :: return text
2015-12-20 23:50:45 +03:00
|= txt/tape
2015-09-02 01:20:17 +03:00
^+ +>
?. ((sane %t) (crip txt)) :: XX upstream validation
2016-10-14 04:18:55 +03:00
~& bad-text+<`*`txt>
+>
2015-09-02 01:20:17 +03:00
?. se-ably (se-talk [%leaf txt]~)
(se-blit %out (tuba txt))
::
++ se-poke :: send a poke
|= {gyl/gill:gall par/pear}
2016-09-08 08:42:40 +03:00
(se-emit [ost.hid %poke (drum-path gyl) gyl par])
2015-09-02 01:20:17 +03:00
::
++ se-peer :: send a peer
|= gyl/gill:gall
2016-09-07 07:32:40 +03:00
%- se-emit(fug (~(put by fug) gyl ~))
2016-09-08 08:42:40 +03:00
[ost.hid %peer (drum-path gyl) gyl /sole]
2015-09-02 01:20:17 +03:00
::
++ se-pull :: cancel subscription
|= gyl/gill:gall
2016-09-08 08:42:40 +03:00
(se-emit [ost.hid %pull (drum-path gyl) gyl ~])
2015-09-02 01:20:17 +03:00
::
++ se-tame :: switch connection
|= gyl/gill:gall
2015-09-02 01:20:17 +03:00
^+ ta
~(. ta gyl (need (~(got by fug) gyl)))
2015-09-02 01:20:17 +03:00
::
++ se-diff :: receive results
|= {gyl/gill:gall fec/sole-effect}
2015-09-02 01:20:17 +03:00
^+ +>
ta-abet:(ta-fec:(se-tame gyl) fec)
::
++ ta :: per target
|_ {gyl/gill:gall target} :: app and state
2016-11-14 04:54:01 +03:00
++ ta-abet :: resolve
2015-09-02 01:20:17 +03:00
^+ ..ta
..ta(fug (~(put by fug) gyl ``target`+<+))
::
2015-12-20 23:50:45 +03:00
++ ta-poke |=(a/pear +>(..ta (se-poke gyl a))) :: poke gyl
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-act :: send action
2015-12-20 23:50:45 +03:00
|= act/sole-action
2015-05-17 22:39:03 +03:00
^+ +>
(ta-poke %sole-action act)
::
2015-09-02 01:20:17 +03:00
++ ta-aro :: hear arrow
2015-12-20 23:50:45 +03:00
|= key/?($d $l $r $u)
2015-05-17 07:50:05 +03:00
^+ +>
=. ris ~
2015-09-02 01:20:17 +03:00
?- key
$d ?. =(num.hit pos.hit)
2015-09-02 01:20:17 +03:00
(ta-mov +(pos.hit))
?: =(0 (lent buf.say.inp))
ta-bel
(ta-hom:ta-nex %set ~)
2015-12-09 04:54:26 +03:00
$l ?: =(0 pos.inp) ta-bel
+>(pos.inp (dec pos.inp))
2015-12-09 04:54:26 +03:00
$r ?: =((lent buf.say.inp) pos.inp)
2015-09-02 01:20:17 +03:00
ta-bel
+>(pos.inp +(pos.inp))
$u ?:(=(0 pos.hit) ta-bel (ta-mov (dec pos.hit)))
2015-09-02 01:20:17 +03:00
==
2015-05-17 07:50:05 +03:00
::
++ ta-bel :: beep
2016-09-07 20:58:48 +03:00
.(..ta (se-blit %bel ~), q.blt ~) :: forget belt
2016-09-09 03:57:05 +03:00
::
++ ta-belt :: handle input
|= bet/dill-belt:dill
2016-09-09 03:57:05 +03:00
^+ +>
2016-09-06 22:55:50 +03:00
?< ?=({?($cru $hey $rez $yow) *} bet) :: target-specific
2016-09-09 03:57:05 +03:00
=. blt [q.blt `bet] :: remember belt
?- bet
{$aro *} (ta-aro p.bet)
{$bac *} ta-bac
{$ctl *} (ta-ctl p.bet)
{$del *} ta-del
{$met *} (ta-met p.bet)
{$ret *} ta-ret
{$txt *} (ta-txt p.bet)
==
::
2015-09-02 01:20:17 +03:00
++ ta-det :: send edit
2015-12-20 23:50:45 +03:00
|= ted/sole-edit
2015-05-17 04:05:56 +03:00
^+ +>
2015-09-02 01:20:17 +03:00
(ta-act %det [[his.ven.say.inp own.ven.say.inp] (sham buf.say.inp) ted])
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-bac :: hear backspace
^+ .
?^ ris
?: =(~ str.u.ris)
ta-bel
.(str.u.ris (scag (dec (lent str.u.ris)) str.u.ris))
?: =(0 pos.inp)
?~ buf.say.inp
(ta-act %clr ~)
ta-bel
(ta-hom %del (dec pos.inp))
2015-09-02 01:20:17 +03:00
::
++ ta-ctl :: hear control
2015-12-20 23:50:45 +03:00
|= key/@ud
2015-05-17 04:05:56 +03:00
^+ +>
=. ris ?.(?=(?($g $r) key) ~ ris)
?+ key ta-bel
$a +>(pos.inp 0)
2015-12-09 04:54:26 +03:00
$b (ta-aro %l)
$c ta-bel
$d ?^ buf.say.inp
ta-del
?: (~(has in (deft-fish our.hid)) gyl)
+>(..ta (se-blit qit+~)) :: quit pier
+>(..ta (se-klin gyl)) :: unlink app
2015-12-09 04:54:26 +03:00
$e +>(pos.inp (lent buf.say.inp))
$f (ta-aro %r)
$g ?~ ris ta-bel
(ta-hom(pos.hit num.hit, ris ~) [%set ~])
2015-12-09 04:54:26 +03:00
$k =+ len=(lent buf.say.inp)
2015-09-02 01:20:17 +03:00
?: =(pos.inp len)
2016-07-04 09:27:08 +03:00
ta-bel
(ta-kil %r [pos.inp (sub len pos.inp)])
2016-09-07 20:58:48 +03:00
$l +>(..ta (se-blit %clr ~))
2015-12-09 04:54:26 +03:00
$n (ta-aro %d)
$p (ta-aro %u)
2016-07-04 09:27:08 +03:00
$r ?~ ris
+>(ris `[pos.hit ~])
2015-09-02 01:20:17 +03:00
?: =(0 pos.u.ris)
ta-bel
(ta-ser ~)
2015-12-09 04:54:26 +03:00
$t =+ len=(lent buf.say.inp)
2015-09-02 01:20:17 +03:00
?: |(=(0 pos.inp) (lth len 2))
ta-bel
=+ sop=(sub pos.inp ?:(=(len pos.inp) 2 1))
(ta-hom (rep:edit [sop 2] (flop (swag [sop 2] buf.say.inp))))
2015-12-09 04:54:26 +03:00
$u ?: =(0 pos.inp)
2015-09-02 01:20:17 +03:00
ta-bel
(ta-kil %l [0 pos.inp])
2015-12-09 04:54:26 +03:00
$v ta-bel
2016-07-05 09:50:32 +03:00
$w ?: =(0 pos.inp)
ta-bel
=+ sop=(ta-pos %l %ace pos.inp)
(ta-kil %l [(sub pos.inp sop) sop])
2016-09-07 20:58:48 +03:00
$x +>(..ta se-anon)
$y ?: =(0 num.kil)
ta-bel
2016-09-08 07:08:34 +03:00
(ta-hom (cat:edit pos.inp ta-yan))
2015-05-17 04:05:56 +03:00
==
::
2015-09-02 01:20:17 +03:00
++ ta-del :: hear delete
2015-05-17 04:05:56 +03:00
^+ .
2015-09-02 01:20:17 +03:00
?: =((lent buf.say.inp) pos.inp)
ta-bel
2015-09-02 01:20:17 +03:00
(ta-hom %del pos.inp)
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-erl :: hear local error
2016-07-04 09:27:08 +03:00
|= pos/@ud
2015-09-02 01:20:17 +03:00
ta-bel(pos.inp (min pos (lent buf.say.inp)))
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-err :: hear remote error
2015-12-20 23:50:45 +03:00
|= pos/@ud
2015-09-02 01:20:17 +03:00
(ta-erl (~(transpose sole say.inp) pos))
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-fec :: apply effect
2015-12-20 23:50:45 +03:00
|= fec/sole-effect
2015-05-17 04:05:56 +03:00
^+ +>
?- fec
{$bel *} ta-bel
{$blk *} +>
2016-09-07 20:58:48 +03:00
{$clr *} +>(..ta (se-blit fec))
{$det *} (ta-got +.fec)
{$err *} (ta-err p.fec)
{$klr *} +>(..ta (se-blit %klr (make:klr p.fec)))
{$mor *} |- ^+ +>.^$
?~ p.fec +>.^$
$(p.fec t.p.fec, +>.^$ ^$(fec i.p.fec))
{$nex *} ta-nex
{$pro *} (ta-pro +.fec)
2016-09-07 20:58:48 +03:00
{$tan *} +>(..ta (se-dump p.fec))
{$sag *} +>(..ta (se-blit fec))
{$sav *} +>(..ta (se-blit fec))
{$txt *} +>(..ta (se-text p.fec))
{$url *} +>(..ta (se-blit fec))
2015-09-02 01:20:17 +03:00
==
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-dog :: change cursor
2015-12-20 23:50:45 +03:00
|= ted/sole-edit
2015-09-02 01:20:17 +03:00
%_ +>
pos.inp
=+ len=(lent buf.say.inp)
%+ min len
|- ^- @ud
?- ted
{$del *} ?:((gth pos.inp p.ted) (dec pos.inp) pos.inp)
{$ins *} ?:((gte pos.inp p.ted) +(pos.inp) pos.inp)
{$mor *} |- ^- @ud
?~ p.ted pos.inp
$(p.ted t.p.ted, pos.inp ^$(ted i.p.ted))
{$nop *} pos.inp
{$set *} len
2015-09-02 01:20:17 +03:00
==
==
2015-05-17 04:05:56 +03:00
::
++ ta-off :: reset buffer offset
|= ted/sole-edit
=. off ?: |- ?. ?=({$mor *} ted)
?=({$set *} ted)
|- ?~(p.ted | |(^$(ted i.p.ted) $(p.ted t.p.ted)))
0
off
+>
::
2015-09-02 01:20:17 +03:00
++ ta-got :: apply change
2015-12-20 23:50:45 +03:00
|= cal/sole-change
2015-09-02 01:20:17 +03:00
=^ ted say.inp (~(receive sole say.inp) cal)
(ta-dog:(ta-off ted.cal) ted)
::
2015-09-02 01:20:17 +03:00
++ ta-hom :: local edit
2015-12-20 23:50:45 +03:00
|= ted/sole-edit
^+ +>
=. +> (ta-det:(ta-off ted) ted)
2016-09-07 00:13:53 +03:00
(ta-dog(say.inp (~(commit sole say.inp) ted)) ted)
2015-05-17 04:05:56 +03:00
::
++ ta-jump :: buffer pos
|= {dir/?($l $r) til/?($ace $edg $wrd) pos/@ud}
^- @ud
%- ?:(?=($l dir) sub add)
[pos (ta-pos dir til pos)]
::
++ ta-kil :: kill selection
|= {dir/?($l $r) sel/{@ @}}
^+ +>
=+ buf=(swag sel buf.say.inp)
%. (cut:edit sel)
%= ta-hom
kil
?. ?& ?=(^ old.kil)
?=(^ p.blt)
?| ?=({$ctl ?($k $u $w)} u.p.blt)
?=({$met ?($d $bac)} u.p.blt)
== ==
%= kil :: prepend
num +(num.kil)
pos +(num.kil)
old (scag max.kil `(list (list @c))`[buf old.kil])
==
%= kil :: cumulative yanks
pos num.kil
old :_ t.old.kil
?- dir
$l (welp buf i.old.kil)
$r (welp i.old.kil buf)
2016-08-28 07:31:35 +03:00
== ==
==
::
2015-09-02 01:20:17 +03:00
++ ta-met :: meta key
2015-12-20 23:50:45 +03:00
|= key/@ud
^+ +>
=. ris ~
?+ key ta-bel
2016-09-07 07:54:25 +03:00
$dot ?. &(?=(^ old.hit) ?=(^ i.old.hit)) :: last "arg" from hist
ta-bel
=+ old=`(list @c)`i.old.hit
=+ sop=(ta-jump(buf.say.inp old) %l %ace (lent old))
(ta-hom (cat:edit pos.inp (slag sop old)))
::
2016-09-07 07:54:25 +03:00
$bac ?: =(0 pos.inp) :: kill left-word
ta-bel
=+ sop=(ta-pos %l %edg pos.inp)
(ta-kil %l [(sub pos.inp sop) sop])
::
2016-09-07 07:54:25 +03:00
$b ?: =(0 pos.inp) :: jump left-word
ta-bel
+>(pos.inp (ta-jump %l %edg pos.inp))
2016-07-03 21:39:40 +03:00
::
2016-09-07 07:54:25 +03:00
$c ?: =(pos.inp (lent buf.say.inp)) :: capitalize
2016-07-03 21:39:40 +03:00
ta-bel
=+ sop=(ta-jump %r %wrd pos.inp)
%- ta-hom(pos.inp (ta-jump %r %edg sop))
%+ rep:edit [sop 1]
^- (list @c) ^- (list @) :: XX unicode
(cuss `tape``(list @)`(swag [sop 1] buf.say.inp))
2016-07-03 21:39:40 +03:00
::
2016-09-07 07:54:25 +03:00
$d ?: =(pos.inp (lent buf.say.inp)) :: kill right-word
ta-bel
(ta-kil %r [pos.inp (ta-pos %r %edg pos.inp)])
::
2016-09-07 07:54:25 +03:00
$f ?: =(pos.inp (lent buf.say.inp)) :: jump right-word
ta-bel
+>(pos.inp (ta-jump %r %edg pos.inp))
2016-07-03 21:39:40 +03:00
::
2016-07-05 07:48:56 +03:00
$r %- ta-hom(lay.hit (~(put by lay.hit) pos.hit ~))
2016-09-07 07:54:25 +03:00
:- %set :: revert hist edit
?: =(pos.hit num.hit) ~
(snag (sub num.hit +(pos.hit)) old.hit)
2016-07-05 07:48:56 +03:00
::
2016-09-07 07:54:25 +03:00
$t =+ a=(ta-jump %r %edg pos.inp) :: transpose words
=+ b=(ta-jump %l %edg a)
=+ c=(ta-jump %l %edg b)
2016-07-04 03:57:43 +03:00
?: =(b c)
ta-bel
=+ next=[b (sub a b)]
=+ prev=[c (ta-pos %r %edg c)]
%- ta-hom(pos.inp a)
2016-07-04 03:57:43 +03:00
:~ %mor
(rep:edit next (swag prev buf.say.inp))
(rep:edit prev (swag next buf.say.inp))
2016-07-04 03:57:43 +03:00
==
2016-07-03 21:39:40 +03:00
::
2016-09-07 07:54:25 +03:00
?($u $l) :: upper/lower case
2016-07-03 21:39:40 +03:00
?: =(pos.inp (lent buf.say.inp))
ta-bel
=+ case=?:(?=($u key) cuss cass)
=+ sop=(ta-jump %r %wrd pos.inp)
=+ sel=[sop (ta-pos %r %edg sop)]
%- ta-hom
%+ rep:edit sel
^- (list @c) ^- (list @) :: XX unicode
(case `tape``(list @)`(swag sel buf.say.inp))
::
2016-09-08 07:08:34 +03:00
$y ?. ?& ?=(^ old.kil) :: rotate & yank
?=(^ p.blt)
?| ?=({$ctl $y} u.p.blt)
?=({$met $y} u.p.blt)
== ==
ta-bel
2016-09-08 07:08:34 +03:00
=+ las=(lent ta-yan)
=. pos.kil ?:(=(1 pos.kil) num.kil (dec pos.kil))
(ta-hom (rep:edit [(sub pos.inp las) las] ta-yan))
2016-07-02 06:31:51 +03:00
==
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-mov :: move in history
2015-12-20 23:50:45 +03:00
|= sop/@ud
2015-09-02 01:20:17 +03:00
^+ +>
?: =(sop pos.hit) +>
2016-09-07 04:00:51 +03:00
%- %= ta-hom
2015-09-02 01:20:17 +03:00
pos.hit sop
2016-09-07 04:00:51 +03:00
lay.hit (~(put by lay.hit) pos.hit buf.say.inp)
2015-09-02 01:20:17 +03:00
==
2016-09-07 04:00:51 +03:00
:- %set
%. (~(get by lay.hit) sop)
(bond |.((snag (sub num.hit +(sop)) old.hit)))
2015-09-02 01:20:17 +03:00
::
++ ta-nex :: advance history
^+ .
=. ris ~
=. lay.hit ~
?: ?| ?=($~ buf.say.inp)
&(?=(^ old.hit) =(buf.say.inp i.old.hit))
==
.(pos.hit num.hit)
2015-09-02 01:20:17 +03:00
%_ .
num.hit +(num.hit)
pos.hit +(num.hit)
old.hit [buf.say.inp old.hit]
==
2015-05-17 04:05:56 +03:00
::
++ ta-pos :: buffer pos offset
|= {dir/?($l $r) til/?($ace $edg $wrd) pos/@ud}
^- @ud
%- ?- til $ace ace:offset
$edg edg:offset
$wrd wrd:offset
==
?- dir $l (flop (scag pos buf.say.inp))
$r (slag pos buf.say.inp)
==
::
2015-09-02 01:20:17 +03:00
++ ta-pro :: set prompt
2015-12-20 23:50:45 +03:00
|= pom/sole-prompt
2016-11-14 05:51:21 +03:00
%_ +>
pom
%_ pom
cad
;: welp
?. ?=($earl (clan:title p.gyl))
(cite:title p.gyl)
2016-11-14 05:51:21 +03:00
(scow %p p.gyl)
::
":"
(trip q.gyl)
cad.pom
==
==
==
2015-09-02 01:20:17 +03:00
::
++ ta-ret :: hear return
2015-10-08 01:42:19 +03:00
(ta-act %ret ~)
2015-05-17 04:05:56 +03:00
::
2015-09-02 01:20:17 +03:00
++ ta-ser :: reverse search
2015-12-20 23:50:45 +03:00
|= ext/(list @c)
2015-05-17 04:05:56 +03:00
^+ +>
2016-09-02 05:39:24 +03:00
?: |(?=($~ ris) =(0 pos.u.ris))
ta-bel
=+ sop=?~(ext (dec pos.u.ris) pos.u.ris)
2015-09-02 01:20:17 +03:00
=+ tot=(weld str.u.ris ext)
=+ dol=(slag (sub num.hit sop) old.hit)
2016-09-02 05:39:24 +03:00
=/ sup
2015-12-09 04:54:26 +03:00
|- ^- (unit @ud)
2015-09-02 01:20:17 +03:00
?~ dol ~
2016-09-02 05:39:24 +03:00
?^ (find tot i.dol)
2015-09-02 01:20:17 +03:00
`sop
$(sop (dec sop), dol t.dol)
?~ sup ta-bel
(ta-mov(str.u.ris tot, pos.u.ris u.sup) (dec u.sup))
2015-09-02 01:20:17 +03:00
::
++ ta-txt :: hear text
2015-12-20 23:50:45 +03:00
|= txt/(list @c)
2015-09-02 01:20:17 +03:00
^+ +>
?^ ris
(ta-ser txt)
(ta-hom (cat:edit pos.inp txt))
2015-09-02 01:20:17 +03:00
::
++ ta-vew :: computed prompt
^- {pom/stub:dill lin/(pair @ud (list @c))}
=; vew/(pair (list @c) styx:dill)
[(make:klr q.vew) pos.inp p.vew]
2016-08-28 07:44:44 +03:00
?: vis.pom
:- buf.say.inp :: default prompt
?~ ris
cad.pom
:(welp "(reverse-i-search)'" (tufa str.u.ris) "': ")
:- (reap (lent buf.say.inp) `@c`'*') :: hidden input
%+ welp
cad.pom
?~ buf.say.inp ~
:(welp "<" (scow %p (end 4 1 (sham buf.say.inp))) "> ")
2016-09-08 07:08:34 +03:00
::
++ ta-yan :: yank
(snag (sub num.kil pos.kil) old.kil)
2015-05-17 04:05:56 +03:00
--
++ edit :: produce sole-edits
|%
++ cat :: mass insert
|= {pos/@ud txt/(list @c)}
^- sole-edit
:- %mor
|- ^- (list sole-edit)
?~ txt ~
[[%ins pos i.txt] $(pos +(pos), txt t.txt)]
::
++ cut :: mass delete
|= {pos/@ud num/@ud}
^- sole-edit
:- %mor
|- ^- (list sole-edit)
?: =(0 num) ~
[[%del pos] $(num (dec num))]
::
++ rep :: mass replace
|= {{pos/@ud num/@ud} txt/(list @c)}
^- sole-edit
:~ %mor
(cut pos num)
(cat pos txt)
==
--
++ offset :: calculate offsets
|%
++ alnm :: alpha-numeric
|= a/@ ^- ?
?| &((gte a '0') (lte a '9'))
&((gte a 'A') (lte a 'Z'))
&((gte a 'a') (lte a 'z'))
==
::
++ ace :: next whitespace
|= a/(list @)
=| {b/_| i/@ud}
|- ^- @ud
?~ a i
=/ c !=(32 i.a)
=. b |(b c)
?: &(b !|(=(0 i) c)) i
$(i +(i), a t.a)
::
++ edg :: next word boundary
|= a/(list @)
=| {b/_| i/@ud}
|- ^- @ud
?~ a i
=/ c (alnm i.a)
=. b |(b c)
?: &(b !|(=(0 i) c)) i
$(i +(i), a t.a)
::
++ wrd :: next or current word
|= a/(list @)
=| i/@ud
|- ^- @ud
?: |(?=($~ a) (alnm i.a)) i
$(i +(i), a t.a)
--
::
++ klr :: styx/stub engine
=, dill
|%
++ make :: stub from styx
2016-10-17 23:45:05 +03:00
|= a/styx ^- stub
2016-10-16 06:03:05 +03:00
=| b/stye
%+ reel
|- ^- stub
2016-10-17 23:45:05 +03:00
%- zing %+ turn a
|= a/$@(@t (pair styl styx))
2016-10-17 23:45:05 +03:00
?@ a [b (tuba (trip a))]~
^$(a q.a, b (styd p.a b))
::
2016-10-16 06:03:05 +03:00
|= {a/(pair stye (list @c)) b/stub}
2016-10-17 23:45:05 +03:00
?~ b [a ~]
?. =(p.a p.i.b) [a b]
[[p.a (weld q.a q.i.b)] t.b]
::
2016-10-17 23:45:05 +03:00
++ styd :: stye from styl
|= {a/styl b/stye} ^+ b :: with inheritance
:+ ?~ p.a p.b
?~ u.p.a ~
(~(put in p.b) u.p.a)
(fall p.q.a p.q.b)
(fall q.q.a q.q.b)
::
++ lent-stye
|= a/stub ^- @
(roll (lnts-stye a) add)
::
++ lent-char
|= a/stub ^- @
(roll (lnts-char a) add)
::
++ lnts-stye :: stub pair head lengths
|= a/stub ^- (list @)
%+ turn a
|= a/(pair stye (list @c))
;: add :: presumes impl of cvrt:ansi in %dill
(mul 5 2) :: bg
(mul 5 2) :: fg
=+ b=~(wyt in p.p.a) :: effect
?:(=(0 b) 0 (mul 4 +(b)))
==
::
++ lnts-char :: stub pair tail lengths
|= a/stub ^- (list @)
%+ turn a
2016-10-16 06:03:05 +03:00
|= a/(pair stye (list @c))
(lent q.a)
::
++ brek :: index + incl-len of
|= {a/@ b/(list @)} :: stub pair w/ idx a
=| {c/@ i/@}
|- ^- (unit (pair @ @))
?~ b ~
=. c (add c i.b)
?: (gte c a)
`[i c]
$(i +(i), b t.b)
::
2016-10-16 06:03:05 +03:00
++ slag :: slag stub, keep stye
|= {a/@ b/stub}
^- stub
=+ c=(lnts-char b)
=+ i=(brek a c)
?~ i b
=+ r=(^slag +(p.u.i) b)
?: =(a q.u.i)
r
=+ n=(snag p.u.i b)
:_ r :- p.n
(^slag (sub (snag p.u.i c) (sub q.u.i a)) q.n)
::
2016-10-16 06:03:05 +03:00
++ scag :: scag stub, keep stye
|= {a/@ b/stub}
^- stub
=+ c=(lnts-char b)
=+ i=(brek a c)
?~ i b
?: =(a q.u.i)
(^scag +(p.u.i) b)
%+ welp
(^scag p.u.i b)
=+ n=(snag p.u.i b)
:_ ~ :- p.n
(^scag (sub (snag p.u.i c) (sub q.u.i a)) q.n)
::
++ swag :: swag stub, keep stye
|= {{a/@ b/@} c/stub}
(scag b (slag a c))
--
2015-05-17 04:05:56 +03:00
--