Skip to content

Commit

Permalink
edit: add the full-screen render mode
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 1, 2021
1 parent c30a0db commit 817889d
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 25 deletions.
8 changes: 6 additions & 2 deletions lib/init-term.sh
Expand Up @@ -84,10 +84,10 @@ function ble/init:term/initialize {
ble/init:term/register-varname _ble_term_xenl

# bce (background color erase)
_ble_term_bce=0
_ble_term_bce=
[[ $_ble_term_tput ]] &&
ble/init:term/tput bce:ut &>/dev/null &&
_ble_term_xenl=1
_ble_term_bce=1
ble/init:term/register-varname _ble_term_bce

# tab width
Expand Down Expand Up @@ -191,6 +191,10 @@ function ble/init:term/initialize {
[[ $_ble_term_civis == $'\e[?25l'* && $_ble_term_cvvis != *$'\e[?25h'* ]] &&
_ble_term_cvvis=$_ble_term_cvvis$'\e[?25h'

# Alternate Screen Buffer
ble/init:term/define-cap _ble_term_smcup '' smcup:ti # \e[?1049h
ble/init:term/define-cap _ble_term_rmcup '' rmcup:te # \e[?1049l

# status lines
ble/init:term/define-cap _ble_term_tsl '' tsl:ts
ble/init:term/define-cap _ble_term_fsl '' fsl:fs
Expand Down
4 changes: 2 additions & 2 deletions memo/ChangeLog.md
Expand Up @@ -17,7 +17,7 @@
- util (visible-bell): work around coordinate mismatches in subshells `#D1495` 01cfb10
- prompt: support `bleopt prompt_status_{line,align}` and `face prompt_status_line` `#D1462` cca1cbc
- prompt: fix missing height allocation for status line `#D1487` b424fa5
- prompt: support `bleopt prompt_status_align=justify` `#D1494` 0000000
- prompt: support `bleopt prompt_status_align=justify` `#D1494` c30a0db
- syntax: properly support case patterns `#D1474` `#D1475` `#D1476` 64b55b7
- keymap/vi: add `ble/keymap:vi/script/get-mode` for user-defined mode strings `#D1488` f25a6e8 462918d

Expand Down Expand Up @@ -87,7 +87,7 @@
- Makefile: fix up f7323b4: restore rule for `keymap/*.txt` `#D1496` 054e5c1
- util, etc: ensure each function to work with arbitrary `IFS` `#D1490` `#D1491` 5f9adfe
- tui, canvas (`ble/canvas/trace`): support `opts=clip` `#D1493` 61ce90c

- tui, edit: add a new render mode for full-screen applications 0000000

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel2
Expand Down
1 change: 1 addition & 0 deletions src/color.sh
Expand Up @@ -10,6 +10,7 @@ _ble_color_gflags_Invisible=0x10
_ble_color_gflags_Strike=0x20
_ble_color_gflags_Blink=0x40

_ble_color_gflags_DecorationMask=0x77
_ble_color_gflags_FgMask=0x00000000FFFFFF00
_ble_color_gflags_BgMask=0x00FFFFFF00000000
_ble_color_gflags_FgIndexed=0x0100000000000000
Expand Down
8 changes: 4 additions & 4 deletions src/decode.sh
Expand Up @@ -893,8 +893,8 @@ function ble-decode-char/csi/.decode {
local button=$((10#${BASH_REMATCH[1]}))
((_ble_term_mouse_button=button&~0x1C,
char==109&&(_ble_term_mouse_button|=0x70),
_ble_term_mouse_x=10#${BASH_REMATCH[2]},
_ble_term_mouse_y=10#${BASH_REMATCH[3]}))
_ble_term_mouse_x=10#${BASH_REMATCH[2]}-1,
_ble_term_mouse_y=10#${BASH_REMATCH[3]}-1))
local key=$_ble_decode_KCODE_MOUSE
((button&32)) && key=$_ble_decode_KCODE_MOUSE_MOVE
ble-decode-char/csi/.modify-key $((button>>2&0x07))
Expand All @@ -905,8 +905,8 @@ function ble-decode-char/csi/.decode {
if rex='^<([0-9]+);([0-9]+)$'; [[ $_ble_decode_csi_args =~ $rex ]]; then
## mouse_select
((_ble_term_mouse_button=128,
_ble_term_mouse_x=10#${BASH_REMATCH[1]},
_ble_term_mouse_y=10#${BASH_REMATCH[2]}))
_ble_term_mouse_x=10#${BASH_REMATCH[1]}-1,
_ble_term_mouse_y=10#${BASH_REMATCH[2]}-1))
local key=$_ble_decode_KCODE_MOUSE
csistat=$key
fi
Expand Down
73 changes: 56 additions & 17 deletions src/edit.sh
Expand Up @@ -250,6 +250,48 @@ bleopt/declare -v line_limit_length 10000
## 一括挿入で文字数を超過した時の動作を指定します。
bleopt/declare -v line_limit_type none

#
#------------------------------------------------------------------------------
# **** Application ****

_ble_app_render_mode=panel
function ble/application/.set-up-render-mode {
[[ $1 == "$_ble_app_render_mode" ]] && return 0
case $1 in
(panel)
ble/term/leave-altscr
ble/canvas/panel/invalidate ;;
(forms:*)
ble/term/enter-altscr
ble/util/buffer "$_ble_term_clear"
ble/util/buffer $'\e[H'
_ble_canvas_x=0 _ble_canvas_y=0 ;;
(*)
ble/util/print "ble/edit: unrecognized render mode '$1'."
return 1 ;;
esac
}
function ble/application/push-render-mode {
ble/application/.set-up-render-mode "$1" || return 1
ble/array#unshift _ble_app_render_mode "$1"
}
function ble/application/pop-render-mode {
[[ ${_ble_app_render_mode[1]} ]] || return 1
ble/application/.set-up-render-mode "${_ble_app_render_mode[1]}"
ble/array#shift _ble_app_render_mode
}
function ble/application/render {
local render=$_ble_app_render_mode
case $render in
(panel)
ble/edit/leave-command-layout # ble/edit 特有
ble/canvas/panel/render ;;
(forms:*)
ble/forms/render "${render#*:}" ;;
esac
ble/util/buffer.flush >&2
}

# canvas.sh 設定

_ble_canvas_panel_focus=0
Expand Down Expand Up @@ -1207,6 +1249,7 @@ function ble/edit/info/.construct-content {

function ble/edit/info/.clear-content {
[[ ${_ble_edit_info[2]} ]] || return 1
[[ $_ble_app_render_mode == panel ]] || return 0

local -a DRAW_BUFF=()
ble/canvas/panel#set-height.draw "$_ble_edit_info_panel" 0
Expand All @@ -1229,6 +1272,8 @@ function ble/edit/info/.render-content {

_ble_edit_info=("$x" "$y" "$content")

[[ $_ble_app_render_mode == panel ]] || return 0

local -a DRAW_BUFF=()
ble/canvas/panel/reallocate-height.draw
ble/canvas/panel#clear.draw "$_ble_edit_info_panel"
Expand Down Expand Up @@ -1855,8 +1900,7 @@ function ble-edit/attach/TRAPWINCH {
ble-edit/bind/stdout.on
ble/edit/enter-command-layout
ble/util/buffer "$_ble_term_ed"
ble/edit/leave-command-layout
ble/canvas/panel/render
ble/application/render
ble-edit/bind/stdout.off
fi
fi
Expand Down Expand Up @@ -7492,9 +7536,7 @@ function ble/builtin/read/.loop {
((timeout<0)) && timeout=
fi

ble/edit/leave-command-layout
ble/canvas/panel/render
ble/util/buffer.flush >&2
ble/application/render

# Note: ble-decode-key が中断しない為の設定 #D0998
# ble/encoding:.../is-intermediate の状態にはないと仮定して、
Expand Down Expand Up @@ -7548,9 +7590,7 @@ function ble/builtin/read/.loop {
ble/util/is-stdin-ready && continue
ble-edit/content/check-limit
ble-decode/.hook/erase-progress
ble/edit/leave-command-layout
ble/canvas/panel/render
ble/util/buffer.flush >&2
ble/application/render
done

# 入力が終わったら消すか次の行へ行く
Expand Down Expand Up @@ -8124,30 +8164,29 @@ function ble-edit/bind/.tail-without-draw {

if ((_ble_bash>=40000)); then
function ble-edit/bind/.tail {
ble/edit/leave-command-layout
ble/canvas/panel/render
ble/util/idle.do && ble/canvas/panel/render
ble/application/render
ble/util/idle.do && ble/application/render
ble/textarea#adjust-for-bash-bind # bash-4.0+
ble-edit/bind/stdout.off
}
else
function ble-edit/bind/.tail {
ble/edit/leave-command-layout
ble/canvas/panel/render # bash-3 では READLINE_LINE を設定する方法はないので常に 0 幅
ble/util/idle.do && ble/canvas/panel/render # bash-4.0+
ble/application/render
ble/util/idle.do && ble/application/render
# bash-3 では READLINE_LINE を設定する方法はないので常に 0 幅
ble-edit/bind/stdout.off
}
fi

## ble-decode.sh 用の設定
## src/decode.sh 用の設定
function ble-decode/PROLOGUE {
ble-edit/exec:gexec/restore-state
ble-edit/bind/.head
ble/decode/bind/adjust-uvw
ble/term/enter
}

## ble-decode.sh 用の設定
## src/decode.sh 用の設定
function ble-decode/EPILOGUE {
if ((_ble_bash>=40000)); then
# 貼付対策:
Expand All @@ -8162,7 +8201,7 @@ function ble-decode/EPILOGUE {

ble-edit/content/check-limit

# _ble_decode_bind_hook で bind/tail される。
# _ble_decode_bind_hook で bind/,tail される。
"ble-edit/exec:$bleopt_internal_exec_type/process" && return 0

ble-edit/bind/.tail
Expand Down
34 changes: 34 additions & 0 deletions src/util.sh
Expand Up @@ -477,8 +477,10 @@ function ble/array#pop {
if ((i$1>=0)); then
builtin eval "ret=\${$1[i$1]}"
builtin unset -v "$1[i$1]"
return 0
else
ret=
return 1
fi
}
## @fn ble/array#unshift arr value...
Expand Down Expand Up @@ -4696,6 +4698,38 @@ function ble/term/modifyOtherKeys/leave {
ble/term/modifyOtherKeys/.update "$value"
}

#---- Alternate Screen Buffer mode --------------------------------------------

_ble_term_altscr_state=
function ble/term/enter-altscr {
[[ $_ble_term_altscr_state ]] && return 0
_ble_term_altscr_state=("$_ble_canvas_x" "$_ble_canvas_y")
if [[ $_ble_term_rmcup ]]; then
ble/util/buffer "$_ble_term_smcup"
else
local -a DRAW_BUFF=()
ble/canvas/put.draw $'\e[?1049h'
ble/canvas/put-cup.draw "$LINES" 0
ble/canvas/put-ind.draw "$LINES"
ble/canvas/bflush.draw
fi
}
function ble/term/leave-altscr {
[[ $_ble_term_altscr_state ]] || return 0
if [[ $_ble_term_rmcup ]]; then
ble/util/buffer "$_ble_term_rmcup"
else
local -a DRAW_BUFF=()
ble/canvas/put-cup.draw "$LINES" 0
ble/canvas/put-ind.draw
ble/canvas/put.draw $'\e[?1049l'
ble/canvas/bflush.draw
fi
_ble_canvas_x=${_ble_term_altscr_state[0]}
_ble_canvas_y=${_ble_term_altscr_state[1]}
_ble_term_altscr_state=()
}

#---- rl variable: convert-meta -----------------------------------------------

_ble_term_rl_convert_meta_adjusted=
Expand Down

0 comments on commit 817889d

Please sign in to comment.