urbit/main/app/terminal/core.hook

366 lines
12 KiB
Plaintext
Raw Normal View History

2014-09-12 06:11:03 +04:00
:: Terminal
::
:::: /hook/core/terminal/app
::
/? 314 :: need urbit 314
2014-10-10 01:58:47 +04:00
/- term-line, kyev
2014-09-12 06:11:03 +04:00
::
:::: structures
::
|% ::
++ axle $: %1 ::
hiz=(map path term-line) ::
2014-09-12 06:11:03 +04:00
== ::
++ gilt ::
$% [%term-line p=term-line] ::
[%hymn p=manx] ::
[%json p=json] ::
== ::
++ gift ::
$% [%rush gilt] ::
[%rust gilt] ::
[%mean p=ares] ::
[%nice ~] ::
2014-10-04 02:31:16 +04:00
[%veer p=@ta q=path r=@t] ::
[%vega p=path] ::
2014-09-12 06:11:03 +04:00
== ::
++ hapt ,[p=ship q=path] ::
++ move ,[p=bone q=(mold note gift)] ::
++ note ::
$% $: %g ::
2014-09-23 02:20:47 +04:00
$% [%cide p=span] ::
[%show p=hapt q=ship r=path] ::
2014-09-12 06:11:03 +04:00
[%sire p=term q=span] ::
2014-10-10 01:58:47 +04:00
[%mess p=hapt q=ship r=[?(%txt %kyev) vase]] ::
2014-09-12 06:11:03 +04:00
== == == ::
++ sign ::
$% $: %g ::
2014-09-23 02:20:47 +04:00
$% [%gone p=hapt] ::
2014-09-12 06:11:03 +04:00
[%mean p=ares] ::
2014-09-23 02:20:47 +04:00
[%nice ~] ::
2014-10-03 02:21:23 +04:00
[%rust p=%term-line q=term-line] ::
[%rush p=%term-line q=term-line] ::
2014-10-04 02:31:16 +04:00
[%veer p=@ta q=path r=@t] ::
[%vega p=path] ::
2014-09-12 06:11:03 +04:00
== == ==
--
::
2014-10-02 23:46:00 +04:00
:::: libs
::
|%
++ encode
|= [a=term b=path] ^- span
(rap 3 a (turn b |=(c=span (cat 3 '_' c))))
::
++ decode |=(a=span `[p=term q=path]`(rash a (most cab sym)))
--
2014-09-12 06:11:03 +04:00
!:
:::: program
::
|_ [hid=hide axle]
++ page
|= pax=path
2014-09-12 06:11:03 +04:00
^- manx
;html
;head
;title: Hi
2014-09-23 05:00:25 +04:00
;script(src "/gen/main/lib/urb.js");
2014-09-18 06:56:49 +04:00
;script(src "//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js");
2014-10-10 01:58:47 +04:00
;script(src "//cdnjs.cloudflare.com/ajax/libs/mousetrap/1.4.6/mousetrap.js");
2014-09-12 06:11:03 +04:00
;script: urb.appl = "{(trip app.hid)}"
;script: urb.term = \{pax: "{(spud pax)}"}
2014-10-07 22:34:21 +04:00
;script(src "//use.typekit.net/fkv0sjk.js");
;script:'try{Typekit.load();}catch(e){}'
2014-09-18 06:56:49 +04:00
;script:'''
jpok = function(a,b){
var dat = {pax:urb.term.pax, act:{}}
dat.act[a] = b
2014-09-18 06:56:49 +04:00
urb.send({data:dat})
}
'''
;style:'''
2014-09-27 05:34:28 +04:00
html {
font-size: 14px;
}
body {
margin: 2rem;
2014-10-10 03:03:31 +04:00
line-height: 1.4rem;
2014-09-27 05:34:28 +04:00
}
body,
span,
2014-10-07 22:34:21 +04:00
pre,
2014-10-10 03:03:31 +04:00
textarea,
2014-09-27 05:34:28 +04:00
input {
2014-10-07 22:34:21 +04:00
font-family: 'source-code-pro', monospace;
2014-09-27 05:34:28 +04:00
font-size: 1rem;
background-color: #000;
color: #fff;
}
button {
border: none;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 600;
font-size: .8rem;
text-transform: uppercase;
letter-spacing: 1px;
color: #000;
background-color: #fff;
padding: 1rem;
}
2014-10-10 03:03:31 +04:00
#prom-cont {
display: block;
position:relative;
}
textarea,
#prom-size {
min-height: 24px;
box-sizing: border-box;
overflow: hidden;
width: 100%;
}
textarea {
height: 100%;
2014-09-27 05:34:28 +04:00
border: 0;
outline: none;
2014-10-10 03:03:31 +04:00
position: absolute;
resize: none;
}
#prom-size {
visibility: hidden;
white-space: pre-wrap;
word-wrap: break-word;
overflow-wrap: break-word;
2014-09-18 06:56:49 +04:00
}
'''
2014-09-12 06:11:03 +04:00
==
;body
2014-09-18 06:56:49 +04:00
;pre#cont;
2014-10-10 03:03:31 +04:00
;span#prem:">"
;div#prom-cont
2014-10-10 04:23:17 +04:00
;textarea.mousetrap#prom(wrap "off");
2014-10-10 03:03:31 +04:00
;div#prom-size;
==
2014-09-27 05:34:28 +04:00
;br;
2014-09-18 06:56:49 +04:00
;script:'''
2014-10-10 03:03:31 +04:00
var prom, prom_size, hist,
2014-10-10 03:07:21 +04:00
hind, size, focus, pos, pax
2014-10-10 03:03:31 +04:00
$(function() {
prom = $("#prom")
prom_size = $("#prom-size")
hist = []
hind = 0
2014-10-10 03:13:17 +04:00
var keys = ['l', 'x', 'r']
for (i in keys) (function(k){
Mousetrap.bind('ctrl+' + k, function(){
jpok('cmd', k)
})
})(keys[i])
2014-10-10 03:03:31 +04:00
prom.keydown(function(e){
switch(e.which){
default: return true
break;
case 13: // %retn
if(e.shiftKey) return true
2014-10-10 04:23:17 +04:00
v = prom.val().replace(/\xa0/g, ' ')
cont.textContent += '\n' + prem.textContent + '\n' + v
2014-10-10 03:03:31 +04:00
jpok('line', v)
hist.unshift(v)
prom.val('')
2014-10-10 03:07:21 +04:00
return false
2014-10-10 03:03:31 +04:00
break;
case 38: // %up
if(hind == hist.length) return true
if(pos().top === false) return true
prom.val([hist[hind], hist[hind] = prom.val()][0])
2014-10-10 04:23:17 +04:00
size()
2014-10-10 03:03:31 +04:00
hind++
return false
break;
case 40: // %down
if(hind == 0) return true
if(pos().bot === false) return true
2014-10-10 04:23:17 +04:00
size()
2014-10-10 03:03:31 +04:00
hind--
prom.val([hist[hind], hist[hind] = prom.val()][0])
return false
}
})
focus = function() { $(prom).focus(); }
$('body').on('click', focus)
focus()
size = function() {
prom_size.html(prom.val()+"<br />")
}
size()
prom.on('input propertychange', size)
pos = function() {
v = prom.val()
_top = v.slice(0,prom[0].selectionStart).indexOf("\n") === -1
_bot = v.slice(prom[0].selectionStart).indexOf("\n") === -1
return {top:_top,bot:_bot}
2014-10-03 03:00:57 +04:00
}
2014-10-10 03:03:31 +04:00
2014-10-10 03:07:21 +04:00
pax = '/lines'
2014-10-10 03:03:31 +04:00
if(urb.term.pax != "/") pax += urb.term.pax
urb.subscribe({path: pax}, function(e, dat){
if(dat.data.ok) return;
2014-10-10 03:07:21 +04:00
hist = dat.data.history
hind = 0
2014-10-10 03:03:31 +04:00
cont.textContent = dat.data.lines.join('\n')
2014-10-10 03:07:21 +04:00
window.scrollTo(0,document.body.scrollHeight)
2014-10-10 03:03:31 +04:00
prem.textContent = dat.data.prompt + '> '
})
});
2014-09-18 06:56:49 +04:00
'''
2014-09-12 06:11:03 +04:00
==
==
::
++ peer
|= [ost=bone you=ship pax=path]
^- [(list move) _+>]
?~ pax
$(pax /term)
2014-09-12 06:11:03 +04:00
?+ -.pax !!
%lines
:_ +>.$
:_ ~
(jell ost t.pax)
%term
=+ tel=(fall (~(get by hiz) t.pax) *term-line)
2014-10-03 03:00:57 +04:00
=^ mof r.tel
=+ aut=%shell
?: (~(has by cub.hid) (encode aut t.pax))
2014-10-03 03:00:57 +04:00
[~ r.tel]
:_ :_(r.tel leaf/"+ {(trip aut)}")
:_ [ost %pass hi/mar/[t.pax] %g %sire [aut (encode aut t.pax)]]~
:^ ost %pass hi/in/[t.pax]
:+ %g %show
[[our.hid [(encode aut t.pax) imp.hid]] you /out]
2014-10-02 23:56:53 +04:00
=. hiz (~(put by hiz) t.pax tel)
2014-10-02 23:46:00 +04:00
:_ +>.$
[[ost %give %rust %hymn (page t.pax)] mof]
2014-09-12 06:11:03 +04:00
==
::
++ poke-json
|= [ost=bone you=ship jon=json]
^- [(list move) _+>]
2014-10-08 23:29:21 +04:00
::~& tem-poke/jon
2014-10-10 02:33:00 +04:00
=+ ^- [pax=path jof=$%([%line p=span] [%res p=span] [%cmd p=char])]
%- need
2014-10-10 01:58:47 +04:00
%. jon => jo
%^ ot
pax/(su ;~(pfix fas (more fas sym)))
act/(of line/so res/so cmd/so ~)
~
2014-10-10 02:33:00 +04:00
|-
=+ tel=(fall (~(get by hiz) pax) *term-line)
2014-09-12 06:11:03 +04:00
?- -.jof
%res
2014-10-03 03:00:57 +04:00
=^ mof r.tel
?. (~(has by cub.hid) (encode p.jof pax))
2014-10-03 03:00:57 +04:00
[~ r.tel]
:_ :_(r.tel leaf/"- {(trip p.jof)}")
[ost %pass hi/mar/pax %g %cide (encode p.jof pax)]~
2014-10-02 23:46:00 +04:00
::~& poke-sire/[jof cub.hid]
2014-10-03 03:00:57 +04:00
=. r.tel :_(r.tel leaf/"+ {(trip p.jof)}")
2014-10-02 23:46:00 +04:00
=. hiz (~(put by hiz) pax tel)
2014-10-10 02:33:00 +04:00
:_ +>.^$
%+ welp mof
2014-10-03 02:21:23 +04:00
:^ [ost %give %nice ~]
:^ ost %pass hi/in/[pax]
2014-10-03 02:21:23 +04:00
:^ %g %show [our.hid (encode p.jof pax) imp.hid]
:- you /out
[ost %pass hi/mar/pax %g %sire [p.jof (encode p.jof pax)]]
(spam pax)
2014-09-23 02:20:47 +04:00
::
2014-09-12 06:11:03 +04:00
%line
2014-10-03 03:00:57 +04:00
=. r.tel :_(r.tel leaf/"{(trip p.tel)}> {(trip p.jof)}")
2014-10-02 23:46:00 +04:00
=. hiz (~(put by hiz) pax tel)
2014-10-10 02:40:45 +04:00
?: =('\\' (end 3 1 p.jof))
$(jof [%cmd (rsh 3 1 p.jof)])
2014-10-10 02:33:00 +04:00
:_ +>.^$
2014-10-10 01:58:47 +04:00
(send ost you pax %txt !>(p.jof))
%cmd
2014-10-10 02:33:00 +04:00
?+ p.jof :_(+>.^$ (send ost you pax %kyev !>(`kyev`[[%ctrl ~ ~] p.jof])))
%r $(jof [%res 'shell'])
==
2014-09-12 06:11:03 +04:00
==
2014-10-10 01:58:47 +04:00
++ send
|= [ost=bone you=ship pax=path mez=[?(%txt %kyev) vase]]
%+ murn (~(tap by cub.hid))
|= [p=span q=term]
?. =(pax q:(decode p)) ~
%- some ^- move
[ost %pass [%txt p pax] %g %mess [our.hid p imp.hid] you mez]
2014-09-12 06:11:03 +04:00
::
++ jell
|= [a=bone b=path]
[a %give %rust %json (tel-to-jon (fall (~(get by hiz) b) *term-line))]
2014-10-02 23:46:00 +04:00
::
++ spam
|= pax=path
2014-10-08 23:29:21 +04:00
::~& tem-spam/(~(run by hiz) |=(term-line p))
%+ murn
(~(tap by sup.hid))
|= [ost=bone @ paf=path]
?. =([%lines pax] paf) ~
(some (jell ost pax))
2014-10-02 23:46:00 +04:00
::
2014-09-12 06:11:03 +04:00
++ pour
2014-10-08 03:05:44 +04:00
|= [ost=bone pax=path sih=*]
2014-09-12 06:11:03 +04:00
^- [(list move) _+>]
2014-10-08 03:05:44 +04:00
=+ sih=((hard sign) sih)
2014-10-04 02:31:16 +04:00
?: ?=(%veer +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
?: ?=(%vega +<.sih) :: vomit
[[ost %give +.sih]~ +>.$]
=* paf |2.pax
?: ?=([%hi %in *] pax)
?+ &2.sih !!
2014-10-03 02:21:23 +04:00
%nice `+>.$
?(%rust %rush)
=+ tol=(fall (~(get by hiz) paf) *term-line)
2014-10-08 23:29:21 +04:00
=. tol ?^ q.q.sih :: XX prompt hack
[p.tol (weld q.q.sih q.tol) (weld r.q.sih r.tol)]
[p.q.sih (weld q.q.sih q.tol) (weld r.q.sih r.tol)]
=. hiz (~(put by hiz) paf tol)
[(spam paf) +>.$]
2014-10-03 02:21:23 +04:00
==
?: ?=(%gone &2.sih)
2014-09-23 02:20:47 +04:00
`+>.$
2014-10-02 23:56:53 +04:00
=+ tel=(fall (~(get by hiz) paf) *term-line)
=+ old=tel
2014-10-03 03:00:57 +04:00
=. r.tel
?. ?=(%mean &2.sih) r.tel
%- welp :_ r.tel
=- (turn - |=(a=tank rose/[~ "! " ~]^[a]~))
2014-10-01 01:07:40 +04:00
^- (list tank)
?~ p.sih ~
2014-10-03 03:00:57 +04:00
(welp q.u.p.sih leaf/(trip p.u.p.sih) ~)
2014-10-02 23:56:53 +04:00
=. hiz (~(put by hiz) paf tel)
2014-10-02 23:46:00 +04:00
:_ +>.$
2014-09-25 04:37:29 +04:00
:- [ost %give +.sih]
2014-10-02 23:56:53 +04:00
?:(=(old tel) ~ (spam paf))
2014-09-12 06:11:03 +04:00
::
++ tel-to-jon
|= tel=term-line
%- jobe
:~ [%prompt %s p.tel]
2014-10-03 03:00:57 +04:00
[%history %a (turn q.tel |=(a=cord [%s a]))]
2014-09-12 06:11:03 +04:00
:+ %lines %a
%- turn :_ jape
^- wall %- zing
^- (list wall)
%- flop
2014-10-03 03:00:57 +04:00
(turn r.tel (cury wash 0 80))
2014-09-12 06:11:03 +04:00
==
--