mirror of
https://github.com/urbit/shrub.git
synced 2024-12-14 20:02:51 +03:00
pub/sole/fab up
This commit is contained in:
parent
da107ab17c
commit
6d76b13162
@ -556,6 +556,7 @@
|
||||
^+ +>
|
||||
?^ ris
|
||||
(ta-ser txt)
|
||||
:: ~& ven.say.inp
|
||||
%- ta-hom(pos.inp (add (lent txt) pos.inp))
|
||||
:- %mor
|
||||
|- ^- (list sole-edit)
|
||||
|
@ -102,6 +102,7 @@
|
||||
++ receive :: naturalize event
|
||||
|= sole-change
|
||||
^- [sole-edit sole-share]
|
||||
~| [ler ven]
|
||||
?> &(=(his.ler his.ven) (lte own.ler own.ven))
|
||||
?> |(!=(own.ler own.ven) =(haw (sham buf)) =(haw 0)) :: trust the clock
|
||||
=. leg (scag (sub own.ven own.ler) leg)
|
||||
|
@ -14,20 +14,20 @@
|
||||
^- ^json
|
||||
=+ cha
|
||||
=< (jobe ted/(. ted) ler/a/~[(jone own.ler) (jone his.ler)] ~)
|
||||
|= ted=sole-edit
|
||||
?- -.ted
|
||||
|= det=sole-edit
|
||||
?- -.det
|
||||
%nop [%s 'nop']
|
||||
%mor [%a (turn p.ted ..$)]
|
||||
%del (joba %del (jone p.ted))
|
||||
%set (joba %set (jape (tufa p.ted)))
|
||||
%ins (joba %ins (jobe at/(jone p.ted) cha/s/(tuft q.ted) ~))
|
||||
%mor [%a (turn p.det ..$)]
|
||||
%del (joba %del (jone p.det))
|
||||
%set (joba %set (jape (tufa p.det)))
|
||||
%ins (joba %ins (jobe at/(jone p.det) cha/s/(tuft q.det) ~))
|
||||
==
|
||||
--
|
||||
--
|
||||
++ wush
|
||||
|= [wid=@u tan=tang]
|
||||
^- tape
|
||||
=+ rolt=|=(a=wall `tape`?~(a ~ :(weld i.a "\0a" $(a t.a))))
|
||||
=+ rolt=|=(a=wall `tape`?~(a ~ ?~(t.a i.a :(weld i.a "\0a" $(a t.a)))))
|
||||
(rolt (turn tan |=(a=tank (rolt (wash 0^wid a)))))
|
||||
::
|
||||
--
|
||||
|
@ -36,14 +36,18 @@
|
||||
;script(type "text/coffeescript") ;- %- trip
|
||||
'''
|
||||
[DOM,recl,rend] = [React.DOM, React.createClass, React.renderComponent]
|
||||
[div, pre] = [DOM.div, DOM.pre]
|
||||
[div, pre, span] = [DOM.div, DOM.pre, DOM.span]
|
||||
str = JSON.stringify
|
||||
|
||||
Prompt = recl render: ->
|
||||
[pro,cur,buf] = [@props.prompt, @props.cursor, @props.input + " "]
|
||||
pre {}, pro,
|
||||
span {style: background: 'lightgray'}, buf.slice(0,cur), "\u0332", buf.slice(cur)
|
||||
|
||||
Matr = recl render: ->
|
||||
[pro,cur] = [@props.prompt + " ", @props.cursor + 1]
|
||||
prompt = "#{pro.slice(0,cur)}\u0332#{pro.slice(cur)}"
|
||||
lines = [prompt, @props.rows...]
|
||||
div {}, lines.slice().reverse().map (lin)->
|
||||
pre {}, lin
|
||||
lines = @props.rows.slice().reverse().map (lin)-> pre {}, lin, " "
|
||||
lines.push Prompt {prompt:@props.prompt, input:@props.input, cursor:@props.cursor}
|
||||
div {}, lines
|
||||
|
||||
$ ->
|
||||
termRev = 0
|
||||
@ -73,21 +77,25 @@
|
||||
flash = ($el, background)->
|
||||
$el.css {background}
|
||||
if background
|
||||
setTimeout (()-> flash $el,''), 50
|
||||
setTimeout (-> flash $el,''), 50
|
||||
|
||||
matr = rend (Matr rows:[], prompt:"", input:"", history:[], cursor:1), term
|
||||
matr = rend (Matr rows:[], prompt:"", input:"", history:[], cursor:0), term
|
||||
update = (a) -> matr.setProps a
|
||||
buffer = new Share ""
|
||||
|
||||
window.buffer = buffer
|
||||
sync = (ted)->
|
||||
update input: buffer.buf, cursor: buffer.transpose ted, matr.props.cursor
|
||||
|
||||
peer = (ruh) ->
|
||||
switch
|
||||
when ruh.map then ruh.map peer
|
||||
when ruh.hop then update cursor: buffer.transpose ruh.hop
|
||||
when ruh.pro then update prompt: ruh.pro.cad
|
||||
when ruh.txt then update rows: [ruh.txt, matr.props.rows...]
|
||||
when ruh.blk then console.log "Stub #{str ruh}"
|
||||
when ruh.act then switch ruh.act
|
||||
if ruh.map then return ruh.map peer
|
||||
switch Object.keys(ruh)[0]
|
||||
when 'txt' then update rows: [ruh.txt, matr.props.rows...]
|
||||
when 'tan' then ruh.tan.split("\n").reverse().map (txt)-> peer {txt}
|
||||
when 'hop' then update cursor: buffer.transpose ruh.hop #; peer act:'bel'
|
||||
when 'pro' then update prompt: ruh.pro.cad
|
||||
when 'blk' then console.log "Stub #{str ruh}"
|
||||
when 'det' then buffer.receive ruh.det; sync ruh.det.ted
|
||||
when 'act' then switch ruh.act
|
||||
when 'clr' then update rows:[]
|
||||
when 'bel' then flash ($ 'body'), 'black'
|
||||
when 'nex' then update
|
||||
@ -98,11 +106,18 @@
|
||||
else v = Object.keys(ruh); console.log v, ruh[v[0]]
|
||||
|
||||
urb.bind "/sole", {wire:"/"}, (err,d)->
|
||||
if d.data then peer d.data
|
||||
if err then console.log err
|
||||
else if d.data then peer d.data
|
||||
|
||||
sendAction = (data)->
|
||||
urb.send {mark: 'sole-action', data}, (n,err)->
|
||||
if err.data then $('#err')[0].innerText = err.data.mess
|
||||
urb.send {mark: 'sole-action', data}, (e,res)->
|
||||
if res.status isnt 200 then $('#err')[0].innerText = err.data.mess
|
||||
|
||||
doEdit = (ted)->
|
||||
det = buffer.transmit ted
|
||||
sync ted
|
||||
sendAction {det}
|
||||
|
||||
#later = (data)->
|
||||
# if data
|
||||
# pressed.push data
|
||||
@ -133,10 +148,19 @@
|
||||
act: 'uncap'
|
||||
if key
|
||||
e.preventDefault()
|
||||
curs = matr.props.cursor
|
||||
if key.str
|
||||
det = buffer.transmit ins: cha: str, at: matr.props.cursor
|
||||
sendAction {det}
|
||||
|
||||
doEdit ins: cha: key.str, at: curs
|
||||
update cursor: curs+1
|
||||
switch key.act
|
||||
when 'entr' then sendAction 'ret'
|
||||
when 'left' then if curs > 0
|
||||
update cursor: curs-1
|
||||
when 'right' then if curs < buffer.buf.length
|
||||
update cursor: curs+1
|
||||
when 'baxp' then doEdit del: curs-1
|
||||
else (if key.act then console.log key.act)
|
||||
|
||||
# amod = (arr)->
|
||||
# for i in arr
|
||||
# unless mod.indexOf(i) < 0
|
||||
|
@ -1,9 +1,10 @@
|
||||
# See /hook/core/sole/lib
|
||||
str = JSON.stringify
|
||||
clog = (a)-> console.log a
|
||||
class window.Share
|
||||
constructor: (@buf = "", @ven = [0, 0], @leg = []) ->
|
||||
#
|
||||
abet: ()-> buf:@buf, leg:@leg.slice(), ven:@ven.slice()
|
||||
abet: -> buf:@buf, leg:@leg.slice(), ven:@ven.slice()
|
||||
apply: (ted)->
|
||||
if 'nop' == ted then return
|
||||
if ted.map then ted.map @apply
|
||||
@ -47,7 +48,6 @@ class window.Share
|
||||
@ven[0]++
|
||||
@leg.push ted
|
||||
@apply ted
|
||||
return @abet()
|
||||
#
|
||||
inverse: (ted)->
|
||||
switch true
|
||||
@ -66,14 +66,17 @@ class window.Share
|
||||
dat = @transmute @leg, ted
|
||||
@ven[1]++; @apply dat; dat
|
||||
#
|
||||
remit: ()-> throw 'stub'
|
||||
remit: -> throw 'stub'
|
||||
transmit: (ted)->
|
||||
act = {ted, ler:[@ven[1], @ven[0]]}
|
||||
@commit ted
|
||||
{ted, ler:[@ven[1], @ven[0]]}
|
||||
return act
|
||||
#
|
||||
transceive: ({ler,ted})->
|
||||
old = new Share @buf
|
||||
dat = @receive {ler, ted}
|
||||
old.inverse dat
|
||||
#
|
||||
transpose: (pos)-> (@transmute @leg, ins: at: pos).ins.at
|
||||
transpose: (ted,pos)->
|
||||
if pos == undefined then @transpose @leg, ted
|
||||
else ((@transmute ted, ins: at: pos).ins ? at:0).at
|
||||
|
Loading…
Reference in New Issue
Block a user