mirror of
https://github.com/urbit/shrub.git
synced 2024-12-12 10:29:01 +03:00
90 lines
2.5 KiB
Plaintext
90 lines
2.5 KiB
Plaintext
|
::
|
||
|
:::: /hook/core/console/lib
|
||
|
::
|
||
|
:: This file is in the public domain.
|
||
|
::
|
||
|
/? 310
|
||
|
/- *console
|
||
|
::
|
||
|
::::
|
||
|
::
|
||
|
|%
|
||
|
++ cs :: shared-state engine
|
||
|
|_ [pos=@ud console-share]
|
||
|
++ abet +<
|
||
|
++ apply
|
||
|
|= ted=console-edit
|
||
|
^+ +>
|
||
|
?- -.ted
|
||
|
%del +>.$(buf (weld (scag p.ted buf) (slag 1 buf)))
|
||
|
%ins +>.$(buf (weld (scag p.ted buf) `_buf`[q.ted buf]))
|
||
|
%mor |- ^+ +>.^$
|
||
|
?~ p.ted
|
||
|
+>.^$
|
||
|
$(p.ted t.p.ted, +>.$ ^$(ted i.p.ted))
|
||
|
%nop +>.$
|
||
|
%set +>.$(buf p.ted, pos (lent p.ted))
|
||
|
==
|
||
|
::
|
||
|
:: symmetric operational transformation. for any console state, obeys
|
||
|
::
|
||
|
:: =+ [x=(transmute a b) y=(transmute b a)]
|
||
|
:: .= (edit-apply:(edit-apply x) b)
|
||
|
:: (edit-apply:(edit-apply a) y)
|
||
|
::
|
||
|
++ transmute :: dex as after sin
|
||
|
|= [sin=console-edit dex=console-edit]
|
||
|
^- console-edit
|
||
|
?: ?=(%mor -.sin)
|
||
|
|- ^- console-edit
|
||
|
?~ p.sin dex
|
||
|
$(p.sin t.p.sin, dex ^$(sin i.p.sin))
|
||
|
::
|
||
|
?: ?=(%mor -.dex)
|
||
|
:- %mor
|
||
|
|- ^- (list console-edit)
|
||
|
?~ p.dex ~
|
||
|
[^$(dex i.p.dex) $(p.dex t.p.dex)]
|
||
|
::
|
||
|
?: |(?=(%nop -.sin) ?=(%nop -.dex)) dex
|
||
|
?: ?=(%set -.sin) [%nop ~]
|
||
|
?: ?=(%set -.dex) dex
|
||
|
::
|
||
|
?- -.sin
|
||
|
%del
|
||
|
?- -.dex
|
||
|
%del ?: =(p.sin p.dex) [%nop ~]
|
||
|
?:((lth p.sin p.dex) dex(p (dec p.dex)) dex)
|
||
|
%ins ?:((lte p.sin p.dex) dex(p (dec p.dex)) dex)
|
||
|
==
|
||
|
::
|
||
|
%ins
|
||
|
?- -.dex
|
||
|
%del ?:((lte p.sin p.dex) dex(p (inc p.dex)) dex)
|
||
|
%ins ?: =(p.sin p.dex)
|
||
|
?:((gth q.sin q.dex) dex dex(p (inc p.dex)))
|
||
|
?:((lte p.sin p.dex) dex(p (inc p.dex)) dex)
|
||
|
==
|
||
|
==
|
||
|
::
|
||
|
++ commit
|
||
|
|= ted=console-edit
|
||
|
^+ +>
|
||
|
(apply(own.ven +(own.ven)) ted)
|
||
|
::
|
||
|
++ receive :: edit from other
|
||
|
|= $: ler=console-clock :: other's clock view
|
||
|
haw=@uvH :: hash at edit
|
||
|
ted=console-edit :: edit content
|
||
|
==
|
||
|
^+ +>
|
||
|
?> &(=(his.ler his.ven) (lte own.ler own.ven))
|
||
|
?> |(!=(own.ler own.ven) =(haw (sham buf)))
|
||
|
=: his.ven +(his.ven)
|
||
|
own.ven +(own.ven)
|
||
|
leg (scag (sub own.ven own.ler) leg)
|
||
|
==
|
||
|
(apply (transmute [%mor leg] ted))
|
||
|
--
|
||
|
--
|