0 Welcome to Konilo

0 Welcome to Konilo
1
2 ,dPYb, ,dPYb,
3 IP'`Yb IP'`Yb
4 I8 8I gg I8 8I
5 I8 8bgg, "" I8 8'
6 I8 dP" "8 ,ggggg, ,ggg,,ggg, gg I8 dP ,ggggg,
7 I8d8bggP" dP" "Y8 ,8" "8P" "8, 88 I8dP dP" "Y8
8 I8P' "Yb, i8' ,8I d8 8I 8I 88 I8P i8' ,8I
9 ,d8 `Yb,,d8, ,d8P8P 8I Yb,_,88,_,d8b,_ ,d8, ,d8'
10 88P Y8P"Y8888P" 8I `Y88P""Y88P'"Y88P"Y8888P"
11
12 `manual` for the users guide
13 `blocks` for help using the block editor
14 `describe name` for help on a specific word
15 `catalogue` to explore the blocks

1 (startup) (set_blocks,_load_extensions)

0 (startup) (set_blocks,_load_extensions)
1
2 . You should setup the numbers of blocks in your system.
3
4 #65536 !Blocks
5
6 . Load desired extensions. As Konilo uses a single shared
7 . buffer for blocks, I wrap these in a quote, and make `call`
8 . the last item in this block. This ensures proper behavior.
9
10 [ @Blocks [ #128 !Blocks
11 '(std) needs '(termina) needs
12 '(tools:describe) needs '(tools:blocks) needs
13 '(tools:manual) needs '(tools:catalogue) needs
14 '(tuhi) needs '(nonix) needs
15 ] dip !Blocks ] call

2 (startup) (local_configuration)

0 (startup) (local_configuration)
1
2 . You should adjust these to match your terminal settings if
3 . using the (termina) based programs.
4
5 #75 !ti:width
6 #20 !ti:height
7
8 . Set the preferred editor to use with `catalogue`
9 [ (n-) set load tuhi ] !Editor
10
11 . This will restrict `needs` to the first 8,192 blocks
12 [ (s-) @Blocks [ #8,192 !Blocks needs ] dip !Blocks ] \needs
13
14 . This will display the startup message in block 0
15 [ #0 set load list* nl ] gc

3

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

4

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

5 (std) (constants)

0 (std) (constants)
1
2 . Constants for numeric range limits.
3
4 :n:MIN #-2,147,483,647 ;
5 :n:MAX #2,147,483,646 ;
6
7 . Constants for flags.
8
9 :TRUE #-1 ;
10 :FALSE #0 ;
11
12 . Constants for memory layout
13
14 :sys:BUFFERS #60,000 ;
15 :sys:EOM #65,535 ;

6 (std) (s:) (constants)

0 (std) (s:) (constants)
1
2 :s:DIGITS '0123456789ABCDEF ;
3 :s:VOWELS 'aeiouAEIOU ;
4 :s:ASCII-UPPERCASE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ;
5 :s:ASCII-LOWERCASE 'abcdefghijklmnopqrstuvwxyz ;
6 :s:ASCII-LETTERS
7 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ;
8 's:WHITESPACE d:create #4 comma
9 #9 comma #10 comma #13 comma #32 comma
10 :s:PUNCTUATION '_!"#$%&'()*+,-./:;<=>?@[\]^`{|}~ ;
11 :s:CONSONANTS 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ ;
12
13
14
15

7 (std) (c:) (classification)

0 (std) (c:) (classification)
1
2 :c:consonant? (c-f) s:CONSONANTS swap s:contains? ;
3 :c:vowel? (c-f) s:VOWELS swap s:contains? ;
4 :c:letter? (c-f) s:ASCII-LETTERS swap s:contains? ;
5 :c:digit? (c-f) s:DIGITS swap s:contains? ;
6 :c:whitespace? (c-f) s:WHITESPACE swap s:contains? ;
7 :c:visible? (c-f) #32 #126 n:between? ;
8 :c:-consonant? (c-f) c:consonant? not ;
9 :c:-vowel? (c-f) c:vowel? not ;
10 :c:-letter? (c-f) c:letter? not ;
11 :c:-digit? (c-f) c:digit? not ;
12 :c:-whitespace? (c-f) c:whitespace? not ;
13 :c:-uppercase? (c-f) c:uppercase? not ;
14 :c:-lowercase? (c-f) c:lowercase? not ;
15 :c:-visible? (c-f) c:visible? not ;

8 (std) (c:) (conversions)

0 (std) (c:) (conversions)
1
2 :c:toggle-case dup c:lowercase? &c:to-upper &c:to-lower choose ;
3
4
5
6
7
8
9
10
11
12
13
14
15

9 (std) (n:) (even,odd,sign,square,sqrt)

0 (std) (n:) (even,odd,sign,square,sqrt)
1
2 :n:odd? (n-f) #1 and #1 eq? ;
3 :n:even? (n-f) n:odd? not ;
4
5 :n:negative? (n-f) #0 lt? ;
6 :n:positive? (n-f) #0 gt? ;
7 :n:strictly-positive? (n-f) #1 gteq? ;
8
9 :n:square (n-n) dup n:mul ;
10
11 :~guess dup-pair n:div over n:sub #2 n:div ;
12 :n:sqrt (n-n) #1 [ ~guess &n:add sip ] while nip ;
13
14 :n:sign (n-n) n:negative? [ #-1 ] [ #1 ] choose ;
15

10 (std) (v:)

0 (std) (v:)
1
2 :v:preserve (aq-) swap dup fetch [ &call dip ] dip swap store ;
3 :v:inc-by (an-) [ fetch n:add ] sip store ;
4 :v:dec-by (an-) [ fetch swap n:sub ] sip store ;
5 :v:on (a-) #-1 swap store ;
6 :v:off (a-) #0 swap store ;
7 :v:update (aq-) swap [ fetch swap call ] sip store ;
8 :v:limit (alu-) [ [ dup fetch ] dip ] dip n:limit swap store ;
9
10
11
12
13
14
15

11 (std) (buffer:)

0 (std) (buffer:)
1
2 {{
3 'Start var 'Ptr var
4 :at @Start @Ptr ;
5 :update @Ptr @Start store ;
6 ---reveal---
7 :buffer:size (-n) at nip ;
8 :buffer:end (-a) at n:inc n:add ;
9 :buffer:start (-a) @Start ;
10 :buffer:empty (-) #0 !Ptr update ;
11 :buffer:add (na-) at a:store &Ptr v:inc update ;
12 :buffer:get (a-) &Ptr v:dec at a:fetch update ;
13 :buffer:set (a-) !Start #0 !Ptr update ;
14 }}
15

12 (std) (s:) (begins-with,ends-with)

0 (std) (s:) (begins-with,ends-with)
1
2 :~prepare dup s:length &swap dip ;
3 :s:begins-with? (ss-f) ~prepare s:left &s:hash bi@ eq? ;
4 :s:ends-with? (ss-f) ~prepare s:right &s:hash bi@ eq? ;
5
6
7
8
9
10
11
12
13
14
15

13 (std) (s:) (contains/s?) (index/s)

0 (std) (s:) (contains/s?) (index/s)
1
2 '~tar var '~src var '~tar.l var '~src.l var
3
4 :s:contains/s? (ss-f)
5 [ s:keep [ s:length !~tar.l ] [ !~tar ] bi
6 s:keep [ s:length !~src.l ] [ !~src ] bi
7 #0 @~src.l @~tar.l n:sub n:inc
8 [ @~src I @~tar.l s:middle @~tar s:eq? or ] indexed-times
9 ] gc ;
10 :s:index/s (ss-n)
11 [ s:keep [ s:length !tar.l ] [ !tar ] bi
12 s:keep [ s:length !src.l ] [ !src ] bi
13 #65535 @src.l @tar.l n:sub n:inc
14 [ @src I @tar.l s:middle @tar s:eq? [ I n:min ] if ]
15 indexed-times ] gc ;

14

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

15 (std) (bit:) (bit-access)

0 (std) (bit:) (bit-access)
1
2 :bit:get (vi-b) [ #1 swap shift-left and ] sip shift-right ;
3 :bit:set (vi-v) #1 swap shift-left or ;
4 :bit:clear (vi-v) #1 swap shift-left not and ;
5
6
7
8
9
10
11
12
13
14
15

16 (std) (b:) (byte-addressing)

0 (std) (b:) (byte-addressing)
1
2 'Byte var
3
4 :byte-mask (xn-b)
5 #255 swap #8 n:mul dup
6 [ shift-left and ] dip shift-right ;
7
8 [ drop @Byte ]
9 [ [ drop @Byte ] dip ]
10 [ [ [ drop @Byte ] dip ] dip ]
11 [ [ [ [ drop @Byte ] dip ] dip ] dip ]
12 'replacements d:create comma comma comma comma
13
14 :replace &replacements n:add fetch call ;
15

17 (std) (b:) (byte-addressing)

0 (std) (b:) (byte-addressing)
1
2 :b:to-byte-address (a-a) #4 n:mul ;
3
4 :b:unpack (c-bbbb)
5 dup #255 and swap
6 dup #8 shift-right #255 and swap
7 dup #16 shift-right #255 and swap
8 #24 shift-right #255 and ;
9
10 :b:pack (bbbb-c)
11 #24 shift-left swap
12 #16 shift-left n:add swap
13 #8 shift-left n:add swap n:add ;
14
15

18 (std) (b:) (byte-addressing)

0 (std) (b:) (byte-addressing)
1
2 :b:fetch (a-b)
3 #4 n:divmod swap
4 #4 n:divmod
5 rot n:add fetch swap byte-mask ;
6
7 :b:store (ba-)
8 swap !Byte
9 #4 n:divmod swap [ dup fetch b:unpack ] dip
10 replace b:pack swap store ;
11
12
13
14
15

19 (std) (pali) (assembler)

0 (std) (pali) (assembler)
1
2 'Instructions d:create #30 comma
3 #5861473 comma #5863578 comma #5863326 comma
4 #5863323 comma #5863823 comma #5863722 comma
5 #5863716 comma #5863524 comma #5863273 comma
6 #5863275 comma #5863282 comma #5863772 comma
7 #5863355 comma #5863640 comma #5863589 comma
8 #5863424 comma #5863376 comma #5863820 comma
9 #5863210 comma #5863821 comma #5863623 comma
10 #5863314 comma #5863220 comma #5863686 comma
11 #5863980 comma #5863812 comma #5863818 comma
12 #5863288 comma #5863297 comma #5863485 comma
13
14 :inst s:hash &Instructions swap a:index ;
15

20 (std) (pali) (reserved)

0 (std) (pali) (reserved)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

21 (std) (pali) (assembler)

0 (std) (pali) (assembler)
1
2 :~split (s-nnnn)
3 dup #2 s:left inst swap dup #2 #2 s:middle inst swap
4 dup #4 #2 s:middle inst swap #2 s:right inst ;
5
6 :assemble:opcode (s-n) ~split b:pack ;
7
8 :i (s-) assemble:opcode comma ;
9 &comma \d (n-)
10 &comma \r (n-)
11 :s (s-) dup s:length comma &comma s:for-each ;
12
13 :code: ("-) s:get/token d:create ;
14
15

22 (std) (reorder,_roll,_unroll) (restructuring-the-stack)

0 (std) (reorder,_roll,_unroll) (restructuring-the-stack)
1
2 {{
3 'values d:create #27 allot
4 :from s:length dup [ [ &values n:add store ] sip n:dec ] times
5 drop ;
6 :to &n:inc &s:length bi
7 [ fetch-next $a n:sub n:inc &values n:add fetch swap ]
8 times drop ;
9 ---reveal---
10 :reorder (...ss-?) &from dip to ;
11 }}
12
13 :roll (abc-cab) swap &swap dip ;
14 :unroll (cba-abc) roll roll ;
15

23 (std) (reset) (quickly-empty-the-stack)

0 (std) (reset) (quickly-empty-the-stack)
1
2 :reset (...-)
3 depth/data dup n:negative?
4 [ n:abs [ #0 ] ]
5 [ &drop ] choose times ;
6
7
8
9
10
11
12
13
14
15

24 (std) (.s) (display-stack)

0 (std) (.s) (display-stack)
1
2 {{
3 'Data d:create #33 allot
4 :gather depth/data dup &Data store-next swap
5 &store-next times drop ;
6 :display &Data a:reverse [ n:put sp ] a:for-each nl ;
7 :restore &Data a:reverse [ ] a:for-each ;
8 ---reveal---
9 :.s (-) gather display restore ;
10 }}
11
12
13
14
15

25 (std) (debug/dump)

0 (std) (debug/dump)
1
2 {{
3 :digits (-s) '0123456789ABCDEF ;
4 :to-digit (n-c) digits swap s:fetch ;
5 :h. (n-) #16 n:divmod swap [ to-digit c:put ] bi@ sp ;
6 :order 'abcd 'dcba reorder ;
7 :bytes (n-n) dup b:unpack order #4 &h. times ;
8 :display (nn-n) bytes sp n:put nl ;
9 ---reveal---
10 :dump (an-) [ dup n:put tab fetch-next display ] times drop ;
11 }}
12
13
14
15

26 (std) (random-number-generator) (xorshift)

0 (std) (random-number-generator) (xorshift)
1
2 #1 'seed var-n
3
4 :n:random (-n)
5 @seed
6 dup #13 shift-left xor
7 dup #17 shift-right xor
8 dup #5 shift-left xor
9 dup !seed ;
10
11 :n:random-mod (n-n)
12 n:random n:abs swap n:mod ;
13
14 . Note: this works well for small projects, but lacks some
15 . range due to ilo's lack of unsigned numbers.

27 (std) (block-tools)

0 (std) (block-tools)
1
2 :block:empty? (n-f)
3 @Block [ set load block:buffer n:dec s:hash #-967633659
4 eq? ] dip !Block load ;
5
6 :block:for-each (q-)
7 @Blocks [ [ I set load block:buffer swap call ] sip ]
8 indexed-times drop ;
9
10
11
12
13
14
15

28 (std) (block-tools)

0 (std) (block-tools)
1
2 {{
3 :prep (-ns) @Block swap s:keep #0 set ;
4 :get (-s) load next block:buffer n:dec ;
5 :match? (ss-sf) over s:begins-with? ;
6 :last? (-f) @Block @Blocks n:dec eq? ;
7 :select (ns-n) drop last? [ drop @Block ] -if ;
8 ---reveal---
9 :block:first-matching (s-n)
10 [ prep [ get match? last? or ] until select ] gc ;
11 }}
12
13
14
15

29 (std) (editor-ext)

0 (std) (editor-ext)
1
2 'Line d:create #64 allot
3
4 :e:copy (n-) e:to-line &Line #64 copy ;
5 :e:paste (n-) e:to-line &Line swap #64 copy ;
6 :e:cut (n-) dup e:copy #32 swap e:to-line #64 fill ;
7
8 {{
9 :get '_ s:temp #64 over store [ n:inc #64 copy ] sip ;
10 :update n:inc swap #64 copy ;
11 :at e:to-line dup get ;
12 ---reveal---
13 :e:indent at #62 s:left '__ s:prepend update ;
14 :e:unindent at #62 s:right '__ s:append update ;
15 }}

30 (std) (editor-ext)

0 (std) (editor-ext)
1
2 :e:for-each-line (q-)
3 #16 [ block:buffer n:dec
4 I #64 n:mul #64 s:middle swap &call sip ]
5 indexed-times drop ;
6
7
8
9
10
11
12 :n (-) next list ;
13 :p (-) prev list ;
14 &list \l
15

31 (std) (fixed-point)

0 (std) (fixed-point)
1
2 #100 'f:scale var-n
3
4 (ff-f) &n:add \f:add
5 (ff-f) &n:sub \f:sub
6 (ff-f) :f:mul n:mul @f:scale n:div ;
7 (ff-f) :f:div [ @f:scale n:mul ] dip n:div ;
8
9 (----) :~pad @f:scale n:to-s s:length n:dec over
10 n:to-s s:length n:sub [ $0 c:put ] times ;
11 (f-) :f:put @f:scale n:divmod n:put $. c:put ~pad n:put ;
12
13
14
15

32 (std) (invoke,_*)

0 (std) (invoke,_*)
1
2 :invoke (ss-)
3 dup d:exists? &nip [ swap needs ] choose
4 d:lookup d:address fetch call ;
5
6 :~title ("-n) s:get/token '(LOAD: s:prepend ') s:append ;
7 :* ("-) #0 set load ~title block:first-matching set load
8 @Block n:-zero?
9 [ &[ n:abs call run &] n:abs call call ] if ;
10
11 . `invoke` takes a block set and a word to run, if the word is
12 . found, it will load the block set, then run the word
13 . `*` takes the name of a LOAD: block. This will have a title of
14 . `(LOAD:name)` and will contain a list of words that load the
15 . dependencies and active block set.

33

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

34

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

35

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

36

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

37

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

38

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

39

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

40

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

41

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

42

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

43

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

44

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

45

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

46

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

47

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

48 (tools:blocks) (block-editor-reference)

0 (tools:blocks) (block-editor-reference)
1
2 . `blocks` starts the editor on a set of tutorial/reference
3 . blocks.
4
5 :blocks (-) #1016 edit ;
6
7
8
9
10
11
12
13
14
15

49

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

50 (tools:manual-viewer)

0 (tools:manual-viewer)
1
2 #8,192 'man:start var-n #8,303 'man:end var-n
3 #0 'man:cur var-n #0 'man:done var-n
4
5 :man:page (-) @man:start @man:cur n:add set load list* ;
6 :man:length (-n) @man:end @man:start n:sub ;
7 :man:hints '(1)_prev__(2)_next__(0)_exit s:put tab c:get ;
8 :man:display (-) @Block man:page !Block load man:hints ;
9 :man:limit (-) @man:cur #0 man:length n:limit !man:cur ;
10 :man:0 (n-n) dup $0 eq? [ #-1 !man:done ] if ;
11 :man:1 (n-n) dup $1 eq? [ &man:cur v:dec ] if ;
12 :man:2 (n-) $2 eq? [ &man:cur v:inc ] if man:limit ;
13 :man:prepare (-) #0 !man:done ;
14 :manual (-) man:prepare
15 [ man:display man:0 man:1 man:2 @man:done ] until ;

51

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

52 (listener)

0 (listener)
1
2 {{
3 'Done var
4 :bye? dup 'bye s:eq? ;
5 :exit (n-) drop #-1 !Done ;
6 ---reveal---
7 :listener (-)
8 'Hi!_Enter_`bye`_when_done. s:put nl
9 #0 !Done [ s:get/token bye?
10 &exit &interpret choose @Done ] until ;
11 }}
12
13 . This implements a tiny nested Forth listener for Konilo. It's
14 . basically intended to allow some interactive use for sessions
15 . started under the kowae launcher.

53

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

54

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

55

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

56

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

57

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

58

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

59

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

60

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

61

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

62

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

63

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

64 Termina : A Vocabulary for Terminal Applications ===============

0 Termina : A Vocabulary for Terminal Applications ===============
1
2 There are two parts to Termina. The first is a set of words for
3 interacting with a DEC compatible terminal. The second builds on
4 these to provide a scaffold for building textual, keyboard
5 centric programs.
6
7
8
9
10
11
12
13
14
15

65 (termina) (terminal-config)

0 (termina) (terminal-config)
1
2 #80 'ti:width var-n
3 #24 'ti:height var-n
4
5
6
7
8
9
10
11
12
13
14
15

66 (termina) (support;_cursor_movement;_clear_screen)

0 (termina) (support;_cursor_movement;_clear_screen)
1
2 . Helper words
3 :vt:esc (-) #27 c:put ;
4 :vt:csi (-) vt:esc $[ c:put ;
5
6 . Words for moving the cursor
7 :vt:home (-) vt:csi $H c:put ;
8 :vt:row,col (nn-) vt:csi swap n:put $; c:put n:put $H c:put ;
9 :vt:up (-) vt:csi n:put $A c:put ;
10 :vt:down (-) vt:csi n:put $B c:put ;
11 :vt:right (-) vt:csi n:put $C c:put ;
12 :vt:left (-) vt:csi n:put $D c:put ;
13 :vt:clear (-) vt:csi '2J s:put ;
14 :vt:reset vt:csi '0m s:put ;
15

67 (termina) (colors)

0 (termina) (colors)
1
2 :vt:set/color (n-) vt:csi n:put $m c:put ;
3
4 (foreground_colors______________background_colors____________)
5 :fg:black #30 vt:set/color ; :bg:black #40 vt:set/color ;
6 :fg:red #31 vt:set/color ; :bg:red #41 vt:set/color ;
7 :fg:green #32 vt:set/color ; :bg:green #42 vt:set/color ;
8 :fg:yellow #33 vt:set/color ; :bg:yellow #43 vt:set/color ;
9 :fg:blue #34 vt:set/color ; :bg:blue #44 vt:set/color ;
10 :fg:magenta #35 vt:set/color ; :bg:magenta #45 vt:set/color ;
11 :fg:cyan #36 vt:set/color ; :bg:cyan #46 vt:set/color ;
12 :fg:white #37 vt:set/color ; :bg:white #47 vt:set/color ;
13
14
15

68 (termina) (key-to-action-mapping)

0 (termina) (key-to-action-mapping)
1
2 'ti:Actions d:create #128 comma #128 allot
3
4 :ti:set-action (qc-) &ti:Actions swap a:store ;
5
6 :ti:reset-actions (-)
7 #128 [ #0 I ti:set-action ] indexed-times ;
8
9 :ti:get-action (c-q) &ti:Actions swap a:fetch ;
10
11 :ti:perform-action (c-)
12 ti:get-action dup n:-zero? &call &drop choose ;
13
14 :ti:input (-) c:get ti:perform-action ;
15

69 (termina) (keyboard-hints)

0 (termina) (keyboard-hints)
1 {{
2 'ti:Hints d:create #130 allot :empty (-s) '____________ ;
3 :constrain (s-s) dup s:length #12 gt? [ #12 s:left ] if ;
4 :pad (s-s) #32 empty n:inc #12 fill
5 empty &n:inc bi@ over n:dec fetch copy empty ;
6 :start (n-a) #13 n:mul &ti:Hints n:add ;
7 :display (-) I n:inc dup #10 eq? [ drop #0 ] if
8 dup n:put sp start s:put sp ;
9 :clean (-) '_ s:temp constrain pad I start #13 copy ;
10 ---reveal---
11 :ti:add-hint (sn-)
12 #13 n:mul &ti:Hints n:add [ constrain pad ] dip #13 copy ;
13 :ti:reset-hints (-) #10 &clean indexed-times ;
14 :ti:hints #10 [ display I #4 eq? &nl if ] indexed-times ;
15 }}

70 (termina) (display)

0 (termina) (display)
1
2 :ti:display/none ;
3
4 &ti:display/none 'ti:Display var-n
5
6 :ti:set-display (a-) !ti:Display ;
7
8 :ti:reset-display (-) &ti:display/none ti:set-display ;
9
10 :ti:display (-)
11 vt:home @ti:Display call
12 @ti:height #3 n:sub #0 vt:row,col @ti:width [ $- c:put ] times
13 nl ti:hints nl ;
14
15

71 (termina) (nested-applications-support)

0 (termina) (nested-applications-support)
1
2 'ti:ptrs d:create #0 comma #5 allot
3 :ti:add-program (a-) &ti:ptrs v:inc &ti:ptrs @ti:ptrs a:store ;
4 :ti:current (-a) &ti:ptrs @ti:ptrs a:fetch ;
5 :ti:more? (-f) @ti:ptrs n:-zero? ;
6 :ti:remove &ti:ptrs v:dec ;
7
8 :ti:load (-)
9 ti:current call
10 !ti:Display ti:reset-hints call ti:reset-actions call ;
11
12
13
14
15

72 (termina) (application-loop)

0 (termina) (application-loop)
1
2 'ti:Done var
3 :ti:done #-1 !ti:Done vt:reset nl ;
4 :ti:done? @ti:Done ;
5
6 :ti:application/run (-)
7 [ #0 !ti:Done ti:display ti:input ti:done? ] until
8 ti:remove ti:more? [ ti:load #0 !ti:Done ] if ;
9
10 :ti:application (q-)
11 ti:add-program ti:load ti:application/run ;
12
13
14
15

73

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

74 (termina) (ti:help)

0 (termina) (ti:help)
1
2 {{
3 'ti:Help var 'ti:Help/Prior var
4 :ti:help/actions &ti:done $0 ti:set-action ;
5 :ti:help/hints 'Quit #0 ti:add-hint ;
6 :ti:help/display
7 vt:clear vt:home
8 @ti:Help set load list* ;
9 ---reveal---
10 :ti:help (n-)
11 @Block !ti:Help/Prior !ti:Help
12 [ &ti:help/actions &ti:help/hints &ti:help/display ]
13 ti:application @ti:Help/Prior set load ;
14 }}
15

75

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

76

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

77

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

78

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

79

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

80 (tools:catalogue) (variables,_actions)

0 (tools:catalogue) (variables,_actions)
1
2 #0 'Page var-n
3 &edit 'Editor var-n
4
5 :constrain @Page #0 @Blocks #16 n:div n:dec n:limit !Page ;
6 :action (n-) ti:done @Page #16 n:mul n:add @Editor call ;
7
8 :catalogue:rename c:get $a n:sub @Page #16 n:mul n:add
9 set load 0 save ;
10
11 :catalogue:list
12 c:get $a n:sub @Page #16 n:mul n:add
13 set load vt:clear vt:home list# sys:info
14 nl 'Press_x_when_done s:put nl
15 [ c:get $x eq? ] until ;

81 (tools:catalogue) (actions,_continued)

0 (tools:catalogue) (actions,_continued)
1
2 :catalogue:jump n:get #16 n:div !Page constrain ;
3
4 :catalogue:leap
5 [ s:get/token s:keep #0 set load
6 [ block:buffer n:dec over s:begins-with? next
7 @Block @Blocks n:dec eq? or ] until drop prev ] gc
8 @Block #16 n:div !Page constrain ;
9
10
11
12
13
14
15

82 (tools:catalogue) (key-bindings)

0 (tools:catalogue) (key-bindings)
1
2 :catalogue:actions/a-i
3 [ #0 action ] $a ti:set-action
4 [ #1 action ] $b ti:set-action
5 [ #2 action ] $c ti:set-action
6 [ #3 action ] $d ti:set-action
7 [ #4 action ] $e ti:set-action
8 [ #5 action ] $f ti:set-action
9 [ #6 action ] $g ti:set-action
10 [ #7 action ] $h ti:set-action
11 [ #8 action ] $i ti:set-action ;
12
13
14
15

83 (tools:catalogue) (key-bindings)

0 (tools:catalogue) (key-bindings)
1
2 :catalogue:actions/j-p
3 [ #9 action ] $j ti:set-action
4 [ #10 action ] $k ti:set-action
5 [ #11 action ] $l ti:set-action
6 [ #12 action ] $m ti:set-action
7 [ #13 action ] $n ti:set-action
8 [ #14 action ] $o ti:set-action
9 [ #15 action ] $p ti:set-action ;
10
11
12
13
14
15

84 (tools:catalogue) (key-bindings)

0 (tools:catalogue) (key-bindings)
1
2 :catalogue:actions
3 catalogue:actions/a-i
4 catalogue:actions/j-p
5 &ti:done $0 ti:set-action
6 [ &Page v:dec constrain ] $1 ti:set-action
7 [ &Page v:inc constrain ] $2 ti:set-action
8 &catalogue:list $3 ti:set-action
9 &catalogue:jump $4 ti:set-action
10 &catalogue:rename $8 ti:set-action
11 &catalogue:leap $9 ti:set-action
12 ;
13
14
15

85 (tools:catalogue) (hints)

0 (tools:catalogue) (hints)
1
2 :catalogue:hints
3 'Previous #1 ti:add-hint
4 'Next #2 ti:add-hint
5 'Display #3 ti:add-hint
6 'Rename #8 ti:add-hint
7 'Quit #0 ti:add-hint
8 'Jump #4 ti:add-hint
9 'Leap #9 ti:add-hint ;
10
11
12
13
14
15

86 (tools:catalogue) (display)

0 (tools:catalogue) (display)
1
2 {{
3 :sep '_|_ s:put ;
4 :key I $a n:add c:put ;
5 :entry @Page #16 n:mul I n:add ;
6 :title entry set load
7 block:buffer n:dec #64 over store s:put ;
8 :num entry n:put nl ;
9 ---reveal---
10 :catalogue:display
11 vt:clear vt:home
12 #16 [ key sep title sep num ] indexed-times ;
13 }}
14
15

87 (tools:catalogue) (top-level)

0 (tools:catalogue) (top-level)
1
2 :catalogue (-)
3 [ &catalogue:actions &catalogue:hints &catalogue:display ]
4 ti:application ;
5
6 &catalogue \catalog
7
8
9
10
11
12
13
14
15

88

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

89 tools:describe

0 tools:describe
1
2 This adds a word, `describe`, that scans the blocks for glossary
3 data. It takes a word name from the input stream, and looks for
4 a block with a title of `Glossary: wordname`
5
6 In example, to display the glossary data for `s:put`, you would
7 run:
8
9 describe s:put
10
11 The output strips blank lines.
12
13 Note that as this requires one block per word it is not a space
14 efficient tool. You will need around 250 blocks to cover the
15 core language, and many more to cover everything.

90 (tools:describe) (glossary-lookups)

0 (tools:describe) (glossary-lookups)
1
2 {{
3 :empty? (-f)
4 #-1 I #2 n:add e:to-line
5 #64 [ fetch-next #32 eq? swap &and dip ] times drop ;
6 ---reveal---
7 :describe:line (-) empty? [ I #2 n:add e:line ] -if ;
8 :describe:word (s-) @Block swap
9 [ 'Glossary:_ s:prepend s:keep @Blocks
10 [ I set load block:buffer n:dec over
11 dup s:length &swap dip s:left &s:hash bi@ eq?
12 [ nl #13 &describe:line indexed-times nl ] if
13 ] indexed-times drop ] gc !Block load ;
14 :describe ('-) s:get/token s:temp describe:word ;
15 }}

91

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

92 (tools:manual) (display)

0 (tools:manual) (display)
1
2 #8,192 'manual:start var-n
3 #8,303 'manual:end var-n
4 'manual:page var
5
6 :manual:display
7 @Block vt:clear vt:home
8 @manual:page @manual:start n:add !Block load list* !Block ;
9
10 :manual:constrain-page
11 @manual:page #0 @manual:end @manual:start n:sub n:dec n:limit
12 !manual:page ;
13
14 :manual:prev &manual:page v:dec manual:constrain-page ;
15 :manual:next &manual:page v:inc manual:constrain-page ;

93 (tools:manual) (hints,_key_bindings,_top_level)

0 (tools:manual) (hints,_key_bindings,_top_level)
1
2 :manual:hints
3 'Prior #1 ti:add-hint
4 'Next #2 ti:add-hint
5 'Quit #0 ti:add-hint ;
6
7 :manual:actions
8 &manual:prev $1 ti:set-action
9 &manual:next $2 ti:set-action
10 &ti:done $0 ti:set-action ;
11
12 :manual
13 [ &manual:actions &manual:hints &manual:display ]
14 ti:application ;
15

94

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

95

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

96 tuhi - a terminal block editor

0 tuhi - a terminal block editor
1
2 This is designed to be similar in spirit to the basic editor in
3 Konilo, but makes use of the (termina) words to present a hotkey
4 driven interface for editing.
5
6 Tuhi has two display modes:
7
8 - plain text shown as a single color
9 - source code shown with syntax highlighting
10
11 Syntax mode will be used if the block starts with a "(" and
12 `tuhi:cfg/syntax` is set to true (non-zero). In other cases
13 the plain text mode is used.
14
15

97 (tuhi) (configuration)

0 (tuhi) (configuration)
1
2 &fg:cyan 'tuhi:cfg/colors,line# var-n
3 &bg:black 'tuhi:cfg/colors,bg var-n
4 &fg:green 'tuhi:cfg/colors,fg var-n
5 #-1 'tuhi:cfg/syntax var-n
6 #0 'tuhi:cfg/status var-n
7
8
9
10
11
12
13
14
15

98 (tuhi) (list:syntax) (default-colors)

0 (tuhi) (list:syntax) (default-colors)
1
2 :~colon bg:black fg:red ; (:
3 :~immed bg:black fg:green ; (word:_[_]_;
4 :~number bg:black fg:cyan ; (#
5 :~char bg:black fg:yellow ; ($
6 :~string bg:black fg:white ; ('
7 :~pointer bg:black fg:magenta ; (&
8 :~comment bg:blue fg:white ; ((
9 :~var bg:black fg:magenta ; (@_or_!
10 :~normal bg:black fg:green ;
11
12 '~SigilColors d:create #8 comma
13 &~colon comma &~number comma &~char comma
14 &~string comma &~pointer comma &~comment comma
15 &~var comma &~var comma

99 (tuhi) (list:syntax) (helpers)

0 (tuhi) (list:syntax) (helpers)
1
2 ':#$'&(@! s:keep \~Sigils
3
4 :~sigil? (c-cf) &~Sigils over s:contains? ;
5
6 :~color-sigil (c-c)
7 &~Sigils over s:index/c &~SigilColors swap a:fetch call ;
8
9 :~space? (c-cf) dup #32 eq? ;
10
11 '~last var
12
13
14
15

100 (tuhi) (list:syntax) (display)

0 (tuhi) (list:syntax) (display)
1
2 :~prepare (n-an) #64 n:mul block:buffer n:add #64 #32 !~last ;
3
4 :e:line/syntax (n-)
5 ~prepare
6 [ fetch-next
7 ~sigil? [ @~last #32 eq? &~color-sigil if ] if
8 ~space? [ @~last #32 -eq? &~normal if ] if
9 dup !~last c:put
10 ] times vt:reset sp $| c:put nl drop ;
11
12 :~line# I dup #10 lt? &sp if n:put sp ;
13
14 :list:syntax (-)
15 #16 [ ~line# I e:line/syntax ] indexed-times ;

101 (tuhi) (display)

0 (tuhi) (display)
1 {{
2 :status @tuhi:cfg/status &sys:info if ;
3 :colorize call ;
4 :line# @tuhi:cfg/colors,line# colorize I $a n:add c:put ;
5 :sep vt:reset '_|_ s:put ;
6 :text @tuhi:cfg/syntax block:buffer fetch $( eq? and
7 [ I e:line/syntax ]
8 [ @tuhi:cfg/colors,bg @tuhi:cfg/colors,fg
9 &colorize bi@ I e:to-line #64 [ fetch-next c:put ]
10 times drop vt:reset sp $| c:put nl ] choose ;
11 :reset @tuhi:cfg/syntax [ bg:black fg:white ] if ;
12 ---reveal---
13 :tuhi:display (-) vt:clear vt:home
14 #16 [ line# sep text reset ] indexed-times status ;
15 }}

102 (tuhi) (key-actions)

0 (tuhi) (key-actions)
1
2 (lines)
3 :tuhi:a #1 #5 vt:row,col 0 ; :tuhi:b #2 #5 vt:row,col 1 ;
4 :tuhi:c #3 #5 vt:row,col 2 ; :tuhi:d #4 #5 vt:row,col 3 ;
5 :tuhi:e #5 #5 vt:row,col 4 ; :tuhi:f #6 #5 vt:row,col 5 ;
6 :tuhi:g #7 #5 vt:row,col 6 ; :tuhi:h #8 #5 vt:row,col 7 ;
7 :tuhi:i #9 #5 vt:row,col 8 ; :tuhi:j #10 #5 vt:row,col 9 ;
8 :tuhi:k #11 #5 vt:row,col 10 ; :tuhi:l #12 #5 vt:row,col 11 ;
9 :tuhi:m #13 #5 vt:row,col 12 ; :tuhi:n #14 #5 vt:row,col 13 ;
10 :tuhi:o #15 #5 vt:row,col 14 ; :tuhi:p #16 #5 vt:row,col 15 ;
11
12 (jump/leap)
13 :tuhi:4 s:get/line s:to-n !Block load ;
14 :tuhi:9 s:get/line block:first-matching !Block load ;
15

103 (tuhi) (key-actions)

0 (tuhi) (key-actions)
1
2 :tuhi:[ c:get $a n:sub e:unindent ;
3 :tuhi:] c:get $a n:sub e:indent ;
4
5 :tuhi:C c:get $a n:sub e:copy ;
6 :tuhi:V c:get $a n:sub e:paste ;
7 :tuhi:X c:get $a n:sub e:cut ;
8
9 :tuhi:? #111 ti:help ;
10
11 :tuhi:Q @tuhi:cfg/status not !tuhi:cfg/status ;
12
13 :tuhi:N new ;
14
15 :tuhi:S vt:clear vt:home sys:info c:get drop ;

104

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

105 (tuhi) (setup-key-actions-part-1)

0 (tuhi) (setup-key-actions-part-1)
1
2 :tuhi:actions/1 (-)
3 &prev $1 ti:set-action &next $2 ti:set-action
4 &tuhi:4 $4 ti:set-action
5 &run $5 ti:set-action &save $6 ti:set-action
6 &load $7 ti:set-action
7 &tuhi:9 $9 ti:set-action &ti:done $0 ti:set-action
8 &tuhi:a $a ti:set-action &tuhi:b $b ti:set-action
9 &tuhi:c $c ti:set-action &tuhi:d $d ti:set-action
10 &tuhi:e $e ti:set-action &tuhi:f $f ti:set-action
11 &tuhi:g $g ti:set-action &tuhi:h $h ti:set-action
12 &tuhi:i $i ti:set-action &tuhi:j $j ti:set-action
13 &tuhi:k $k ti:set-action &tuhi:l $l ti:set-action
14 &tuhi:m $m ti:set-action &tuhi:n $n ti:set-action
15 &tuhi:o $o ti:set-action &tuhi:p $p ti:set-action ;

106 (tuhi) (setup-key-actions-part-2)

0 (tuhi) (setup-key-actions-part-2)
1
2 :tuhi:actions/2 (-)
3 &tuhi:[ $[ ti:set-action &tuhi:] $] ti:set-action
4 &tuhi:C $C ti:set-action &tuhi:V $V ti:set-action
5 &tuhi:X $X ti:set-action &tuhi:Q $Q ti:set-action
6 &tuhi:? $? ti:set-action
7 &tuhi:N $N ti:set-action &tuhi:S $S ti:set-action
8 ;
9
10
11
12
13
14
15 :tuhi:actions (-) tuhi:actions/1 tuhi:actions/2 ;

107 (tuhi) (hints,_main_loop)

0 (tuhi) (hints,_main_loop)
1
2 :tuhi:hints (-)
3 'Previous #1 ti:add-hint
4 'Next #2 ti:add-hint
5 'Jump #4 ti:add-hint
6 'Run #5 ti:add-hint
7 'Save #6 ti:add-hint
8 'Load #7 ti:add-hint
9 'Leap #9 ti:add-hint
10 'Quit #0 ti:add-hint
11 ;
12
13 :tuhi (-)
14 [ &tuhi:actions &tuhi:hints &tuhi:display ] ti:application ;
15

108

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

109

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

110

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

111 tuhi shortcuts =================================================

0 tuhi shortcuts =================================================
1
2 a - p line entry
3 X cut
4 C copy
5 V paste
6 [ un-indent line
7 ] indent line
8 Q toggle status line
9 N erase block contents
10 S display some status information
11 ? display this help screen
12
13
14
15

112 nonix : a unix-inspired set of words for working with the blocks

0 nonix : a unix-inspired set of words for working with the blocks
1
2 This provides:
3
4 +--------+--------------+-------------------------------------+
5 | cp | src dest | copy block src to block dest |
6 | mv | src dest | move block src to block dest |
7 | rm | block | erase block |
8 | cat | block | display contents of a block (text) |
9 | locate | text | show blocks starting with text |
10 | xcp | src dest num | copy num blocks from src to dest |
11 | xmv | src dest num | move num blocks from src to dest |
12 | xrm | start num | remove num blocks starting at start |
13 | clear | | clear the screen |
14 +--------+--------------+-------------------------------------+
15

113 (nonix) (basic-commands)

0 (nonix) (basic-commands)
1
2 :cp n:get set load n:get set save ;
3 :rm n:get set new save ;
4 :mv n:get dup set load n:get set save set new save ;
5 :cat n:get set load list* ;
6 :locate s:get/token s:temp
7 [ s:keep @Blocks
8 [ I set load block:buffer n:dec over s:begins-with?
9 [ I n:put tab #0 e:line ] if ] indexed-times drop ] gc ;
10
11 :clear (-) vt:clear vt:home ;
12
13
14
15

114 (nonix) (extended-commands)

0 (nonix) (extended-commands)
1
2 {{
3 :relocate over set load dup set save ;
4 :erase over set new save ;
5 :next &n:inc bi@ ;
6 :args n:get n:get n:get ;
7 ---reveal---
8 :xmv ("from,to,count")
9 args [ relocate erase next ] times drop-pair ;
10 :xcp ("from,to,count")
11 args [ relocate next ] times drop-pair ;
12 :xrm ("start,count")
13 n:get n:get swap set [ new save next ] times ;
14 }}
15

115

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

116

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

117

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

118

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

119

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

120

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

121

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

122

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

123

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

124

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

125

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

126

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

127

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15