-
Notifications
You must be signed in to change notification settings - Fork 1
/
buffermaker
executable file
·2243 lines (2060 loc) · 50.4 KB
/
buffermaker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
buffermaker_version="0.11.6"
## Buffermaker
# Pure bash tui framework (wip)
shopt -s lastpipe # For syntax highlighting
shopt -s extglob # Ensure advanced pattern matching is available
shopt -s checkwinsize && (:;:) # Enable and then trigger a terminal size refresh
declare -r DEFIFS="$IFS"
declare -A highlight faces faces_raw options charmap hooks resources
declare -A keys_global
declare -a k_hex buffers_l modes=('keys_global')
declare -n buffer bf_s bf_e bf_d
declare -i ismenu comment current_count
declare reset readin
source bxcommon
function load-default-config {
## Configuration
# The magic :: function
# :: sets value to option depending on current context:
# set-options → define-options() → ass. array options
# global-set → global-set-key → define-key global → as. ar. keys_global
# add-mode → local-set-key → define-key <keys> → a. a. keys_<keys>
# mode-options → local-set-mode-option → define-mode-option → a. a. key_options_<keys>
# set-alias → add-alias → a. a. alias
# add-menu → local-set-menu → define-menu <menu> → menu_<menu>_0 & menu_<menu>_1
# set-highlight → add-highlight → a. a. highlight
options=(
[mouse]=0
[todonote]=0
[line-number-mode]=0
[empty-line-char]=''
[tty-linuxfb]=1 # enable truecolor support for framebuffer
[full-redraw]=0 # redraws whole buffer, can fix artifacting in linuxfb at cost of performance
[esc-to-meta]=0
)
## Key bindings configuration
# A keybinding is defined via either
# global-set; :: ... ... or add-mode <mode>; :: ... ...
# :: <key> <command>
# <key> is defined either via
# Hexadecimal format (with ' 0' added as suffix).
# Name of key like '[<key>]'
# Emacsy "$(kbd <key> )" (<key> being something like C-s M-e ...)
# The name of key and $(kbd) get translated into hex. format on startup.
#
# mode-options sets magic :: to defining mode options
# :: option value
add-mode empty
mode-options
:: else :
:: disable-global 1
add-mode menu
:: '[up]' menu.up
:: "$(kbd k)" menu.up
:: 'C-p' menu.up
:: '[down]' menu.down
:: "$(kbd j)" menu.down
:: 'C-n' menu.down
:: 'RET' menu.select
mode-options
:: else menu.exit
:: disable-global 1
add-mode basic
:: '[left]' format-left
:: '[up]' format-up
:: '[right]' format-right
:: '[down]' format-down
:: RET link-enter
:: C-c die
mode-options
:: else :
## Faces
# Defined in escape codes
# Helper functions:
# :weight
# normal
# bold
# :slant
# normal
# italic
# :underline
# t (enables)
# nil (do nothing)
# :background & :foreground
# either hex. colour, colour name, or c<index> for 256 indexed colours
# See extensions/gruvboxdark for another example
default_faces=(
reset '\e[m'
default "$(:weight normal)"
border-highlight "$(:mode inverse)"
border-shadow "$(:mode inverse :foreground gray)"
menu "$(:background yellow :foreground black)"
menu-divider "$(:underline t)"
menu-highlight "$(:weight bold :underline t)"
menu-enabled "$(:background yellow :foreground black)"
menu-selected "$(:background light-yellow :foreground black :weight bold)"
checkbox-disabled "$(:foreground light-gray)"
checkbox-enabled "$(:foreground yellow :weight bold)"
action "$(:foreground light-blue)"
button "$(:mode inverse :underline t)"
link "$(:underline t :foreground light-blue)"
link-highlight "$(:weight bold :underline t :foreground light-blue)"
title "$(:weight bold)"
alt "$(:slant italic)"
highlight "\e[4m$(:weight bold)"
accent "$(:foreground yellow)"
background-highlight "$(:background black)"
dim "$(:weight dim)"
divider "$(:foreground gray)"
name "$(:foreground magenta)"
hint "$(:foreground light-yellow)"
hint-highlight "$(:underline t :foreground light-yellow)"
line-number "$(:foreground gray)"
line-number-empty "$(:weight dim :foreground gray)"
line-number-current-line "$(:weight bold :foreground light-red)"
tab-face "$(:weight dim :foreground gray)"
region "$(:weight bold :background gray)"
minibuffer-prompt "$(:weight normal)"
#
TODO "$(:background magenta)"
NOTE "$(:background gray)"
# common colors for format stuff
black '\e[30m' gray '\e[90m'
red '\e[31m' light-red '\e[91m'
green '\e[32m' light-green '\e[92m'
yellow '\e[33m' light-yellow '\e[93m'
blue '\e[34m' light-blue '\e[94m'
magenta '\e[35m' light-magenta '\e[95m'
cyan '\e[36m' light-cyan '\e[96m'
light-gray '\e[37m' white '\e[97m'
bg-black '\e[40m' bg-gray '\e[100m'
bg-red '\e[41m' bg-light-red '\e[101m'
bg-green '\e[42m' bg-light-green '\e[102m'
bg-yellow '\e[43m' bg-light-yellow '\e[103m'
bg-blue '\e[44m' bg-light-blue '\e[104m'
bg-magenta '\e[45m' bg-light-magenta '\e[105m'
bg-cyan '\e[46m' bg-light-cyan '\e[106m'
bg-light-gray '\e[47m' bg-white '\e[107m'
)
load-theme default_faces
resources=(
[&]='&'
[line]='─'
[bold-line]='━'
[column]='│'
[bold-column]='┃'
[angle-down-right]='┌'
[bold-angle-down-right]='┏'
[angle-down-left]='┐'
[bold-angle-down-left]='┓'
[angle-up-right]='└'
[bold-angle-up-right]='┗'
[angle-up-left]='┘'
[bold-angle-up-left]='┛'
[double-line]='═'
[double-column]='║'
[double-angle-down-right]='╔'
[double-angle-down-left]='╗'
[double-angle-up-right]='╚'
[double-angle-up-left]='╝'
[item]='*'
[item-number]='.'
[tab]=' '
[checkbox-disabled]='[ ]'
[checkbox-enabled]='[x]'
)
}
## syntaxy sugar sugary syntax
function @ifs { IFS="$DEFIFS"; }
function ::
case "$_last_add" in
add-menu) local-set-menu "$@";;
set-highlight) add-highlight "$@";;
global-set) global-set-key "$@";;
set-options) define-option "$@";;
add-mode) local-set-key "$@";;
mode-options) local-set-mode-option "$@";;
set-buffer) local-set-buffer-data "$@"
esac
## focus set magic # function
function focus {
_last_add="$1"
}
function declare-buffer {
_last_add='set-buffer'
set-buffer "${1}" # name
buffers_l+=("$current_buffer")
last_line=1
declare -Ag "${current_buffer}_bf_t"
declare -Ag "${current_buffer}_bf_h"
declare -Ag "${current_buffer}_bf_d"
bf_d=(
# some sane default values
[line]=0
[base]=1
[column]=0
[modified]=0
[loc-x]=1
[loc-y]=1
[size-x]=$COLUMNS
[size-y]=$LINES
)
}
## local-set-buffer-data
# set bf_d[] array of currently \"focused\" buffer
function local-set-buffer-data {
while [ -n "$2" ]; do
bf_d["$1"]="$2"
shift 2
done
}
## [auto] Checks bf_d[] array and set\'s needed missing values automatically
function [auto] {
[ -z "${bf_d[loc-x]}" ] && bf_d[loc-x]=1
[ -z "${bf_d[loc-y]}" ] && bf_d[loc-y]=1
[ -z "${bf_d[size-x]}" ] && bf_d[size-x]=$COLUMNS
[ -z "${bf_d[size-y]}" ] && bf_d[size-y]=$((LINES - 1))
[ -z "${bf_d[syntax]}" ] && set-syntax
}
## fn Shorthand for one line functions
function fn {
[ -z "$*" ] && exit 1 # error if empty
local name="$1"
shift
eval "function $name { $@; }"
}
## kbd Converts Emacs like key notation into hex.
function kbd {
local -i i=0
local out
local in
local -i ch=1
# Surely there is better solution...
ch=0
case "${1:0:2}" in
M-) in="${1:2:1}";;
*) in="$1"
esac
((ch)) && return
echo "$in" | {
while read -rsn1; do
out+="$(printf "%x\n" "'${in:$i}") "
((i++))
done
}
out=${out::-1}
printf '%s' "${out}"
}
## define-key defines keybinding
# '$1' can be either:
# '[function-key]'
# '[arrow-key]'
# '[prior | next]'
# 'RET'
# 'DEL'
# '[delechar]'
# 'hex code ending with 0'
function define-key {
local -n keys="keys_$1"
case "$2" in
#control
C-a) keys[1 0]="$3" ;; C-b) keys[2 0]="$3" ;;
C-c) keys[3 0]="$3" ;; C-d) keys[4 0]="$3" ;;
C-e) keys[5 0]="$3" ;; C-f) keys[6 0]="$3" ;;
C-g) keys[7 0]="$3" ;; C-h) keys[8 0]="$3" ;;
C-i) keys[9 0]="$3" ;; C-j) keys[a 0]="$3" ;;
C-k) keys[b 0]="$3" ;; C-l) keys[c 0]="$3" ;;
C-m) keys[d 0]="$3" ;; C-n) keys[e 0]="$3" ;;
C-o) keys[f 0]="$3" ;; C-p) keys[10 0]="$3";;
C-q) keys[11 0]="$3";; C-r) keys[12 0]="$3";;
C-s) keys[13 0]="$3";; C-t) keys[14 0]="$3";;
C-u) keys[15 0]="$3";; C-v) keys[16 0]="$3";;
C-w) keys[17 0]="$3";; C-x) keys[18 0]="$3";;
C-y) keys[19 0]="$3";; C-z) keys[1a 0]="$3";;
#function keys
'[f1]') keys[1b 4f 50 0]="$3";;
'[f2]') keys[1b 4f 51 0]="$3";;
'[f3]') keys[1b 4f 52 0]="$3";;
'[f4]') keys[1b 4f 53 0]="$3";;
'[f5]') keys[1b 5b 31 35 7e 0]="$3";;
'[f6]') keys[1b 5b 31 37 7e 0]="$3";;
'[f7]') keys[1b 5b 31 38 7e 0]="$3";;
'[f8]') keys[1b 5b 32 39 7e 0]="$3";;
'[f9]') keys[1b 5b 32 30 7e 0]="$3";;
'[f10]') keys[1b 5b 32 31 7e 0]="$3";;
'[f11]') keys[1b 5b 32 33 7e 0]="$3";;
'[f12]') keys[1b 5b 32 34 7e 0]="$3";;
#arrow keys
'[left]') keys[1b 5b 44 0]="$3";;
'[up]') keys[1b 5b 41 0]="$3";;
'[right]') keys[1b 5b 43 0]="$3";;
'[down]') keys[1b 5b 42 0]="$3";;
#pg up & down
'[prior]') keys[1b 5b 36 7e 0]="$3";;
'[next]') keys[1b 5b 35 7e 0]="$3";;
#return
'RET') keys[a 0]="$3";;
#backspace & delete
'DEL') keys[7f 0]="$3";;
'[deletechar]') keys[1b 5b 33 7e 0]="$3";;
'ESC') keys[1b 0 0]="$3";;
'[deletechar]') keys[1b 5b 33 7e 0]="$3";;
*) keys["$2"]="$3"
esac
}
## local-set-key
# Sets keybinding of lastly defined mode
# See define-key for details
fn local-set-key 'define-key "$_last_keys" "$@"'
## global-set-key
# Sets keybinding of global mode
# See define-key for details
fn global-set-key 'define-key global "$@"'
## define-mode-option
# Sets option of mode '$1'
function define-mode-option {
local -n ko="key_options_$1"
ko["$2"]="$3"
}
## local-set-mode-option See define-mode-option
fn local-set-mode-option 'define-mode-option "$_last_keys" "$@"'
## mode-options Brings mode-options of lastly defined mode into \"focus\"
fn mode-options '_last_add="mode-options"'
## add-highlight Sets highlighting mode '$1' for file types '$2...'
function add-highlight {
local name="$1"
shift
for i in "$@"; {
highlight["$i"]="$name"
}
}
## set-alias Brings into \"focus\" highlight setting
fn set-highlight '_last_add=set-highlight'
## clear-screen clears screen
fn clear-screen "printf '\033c'"
## add-mode
# Adds keybing mode
function add-mode {
_last_keys="$1"
_last_add='add-mode'
modes+=("keys_$1")
declare -Ag "keys_$1"
declare -Ag "key_options_$1"
}
## global-set Brings into \"focus\" global mode
fn global-set '_last_add=global-set'
## define-option Defines options[] buffer
fn define-option 'options["$1"]="$2"'
## set-options Brings into \"focus\" options setting
fn set-options '_last_add=set-options'
function menu.add {
# create new menu function & array
eval "function @menu:${1} { menu $1; }"
declare -ag "menu_${1}_0"
declare -ag "menu_${1}_1"
declare -ag "menu_${1}_2"
local -n menu_0="menu_${1}_0"
local -n menu_1="menu_${1}_1"
local -n menu_1="menu_${1}_2"
local -i c=-1
local type
local -n menu="$1"
for i in "${menu[@]}"; do
case "$i" in
't:'|'text:')
type=text
((c++))
continue;;
'c:'|'cmd:'|'command:')
type=command
continue;;
'f:'|'face:')
type=face
continue
esac
case "$type" in
'text')
menu_0[c]+=" $i"
;;
'command')
menu_1[c]+="$i "
;;
'face')
menu_2[c]+="$i"
esac
done
menu.layout "$1"
}
function menu.layout {
local -n menu_0="menu_${1}_0"
local -i max=0
for i in "${menu_0[@]}"; do
((${#i} > max)) && max="${#i}"
done
for i in "${!menu_0[@]}"; do
for ((l=$((max - ${#menu_0[i]})) + 1; l>0; l--)); do
menu_0[i]+=' '
done
done
}
## load-theme Loads theme from array
function load-theme {
local -i t=0
local k
local -n theme="$1"
for i in "${theme[@]}"; {
((t==0)) && {
k="$i"
t=1
} || {
faces["$k"]="$i"
faces_raw["$k"]="$(printf '%b' "$i")"
t=0
}
}
((t)) && errno=1 die
}
## rest of this garbageware
## refresh Refreshes buffer
# 'clears screen, reset syntax, redraws'
# 'See <a> doc-goto clear-screen : <f> link clear-screen </f> </a> for more info.'
function refresh {
clear-screen
bf_s=''
redraw
}
## switch-mode
# Change current mode of buffer into '$1'
function switch-mode {
bckmode="${bf_d[mode]}"
bf_d[mode]="$1"
}
## mode-back
# Restores previous mode
function mode-back {
bf_d[mode]="$bckmode"
unset bckmode
}
## read-command
# Works like normal "'read'" but for bottom commanline
function read-command {
local -i loc
[ -n "$4" ] && loc="$4" || loc=$((bf_d[size-y] + bf_d[loc-y]))
printf '\e[%s;0H' "$loc"
printf '\e[?25h'
read -re -p "$1" -i "$3" "$2" || return 1
}
## base-name
# Basically equivalent to the "'basename'" coreutil
function base-name
for file in "$@"; {
file="${file%/}"
printf '%s\n' "${file##*/}"
}
### TODO: make this make sense
## make-render Creates syntax highlighting for currently visible lines
function make-render {
make-render-area "${bf_d[base]}" $((bf_d[base] + bf_d[size-y] + bf_d[loc-y]))
}
## make-render-area
# Creates syntax highlighting for lines from '$1' to '$2'
function make-render-area {
local -i line="$1"
local -i syntaxline=$line
local -n linearray="${current_buffer}_syntax${syntaxline}"
linearray=()
bckeIFS="${IFS}"
IFS=
for ((l=syntaxline;l<${2};l++)); do
((l > $2)) && break
local -n linearray="${current_buffer}_syntax${syntaxline}"
linearray=()
bf_s[syntaxline]="${current_buffer}_syntax${syntaxline}"
((syntaxline++))
line="$l"
local -a s
case "${bf_d[render-type]}" in
'per-char') make-render-line-loop-char;;
'per-word') make-render-line-loop;;
*) make-render-line-loop
esac
done
IFS="$bckeIFS"
}
## make-render-line
# Syntax highlights single line '$1'
# Defaults to currently selected line if no argument is passed
function make-render-line {
local -i line=${1:-bf_d[line]}
local -i syntaxline=$line
local -n linearray="${current_buffer}_syntax${syntaxline}"
bf_s[syntaxline]="${current_buffer}_syntax${syntaxline}"
linearray=()
bckeIFS="${IFS}"
IFS=
local -a s
case "${bf_d[render-type]}" in
'per-char') make-render-line-loop-char;;
'per-word') make-render-line-loop;;
*) make-render-line-loop
esac
IFS="$bckeIFS"
}
function make-render-line-loop {
local -i comment=0
local -i skip_next_space=0
local word=''
bf_e[line]=''
for _link in ${bf_c[line]}; do
unset "$_link"
done
unset bf_c[line]
column=0
IFS=' '
while read -rs word; do
IFS=''
syntax-word
IFS=' '
done <<< "${buffer[line]}"
}
## make-render-line-loop
# Backend for make-render-area \& make-render-line
# Also creates bf_e charmap for movenment
# "Tab is 't'"
# "Space is 's'"
# "Any unmaped char is '0'"
function make-render-line-loop-char {
local -i comment=0
local -i skip_next_space=0
local word=''
bf_e[line]=''
for _link in ${bf_c[line]}; do
unset "$_link"
done
unset bf_c[line]
column=0
while read -rsn1 char; do
case "$char" in
' ')
syntax-word
word=''
((skip_next_space==1)) && skip_next_space=0 && continue
bf_e[line]+='s'
face-no-expand "${facename:-${bf_d[background]:-default}}" ' '
((column++));;
' ')
syntax-word
word=''
local -i i
for ((i = ${#resources[tab]}; i > 0 ; i--)); do
bf_e[line]+="${charmap[ ]}"
done
face-no-expand tab-face "${resources[tab]}"
((column+=${#resources[tab]}));;
'')
syntax-word
word=''
skip_next_space=0
face-no-expand "${bf_d[background]:-default}" ' '
newline=1 # tell syntax functions that the previous char was newline # used for format thing
return;;
*)
word+="${char}"
esac
done <<< "${buffer[line]}"
}
## syntax-word
# Decides what a word should highlighted as:
# 'If todonote option is enabled, highlight "NOTE:" & "TODO:"'
# 'If the word is supposed to be comment highlight it as it'
# 'Else pass it to current syntax function'
function syntax-word {
(("${options[todonote]}"==1)) && {
case "$word" in
'NOTE:') face NOTE "${word}"; return ;;
'TODO:') face TODO "${word}"; return ;;
esac
}
((comment)) && set-face font-lock-comment-face ||
"${bf_d[syntax]}"
((bf_d[syntax-exec])) || face "$syntax_face" "$word" # s_ex controls syntax extended
}
## face
# Add highlighted word to multidimensional nonsense "'bf_s'" arry
function face {
IFS=' '
[[ "$2" =~ ${2//?/(.)} ]]
linearray+=("${faces_raw[reset]}${faces_raw[${1}]}${BASH_REMATCH[@]:1}")
IFS=''
for ((iw=0; iw < ${#2}; iw++)); do
bf_e[line]+='0'
done
}
## face-no-expand
# Add highlighted word to multidimensional nonsense "'bf_s'" arry without adding anything to bf_e[] array
function face-no-expand {
IFS=' '
[[ "$2" =~ ${2//?/(.)} ]]
linearray+=("${faces_raw[reset]}${faces_raw[${1}]}${BASH_REMATCH[@]:1}")
IFS=''
}
## set-face Sets face for syntax highlighting
fn set-face 'syntax_face="$1"'
## size-full
# Sets size of buffer to be fullscreen
function size-full {
bf_d+=(
[loc-x]=1
[loc-y]=1
[size-x]=$COLUMNS
[size-y]=$LINES
)
}
## set-buffer
# Switch to buffer \$1
function set-buffer {
current_buffer="$1"
declare -ng buffer="${current_buffer}_buffer" # source
declare -ng bf_s="${current_buffer}_bf_s" # syntax
declare -ng bf_e="${current_buffer}_bf_e" # charmap
declare -ng bf_d="${current_buffer}_bf_d" # data
declare -ng bf_c="${current_buffer}_bf_c" # commands/objects
declare -ng bf_h="${current_buffer}_bf_h" # hooks
declare -ng bf_t="${current_buffer}_bf_t" # tmp cache
}
function switch-buffer {
set-buffer "$1"
redraw
}
## add-to-list
# Adds a buffer into currently active buffer list
function add-to-list {
buffers_l+=("$current_buffer")
}
## clear-buffer
# Empties buffer bf_s bf_e \& bf_d
function clear-buffer {
buffer=()
for l in "${bf_s[@]}"; {
unset "$l"
}
bf_s=()
bf_e=()
for l in "${bf_c[@]}"; {
unset "$l"
}
bf_c=()
}
## list-directory
# Basically like ls command
function list-directory {
((options[display-dotfiles]==1)) && shopt -s dotglob
((options[display-dotfiles]==0)) && shopt -u dotglob
printf '..\n'
printf '%s\n' *
}
## current-time
# Basically like coreutil "'date'"
fn current-time 'printf "%($1)T\\n"'
## goto Load array into buffer
function goto {
clear-buffer
bf_d[line]=1
bf_d[column]=0
copy-array "$1" buffer
redraw
}
function syntax-none {
set-face "${bf_d[background]:-default}"
}
########################################################################################################################
function format-include {
_buffer="$current_buffer"
for bf in "${format_include_buffers[@]}"; do
set-buffer "$bf"
redraw
done
set-buffer "$_buffer"
}
function syntax-format {
((skip_word==1)) && {
skip_next_space=1
[ "$word" = '-->' ] && skip_word=0
return
}
[ "$word" = '<!--' ] && {
skip_next_space=1
skip_word=1
return
}
((insert_bf==1)) && {
skip_next_space=1
[ "$word" = '>>' ] && {
insert_bf=0
format_include_buffers+=("${insert_arg[1]}")
insert_arg=()
return
}
insert_arg+=("$word")
return
}
[ "$word" = '<<' ] && {
skip_next_space=1
insert_bf=1
insert_arg=()
return
}
((newline==1)) && {
bf_t[ichar]="${bf_t[indent_spaces]}"
bf_t[iexp]="${bf_t[indent_spaces_e]}"
}
((newline==0)) && {
bf_t[ichar]=
bf_t[iexp]=
}
((escape==2)) && {
escape=1
facename="$word"
skip_next_space=1
return
}
((escape==1)) && {
escape=0
face "$facename" "${bf_t[ichar]}$word"
return
}
[ "$word" = '<\>' ] && {
escape=1
skip_next_space=1
facename='unknown'
return
}
[ "$word" = '<[>' ] && {
escape=2
skip_next_space=1
return
}
((variable==1)) && {
variable=0
word="${!word}"
}
[ "$word" = '<v>' ] && {
variable=1
varname=
skip_next_space=1
return
}
[ "$word" = '</u>' ] && {
upper=0
skip_next_space=1
return
}
[ "$word" = '<u>' ] && {
upper=1
skip_next_space=1
return
}
[ "$word" = '</f>' ] && {
unset linearray[-1]
bf_e[line]=${bf_e[line]::-1}
((column--))
unset facename
[ -n "$bckfacename" ] && {
facename="$bckfacename"
unset bckfacename
}
return
}
[ "$word" = '</f->' ] && {
unset linearray[-1]
bf_e[line]=${bf_e[line]::-1}
((column--))
skip_next_space=1
[ -n "$bckfacename" ] && {
facename="$bckfacename"
unset bckfacename
}
return
}
((facedef==1)) && {
skip_next_space=1
facedef=0
facename="$word"
return
}
[ "$word" = '<f>' ] && {
bckfacename="$facename"
skip_next_space=1
facedef=1
return
}
[ "$word" = '<-f>' ] && {
unset linearray[-1]
bf_e[line]=${bf_e[line]::-1}
((column--))
bckfacename="$facename"
skip_next_space=1
facedef=1
return
}
[ "$word" = '</h>' ] || [ "$word" = '</h3>' ] && {
unset linearray[-1]
bf_e[line]=${bf_e[line]::-1}
((column--))
unset facename
upper=0
[ -n "$bckfacename" ] && {
facename="$bckfacename"
unset bckfacename
}
return
}
[ "$word" = '<h>' ] || [ "$word" = '<h3>' ] && {
bckfacename="$facename"
skip_next_space=1
facename=title
upper=1
return
}
[ "$word" = '</b>' ] || [ "$word" = '</strong>' ] || [ "$word" = '</i>' ] && {
unset linearray[-1]
bf_e[line]=${bf_e[line]::-1}
((column--))
unset facename
[ -n "$bckfacename" ] && {
facename="$bckfacename"
unset bckfacename
}
return
}
[ "$word" = '<b>' ] && {
bckfacename="$facename"
skip_next_space=1
facename=title
return
}
[ "$word" = '<i>' ] && {
bckfacename="$facename"
skip_next_space=1
facename=alt
return
}
[ "$word" = '<strong>' ] && {
bckfacename="$facename"
skip_next_space=1
facename=highlight
return
}
((sethighlight==2)) && {
sethighlight=1
skip_next_space=1
tmp_sex="$word"
return
}
((sethighlight==1)) && {
sethighlight=0
skip_next_space=1
bf_d[syntax-exec]="$tmp_sex"
bf_d[syntax]="syntax-$word"
return
}
[ "$word" = '<change-syntax>' ] && {
skip_next_space=1
sethighlight=2
return
}
[ "$word" = '<tab>' ] || [ "$word" = '<->' ] && {
skip_next_space=1
face-no-expand tab-face "${resources[tab]}"
for ((if=0; if< ${#resources[tab]}; if++)) {
bf_e[line]+='t'
((column++))
}
return
}
[ "$word" = '</indent>' ] && {
bf_t[indent_spaces]=
bf_t[indent_spaces_e]=
return
}
((bf_t[indent]==1)) && {
bf_t[indent]=0
skip_next_space=1
bf_t[indent_spaces]=
bf_t[indent_spaces_e]=
bf_t[indent_spaces_f]=tab
case "$word" in
'&tab')
bf_t[indent_spaces]="${resources[tab]}"
for ((if=0; if< ${#resources[tab]}; if++)) {
bf_t[indent_spaces_e]+='t'
}
return
esac
for ((if=0; if< word; if++)) {
bf_t[indent_spaces]+=' '
bf_t[indent_spaces_e]+='s'
}
return
}
[ "$word" = '<indent>' ] && {
bf_t[indent]=1
skip_next_space=1
return
}
((link==2)) && {
[ "$word" = ':' ] && {
((
skip_next_space=1,
link=1
))
return
}
skip_next_space=1
linkfn+="$word "
return