From c3362aefa2e762211409923cfff065541bebf9e7 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Sun, 22 May 2022 00:37:40 +0530 Subject: ble.sh & z4h addition --- .local/src/blesh/keymap/vi_digraph.sh | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .local/src/blesh/keymap/vi_digraph.sh (limited to '.local/src/blesh/keymap/vi_digraph.sh') diff --git a/.local/src/blesh/keymap/vi_digraph.sh b/.local/src/blesh/keymap/vi_digraph.sh new file mode 100644 index 0000000..dce0bf4 --- /dev/null +++ b/.local/src/blesh/keymap/vi_digraph.sh @@ -0,0 +1,51 @@ +# this script is a part of blesh (https://github.com/akinomyoga/ble.sh) under BSD-3-Clause license +_ble_keymap_vi_digraph__hook= +function ble/widget/vi_digraph/.proc { + local code=$1 + local hook=${_ble_keymap_vi_digraph__hook:-ble-decode-key} + _ble_keymap_vi_digraph__hook= + ble/decode/keymap/pop + builtin eval -- "$hook $code" +} +function ble/widget/vi_digraph/defchar { + ble/widget/vi_digraph/.proc "${KEYS[0]}" +} +function ble/widget/vi_digraph/default { + local key=${KEYS[0]} + local flag=$((key&_ble_decode_MaskFlag)) char=$((key&_ble_decode_MaskChar)) + if ((flag==_ble_decode_Ctrl&&63<=char&&char<128&&(char&0x1F)!=0)); then + ((char=char==63?127:char&0x1F)) + ble/widget/vi_digraph/.proc "$char" + return 0 + fi + ble/widget/.bell + return 0 +} +function ble-decode/keymap:vi_digraph/define { + ble-bind -f __defchar__ vi_digraph/defchar + ble-bind -f __default__ vi_digraph/default + ble-bind -f __line_limit__ nop + local lines; ble/util/mapfile lines < "$_ble_base/keymap/vi_digraph.txt" + local line field ch1 ch2 code + for line in "${lines[@]}"; do + [[ $line == ??' '* ]] || continue + ch1=${line::1} + ch2=${line:1:1} + code=${line:3} + ble-bind -f "$ch1 $ch2" "vi_digraph/.proc $code" + done +} +function ble-decode/keymap:vi_digraph/initialize { + local fname_keymap_cache=$_ble_base_cache/keymap.vi_digraph + if [[ -s $fname_keymap_cache && + $fname_keymap_cache -nt $_ble_base/keymap/vi_digraph.sh && + $fname_keymap_cache -nt $_ble_base/keymap/vi_digraph.txt ]]; then + source "$fname_keymap_cache" + return 0 + fi + ble/edit/info/immediate-show text "ble.sh: updating cache/keymap.vi_digraph..." + : >| "$fname_keymap_cache" + ble/decode/keymap#load vi_digraph dump 3>> "$fname_keymap_cache" + ble/edit/info/immediate-show text "ble.sh: updating cache/keymap.vi_digraph... done" +} +ble-decode/keymap:vi_digraph/initialize -- cgit v1.2.3