shrub/app/talk.hoon

2567 lines
69 KiB
Plaintext
Raw Normal View History

2018-02-01 01:20:39 +03:00
:: :: ::
:::: /app/talk/hoon :: ::
2017-03-23 03:34:56 +03:00
:: :: ::
::
::TODO maybe keep track of received grams per circle, too?
2017-11-10 00:35:24 +03:00
::
2017-10-27 22:09:36 +03:00
::TODO [type query] => [press tab to cycle search results, newest-first]
:: => [escape to clear]
::
:: This client implementation makes use of the %inbox
:: for all its subscriptions and messaging. All
:: rumors received are exclusively about the %inbox,
:: since that's the only thing the client ever
:: subscribes to.
::
2018-12-12 00:27:33 +03:00
/- sole-sur=sole :: structures
/+ *hall, sole-lib=sole :: libraries
2017-03-23 03:34:56 +03:00
/= seed /~ !>(.)
2017-11-10 02:04:07 +03:00
::
2017-03-23 03:34:56 +03:00
::::
::
2018-05-25 01:39:56 +03:00
=> :: #
:: # %arch
:: #
:: data structures
::
|%
2018-05-25 01:39:56 +03:00
++ state :: application state
$: :: messaging state ::
2018-05-25 01:39:56 +03:00
grams/(list telegram) :: all history
known/(map serial @ud) :: messages heard
last/@ud :: last heard
count/@ud :: (lent grams)
sources/(set circle) :: our subscriptions
:: circle details ::
2018-05-25 01:39:56 +03:00
remotes/(map circle group) :: remote presences
mirrors/(map circle config) :: remote configs
:: ui state ::
2018-05-25 01:39:56 +03:00
nicks/(map ship nick) :: human identities
bound/(map audience char) :: bound circle glyphs
binds/(jug char audience) :: circle glyph lookup
cli/shell :: interaction state
2017-03-24 01:10:28 +03:00
== ::
2018-05-25 01:39:56 +03:00
++ shell :: console session
$: id/bone :: identifier
latest/@ud :: latest shown msg num
2018-12-12 00:27:33 +03:00
say/sole-share:sole-sur :: console state
2018-05-25 01:39:56 +03:00
active/audience :: active targets
settings/(set term) :: frontend settings
width/@ud :: display width
timez/(pair ? @ud) :: timezone adjustment
2017-03-23 03:34:56 +03:00
== ::
2018-05-25 01:39:56 +03:00
++ move (pair bone card) :: all actions
++ lime :: diff fruit
2018-12-12 00:27:33 +03:00
$% {$sole-effect sole-effect:sole-sur} ::
== ::
2018-05-25 01:39:56 +03:00
++ pear :: poke fruit
$% {$hall-command command} ::
{$hall-action action} ::
== ::
2018-05-25 01:39:56 +03:00
++ card :: general card
$% {$diff lime} ::
{$poke wire dock pear} ::
{$peer wire dock path} ::
2018-03-19 07:18:20 +03:00
{$pull wire dock ~} ::
== ::
2018-05-25 01:39:56 +03:00
++ work :: interface action
$% :: circle management ::
2018-05-25 01:39:56 +03:00
{$join (map circle range)} :: subscribe to
{$leave audience} :: unsubscribe from
{$create security name cord} :: create circle
{$delete name (unit cord)} :: delete circle
{$depict name cord} :: change description
{$filter name ? ?} :: change message rules
{$invite name (set ship)} :: give permission
{$banish name (set ship)} :: deny permission
{$source name (map circle range)} :: add source
{$unsource name (map circle range)} :: remove source
{$read name @ud} :: set read count
2017-11-02 18:53:19 +03:00
:: personal metadata ::
2018-05-25 01:39:56 +03:00
{$attend audience (unit presence)} :: set our presence
{$name audience human} :: set our name
:: messaging ::
2018-05-25 01:39:56 +03:00
{$say (list speech)} :: send message
{$eval cord hoon} :: send #-message
{$target p/audience q/(unit work)} :: set active targets
{$reply $@(@ud {@u @ud}) (list speech)} :: reply to
:: displaying info ::
2018-05-25 01:39:56 +03:00
{$number $@(@ud {@u @ud})} :: relative/absolute
{$who audience} :: presence
{$what (unit $@(char audience))} :: show bound glyph
{$circles ~} :: show our circles
{$sources circle} :: show active sources
:: ui settings ::
2018-05-25 01:39:56 +03:00
{$bind char (unit audience)} :: bind glyph
{$unbind char (unit audience)} :: unbind glyph
{$nick (unit ship) (unit cord)} :: un/set/show nick
{$set term} :: enable setting
{$unset term} :: disable setting
{$width @ud} :: change display width
{$timez ? @ud} :: adjust shown times
:: miscellaneous ::
2018-05-25 01:39:56 +03:00
{$show circle} :: show membership
{$hide circle} :: hide membership
{$help ~} :: print usage info
== ::
2018-05-25 01:39:56 +03:00
++ glyphs `wall`~[">=+-" "}),." "\"'`^" "$%&@"] :: circle char pool '
2017-03-23 03:34:56 +03:00
--
::
2018-05-25 01:39:56 +03:00
:: #
:: # %work
:: #
:: functional cores and arms.
::
2018-04-12 17:47:44 +03:00
|_ {bol/bowl:gall $1 state}
::
2018-05-25 01:39:56 +03:00
:: # %transition
:: prep transition
2018-05-29 09:42:16 +03:00
+| %transition
::
++ prep
2018-05-25 01:39:56 +03:00
:: adapts state
::
=> |%
++ states
2018-04-12 17:47:44 +03:00
$%({$1 s/state} {$0 s/state-0})
::
++ state-0
(cork state |=(a/state a(mirrors (~(run by mirrors.a) config-0))))
++ config-0
{src/(set source-0) cap/cord tag/tags fit/filter con/control}
++ source-0
{cir/circle ran/range-0}
++ range-0
%- unit
$: hed/place-0
tal/(unit place-0)
==
++ place-0
$% {$da @da}
{$ud @ud}
{$sd @sd}
==
--
=| mos/(list move)
|= old/(unit states)
^- (quip move _..prep)
?~ old
ta-done:ta-init:ta
2018-02-22 17:17:12 +03:00
?- -.u.old
2018-04-12 17:47:44 +03:00
$1
2018-02-22 17:17:12 +03:00
[mos ..prep(+<+ u.old)]
2018-04-12 17:47:44 +03:00
::
$0
=. mos [[ost.bol %pull /server/inbox server ~] peer-inbox mos]
=- $(old `[%1 s.u.old(mirrors -)])
|^
(~(run by mirrors.s.u.old) prep-config)
::
++ prep-config
|= cof/config-0
^- config
=. src.cof
2018-04-12 17:47:44 +03:00
%- ~(gas in *(set source))
(murn ~(tap in src.cof) prep-source)
:* src.cof
cap.cof
tag.cof
fit.cof
con.cof
0
2018-04-12 17:47:44 +03:00
==
::
++ prep-source
|= src/source-0
^- (unit source)
=+ nan=(prep-range ran.src)
?~ nan
~& [%forgetting-source src]
~
`src(ran u.nan)
::
++ prep-range
|= ran/range-0
^- (unit range)
?~ ran `ran
:: ranges with a relative end aren't stored because they end
:: immediately, so if we find one we can safely discard it.
?: ?=({$~ {$sd @sd}} tal.u.ran) ~
:: we replace relative range starts with the current date.
:: this is practically correct.
?: ?=({$sd @sd} hed.u.ran)
`ran(hed.u [%da now.bol])
`ran
--
==
::
2018-05-25 01:39:56 +03:00
:: #
:: # %utility
:: #
:: small utility functions.
2018-05-29 09:42:16 +03:00
+| %utility
::
2017-12-13 00:34:04 +03:00
++ self
(true-self [our now our]:bol)
::
++ server
2018-05-25 01:39:56 +03:00
:: our hall instance
^- dock
2017-12-13 00:34:04 +03:00
[self %hall]
::
++ inbox
2018-05-25 01:39:56 +03:00
:: client's circle name
::
:: produces the name of the circle used by this
:: client for all its operations
2017-12-18 16:20:45 +03:00
^- name
%inbox
::
++ incir
2018-05-25 01:39:56 +03:00
:: client's circle
::
:: ++inbox, except a full circle.
^- circle
2017-12-13 00:34:04 +03:00
[self inbox]
::
++ renum
2018-05-25 01:39:56 +03:00
:: find the grams list index for gram with serial.
|= ser/serial
^- (unit @ud)
=+ num=(~(get by known) ser)
?~ num ~
`(sub count +(u.num))
::
++ recall
2018-05-25 01:39:56 +03:00
:: find a known gram with serial {ser}.
|= ser/serial
^- (unit telegram)
=+ num=(renum ser)
?~ num ~
`(snag u.num grams)
::
++ bound-from-binds
2018-05-25 01:39:56 +03:00
:: bound from binds
::
:: using a mapping of character to audiences, create
:: a mapping of audience to character.
::
2018-02-01 02:36:48 +03:00
|: bin=binds
^+ bound
%- ~(gas by *(map audience char))
=- (zing -)
%+ turn ~(tap by bin)
|= {a/char b/(set audience)}
(turn ~(tap by b) |=(c/audience [c a]))
::
++ glyph
2018-05-25 01:39:56 +03:00
:: finds a new glyph for assignment.
::
|= idx/@
=< cha
%+ reel glyphs
|= {all/tape ole/{cha/char num/@}}
=+ new=(snag (mod idx (lent all)) all)
=+ num=~(wyt in (~(get ju binds) new))
?~ cha.ole [new num]
?: (lth num.ole num)
ole
[new num]
::
++ peer-client
2018-05-25 01:39:56 +03:00
:: ui state peer move
^- move
:* ost.bol
%peer
/server/client
server
/client
==
::
++ peer-inbox
^- move
:* ost.bol
%peer
/server/inbox
server
::
%+ welp /circle/[inbox]/grams/config/group
2018-02-22 21:47:56 +03:00
?. =(0 count)
[(scot %ud last) ~]
=+ history-msgs=200
[(cat 3 '-' (scot %ud history-msgs)) ~]
==
::
2018-05-25 01:39:56 +03:00
:: #
:: # %engines
:: #
:: main cores.
2018-05-29 09:42:16 +03:00
+| %engines
::
++ ta
2018-05-25 01:39:56 +03:00
:: per transaction
::
:: for every transaction/event (poke, peer etc.)
:: talk receives, the ++ta transaction core is
:: called.
:: in processing transactions, ++ta may modify app
:: state, or create moves. these moves get produced
:: upon finalizing the core's with with ++ta-done.
:: when making changes to the shell, the ++sh core is
:: used.
::
|_ :: moves: moves created by core operations.
::
moves/(list move)
::
2018-05-25 01:39:56 +03:00
:: # %resolve
2018-05-29 09:42:16 +03:00
+| %resolve
::
++ ta-done
2018-05-25 01:39:56 +03:00
:: resolve core
::
:: produces the moves stored in ++ta's moves.
:: %sole-effect moves get squashed into a %mor.
::
^+ [*(list move) +>]
:_ +>
:: seperate our sole-effects from other moves.
=/ yop
2018-12-12 00:27:33 +03:00
|- ^- (pair (list move) (list sole-effect:sole-sur))
?~ moves [~ ~]
=+ mor=$(moves t.moves)
?: ?& =(id.cli p.i.moves)
?=({$diff $sole-effect *} q.i.moves)
==
[p.mor [+>.q.i.moves q.mor]]
[[i.moves p.mor] q.mor]
:: flop moves, flop and squash sole-effects into a %mor.
=+ moz=(flop p.yop)
2018-12-12 00:27:33 +03:00
=/ foc/(unit sole-effect:sole-sur)
?~ q.yop ~
?~ t.q.yop `i.q.yop :: single sole-effect
`[%mor (flop q.yop)] :: more sole-effects
:: produce moves or sole-effects and moves.
?~ foc moz
?~ id.cli ~&(%client-no-sole moz)
[[id.cli %diff %sole-effect u.foc] moz]
2017-03-23 03:34:56 +03:00
::
2018-05-25 01:39:56 +03:00
:: #
:: # %emitters
:: #
:: arms that create outward changes.
2018-05-29 09:42:16 +03:00
+| %emitters
::
++ ta-emil
2018-05-25 01:39:56 +03:00
:: emit move list
::
:: adds multiple moves to the core's list.
:: flops to emulate ++ta-emit.
::
|= mol/(list move)
%_(+> moves (welp (flop mol) moves))
::
++ ta-emit
2018-05-25 01:39:56 +03:00
:: adds a move to the core's list.
::
|= mov/move
%_(+> moves [mov moves])
::
2018-05-25 01:39:56 +03:00
:: #
:: # %interaction-events
:: #
:: arms that apply events we received.
2018-05-29 09:42:16 +03:00
+| %interaction-events
::
++ ta-init
2018-05-25 01:39:56 +03:00
:: subscribes to our hall.
::
%- ta-emil
^- (list move)
~[peer-client peer-inbox]
::
++ ta-take
2018-05-25 01:39:56 +03:00
:: accept prize
::
|= piz/prize
^+ +>
2017-10-09 12:57:36 +03:00
?+ -.piz +>
$client
%= +>
binds gys.piz
bound (bound-from-binds gys.piz)
nicks nis.piz
==
::
$circle
%. nes.piz
%= ta-unpack
sources (~(run in src.loc.cos.piz) head)
mirrors (~(put by rem.cos.piz) incir loc.cos.piz)
remotes (~(put by rem.pes.piz) incir loc.pes.piz)
==
==
::
++ ta-hear
2018-05-25 01:39:56 +03:00
:: apply change
::
|= rum/rumor
^+ +>
2017-10-09 12:57:36 +03:00
?+ -.rum +>
$client
?- -.rum.rum
$glyph
(ta-change-glyph +.rum.rum)
::
$nick
+>(nicks (change-nicks nicks who.rum.rum nic.rum.rum))
==
::
$circle
(ta-change-circle rum.rum)
==
::
++ ta-change-circle
2018-05-25 01:39:56 +03:00
:: apply circle change
::
|= rum/rumor-story
^+ +>
?+ -.rum
~&([%unexpected-circle-rumor -.rum] +>)
::
$gram
(ta-open nev.rum)
::
$config
=+ cur=(fall (~(get by mirrors) cir.rum) *config)
=. +>.$
=< sh-done
%- ~(sh-show-config sh cli)
[cir.rum cur dif.rum]
=? +>.$
?& ?=($source -.dif.rum)
add.dif.rum
=(cir.rum incir)
==
=* cir cir.src.dif.rum
=+ ren=~(cr-phat cr cir)
=+ gyf=(~(get by bound) [cir ~ ~])
=< sh-done
=/ sho
:: only present if we're here indefinitely.
=* ran ran.src.dif.rum
2018-03-19 07:18:20 +03:00
?. |(?=(~ ran) ?=(~ tal.u.ran))
~(. sh cli)
%- ~(sh-act sh cli)
[%notify [cir ~ ~] `%hear]
?^ gyf
(sh-note:sho "has glyph {[u.gyf ~]} for {ren}")
:: we use the rendered circle name to determine
:: the glyph for higher glyph consistency when
:: federating.
=+ cha=(glyph (mug ren))
(sh-work:sho %bind cha `[cir ~ ~])
%= +>.$
sources
?. &(?=($source -.dif.rum) =(cir.rum incir))
sources
%. cir.src.dif.rum
?: add.dif.rum
~(put in sources)
~(del in sources)
::
mirrors
?: ?=($remove -.dif.rum) (~(del by mirrors) cir.rum)
%+ ~(put by mirrors) cir.rum
(change-config cur dif.rum)
==
::
$status
=+ rem=(fall (~(get by remotes) cir.rum) *group)
=+ cur=(fall (~(get by rem) who.rum) *status)
=. +>.$
=< sh-done
%- ~(sh-show-status sh cli)
[cir.rum who.rum cur dif.rum]
%= +>.$
remotes
%+ ~(put by remotes) cir.rum
?: ?=($remove -.dif.rum) (~(del by rem) who.rum)
%+ ~(put by rem) who.rum
(change-status cur dif.rum)
==
==
::
++ ta-change-glyph
2018-05-25 01:39:56 +03:00
:: applies new set of glyph bindings.
::
|= {bin/? gyf/char aud/audience}
^+ +>
=+ nek=(change-glyphs binds bin gyf aud)
?: =(nek binds) +>.$ :: no change
=. binds nek
=. bound (bound-from-binds nek)
sh-done:~(sh-prod sh cli)
::
2018-05-25 01:39:56 +03:00
:: #
:: # %messages
:: #
:: storing and updating messages.
2018-05-29 09:42:16 +03:00
+| %messages
::
++ ta-unpack
2018-05-25 01:39:56 +03:00
:: open envelopes
::
:: the client currently doesn't care about nums.
::
|= nes/(list envelope)
^+ +>
?~ nes +>
$(nes t.nes, +> (ta-open i.nes))
::
++ ta-open
2018-05-25 01:39:56 +03:00
:: learn message from an envelope.
2017-03-23 03:34:56 +03:00
::
|= nev/envelope
^+ +>
=? last (gth num.nev last) num.nev
(ta-learn gam.nev)
::
++ ta-learn
2018-05-25 01:39:56 +03:00
:: save/update message
::
:: store an incoming telegram, updating if it
:: already exists.
::
|= gam/telegram
^+ +>
=+ old=(renum uid.gam)
?~ old
(ta-append gam) :: add
(ta-revise u.old gam) :: modify
::
++ ta-append
2018-05-25 01:39:56 +03:00
:: store a new telegram.
2017-03-23 03:34:56 +03:00
::
|= gam/telegram
^+ +>
=: grams [gam grams]
count +(count)
known (~(put by known) uid.gam count)
==
=< sh-done
(~(sh-gram sh cli) gam)
::
++ ta-revise
2018-05-25 01:39:56 +03:00
:: modify a telegram we know.
::
|= {num/@ud gam/telegram}
=+ old=(snag num grams)
?: =(gam old) +>.$ :: no change
=. grams
%+ welp
(scag num grams)
[gam (slag +(num) grams)]
?: =(sep.gam sep.old) +>.$ :: no worthy change
=< sh-done
(~(sh-gram sh cli) gam)
::
2018-05-25 01:39:56 +03:00
:: #
:: # %console
:: #
:: arms for shell functionality.
2018-05-29 09:42:16 +03:00
+| %console
::
++ ta-console
2018-05-25 01:39:56 +03:00
:: initialize the shell of this client.
::
^+ .
=| she/shell
=. id.she ost.bol
:: XXX: +sy should be smarter than this
=/ circle-list=(list circle) [incir ~]
=. active.she (sy circle-list)
=. width.she 80
sh-done:~(sh-prod sh she)
::
++ ta-sole
2018-05-25 01:39:56 +03:00
:: apply sole input
::
2018-12-12 00:27:33 +03:00
|= act/sole-action:sole-sur
^+ +>
?. =(id.cli ost.bol)
~&(%strange-sole !!)
sh-done:(~(sh-sole sh cli) act)
::
++ sh
2018-05-25 01:39:56 +03:00
:: per console
::
2018-05-25 01:39:56 +03:00
:: shell core, responsible for handling user input
:: and the related actions, and outputting changes
:: to the cli.
::
|_ $: :: she: console state.
::
she/shell
==
::
2018-05-25 01:39:56 +03:00
:: # %resolve
2018-05-29 09:42:16 +03:00
+| %resolve
::
++ sh-done
2018-05-25 01:39:56 +03:00
:: stores changes to the cli.
::
^+ +>
+>(cli she)
::
2018-05-25 01:39:56 +03:00
:: #
:: # %emitters
:: #
:: arms that create outward changes.
2018-05-29 09:42:16 +03:00
+| %emitters
::
++ sh-fact
2018-05-25 01:39:56 +03:00
:: adds a console effect to ++ta's moves.
::
2018-12-12 00:27:33 +03:00
|= fec/sole-effect:sole-sur
^+ +>
+>(moves [[id.she %diff %sole-effect fec] moves])
::
++ sh-act
2018-05-25 01:39:56 +03:00
:: adds an action to ++ta's moves.
::
|= act/action
^+ +>
%= +>
moves
:_ moves
:* ost.bol
%poke
/client/action
server
[%hall-action act]
==
==
::
2018-05-25 01:39:56 +03:00
:: #
:: # %cli-interaction
:: #
:: processing user input as it happens.
2018-05-29 09:42:16 +03:00
+| %cli-interaction
::
++ sh-sole
2018-05-25 01:39:56 +03:00
:: applies sole action.
::
2018-12-12 00:27:33 +03:00
|= act/sole-action:sole-sur
^+ +>
?- -.act
$det (sh-edit +.act)
$clr ..sh-sole :: (sh-pact ~) :: XX clear to PM-to-self?
$ret sh-obey
==
::
++ sh-edit
2018-05-25 01:39:56 +03:00
:: apply sole edit
::
:: called when typing into the cli prompt.
:: applies the change and does sanitizing.
::
2018-12-12 00:27:33 +03:00
|= cal/sole-change:sole-sur
^+ +>
=^ inv say.she (~(transceive sole-lib say.she) cal)
=+ fix=(sh-sane inv buf.say.she)
?~ lit.fix
+>.$
:: just capital correction
?~ err.fix
(sh-slug fix)
:: allow interior edits and deletes
?. &(?=($del -.inv) =(+(p.inv) (lent buf.say.she)))
+>.$
(sh-slug fix)
::
++ sh-read
2018-05-25 01:39:56 +03:00
:: command parser
::
:: parses the command line buffer. produces work
:: items which can be executed by ++sh-work.
::
=< work
2018-05-25 01:39:56 +03:00
:: # %parsers
:: various parsers for command line input.
|%
++ expr
2018-05-25 01:39:56 +03:00
:: [cord hoon]
|= tub/nail %. tub
%+ stag (crip q.tub)
wide:(vang & [&1:% &2:% (scot %da now.bol) |3:%])
2017-03-23 03:34:56 +03:00
::
++ dare
2018-05-25 01:39:56 +03:00
:: @dr
%+ sear
|= a/coin
?. ?=({$$ $dr @} a) ~
(some `@dr`+>.a)
nuck:so
::
2018-05-25 01:39:56 +03:00
++ ship ;~(pfix sig fed:ag) :: ship
++ shiz :: ship set
%+ cook
|=(a/(list ^ship) (~(gas in *(set ^ship)) a))
(most ;~(plug com (star ace)) ship)
::
2018-05-25 01:39:56 +03:00
++ cire :: local circle
2017-12-18 16:21:52 +03:00
;~(pfix cen urs:ab)
2017-04-17 14:14:04 +03:00
::
2018-05-25 01:39:56 +03:00
++ circ :: circle
2017-03-23 03:34:56 +03:00
;~ pose
(cold incir col)
2017-12-18 16:21:52 +03:00
;~(pfix cen (stag self urs:ab))
;~(pfix net (stag (^sein:title self) urs:ab))
::
%+ cook
|= {a/@p b/(unit term)}
[a ?^(b u.b %inbox)]
;~ plug
ship
2018-03-14 07:36:10 +03:00
(punt ;~(pfix net urs:ab))
==
2017-03-23 03:34:56 +03:00
==
::
2018-05-25 01:39:56 +03:00
++ circles-flat :: collapse mixed list
2017-10-27 22:09:36 +03:00
|= a/(list (each circle (set circle)))
^- (set circle)
?~ a ~
?- -.i.a
2018-03-19 06:54:47 +03:00
%& (~(put in $(a t.a)) p.i.a)
%| (~(uni in $(a t.a)) p.i.a)
2017-10-27 22:09:36 +03:00
==
::
2018-05-25 01:39:56 +03:00
++ cirs :: non-empty circles
2017-10-27 22:09:36 +03:00
%+ cook circles-flat
%+ most ;~(plug com (star ace))
(^pick circ (sear sh-glyf glyph))
::
++ drat
2018-05-25 01:39:56 +03:00
:: @da or @dr
::
:: pas: whether @dr's are in the past or not.
|= pas/?
=- ;~(pfix sig (sear - crub:so))
|= a/^dime
^- (unit @da)
?+ p.a ~
$da `q.a
$dr :- ~
%. [now.bol q.a]
?:(pas sub add)
==
::
2018-05-25 01:39:56 +03:00
++ pont :: point for range
:: hed: whether this is the head or tail point.
|= hed/?
;~ pose
(cold [%da now.bol] (jest 'now'))
(stag %da (drat hed))
placer
==
::
2018-05-25 01:39:56 +03:00
++ rang :: subscription range
=+ ;~ pose
2018-03-14 07:36:10 +03:00
(cook some ;~(pfix net (pont |)))
(easy ~)
==
;~ pose
2018-03-14 07:36:10 +03:00
(cook some ;~(plug ;~(pfix net (pont &)) -))
(easy ~)
==
::
2018-05-25 01:39:56 +03:00
++ sorz :: non-empty sources
%+ cook ~(gas by *(map circle range))
(most ;~(plug com (star ace)) ;~(plug circ rang))
::
2018-05-25 01:39:56 +03:00
++ pick :: message reference
2018-03-14 07:36:10 +03:00
;~(pose nump (cook lent (star mic)))
::
2018-05-25 01:39:56 +03:00
++ nump :: number reference
;~ pose
;~(pfix hep dem:ag)
;~ plug
(cook lent (plus (just '0')))
;~(pose dem:ag (easy 0))
==
(stag 0 dem:ag)
==
::
2018-05-25 01:39:56 +03:00
++ pore :: security
(perk %channel %village %journal %mailbox ~)
2017-03-23 03:34:56 +03:00
::
2018-05-25 01:39:56 +03:00
++ lobe :: y/n loob
;~ pose
(cold %& ;~(pose (jest 'y') (jest '&') (just 'true')))
(cold %| ;~(pose (jest 'n') (jest '|') (just 'false')))
==
::
2018-05-25 01:39:56 +03:00
++ message :: exp, lin or url msg
;~ pose
;~(plug (cold %eval hax) expr)
(stag %say speeches)
==
::
2018-05-25 01:39:56 +03:00
++ speeches :: lin or url msgs
%+ most (jest '•')
;~ pose
(stag %url aurf:de-purl:html)
2018-03-19 06:38:01 +03:00
:(stag %lin & ;~(pfix vat text))
2018-03-14 07:36:10 +03:00
:(stag %lin | ;~(less mic hax text))
==
::
2018-05-25 01:39:56 +03:00
++ text :: msg without break
%+ cook crip
(plus ;~(less (jest '•') next))
::
2018-05-25 01:39:56 +03:00
++ nick (cook crip (plus next)) :: nickname
++ glyph (mask "/\\\{(<!?{(zing glyphs)}") :: circle postfix
++ setting :: setting flag
%- perk :~
%nicks
%quiet
%notify
%showtime
==
2018-05-25 01:39:56 +03:00
++ work :: full input
%+ knee *^work |. ~+
2018-03-14 07:36:10 +03:00
=- ;~(pose ;~(pfix mic -) message)
;~ pose
::
:: circle management
::
;~((glue ace) (perk %read ~) cire dem:ag)
::
;~((glue ace) (perk %join ~) sorz)
::
;~((glue ace) (perk %leave ~) cirs)
::
;~ (glue ace) (perk %create ~)
pore
cire
qut
==
::
;~ plug (perk %delete ~)
2017-12-18 16:20:45 +03:00
;~(pfix ace cire)
;~ pose
(cook some ;~(pfix ace qut))
(easy ~)
==
==
::
;~((glue ace) (perk %depict ~) cire qut)
::
;~((glue ace) (perk %filter ~) cire lobe lobe)
::
;~((glue ace) (perk %invite ~) cire shiz)
::
;~((glue ace) (perk %banish ~) cire shiz)
::
;~((glue ace) (perk %source ~) cire sorz)
::
;~((glue ace) (perk %unsource ~) cire sorz)
::TODO why do these nest-fail when doing perk with multiple?
::
:: personal metadata
::
;~ (glue ace)
(perk %attend ~)
cirs
;~ pose
(cold ~ sig)
(cook some (perk %gone %idle %hear %talk ~))
==
==
::
;~ plug
(perk %name ~)
;~(pfix ace cirs)
;~(pfix ace ;~(pose (cook some qut) (cold ~ sig)))
;~ pose
;~ pfix ace
%+ cook some
;~ pose
;~((glue ace) qut (cook some qut) qut)
;~(plug qut (cold ~ ace) qut)
==
==
;~(pfix ace (cold ~ sig))
(easy ~)
==
==
::
:: displaying info
::
;~(plug (perk %who ~) ;~(pose ;~(pfix ace cirs) (easy ~)))
::
;~ plug
(perk %what ~)
;~ pose
;~(pfix ace (cook some ;~(pose glyph cirs)))
(easy ~)
==
==
::
;~(plug (perk %circles ~) (easy ~))
::
;~((glue ace) (perk %sources ~) circ)
::
;~((glue ace) (perk %show ~) circ)
::
;~((glue ace) (perk %hide ~) circ)
::
:: ui settings
::
;~(plug (perk %bind ~) ;~(pfix ace glyph) (punt ;~(pfix ace cirs)))
::
;~(plug (perk %unbind ~) ;~(pfix ace glyph) (punt ;~(pfix ace cirs)))
::
;~ plug (perk %nick ~)
;~ pose
;~ plug
2017-03-23 03:34:56 +03:00
(cook some ;~(pfix ace ship))
(cold (some '') ;~(pfix ace sig))
2017-03-23 03:34:56 +03:00
==
;~ plug
;~ pose
(cook some ;~(pfix ace ship))
(easy ~)
==
;~ pose
(cook some ;~(pfix ace nick))
(easy ~)
==
2017-03-23 03:34:56 +03:00
==
==
==
::
;~(plug (cold %width (jest 'set width ')) dem:ag)
::
;~ plug
(cold %timez (jest 'set timezone '))
::
;~ pose
(cold %| (just '-'))
(cold %& (just '+'))
==
::
%+ sear
|= a/@ud
^- (unit @ud)
?: &((gte a 0) (lte a 14))
`a ~
dem:ag
==
::
;~(plug (perk %set ~) ;~(pose ;~(pfix ace setting) (easy %$)))
::
;~(plug (perk %unset ~) ;~(pfix ace setting))
::
:: miscellaneous
::
;~(plug (perk %help ~) (easy ~))
::
:: (parsers below come last because they match quickly)
::
:: messaging
::
(stag %target ;~(plug cirs (punt ;~(pfix ace message))))
::
(stag %reply ;~(plug pick ;~(pfix ace speeches)))
::
:: displaying info
::
(stag %number pick)
2017-03-23 03:34:56 +03:00
==
--
2017-03-23 03:34:56 +03:00
::
++ sh-sane
2018-05-25 01:39:56 +03:00
:: sanitize input
::
:: parses cli prompt input using ++sh-read and
:: sanitizes when invalid.
::
2018-12-12 00:27:33 +03:00
|= {inv/sole-edit:sole-sur buf/(list @c)}
^- {lit/(list sole-edit:sole-sur) err/(unit @u)}
=+ res=(rose (tufa buf) sh-read)
2018-03-19 06:54:47 +03:00
?: ?=(%| -.res) [[inv]~ `p.res]
:_ ~
?~ p.res ~
=+ wok=u.p.res
2018-12-12 00:27:33 +03:00
|- ^- (list sole-edit:sole-sur)
?+ -.wok
~
::
$target
?~(q.wok ~ $(wok u.q.wok))
==
::
++ sh-slug
2018-05-25 01:39:56 +03:00
:: corrects invalid prompt input.
::
2018-12-12 00:27:33 +03:00
|= {lit/(list sole-edit:sole-sur) err/(unit @u)}
^+ +>
?~ lit +>
=^ lic say.she
2018-12-12 00:27:33 +03:00
(~(transmit sole-lib say.she) `sole-edit:sole-sur`?~(t.lit i.lit [%mor lit]))
(sh-fact [%mor [%det lic] ?~(err ~ [%err u.err]~)])
2017-03-23 03:34:56 +03:00
::
++ sh-obey
2018-05-25 01:39:56 +03:00
:: apply result
::
:: called upon hitting return in the prompt. if
:: input is invalid, ++sh-slug is called.
:: otherwise, the appropriate work is done and
:: the entered command (if any) gets displayed
:: to the user.
::
=+ fix=(sh-sane [%nop ~] buf.say.she)
?^ lit.fix
(sh-slug fix)
=+ jub=(rust (tufa buf.say.she) sh-read)
?~ jub (sh-fact %bel ~)
%. u.jub
=< sh-work
=+ buf=buf.say.she
=? ..sh-obey &(?=({$';' *} buf) !?=($reply -.u.jub))
(sh-note (tufa `(list @)`buf))
=^ cal say.she (~(transmit sole-lib say.she) [%set ~])
%+ sh-fact %mor
:~ [%nex ~]
[%det cal]
2017-03-23 03:34:56 +03:00
==
::
2018-05-25 01:39:56 +03:00
:: #
:: # %user-action
:: #
:: processing user actions.
2018-05-29 09:42:16 +03:00
+| %user-action
2017-03-23 03:34:56 +03:00
::
++ sh-work
2018-05-25 01:39:56 +03:00
:: do work
::
:: implements worker arms for different talk
:: commands.
:: worker arms must produce updated state.
::
|= job/work
^+ +>
=< work
|%
::
2018-05-25 01:39:56 +03:00
:: #
:: # %helpers
:: #
2018-05-29 09:42:16 +03:00
+| %helpers
::
++ work
2018-05-25 01:39:56 +03:00
:: call correct worker
?- -.job
:: circle management
$join (join +.job)
$leave (leave +.job)
$create (create +.job)
$delete (delete +.job)
$depict (depict +.job)
$filter (filter +.job)
2017-11-02 18:53:19 +03:00
$invite (permit & +.job)
$banish (permit | +.job)
$source (source & +.job)
$unsource (source | +.job)
$read (read +.job)
:: personal metadata
$attend (attend +.job)
2017-12-18 16:20:45 +03:00
$name (set-name +.job)
:: messaging
$say (say +.job)
$eval (eval +.job)
$target (target +.job)
$reply (reply +.job)
:: displaying info
$number (number +.job)
$who (who +.job)
$what (what +.job)
$circles circles
$sources (list-sources +.job)
:: ui settings
$bind (bind +.job)
$unbind (unbind +.job)
$nick (nick +.job)
$set (wo-set +.job)
$unset (unset +.job)
$width (width +.job)
$timez (timez +.job)
:: miscelaneous
$show (public & +.job)
$hide (public | +.job)
$help help
==
::
++ activate
2018-05-25 01:39:56 +03:00
:: prints message details.
::
|= gam/telegram
^+ ..sh-work
=+ tay=~(. tr settings.she gam)
=. ..sh-work (sh-fact tr-fact:tay)
sh-prod(active.she aud.gam)
::
++ deli
2018-05-25 01:39:56 +03:00
:: gets absolute message number from relative.
::
|= {max/@ud nul/@u fin/@ud}
^- @ud
=+ dog=|-(?:(=(0 fin) 1 (mul 10 $(fin (div fin 10)))))
=. dog (mul dog (pow 10 nul))
=- ?:((lte - max) - (sub - dog))
(add fin (sub max (mod max dog)))
::
++ set-glyph
2018-05-25 01:39:56 +03:00
:: new glyph binding
::
:: applies glyph binding to our state and sends
:: an action.
::
|= {cha/char aud/audience}
=: bound (~(put by bound) aud cha)
binds (~(put ju binds) cha aud)
==
sh-prod:(sh-act %glyph cha aud &)
::
++ unset-glyph
2018-05-25 01:39:56 +03:00
:: remote old glyph binding
::
:: removes either {aud} or all bindings on a
:: glyph and sends an action.
::
|= {cha/char aud/(unit audience)}
=/ ole/(set audience)
?^ aud [u.aud ~ ~]
(~(get ju binds) cha)
=. ..sh-work (sh-act %glyph cha (fall aud ~) |)
|- ^+ ..sh-work
?~ ole ..sh-work
=. ..sh-work $(ole l.ole)
=. ..sh-work $(ole r.ole)
%= ..sh-work
bound (~(del by bound) n.ole)
binds (~(del ju binds) cha n.ole)
==
::
++ reverse-nicks
2018-05-25 01:39:56 +03:00
:: finds all ships whose handle matches {nym}.
::
|= nym/^nick
^- (list ship)
%+ murn ~(tap by nicks)
|= {p/ship q/^nick}
?. =(q nym) ~
[~ u=p]
::
++ hoon-head
2018-05-25 01:39:56 +03:00
:: eval data
::
:: makes a vase of environment data to evaluate
:: against (for #-messages).
::
^- vase
!> ^- {our/@p now/@da eny/@uvI}
2017-12-13 00:34:04 +03:00
[self now.bol (shas %eny eny.bol)]
::
2018-05-25 01:39:56 +03:00
:: #
:: # %circle-management
:: #
2018-05-29 09:42:16 +03:00
+| %circle-management
::
++ join
2018-05-25 01:39:56 +03:00
:: %join
::
:: change local mailbox config to include
:: subscriptions to {pas}.
::
|= pos/(map circle range)
^+ ..sh-work
=+ pas=~(key by pos)
=. ..sh-work
sh-prod(active.she pas)
:: default to a day of backlog
=. pos
%- ~(run by pos)
|= r/range
?~(r `[da+(sub now.bol ~d1) ~] r)
(sh-act %source inbox & pos)
::
++ leave
2018-05-25 01:39:56 +03:00
:: %leave
::
:: change local mailbox config to exclude
:: subscriptions to {pas}.
::
|= pas/(set circle)
^+ ..sh-work
:: remove *all* sources relating to {pas}.
=/ pos
%- ~(gas in *(set ^source))
%- zing
=/ sos
=- ~(tap in src:-)
(fall (~(get by mirrors) incir) *config)
%+ turn ~(tap in pas)
|= c/circle
%+ skim sos
|=(s/^source =(cir.s c))
=. ..sh-work
(sh-act %source inbox | pos)
(sh-act %notify pas ~)
::
++ create
2018-05-25 01:39:56 +03:00
:: %create
::
:: creates circle {nom} with specified config.
::
2017-12-18 16:20:45 +03:00
|= {sec/security nom/name txt/cord}
^+ ..sh-work
=. ..sh-work
2017-04-27 00:33:25 +03:00
(sh-act %create nom txt sec)
2017-12-13 00:34:04 +03:00
(join [[[self nom] ~] ~ ~])
::
++ delete
2018-05-25 01:39:56 +03:00
:: %delete
::
:: deletes our circle {nom}, after optionally
:: sending a last announce message {say}.
::
2017-12-18 16:20:45 +03:00
|= {nom/name say/(unit cord)}
^+ ..sh-work
(sh-act %delete nom say)
::
++ depict
2018-05-25 01:39:56 +03:00
:: %depict
::
:: changes the description of {nom} to {txt}.
::
2017-12-18 16:20:45 +03:00
|= {nom/name txt/cord}
^+ ..sh-work
(sh-act %depict nom txt)
::
++ permit
2018-05-25 01:39:56 +03:00
:: %invite / %banish
::
:: invites or banishes {sis} to/from our
:: circle {nom}.
::
2017-12-18 16:20:45 +03:00
|= {inv/? nom/name sis/(set ship)}
^+ ..sh-work
=. ..sh-work (sh-act %permit nom inv sis)
=- (sh-act %phrase - [%inv inv [self nom]]~)
%- ~(rep in sis)
|= {s/ship a/audience}
2019-01-12 00:32:15 +03:00
(~(put in a) [s %i])
::
++ filter
2017-12-18 16:20:45 +03:00
|= {nom/name cus/? utf/?}
^+ ..sh-work
(sh-act %filter nom cus utf)
::
++ source
2018-05-25 01:39:56 +03:00
:: %source
::
:: adds {pas} to {nom}'s src.
::
2017-12-18 16:20:45 +03:00
|= {sub/? nom/name pos/(map circle range)}
^+ ..sh-work
(sh-act %source nom sub pos)
::
++ read
:: %read
::
:: set {red} for {nom}
::
|= {nom/name red/@ud}
^+ ..sh-work
(sh-act %read nom red)
::
2018-05-25 01:39:56 +03:00
:: #
:: # %personal-metadata
:: #
2018-05-29 09:42:16 +03:00
+| %personal-metadata
::
++ attend
2018-05-25 01:39:56 +03:00
:: sets our presence to {pec} for {aud}.
::
|= {aud/audience pec/(unit presence)}
^+ ..sh-work
(sh-act %notify aud pec)
::
++ set-name
2018-05-25 01:39:56 +03:00
:: sets our name to {man} for {aud}.
::
|= {aud/audience man/human}
^+ ..sh-work
(sh-act %naming aud man)
::
2018-05-25 01:39:56 +03:00
:: #
:: # %messaging
:: #
2018-05-29 09:42:16 +03:00
+| %messaging
::
++ say
2018-05-25 01:39:56 +03:00
:: sends message.
::
|= sep/(list speech)
^+ ..sh-work
(sh-act %phrase active.she sep)
::
++ eval
2018-05-25 01:39:56 +03:00
:: run
::
:: executes {exe} and sends both its code and
:: result.
::
|= {txt/cord exe/hoon}
=> |.([(sell (slap (slop hoon-head seed) exe))]~)
=+ tan=p:(mule .)
(say [%exp txt tan] ~)
::
++ target
2018-05-25 01:39:56 +03:00
:: %target
::
:: sets messaging target, then execute {woe}.
::
|= {aud/audience woe/(unit ^work)}
^+ ..sh-work
=. ..sh-pact (sh-pact aud)
?~(woe ..sh-work work(job u.woe))
::
++ reply
2018-05-25 01:39:56 +03:00
:: %reply
::
:: send a reply to the selected message.
::
|= {num/$@(@ud {p/@u q/@ud}) sep/(list speech)}
^+ ..sh-work
:: =- (say (turn ... [%ire - s])) nest-fails on the - ???
::TODO what's friendlier, reply-to-null or error?
=/ ser/serial
?@ num
?: (gte num count) 0v0
uid:(snag num grams)
?: (gth q.num count) 0v0
?: =(count 0) 0v0
=+ msg=(deli (dec count) num)
uid:(snag (sub count +(msg)) grams)
(say (turn sep |=(s/speech [%ire ser s])))
::
2018-05-25 01:39:56 +03:00
:: #
:: # %displaying-info
:: #
2018-05-29 09:42:16 +03:00
+| %displaying-info
::
++ who
2018-05-25 01:39:56 +03:00
:: %who
::
:: prints presence lists for {cis} or all.
::
|= cis/(set circle) ^+ ..sh-work
=< (sh-fact %mor (murn (sort ~(tap by remotes) aor) .))
2018-12-12 00:27:33 +03:00
|= {cir/circle gop/group} ^- (unit sole-effect:sole-sur)
?. |(=(~ cis) (~(has in cis) cir)) ~
?: =(%mailbox sec.con:(fall (~(get by mirrors) cir) *config)) ~
?. (~(has in sources) cir) ~
=- `[%tan rose+[", " `~]^- leaf+~(cr-full cr cir) ~]
=< (murn (sort ~(tap by gop) aor) .)
|= {a/ship b/presence c/human} ^- (unit tank)
2017-10-10 17:44:37 +03:00
=? c =(han.c `(scot %p a)) [~ tru.c]
?- b
$gone ~
$idle `leaf+:(weld "idle " (scow %p a) " " (trip (fall han.c '')))
$hear `leaf+:(weld "hear " (scow %p a) " " (trip (fall han.c '')))
$talk `leaf+:(weld "talk " (scow %p a) " " (trip (fall han.c '')))
==
::
++ what
2018-05-25 01:39:56 +03:00
:: %what
::
:: prints binding details. goes both ways.
::
|= qur/(unit $@(char audience))
^+ ..sh-work
?^ qur
?^ u.qur
=+ cha=(~(get by bound) u.qur)
(sh-fact %txt ?~(cha "none" [u.cha]~))
=+ pan=~(tap in (~(get ju binds) u.qur))
?: =(~ pan) (sh-fact %txt "~")
=< (sh-fact %mor (turn pan .))
|=(a/audience [%txt ~(ar-phat ar a)])
%+ sh-fact %mor
%- ~(rep by binds)
|= $: {gyf/char aus/(set audience)}
2018-12-12 00:27:33 +03:00
lis/(list sole-effect:sole-sur)
==
%+ weld lis
2018-12-12 00:27:33 +03:00
^- (list sole-effect:sole-sur)
%- ~(rep in aus)
2018-12-12 00:27:33 +03:00
|= {a/audience l/(list sole-effect:sole-sur)}
%+ weld l
2018-12-12 00:27:33 +03:00
^- (list sole-effect:sole-sur)
[%txt [gyf ' ' ~(ar-phat ar a)]]~
::
++ number
2018-05-25 01:39:56 +03:00
:: %number
::
:: finds selected message, expand it.
::
|= num/$@(@ud {p/@u q/@ud})
^+ ..sh-work
|-
?@ num
?: (gte num count)
(sh-lame "{(scow %s (new:si | +(num)))}: no such telegram")
=. ..sh-fact (sh-fact %txt "? {(scow %s (new:si | +(num)))}")
(activate (snag num grams))
?. (gte q.num count)
?: =(count 0)
(sh-lame "0: no messages")
=+ msg=(deli (dec count) num)
=. ..sh-fact (sh-fact %txt "? {(scow %ud msg)}")
(activate (snag (sub count +(msg)) grams))
(sh-lame "…{(reap p.num '0')}{(scow %ud q.num)}: no such telegram")
::
++ circles
2018-05-25 01:39:56 +03:00
:: %circles
::
:: list all local circles.
::
^+ ..sh-work
=/ piz
=- .^(prize %gx -)
%+ weld /(scot %p our.bol)/hall/(scot %da now.bol)
/circles/(scot %p our.bol)/hall-prize
?> ?=($circles -.piz)
%+ sh-fact %mor
%+ turn (sort ~(tap in cis.piz) lth)
|= a/name [%txt "%{(trip a)}"]
::
++ list-sources
2018-05-25 01:39:56 +03:00
:: %sources
::
:: display the active sources for our circle.
::
|= cir/circle
^+ ..sh-work
%+ sh-fact %mor
%+ turn
:: make sure to exclude {nom} itself.
=- ~(tap in (~(del in src:-) [cir ~]))
(fall (~(get by mirrors) cir) *config)
|= s/^source
2018-12-12 00:27:33 +03:00
^- sole-effect:sole-sur
:- %txt
%+ weld ~(cr-phat cr cir.s)
%+ roll (range-to-path ran.s)
|= {a/@ta b/tape}
:(weld b "/" (trip a))
::
2018-05-25 01:39:56 +03:00
:: #
:: # %ui-settings
:: #
2018-05-29 09:42:16 +03:00
+| %ui-settings
::
++ bind
2018-05-25 01:39:56 +03:00
:: %bind
::
:: binds targets {aud} to the glyph {cha}.
::
|= {cha/char aud/(unit audience)}
^+ ..sh-work
?~ aud $(aud `active.she)
=+ ole=(~(get by bound) u.aud)
?: =(ole [~ cha]) ..sh-work
%. "bound {<cha>} {<u.aud>}"
sh-note:sh-prod:(set-glyph cha u.aud)
::
++ unbind
2018-05-25 01:39:56 +03:00
:: %unbind
::
:: unbinds targets {aud} to glyph {cha}.
::
|= {cha/char aud/(unit audience)}
^+ ..sh-work
?. ?| &(?=(^ aud) (~(has by bound) u.aud))
2018-03-19 07:18:20 +03:00
&(?=(~ aud) (~(has by binds) cha))
==
..sh-work
%. "unbound {<cha>}"
sh-note:sh-prod:(unset-glyph cha aud)
::
++ nick
2018-05-25 01:39:56 +03:00
:: %nick
::
:: either shows, sets or unsets nicknames
:: depending on arguments.
::
|= {her/(unit ship) nym/(unit ^nick)}
^+ ..sh-work
:: no arguments, show all
2018-03-19 07:18:20 +03:00
?: ?=({~ ~} +<)
%+ sh-fact %mor
%+ turn ~(tap by nicks)
|= {p/ship q/^nick}
:- %txt
"{<p>}: {<q>}"
:: show her nick
?~ nym
?> ?=(^ her)
=+ asc=(~(get by nicks) u.her)
%+ sh-fact %txt
?~ asc "{<u.her>} unbound"
"{<u.her>}: {<u.asc>}"
:: show nick ship
?~ her
%+ sh-fact %mor
%+ turn (reverse-nicks u.nym)
|= p/ship
[%txt "{<p>}: {<u.nym>}"]
%. [%nick u.her (fall nym '')]
%= sh-act
nicks
?~ u.nym
:: unset nickname
(~(del by nicks) u.her)
:: set nickname
(~(put by nicks) u.her u.nym)
==
::
++ wo-set
2018-05-25 01:39:56 +03:00
:: %set
::
:: enables ui setting flag.
::
|= seg/term
^+ ..sh-work
?~ seg
%+ sh-fact %mor
%+ turn ~(tap in settings.she)
|= s/term
[%txt (trip s)]
%= ..sh-work
settings.she (~(put in settings.she) seg)
==
::
++ unset
2018-05-25 01:39:56 +03:00
:: %unset
::
:: disables ui setting flag.
::
|= neg/term
^+ ..sh-work
%= ..sh-work
settings.she (~(del in settings.she) neg)
==
::
++ width
2018-05-25 01:39:56 +03:00
:: ;set width
::
:: change the display width in cli.
::
|= wid/@ud
^+ ..sh-work
..sh-work(width.she (max 30 wid))
::
++ timez
2018-05-25 01:39:56 +03:00
:: ;set timezone
::
:: adjust the displayed timestamp.
::
|= tim/(pair ? @ud)
^+ ..sh-work
..sh-work(timez.she tim)
::
2018-05-25 01:39:56 +03:00
:: #
:: # %miscellaneous
:: #
2018-05-29 09:42:16 +03:00
+| %miscellaneous
::
++ public
2018-05-25 01:39:56 +03:00
:: show/hide membership
::
:: adds or removes the circle from the public
:: membership list.
::
|= {add/? cir/circle}
(sh-act %public add cir)
::
++ help
2018-05-25 01:39:56 +03:00
:: %help
::
:: prints help message
::
(sh-fact %txt "see http://urbit.org/docs/using/messaging/")
--
::
++ sh-pact
2018-05-25 01:39:56 +03:00
:: update active aud
::
:: change currently selected audience to {aud}
:: and update the prompt.
::
|= aud/audience
^+ +>
:: ensure we can see what we send.
=+ act=(sh-pare aud)
?: =(active.she act) +>.$
sh-prod(active.she act)
::
++ sh-pare
2018-05-25 01:39:56 +03:00
:: adjust target list
::
:: if the audience {aud} does not contain a
:: circle we're subscribed to, add our mailbox
:: to the audience (so that we can see our own
:: message).
::
|= aud/audience
?: (sh-pear aud) aud
(~(put in aud) incir)
::
++ sh-pear
2018-05-25 01:39:56 +03:00
:: hearback
::
:: produces true if any circle is included in
:: our subscriptions, meaning, we hear messages
:: sent to {aud}.
::
|= aud/audience
?~ aud |
?| (~(has in sources) `circle`n.aud)
$(aud l.aud)
$(aud r.aud)
==
::
++ sh-glyf
2018-05-25 01:39:56 +03:00
:: decode glyph
::
:: finds the circle(s) that match a glyph.
::
|= cha/char ^- (unit audience)
=+ lax=(~(get ju binds) cha)
:: no circle.
?: =(~ lax) ~
:: single circle.
2018-03-19 07:18:20 +03:00
?: ?=({* ~ ~} lax) `n.lax
:: in case of multiple audiences, pick the most recently active one.
|- ^- (unit audience)
?~ grams ~
:: get first circle from a telegram's audience.
=+ pan=(silt ~(tap in aud.i.grams))
?: (~(has in lax) pan) `pan
$(grams t.grams)
::
2018-05-25 01:39:56 +03:00
:: #
:: # %differs
:: #
:: arms that calculate differences between datasets.
2018-05-29 09:42:16 +03:00
+| %differs
::
++ sh-group-diff
2018-05-25 01:39:56 +03:00
:: group diff parts
::
:: calculates the difference between two presence
:: lists, producing lists of removed, added and
:: changed presences.
::
2017-04-27 00:33:25 +03:00
|= {one/group two/group}
=| $= ret
$: old/(list (pair ship status))
new/(list (pair ship status))
cha/(list (pair ship status))
==
^+ ret
=. ret
=+ eno=~(tap by one)
|- ^+ ret
?~ eno ret
=. ret $(eno t.eno)
?: =(%gone pec.q.i.eno) ret
=+ unt=(~(get by two) p.i.eno)
?~ unt
ret(old [i.eno old.ret])
?: =(%gone pec.u.unt)
ret(old [i.eno old.ret])
?: =(q.i.eno u.unt) ret
ret(cha [[p.i.eno u.unt] cha.ret])
=. ret
=+ owt=~(tap by two)
|- ^+ ret
?~ owt ret
=. ret $(owt t.owt)
?: =(%gone pec.q.i.owt) ret
?. (~(has by one) p.i.owt)
ret(new [i.owt new.ret])
?: =(%gone pec:(~(got by one) p.i.owt))
ret(new [i.owt new.ret])
ret
ret
::
++ sh-rempe-diff
2018-05-25 01:39:56 +03:00
:: remotes diff
::
:: calculates the difference between two remote
:: presence maps, producing a list of removed,
:: added and changed presences maps.
::
|= {one/(map circle group) two/(map circle group)}
=| $= ret
$: old/(list (pair circle group))
new/(list (pair circle group))
cha/(list (pair circle group))
==
^+ ret
=. ret
=+ eno=~(tap by one)
|- ^+ ret
?~ eno ret
=. ret $(eno t.eno)
=+ unt=(~(get by two) p.i.eno)
?~ unt
ret(old [i.eno old.ret])
?: =(q.i.eno u.unt) ret
ret(cha [[p.i.eno u.unt] cha.ret])
=. ret
=+ owt=~(tap by two)
|- ^+ ret
?~ owt ret
=. ret $(owt t.owt)
?: (~(has by one) p.i.owt)
ret
ret(new [i.owt new.ret])
ret
::
++ sh-remco-diff
2018-05-25 01:39:56 +03:00
:: config diff parts
::
:: calculates the difference between two config
:: maps, producing lists of removed, added and
:: changed configs.
::
|= {one/(map circle config) two/(map circle config)}
=| $= ret
$: old/(list (pair circle config))
new/(list (pair circle config))
cha/(list (pair circle config))
==
^+ ret
=. ret
=+ eno=~(tap by one)
|- ^+ ret
?~ eno ret
=. ret $(eno t.eno)
=+ unt=(~(get by two) p.i.eno)
?~ unt
ret(old [i.eno old.ret])
?: =(q.i.eno u.unt) ret
ret(cha [[p.i.eno u.unt] cha.ret])
=. ret
=+ owt=~(tap by two)
|- ^+ ret
?~ owt ret
=. ret $(owt t.owt)
?: (~(has by one) p.i.owt)
ret
ret(new [i.owt new.ret])
ret
::
++ sh-set-diff
2018-05-25 01:39:56 +03:00
:: set diff
::
:: calculates the difference between two sets,
:: procuding lists of removed and added items.
::
|* {one/(set *) two/(set *)}
:- ^= old ~(tap in (~(dif in one) two))
^= new ~(tap in (~(dif in two) one))
::
2018-05-25 01:39:56 +03:00
:: #
:: # %printers
:: #
:: arms for printing data to the cli.
2018-05-29 09:42:16 +03:00
+| %printers
::
++ sh-lame
2018-05-25 01:39:56 +03:00
:: send error
::
:: just puts some text into the cli as-is.
::
|= txt/tape
(sh-fact [%txt txt])
::
++ sh-note
2018-05-25 01:39:56 +03:00
:: shell message
::
:: left-pads {txt} with heps and prints it.
::
|= txt/tape
^+ +>
=+ lis=(simple-wrap txt (sub width.she 16))
%+ sh-fact %mor
=+ ?:((gth (lent lis) 0) (snag 0 lis) "")
:- txt+(runt [14 '-'] '|' ' ' -)
%+ turn (slag 1 lis)
|=(a/tape txt+(runt [14 ' '] '|' ' ' a))
::
++ sh-prod
2018-05-25 01:39:56 +03:00
:: show prompt
::
:: makes and stores a move to modify the cli
:: prompt to display the current audience.
::
^+ .
%+ sh-fact %pro
:+ & %talk-line
^- tape
=/ rew/(pair (pair cord cord) audience)
[['[' ']'] active.she]
=+ cha=(~(get by bound) q.rew)
?^ cha ~[u.cha ' ']
=+ por=~(ar-prom ar q.rew)
(weld `tape`[p.p.rew por] `tape`[q.p.rew ' ' ~])
::
++ sh-rend
2018-05-25 01:39:56 +03:00
:: prints a telegram as rendered by ++tr-rend.
::
|= gam/telegram
^+ +>
=+ lis=~(tr-rend tr settings.she gam)
?~ lis +>.$
%+ sh-fact %mor
%+ turn `(list tape)`lis
2017-12-13 00:34:04 +03:00
=+ nom=(scag 7 (cite:title self))
|= t/tape
?. ?& (~(has in settings.she) %notify)
?=(^ (find nom (slag 15 t)))
==
[%txt t]
[%mor [%txt t] [%bel ~] ~]
::
++ sh-numb
2018-05-25 01:39:56 +03:00
:: prints a message number, left-padded by heps.
::
|= num/@ud
^+ +>
=+ bun=(scow %ud num)
%+ sh-fact %txt
(runt [(sub 13 (lent bun)) '-'] "[{bun}]")
::
++ sh-cure
2018-05-25 01:39:56 +03:00
:: renders a security kind.
::
2017-04-27 00:33:25 +03:00
|= a/security
^- tape
(scow %tas a)
::
++ sh-scis
2018-05-25 01:39:56 +03:00
:: render status
::
:: gets the presence of {saz} as a tape.
::
|= sat/status
^- tape
['%' (trip pec.sat)]
::
++ sh-show-status
2018-05-25 01:39:56 +03:00
:: prints presence changes to the cli.
::
|= {cir/circle who/ship cur/status dif/diff-status}
^+ +>
?: (~(has in settings.she) %quiet) +>
%- sh-note
%+ weld
(weld ~(cr-phat cr cir) ": ")
?- -.dif
$full
"hey {(scow %p who)} {(scow %tas pec.sat.dif)}"
::
$presence
"see {(scow %p who)} {(scow %tas pec.dif)}"
::
$human
%+ weld "nom {(scow %p who)}"
?: ?=($true -.dif.dif) ~
=- " '{(trip (fall han.man.cur ''))}' -> '{-}'"
%- trip
=- (fall - '')
?- -.dif.dif
$full han.man.dif.dif
$handle han.dif.dif
==
::
$remove
"bye {(scow %p who)}"
==
::
++ sh-show-config
2018-05-25 01:39:56 +03:00
:: prints config changes to the cli.
::
|= {cir/circle cur/config dif/diff-config}
^+ +>
?: (~(has in settings.she) %quiet) +>
?: ?=($full -.dif)
=. +>
(sh-note (weld "new " (~(cr-show cr cir) ~)))
=. +> $(dif [%caption cap.cof.dif])
$(dif [%filter fit.cof.dif])
?: ?=($remove -.dif)
(sh-note (weld "rip " (~(cr-show cr cir) ~)))
?: ?=($usage -.dif) +>
%- sh-note
2017-11-17 15:47:16 +03:00
%+ weld
(weld ~(cr-phat cr cir) ": ")
?- -.dif
$source
%+ weld ?:(add.dif "onn " "off ")
~(cr-full cr cir.src.dif)
::
$caption
"cap: {(trip cap.dif)}"
::
$read
"red: {(scow %ud red.dif)}"
::
$filter
;: weld
"fit: caps:"
?:(cas.fit.dif "Y" "n")
" unic:"
?:(utf.fit.dif "✔" "n")
==
::
$secure
"sec {(trip sec.con.cur)} -> {(trip sec.dif)}"
::
$permit
%+ weld
=? add.dif
?=(?($channel $mailbox) sec.con.cur)
!add.dif
?:(add.dif "inv " "ban ")
^- tape
%- ~(rep in sis.dif)
|= {s/ship t/tape}
=? t ?=(^ t) (weld t ", ")
(weld t (cite:title s))
==
::
++ sh-gram
2018-05-25 01:39:56 +03:00
:: show telegram
::
:: prints the telegram. every fifth message,
:: print the message number also.
::
|= gam/telegram
^+ +>
=+ num=(~(got by known) uid.gam)
=. +>.$
:: if the number isn't directly after latest, print it always.
?. =(num +(latest.she))
(sh-numb num)
:: if the number is directly after latest, print every fifth.
?. =(0 (mod num 5)) +>.$
(sh-numb num)
(sh-rend(latest.she num) gam)
::
++ sh-grams
2018-05-25 01:39:56 +03:00
:: prints multiple telegrams.
::
|= gaz/(list telegram)
^+ +>
?~ gaz +>
$(gaz t.gaz, +> (sh-gram i.gaz))
2017-03-23 03:34:56 +03:00
--
--
::
2018-05-25 01:39:56 +03:00
:: #
:: # %renderers
:: #
:: rendering cores.
2018-05-29 09:42:16 +03:00
+| %renderers
::
++ cr
2018-05-25 01:39:56 +03:00
:: circle renderer
::
:: used in both circle and ship rendering.
2017-03-23 03:34:56 +03:00
::
2018-05-25 01:39:56 +03:00
|_ :: one: the circle.
::
one/circle
::
++ cr-beat
2018-05-25 01:39:56 +03:00
:: {one} more relevant?
::
:: returns true if one is better to show, false
:: otherwise. prioritizes: our > main > size.
2017-03-23 03:34:56 +03:00
::
|= two/circle
2017-03-23 03:34:56 +03:00
^- ?
:: the circle that's ours is better.
2017-12-13 00:34:04 +03:00
?: =(self hos.one)
?. =(self hos.two) &
2017-04-25 22:09:20 +03:00
?< =(nom.one nom.two)
:: if both circles are ours, the main story is better.
?: =(%inbox nom.one) &
?: =(%inbox nom.two) |
2017-04-25 22:09:20 +03:00
:: if neither are, pick the "larger" one.
(lth nom.one nom.two)
:: if one isn't ours but two is, two is better.
2017-12-13 00:34:04 +03:00
?: =(self hos.two) |
?: =(hos.one hos.two)
:: if they're from the same ship, pick the "larger" one.
(lth nom.one nom.two)
2017-04-25 22:09:20 +03:00
:: if they're from different ships, neither ours, pick hierarchically.
(lth (xeb hos.one) (xeb hos.two))
2017-03-23 03:34:56 +03:00
::
++ cr-best
2018-05-25 01:39:56 +03:00
:: returns the most relevant circle.
::
|= two/circle
?:((cr-beat two) one two)
::
++ cr-curt
2018-05-25 01:39:56 +03:00
:: prints a ship name in 14 characters.
::
:: left-pads with spaces. {mup} signifies
:: "are there other targets besides this one?"
2017-03-23 03:34:56 +03:00
::
|= mup/?
^- tape
=+ raw=(cite:title hos.one)
2017-03-23 03:34:56 +03:00
(runt [(sub 14 (lent raw)) ' '] raw)
::
++ cr-nick
2018-05-25 01:39:56 +03:00
:: get nick for ship, or shortname if no nick.
::
:: left-pads with spaces.
2017-03-23 03:34:56 +03:00
::
|= aud/audience
^- tape
=/ nic/(unit cord)
?: (~(has by nicks) hos.one)
(~(get by nicks) hos.one)
%- ~(rep in aud)
|= {cir/circle han/(unit cord)}
?^ han han
=+ gop=(~(get by remotes) cir)
?~ gop ~
han.man:(fall (~(get by u.gop) hos.one) *status)
?~ nic (cr-curt |)
=+ raw=(scag 14 (trip u.nic))
2017-03-23 03:34:56 +03:00
=+ len=(sub 14 (lent raw))
(weld (reap len ' ') raw)
::
:: todo: figure out why enabling the doccord causes a nest fail, even when
:: attached to the arm instead of the product.
::
2018-05-25 01:39:56 +03:00
++ cr-phat ::: render accurately
::: prints a circle fully, but still taking
::: "shortcuts" where possible:
::: ":" for local mailbox, "~ship" for foreign
::: mailbox, "%channel" for local circle,
::: "/channel" for parent circle.
2017-03-23 03:34:56 +03:00
::
^- tape
2017-12-13 00:34:04 +03:00
?: =(hos.one self)
?: =(nom.one inbox)
2017-03-23 03:34:56 +03:00
":"
['%' (trip nom.one)]
=+ wun=(cite:title hos.one)
?: =(nom.one %inbox)
2017-03-23 03:34:56 +03:00
wun
?: =(hos.one (^sein:title self))
['/' (trip nom.one)]
:(welp wun "/" (trip nom.one))
::
2018-05-25 01:39:56 +03:00
++ cr-full (cr-show ~) :: render full width
::
++ cr-show
2018-05-25 01:39:56 +03:00
:: renders a circle as text.
::
:: moy: multiple circles in audience?
2017-03-23 03:34:56 +03:00
|= moy/(unit ?)
^- tape
:: render circle (as glyph if we can).
?~ moy
=+ cha=(~(get by bound) one ~ ~)
=- ?~(cha - "{u.cha ~} {-}")
~(cr-phat cr one)
(~(cr-curt cr one) u.moy)
2017-03-23 03:34:56 +03:00
--
::
++ ar
2018-05-25 01:39:56 +03:00
:: audience renderer
::
2018-05-25 01:39:56 +03:00
:: used for representing audiences (sets of circles)
:: as tapes.
::
|_ :: aud: members of the audience.
::
aud/audience
2017-03-23 03:34:56 +03:00
::
++ ar-best
2018-05-25 01:39:56 +03:00
:: find the most relevant circle in the set.
2017-03-23 03:34:56 +03:00
::
^- (unit circle)
?~ aud ~
2017-03-23 03:34:56 +03:00
:- ~
|- ^- circle
=+ lef=`(unit circle)`ar-best(aud l.aud)
=+ rit=`(unit circle)`ar-best(aud r.aud)
=? n.aud ?=(^ lef) (~(cr-best cr n.aud) u.lef)
=? n.aud ?=(^ rit) (~(cr-best cr n.aud) u.rit)
n.aud
2017-03-23 03:34:56 +03:00
::
++ ar-deaf
2018-05-25 01:39:56 +03:00
:: remove ourselves from the audience.
2017-03-23 03:34:56 +03:00
::
^+ .
.(aud (~(del in aud) `circle`incir))
2017-03-23 03:34:56 +03:00
::
++ ar-maud
2018-05-25 01:39:56 +03:00
:: multiple audience
::
:: checks if there's multiple circles in the
:: audience via pattern matching.
2017-03-23 03:34:56 +03:00
::
^- ?
=. . ar-deaf
2018-03-19 07:18:20 +03:00
!?=($@(~ {* ~ ~}) aud)
2017-03-23 03:34:56 +03:00
::
++ ar-phat
2018-05-25 01:39:56 +03:00
:: render all circles, no glyphs.
::
^- tape
%- ~(rep in aud)
|= {c/circle t/tape}
=? t ?=(^ t)
(weld t ", ")
(weld t ~(cr-phat cr c))
::
++ ar-prom
2018-05-25 01:39:56 +03:00
:: render all circles, ordered by relevance.
2017-03-23 03:34:56 +03:00
::
^- tape
=. . ar-deaf
=/ all
%+ sort `(list circle)`~(tap in aud)
|= {a/circle b/circle}
(~(cr-beat cr a) b)
2017-03-23 03:34:56 +03:00
=+ fir=&
|- ^- tape
?~ all ~
;: welp
?:(fir "" " ")
(~(cr-show cr i.all) ~)
2017-03-23 03:34:56 +03:00
$(all t.all, fir |)
==
::
++ ar-whom
2018-05-25 01:39:56 +03:00
:: render sender as the most relevant circle.
2017-03-23 03:34:56 +03:00
::
(~(cr-show cr (need ar-best)) ~ ar-maud)
2017-03-23 03:34:56 +03:00
::
++ ar-dire
2018-05-25 01:39:56 +03:00
:: returns true if circle is a mailbox of ours.
2017-03-23 03:34:56 +03:00
::
|= cir/circle ^- ?
2017-12-13 00:34:04 +03:00
?& =(hos.cir self)
=+ sot=(~(get by mirrors) cir)
&(?=(^ sot) ?=($mailbox sec.con.u.sot))
2017-03-23 03:34:56 +03:00
==
::
++ ar-glyf
:: todo: another place where doccords break things.
::
2018-05-25 01:39:56 +03:00
::: audience glyph
:::
::: get the glyph that corresponds to the audience.
::: for mailbox messages and complex audiences, use
::: reserved "glyphs".
2017-03-23 03:34:56 +03:00
::
^- tape
=+ cha=(~(get by bound) aud)
2017-11-03 22:00:11 +03:00
?^ cha ~[u.cha]
?. (lien ~(tap by aud) ar-dire)
2017-11-03 22:00:11 +03:00
"*"
2018-03-19 07:18:20 +03:00
?: ?=({^ ~ ~} aud)
2017-11-03 22:00:11 +03:00
":"
";"
2017-03-23 03:34:56 +03:00
--
::
++ tr
2018-05-25 01:39:56 +03:00
:: telegram renderer
::
:: responsible for converting telegrams and
:: everything relating to them to text to be
:: displayed in the cli.
::
|_ $: :: sef: settings flags.
:: who: author.
:: sen: unique identifier.
:: aud: audience.
:: wen: timestamp.
:: sep: message contents.
2017-03-23 03:34:56 +03:00
::
sef/(set term)
2017-03-23 03:34:56 +03:00
who/ship
sen/serial
aud/audience
wen/@da
sep/speech
==
::
++ tr-fact
2018-05-25 01:39:56 +03:00
:: activate effect
::
:: produces sole-effect for printing message
:: details.
2017-03-23 03:34:56 +03:00
::
2018-12-12 00:27:33 +03:00
^- sole-effect:sole-sur
2017-03-23 03:34:56 +03:00
~[%mor [%tan tr-meta] tr-body]
::
++ tr-rend
2018-05-25 01:39:56 +03:00
:: renders a telegram
::
:: the first line will contain the author and
:: optional timestamp.
::
^- (list tape)
=/ wyd
%+ sub width.cli :: termwidth,
%+ add 14 :: minus author,
?:((~(has in sef) %showtime) 10 0) :: minus timestamp.
=+ txs=(tr-text wyd)
?~ txs ~
:: render the author.
=/ nom/tape
?: (~(has in sef) %nicks)
(~(cr-nick cr [who %inbox]) aud)
(~(cr-curt cr [who %inbox]) |)
:: regular indent.
=/ den/tape
(reap (lent nom) ' ')
:: timestamp, if desired.
=/ tam/tape
?. (~(has in sef) %showtime) ""
=. wen
%. [wen (mul q.timez.cli ~h1)]
?:(p.timez.cli add sub)
=+ dat=(yore wen)
=/ t
|= a/@
2017-03-23 03:34:56 +03:00
%+ weld
?:((lth a 10) "0" ~)
(scow %ud a)
=/ time
;: weld
"~" (t h.t.dat)
"." (t m.t.dat)
"." (t s.t.dat)
==
%+ weld
(reap (sub +(wyd) (min wyd (lent (tuba i.txs)))) ' ')
time
%- flop
%+ roll `(list tape)`txs
|= {t/tape l/(list tape)}
?~ l [:(weld nom t tam) ~]
[(weld den t) l]
2017-03-23 03:34:56 +03:00
::
++ tr-meta
2018-05-25 01:39:56 +03:00
:: metadata
::
:: builds string that display metadata, including
:: message serial, timestamp, author and audience.
2017-03-23 03:34:56 +03:00
::
^- tang
=. wen (sub wen (mod wen (div wen ~s0..0001))) :: round
2017-03-23 03:34:56 +03:00
=+ hed=leaf+"{(scow %uv sen)} at {(scow %da wen)}"
=/ cis
%+ turn ~(tap in aud)
|= a/circle
leaf+~(cr-full cr a)
[%rose [" " ~ ~] [hed >who< [%rose [", " "to " ~] cis] ~]]~
2017-03-23 03:34:56 +03:00
::
++ tr-body
2018-05-25 01:39:56 +03:00
:: message content
::
:: long-form display of message contents, specific
:: to each speech type.
2017-03-23 03:34:56 +03:00
::
2018-12-12 00:27:33 +03:00
|- ^- sole-effect:sole-sur
?- -.sep
$lin
tan+~[leaf+"{?:(pat.sep "@ " "")}{(trip msg.sep)}"]
::
$url
url+(crip (apix:en-purl:html url.sep))
::
$exp
mor+~[txt+"# {(trip exp.sep)}" tan+res.sep]
::
$ire
=+ num=(~(get by known) top.sep)
?~ num $(sep sep.sep)
=+ gam=(snag (sub count +(u.num)) grams)
=- mor+[tan+- $(sep sep.sep) ~]
%- flop %+ weld
:_ ~ :- %leaf
%+ weld "in reply to: {(cite:title aut.gam)}: "
"[{(scow %ud u.num)}]"
%+ turn (~(tr-text tr sef gam) width.cli)
|=(t/tape [%leaf t])
::
$fat
2017-04-27 00:33:25 +03:00
[%mor $(sep sep.sep) tan+(tr-tach tac.sep) ~]
::
$inv
:- %tan
:_ ~
:- %leaf
%+ weld
?: inv.sep
"you have been invited to "
"you have been banished from "
~(cr-phat cr cir.sep)
::
$app
[%mor tan+~[leaf+"[{(trip app.sep)}]: "] $(sep sep.sep) ~]
2017-03-23 03:34:56 +03:00
==
::
++ tr-tach
2018-05-25 01:39:56 +03:00
:: renders an attachment.
2017-03-23 03:34:56 +03:00
::
2018-02-01 01:20:39 +03:00
|= att/attache
^- tang
2018-02-01 01:20:39 +03:00
?- -.att
$name (welp $(att tac.att) leaf+"= {(trip nom.att)}" ~)
$tank +.att
$text (turn (flop `(list cord)`+.att) |=(b/cord leaf+(trip b)))
2017-03-23 03:34:56 +03:00
==
::
++ tr-chow
2018-05-25 01:39:56 +03:00
:: truncate
::
:: truncates the {txt} to be of max {len}
:: characters. if it does truncate, indicates it
:: did so by appending _ or ….
2017-03-23 03:34:56 +03:00
::
|= {len/@u txt/tape}
^- tape
2017-03-23 03:34:56 +03:00
?: (gth len (lent txt)) txt
=. txt (scag len txt)
|-
?~ txt txt
?: =(' ' i.txt)
|-
:- '_'
?. ?=({$' ' *} t.txt)
t.txt
$(txt t.txt)
2017-03-23 03:34:56 +03:00
?~ t.txt "…"
[i.txt $(txt t.txt)]
::
++ tr-text
2018-05-25 01:39:56 +03:00
:: compact contents
::
:: renders just the most important data of the
:: message. if possible, these stay within a single
:: line.
::
:: pre: replace/append line prefix
::TODO this should probably be redone someday.
=| pre/(unit (pair ? tape))
|= wyd/@ud
^- (list tape)
?- -.sep
2017-03-23 03:34:56 +03:00
$fat
%+ weld $(sep sep.sep)
^- (list tape)
?+ -.tac.sep [" attached: ..." ~]
$name [(scag wyd " attached: {(trip nom.tac.sep)}") ~]
2017-03-23 03:34:56 +03:00
==
::
$exp
:- (tr-chow wyd '#' ' ' (trip exp.sep))
?~ res.sep ~
=- [' ' (tr-chow (dec wyd) ' ' -)]~
~(ram re (snag 0 `(list tank)`res.sep))
::
$ire
$(sep sep.sep, pre `[| "^ "])
::
$url
:_ ~
=+ ful=(apix:en-purl:html url.sep)
=+ pef=q:(fall pre [p=| q=""])
:: clean up prefix if needed.
=? pef =((scag 1 (flop pef)) " ")
(scag (dec (lent pef)) pef)
=. pef (weld "/" pef)
=. wyd (sub wyd +((lent pef))) :: account for prefix.
:: if the full url fits, just render it.
?: (gte wyd (lent ful)) :(weld pef " " ful)
:: if it doesn't, prefix with _ and render just (the tail of) the domain.
%+ weld (weld pef "_")
=+ hok=r.p.p.url.sep
=- (swag [a=(sub (max wyd (lent -)) wyd) b=wyd] -)
^- tape
2018-03-19 06:54:47 +03:00
=< ?: ?=(%& -.hok)
(reel p.hok .)
+:(scow %if p.hok)
|= {a/knot b/tape}
?~ b (trip a)
(welp b '.' (trip a))
::
2017-03-23 03:34:56 +03:00
$lin
:: glyph prefix
=/ pef/tape
?: &(?=(^ pre) p.u.pre) q.u.pre
?: pat.sep " "
=- (weld - q:(fall pre [p=| q=" "]))
2018-04-04 21:15:10 +03:00
%~ ar-glyf ar
2018-04-04 21:07:05 +03:00
?: =(who self) aud
(~(del in aud) [who %inbox])
=/ lis/(list tape)
%+ simple-wrap
`tape``(list @)`(tuba (trip msg.sep))
(sub wyd (min (div wyd 2) (lent pef)))
=+ lef=(lent pef)
=+ ?:((gth (lent lis) 0) (snag 0 lis) "")
:- (weld pef -)
%+ turn (slag 1 lis)
|=(a/tape (runt [lef ' '] a))
::
$inv
:_ ~
%+ tr-chow wyd
%+ weld
?: inv.sep
" invited you to "
" banished you from "
~(cr-phat cr cir.sep)
::
2017-03-23 03:34:56 +03:00
$app
$(sep sep.sep, pre `[& "[{(trip app.sep)}]: "])
2017-03-23 03:34:56 +03:00
==
--
::
2018-05-25 01:39:56 +03:00
:: #
:: # %events
:: #
2018-05-29 09:42:16 +03:00
+| %events
::
++ quit-server-client
|= wir/wire
^- (quip move _+>)
[[peer-client]~ +>]
::
++ quit-server-inbox
|= wir/wire
^- (quip move _+>)
[[peer-inbox]~ +>]
::
++ peer
2018-05-25 01:39:56 +03:00
:: incoming subscription on pax.
::
|= pax/path
^- (quip move _+>)
?. =(src.bol our.bol)
~! [%peer-talk-stranger src.bol]
!!
?. ?=({$sole *} pax)
~! [%peer-talk-strange pax]
!!
ta-done:ta-console:ta
::
++ diff-hall-prize
2018-05-25 01:39:56 +03:00
:: accept query answer
::
|= {way/wire piz/prize}
^- (quip move _+>)
ta-done:(ta-take:ta piz)
::
++ diff-hall-rumor
2018-05-25 01:39:56 +03:00
:: accept query change
::
|= {way/wire rum/rumor}
^- (quip move _+>)
ta-done:(ta-hear:ta rum)
::
++ poke-sole-action
2018-05-25 01:39:56 +03:00
:: incoming sole action. process it.
::
2018-12-12 00:27:33 +03:00
|= act/sole-action:sole-sur
ta-done:(ta-sole:ta act)
::
::TODO for debug purposes. remove eventually.
2017-12-14 03:55:33 +03:00
:: users beware, here be dragons.
++ poke-noun
|= a/@t
^- (quip move _+>)
2017-12-14 03:55:33 +03:00
?: =(a 'check')
~& 'verifying message reference integrity...'
=- ~&(- [~ +>.$])
~& [%count--lent count (lent grams)]
=+ %- ~(rep by known)
|= {{u/serial a/@ud} k/@ud m/@ud}
:- ?:((gth a k) a k)
?: =(u uid:(snag (sub count +(a)) grams)) m +(m)
:- %check-talk
[known=k mismatch=m]
?: =(a 'rebuild')
2017-12-14 03:55:33 +03:00
~& 'rebuilding message references...'
=+ %+ reel grams
|= {t/telegram c/@ud k/(map serial @ud)}
[+(c) (~(put by k) uid.t c)]
[~ +>.$(count c, known k)]
2017-12-14 03:55:33 +03:00
?: =(a 'reconnect')
~& 'disconnecting and reconnecting to hall...'
:_ +>
:~ [ost.bol %pull /server/client server ~]
[ost.bol %pull /server/inbox server ~]
2017-12-14 03:55:33 +03:00
peer-client
peer-inbox
==
?: =(a 'reset')
~& 'full reset incoming, hold on to your cli...'
:_ +>(grams ~, known ~, count 0, last 0)
:~ [ost.bol %pull /server/client server ~]
[ost.bol %pull /server/inbox server ~]
peer-client
peer-inbox
==
:: this deletes a message from your backlog, and may
:: make talk throw stack traces.
:: **aka don't run this!**
?: =(a 'screw')
~& 'screwing things up...'
:- ~
+>(grams (oust [0 1] grams))
[~ +>]
::
++ coup-client-action
2018-05-25 01:39:56 +03:00
:: accept n/ack
::
|= {wir/wire fal/(unit tang)}
^- (quip move _+>)
?~ fal [~ +>]
%- (slog leaf+"action failed: " u.fal)
[~ +>]
--