Skip to content

Commit

Permalink
decode, canvas, etc.: explicitly treat CSI arguments as decimal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 6, 2022
1 parent 558322c commit 97bce68
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/canvas.sh
Expand Up @@ -655,7 +655,7 @@ function ble/canvas/trace/.process-csi-sequence {
return ;;
([ABCDEFGIZ\`ade])
local arg=0
[[ $param =~ ^[0-9]+$ ]] && arg=$param
[[ $param =~ ^[0-9]+$ ]] && ((arg=10#$param))
((arg==0&&(arg=1)))

local x0=$x y0=$y
Expand Down Expand Up @@ -730,6 +730,7 @@ function ble/canvas/trace/.process-csi-sequence {
# HVP "CSI f"
local -a params
ble/string#split-words params "${param//[^0-9]/ }"
params=("${params[@]/#/10#}")
local x1 y1
((x1=params[1]-1))
((y1=params[0]-1))
Expand Down
41 changes: 25 additions & 16 deletions src/decode.sh
Expand Up @@ -560,19 +560,23 @@ function ble-decode-char/csi/.modify-key {
function ble-decode-char/csi/.decode {
local char=$1 rex key
if ((char==126)); then
if rex='^27;([1-9][0-9]*);?([1-9][0-9]*)$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
if rex='^>?27;([0-9]+);?([0-9]+)$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# xterm "CSI 2 7 ; <mod> ; <char> ~" sequences
local key=$((BASH_REMATCH[2]&_ble_decode_MaskChar))
ble-decode-char/csi/.modify-key "${BASH_REMATCH[1]}"
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
local key=$((param2&_ble_decode_MaskChar))
ble-decode-char/csi/.modify-key "$param1"
csistat=$key
return
fi

if rex='^([1-9][0-9]*)(;([1-9][0-9]*))?$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
if rex='^>?([0-9]+)(;([0-9]+))?$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# "CSI <key> ; <mod> ~" sequences
key=${_ble_decode_csimap_tilde[BASH_REMATCH[1]]}
local param1=$((10#${BASH_REMATCH[1]}))
local param3=$((10#${BASH_REMATCH[3]}))
key=${_ble_decode_csimap_tilde[param1]}
if [[ $key ]]; then
ble-decode-char/csi/.modify-key "${BASH_REMATCH[3]}"
ble-decode-char/csi/.modify-key "$param3"
csistat=$key
return
fi
Expand All @@ -583,20 +587,22 @@ function ble-decode-char/csi/.decode {
# Note: 実は "CSI 1 ; mod u" が kp5 とする端末がある事に注意する。
local rematch1=${BASH_REMATCH[1]}
if [[ $rematch1 != 1 ]]; then
local key=$rematch1 mods=${BASH_REMATCH:${#rematch1}+1}
local key=$((10#$rematch1)) mods=$((10#${BASH_REMATCH:${#rematch1}+1}))
ble-decode-char/csi/.modify-key "$mods"
csistat=$key
fi
return
fi
elif ((char==94||char==64)); then
if rex='^[1-9][0-9]*$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
elif ((char==94||char==64)); then # ^, @
if rex='^[0-9]+$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
# rxvt "CSI <key> ^", "CSI <key> @" sequences
key=${_ble_decode_csimap_tilde[BASH_REMATCH[1]]}
local param1=$((10#${BASH_REMATCH[1]}))
local param3=$((10#${BASH_REMATCH[3]}))
key=${_ble_decode_csimap_tilde[param1]}
if [[ $key ]]; then
((key|=_ble_decode_Ctrl,
char==64&&(key|=_ble_decode_Shft)))
ble-decode-char/csi/.modify-key "${BASH_REMATCH[3]}"
ble-decode-char/csi/.modify-key "$param3"
csistat=$key
return
fi
Expand All @@ -617,19 +623,22 @@ function ble-decode-char/csi/.decode {
if rex='^([0-9]+);([0-9]+)$'; [[ $_ble_decode_csi_args =~ $rex ]]; then
# DSR(6) に対する応答 CPR "CSI Pn ; Pn R"
# Note: Poderosa は DSR(Pn;Pn) "CSI Pn ; Pn n" で返す。
ble/term/CPR/notify $((10#${BASH_REMATCH[1]})) $((10#${BASH_REMATCH[2]}))
local param1=$((10#${BASH_REMATCH[1]}))
local param2=$((10#${BASH_REMATCH[2]}))
ble/term/CPR/notify "$param1" "$param2"
csistat=$_ble_decode_KCODE_IGNORE
return
return 0
fi
fi

# pc-style "CSI 1; <mod> A" sequences
key=${_ble_decode_csimap_alpha[char]}
if [[ $key ]]; then
if rex='^(1?|1;([1-9][0-9]*))$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
ble-decode-char/csi/.modify-key "${BASH_REMATCH[2]}"
if rex='^(1?|>?1;([0-9]+))$' && [[ $_ble_decode_csi_args =~ $rex ]]; then
local param2=$((10#${BASH_REMATCH[2]}))
ble-decode-char/csi/.modify-key "$param2"
csistat=$key
return
return 0
fi
fi

Expand Down

0 comments on commit 97bce68

Please sign in to comment.