switching sole

This commit is contained in:
Anton Dyudin 2015-05-14 14:59:45 -07:00
parent 5ac01defea
commit 8ba1b0ccf3
3 changed files with 39 additions and 29 deletions

View File

@ -1133,7 +1133,8 @@
:: ::
++ del-subs :: XX per path? ++ del-subs :: XX per path?
|= [a=dock %json b=wire c=path] ^+ ..ix |= [a=dock %json b=wire c=path] ^+ ..ix
(hurl-note [a b] [%g %deal [him -.a] +.a %pull ~]) =. ..ix (hurl-note [a b] [%g %deal [him -.a] +.a %pull ~])
(nice-json:pop-duct:(ire-ix ire)) :: XX gall ack
:: ::
++ get-rush ++ get-rush
|= [a=whir-of b=json] ^+ ..ix |= [a=whir-of b=json] ^+ ..ix

View File

@ -244,12 +244,11 @@ window.urb.unsubscribe = function(params,cb) {
if(!params.path) throw new Error("You must specify a path for urb.unsubscribe.") if(!params.path) throw new Error("You must specify a path for urb.unsubscribe.")
if(!params.appl) throw new Error("You must specify an appl for urb.unsubscribe.") if(!params.appl) throw new Error("You must specify an appl for urb.unsubscribe.")
if(!cb) throw new Error("You must supply a callback to urb.unsubscribe.")
url = "/~/is/"+this.gsig(params)+".json" url = "/~/is/"+this.gsig(params)+".json"
method = "delete" method = "delete"
this.req("delete",url,params,true,function(err,res) { this.req("delete",url,params,true,function(err,res) {
cb(err,res) if(cb) cb(err,res)
}) })
} }

View File

@ -3,8 +3,8 @@
str = JSON.stringify str = JSON.stringify
Prompt = recl render: -> Prompt = recl render: ->
[pro,cur,buf] = [@props.appl+@props.prompt[@props.appl], @props.cursor, @props.input + " "] [pro,cur,buf] = [@props.prompt[@props.appl] ? "X", @props.cursor, @props.input + " "]
pre {}, pro, pre {}, @props.appl+pro,
span {style: background: 'lightgray'}, buf.slice(0,cur), "\u0332", buf.slice(cur) span {style: background: 'lightgray'}, buf.slice(0,cur), "\u0332", buf.slice(cur)
Matr = recl render: -> Matr = recl render: ->
@ -54,17 +54,28 @@ $ ->
offset:0 ), term offset:0 ), term
window.matr = matr window.matr = matr
update = (a) -> matr.setProps a update = (a) -> matr.setProps a
buffer = new Share "" buffer = "": new Share ""
window.buffer = buffer window.buffer = buffer
choose = (appl)-> urb.appl = appl; update {appl} choose = (appl)->
urb.appl = appl
buffer[appl] ?= new Share ""
updPrompt '', null
update {appl, cursor: 0, input: buffer[appl].buf}
print = (txt)-> update rows: [matr.props.rows..., txt] print = (txt)-> update rows: [matr.props.rows..., txt]
sync = (ted)-> sync = (ted,app)->
update input: buffer.buf, cursor: buffer.transpose ted, matr.props.cursor app ?= matr.props.appl
if app isnt matr.props.appl then return
b = buffer[app]
update input: b.buf, cursor: b.transpose ted, matr.props.cursor
updPrompt = (app,pro) -> updPrompt = (app,pro) ->
prompt = $.extend {}, matr.props.prompt prompt = $.extend {}, matr.props.prompt
if pro? then prompt[app] = pro else delete prompt[app] if pro? then prompt[app] = pro else delete prompt[app]
update {prompt} update {prompt}
sysStatus = ()-> updPrompt '', (
[app,pro] = [matr.props.appl, (k for k,v of matr.props.prompt when k isnt '')]
if app is '' then (pro.join ', ')+'# ' else null
)
peer = (ruh,app) -> peer = (ruh,app) ->
app ?= urb.appl app ?= urb.appl
if ruh.map then return ruh.map (rul)-> peer rul, app if ruh.map then return ruh.map (rul)-> peer rul, app
@ -75,7 +86,7 @@ $ ->
when 'pro' then updPrompt app, ruh.pro.cad when 'pro' then updPrompt app, ruh.pro.cad
when 'hop' then update cursor: ruh.hop; bell() # XX buffer.transpose? when 'hop' then update cursor: ruh.hop; bell() # XX buffer.transpose?
when 'blk' then console.log "Stub #{str ruh}" when 'blk' then console.log "Stub #{str ruh}"
when 'det' then buffer.receive ruh.det; sync ruh.det.ted when 'det' then buffer[app].receive ruh.det; sync ruh.det.ted, app
when 'act' then switch ruh.act when 'act' then switch ruh.act
when 'clr' then update rows:[] when 'clr' then update rows:[]
when 'bel' then bell() when 'bel' then bell()
@ -93,19 +104,21 @@ $ ->
if matr.props.prompt[app]? if matr.props.prompt[app]?
return print '# already-joined: '+app return print '# already-joined: '+app
choose app choose app
updPrompt "", null
urb.bind "/sole", {wire:"/"}, (err,d)-> urb.bind "/sole", {wire:"/"}, (err,d)->
if err then console.log err if err then console.log err
else if d.data then peer d.data, app else if d.data then peer d.data, app
cycle = ()-> cycle = ()->
apps = Object.keys matr.props.prompt apps = Object.keys matr.props.prompt
update appl: apps[1 + apps.indexOf matr.props.appl] ? apps[0] if apps.length < 2 then return
choose apps[1 + apps.indexOf urb.appl] ? apps[0]
part = (appl)-> part = (appl)->
unless matr.props.prompt[app]? mapr = matr.props
return print '# not-joined: '+app unless mapr.prompt[appl]?
return print '# not-joined: '+appl
urb.unsubscribe {appl, path: "/sole", wire: "/"} urb.unsubscribe {appl, path: "/sole", wire: "/"}
if appl is matr.props.appl then cycle() if appl is mapr.appl then cycle()
updPrompt appl, null updPrompt appl, null
sysStatus()
join urb.appl join urb.appl
window.join = join; window.part = part window.join = join; window.part = part
@ -123,19 +136,19 @@ $ ->
# ), 500 # ), 500
sendAction = (data)-> sendAction = (data)->
if urb.appl then urb.send {mark: 'sole-action', data}, (e,res)-> if matr.props.appl then urb.send {mark: 'sole-action', data}, (e,res)->
if res.status isnt 200 then $('#err')[0].innerText = res.data.mess if res.status isnt 200 then $('#err')[0].innerText = res.data.mess
else if data is 'ret' else if data is 'ret'
app = /^[a-z-]+$/.exec(buffer.buf.slice(1)) app = /^[a-z-]+$/.exec(buffer[""].buf.slice(1))
unless app? unless app? and app[0]?
return bell() return bell()
else switch buffer.buf[0] else switch buffer[""].buf[0]
when '+' then join app when '+' then doEdit set: ""; join app[0]
when '-' then part app when '-' then doEdit set: ""; part app[0]
else bell() else bell()
doEdit = (ted)-> doEdit = (ted)->
det = buffer.transmit ted det = buffer[matr.props.appl].transmit ted
sync ted sync ted
sendAction {det} sendAction {det}
@ -185,12 +198,9 @@ $ ->
when 'g' then bell() when 'g' then bell()
when 'x' then cycle() when 'x' then cycle()
when 'v' when 'v'
if mapr.appl = "" appl = if mapr.appl isnt '' then '' else urb.appl
updPrompt "", null update {appl, cursor:0, input:buffer[appl].buf}
cycle() sysStatus()
apps = Object.keys mapr.prompt
updPrompt "", (apps.join ", ")+'# '
choose ''
when 't' when 't'
if mapr.cursor is 0 or mapr.input.length < 2 if mapr.cursor is 0 or mapr.input.length < 2
return bell() return bell()