Skip to content

Commit

Permalink
edit: support "bleopt canvas_winch_action"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Oct 30, 2021
1 parent 61705bf commit 2243e91
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
17 changes: 17 additions & 0 deletions blerc
Expand Up @@ -347,6 +347,23 @@

#bleopt grapheme_cluster=extended


## This option controls the behavior when ble.sh receives SIGWINCH.
## When the value "redraw-here" is specified, ble.sh redraws the new
## prompt starting from the line of the current cursor position. When
## the value "redraw-prev" is specified, ble.sh tries to go to the
## beginning of the current prompt and overwrite the current one.
## This is similar to the behavior of GNU Readline. This possibly
## erases the output of the previous command because ble.sh tries to
## go to the beginning of the current prompt assuming that the number
## of lines of the prompt does not change on the terminal resize.
## When the value "clear" is specified, the terminal content is erased
## and the new prompt will be drawn at the top of the terminal. The
## previous terminal contents including the command outputs will be
## lost.

#bleopt grapheme_cluster=redraw-here

##-----------------------------------------------------------------------------
## User input settings

Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -76,6 +76,7 @@
- rlfunc: support nsearch widgets in `vi_nmap` keymap (requested by cornfeedhobo) `#D1651` 9a7c8b1
- prompt: support `bleopt prompt_ruler` (motivated by Barbarossa93) `#D1666` 05cf638
- prompt: fix hanging by a zero-width `prompt_ruler` `#D1673` 9033f29
- edit: support `bleopt canvas_winch_action` `#D1679` 0000000

## Changes

Expand Down
51 changes: 51 additions & 0 deletions note.txt
Expand Up @@ -5450,6 +5450,57 @@ bash_tips

2021-10-30

* edit: WINCH の際の再描画 (reported by Johann-Goncalves-Pereira, guptapriyanshu7) [#D1679]
https://github.com/akinomyoga/ble.sh/issues/142

* 前回よりも幅が小さい時には行数は同じか増える筈なので遡って削除する。

それ以外で問題が起こるのは幅が増える時という事になる。

* 幅が増えた時、前回 rprompt が表示されている時、またはプロンプトが改行され
ていない時(右端まで到達していない時) には、恐らく右端を通り越して出力した
事による折り返しは起こっていないので、配置に変化はないと仮定する。

と思って実装を確認したが WINCH に対する処理は ble/application/render によっ
て実行しているので、このレベルだと実際の描画内容に基づいて text reflow が起
こったかどうかを判定する術はない。うーん。panel::hasLineWrap の様な関数を追
加する必要がある気がする。

その様に考えると現在の描画内容に応じて遡るかどうかを決定するのは余り綺麗
でない様な気がする。やはり下手に予測しようとするよりもオプションなどで振
る舞いを一括で変更した方が良いのだろうか。

----

うーん。然し端末によっては折り返しが起こったかどうかに関わらず、一番右端に
文字があるかどうかで折り返しを判断するという実装も可能かもしれない。そう言っ
た場合にもちゃんと動く様な信頼できる方法があってそれが単純であればその方が
良い。その実装が複雑に成るのであれば、実際その様な端末が確認された訳でもな
いので、其処まで気にしなくても良い。

* info の折返し判定について。うーん。menu は別の描画機構を用いているので、
また別に処理する必要がある。試してみた感じだと menu_style=dense の時には
折り返しになっている様である。

というかこれを考えるとそもそも menu の再配置を先に実行するべきの気もする。

---

* 取り敢えず暫定的にオプション

段々と大掛かりになって来た気がする。折返しが発生しているかどうかの判定を
用いて遡るかどうか判定するのは今後対応する事にして、現在は暫定処置として
オプションで一括で対応するという方向も考えられる。

bleopt prompt_erase_previous_on_winch=xxx
bleopt textarea_winch_reposition=xxx
bleopt canvas_winch_reposition=xxx
bleopt canvas_winch_position=here|prev|
bleopt canvas_winch_redraw=here|back|clear

うーん。時間がかかっているので取り敢えずはオプションを提供する事にする。
選択肢として redraw-here, redraw-prev, clear を用意する事にした。

* edit: inputrc キャッシュの読み出しでエラーが発生する (reported by laoshaw) [#D1678]

.bashrc から単純に source ble.sh を実行すると以下のエラーが出るという事。
Expand Down
25 changes: 24 additions & 1 deletion src/edit.sh
Expand Up @@ -247,6 +247,7 @@ bleopt/declare -v line_limit_type none
# **** Application ****

_ble_app_render_mode=panel
_ble_app_winsize=()
function ble/application/.set-up-render-mode {
[[ $1 == "$_ble_app_render_mode" ]] && return 0
case $1 in
Expand Down Expand Up @@ -281,6 +282,7 @@ function ble/application/render {
(forms:*)
ble/forms/render "${render#*:}" ;;
esac
_ble_app_winsize=("$COLUMNS" "$LINES")
ble/util/buffer.flush >&2
}

Expand Down Expand Up @@ -2305,6 +2307,8 @@ function ble-edit/eval-IGNOREEOF {
fi
}

bleopt/declare -n canvas_winch_action redraw-here

function ble-edit/attach/TRAPWINCH {
local FUNCNEST=
local IFS=$_ble_term_IFS
Expand All @@ -2326,8 +2330,27 @@ function ble-edit/attach/TRAPWINCH {
ble/util/joblist.check ignore-volatile-jobs
local size=$LINES:$COLUMNS
[[ $size == "$old_size" ]] && break

old_size=$size

case $bleopt_canvas_winch_action in
(clear)
# 全消去して一番上から再描画
ble/util/buffer "$_ble_term_clear" ;;
(redraw-here)
# 現在位置から再描画 (幅が減った時は前のコマンドの出力結果を破壊しな
# いので戻る)
if ((COLUMNS<_ble_app_winsize[0])); then
local -a DRAW_BUFF=()
ble/canvas/panel#goto.draw 0 0 0
ble/canvas/bflush.draw
fi ;;
(redraw-prev)
# 前回の開始相対位置が変化していないと仮定して戻って再描画
local -a DRAW_BUFF=()
ble/canvas/panel#goto.draw 0 0 0
ble/canvas/bflush.draw ;;
esac

ble/canvas/panel/invalidate height # 高さの再確保も含めて。
ble/application/render
done
Expand Down

0 comments on commit 2243e91

Please sign in to comment.