2015-02-09 00:22:33 +03:00
|
|
|
::
|
|
|
|
:::: /hook/core/console/lib
|
|
|
|
::
|
|
|
|
:: This file is in the public domain.
|
|
|
|
::
|
|
|
|
/? 310
|
|
|
|
/- *console
|
2015-02-09 09:25:00 +03:00
|
|
|
!:
|
2015-02-09 00:22:33 +03:00
|
|
|
::::
|
|
|
|
::
|
|
|
|
|%
|
|
|
|
++ cs :: shared-state engine
|
2015-02-12 05:57:33 +03:00
|
|
|
|_ console-share
|
2015-02-09 00:22:33 +03:00
|
|
|
++ abet +<
|
|
|
|
++ apply
|
|
|
|
|= ted=console-edit
|
|
|
|
^+ +>
|
|
|
|
?- -.ted
|
2015-02-12 05:57:33 +03:00
|
|
|
%del +>.$(buf (weld (scag p.ted buf) (slag +(p.ted) buf)))
|
|
|
|
%ins +>.$(buf (weld (scag p.ted buf) `_buf`[q.ted (slag p.ted buf)]))
|
2015-02-09 00:22:33 +03:00
|
|
|
%mor |- ^+ +>.^$
|
|
|
|
?~ p.ted
|
|
|
|
+>.^$
|
2015-02-09 09:25:00 +03:00
|
|
|
$(p.ted t.p.ted, +>.^$ ^$(ted i.p.ted))
|
2015-02-09 00:22:33 +03:00
|
|
|
%nop +>.$
|
2015-02-12 05:57:33 +03:00
|
|
|
%set +>.$(buf p.ted)
|
2015-02-09 00:22:33 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
:: 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
|
2015-02-09 09:25:00 +03:00
|
|
|
%del ?:((lte p.sin p.dex) dex(p +(p.dex)) dex)
|
2015-02-09 00:22:33 +03:00
|
|
|
%ins ?: =(p.sin p.dex)
|
2015-02-09 09:25:00 +03:00
|
|
|
?:((gth q.sin q.dex) dex dex(p +(p.dex)))
|
|
|
|
?:((lte p.sin p.dex) dex(p +(p.dex)) dex)
|
2015-02-09 00:22:33 +03:00
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ commit
|
|
|
|
|= ted=console-edit
|
|
|
|
^+ +>
|
|
|
|
(apply(own.ven +(own.ven)) ted)
|
|
|
|
::
|
2015-02-12 05:57:33 +03:00
|
|
|
++ transmit
|
|
|
|
|= ted=console-edit
|
|
|
|
^- [console-change _+>]
|
|
|
|
[[[his.ven own.ven] (sham buf) ted] (commit ted)]
|
|
|
|
::
|
2015-02-09 00:22:33 +03:00
|
|
|
++ receive :: edit from other
|
|
|
|
|= $: ler=console-clock :: other's clock view
|
|
|
|
haw=@uvH :: hash at edit
|
|
|
|
ted=console-edit :: edit content
|
|
|
|
==
|
|
|
|
^+ +>
|
2015-02-12 05:57:33 +03:00
|
|
|
?. &(=(his.ler his.ven) (lte own.ler own.ven))
|
|
|
|
~& [%receive-mismatch ler/ler ven/ven ~]
|
|
|
|
!!
|
2015-02-09 00:22:33 +03:00
|
|
|
?> &(=(his.ler his.ven) (lte own.ler own.ven))
|
|
|
|
?> |(!=(own.ler own.ven) =(haw (sham buf)))
|
|
|
|
=: his.ven +(his.ven)
|
|
|
|
leg (scag (sub own.ven own.ler) leg)
|
|
|
|
==
|
|
|
|
(apply (transmute [%mor leg] ted))
|
|
|
|
--
|
|
|
|
--
|