diff --git a/lib/core-complete.sh b/lib/core-complete.sh index 638a3939..ec07d4c3 100644 --- a/lib/core-complete.sh +++ b/lib/core-complete.sh @@ -5767,7 +5767,7 @@ function ble/complete/auto-complete/.search-history-heavy { _ble_complete_ac_history_needle=$needle ((ext)) && return "$ext" - ble/history/get-editted-entry -v ret "$index" + ble/history/get-edited-entry -v ret "$index" return 0 } @@ -6553,7 +6553,7 @@ function ble/complete/dabbrev/.search.fib { local dabbrev_pos=$pos local dabbrev_current_match=${_ble_edit_str:_ble_edit_mark:_ble_edit_ind-_ble_edit_mark} - local line; ble/history/get-editted-entry -v line "$index" + local line; ble/history/get-edited-entry -v line "$index" if ! ble/complete/dabbrev/search-in-history-entry "$line" "$index"; then ((index--,dabbrev_pos=0)) diff --git a/lib/test-canvas.sh b/lib/test-canvas.sh index bef24727..dee172f4 100644 --- a/lib/test-canvas.sh +++ b/lib/test-canvas.sh @@ -35,7 +35,7 @@ function ble/test:canvas/trace.contra { #------------------------------------------------------------------------------ # from lib/test-canvas.sh -ble/test/start-section 'ble/canvas/trace (relative:confine:measure-bbox)' 10 +ble/test/start-section 'ble/canvas/trace (relative:confine:measure-bbox)' 12 # test1 @@ -270,4 +270,45 @@ if [[ $_ble_test_canvas_contra ]]; then ble/test 'echo "bbox:$x1,$y1-$x2,$y2"' stdout='bbox:2,0-6,1' fi +#------------------------------------------------------------------------------ +# trace-text + +ble/test/start-section 'ble/canvas/trace-text' 11 + +( + sgr0= sgr1= + + # truncate + lines=1 cols=10 _ble_term_xenl=1 x=0 y=0 + ble/test 'ble/canvas/trace-text "Hello World";ret="$x,$y,$ret"' ret='10,0,Hello Worl' + lines=1 cols=10 _ble_term_xenl= x=0 y=0 + ble/test 'ble/canvas/trace-text "Hello World";ret="$x,$y,$ret"' ret='9,0,Hello Wor' + lines=1 cols=10 _ble_term_xenl=1 x=3 y=0 + ble/test 'ble/canvas/trace-text "Hello World";ret="$x,$y,$ret"' ret='10,0,Hello W' + + # 折返し + lines=3 cols=10 _ble_term_xenl=1 x=3 y=0 + ble/test 'ble/canvas/trace-text "Hello Bash World";ret="$x,$y,$ret"' ret='9,1,Hello Bash World' + + # 全角文字の折返し (nonewline on/off) + lines=3 cols=10 _ble_term_xenl=1 x=3 y=0 + ble/test 'ble/canvas/trace-text "これは日本語の文章";ret="$x,$y,$ret"' ret=$'2,2,これは\n日本語の文章' + lines=3 cols=10 _ble_term_xenl=1 x=3 y=0 + ble/test 'ble/canvas/trace-text "これは日本語の文章" nonewline;ret="$x,$y,$ret"' ret='2,2,これは 日本語の文章' + + # 行末での改行 (nonewline) + lines=3 cols=10 _ble_term_xenl=1 x=0 y=0 + ble/test 'ble/canvas/trace-text "これは日本";ret="$x,$y,$ret"' ret=$'0,1,これは日本\n' + lines=3 cols=10 _ble_term_xenl=0 x=0 y=0 + ble/test 'ble/canvas/trace-text "これは日本";ret="$x,$y,$ret"' ret=$'0,1,これは日本' + lines=3 cols=10 _ble_term_xenl=1 x=0 y=0 + ble/test 'ble/canvas/trace-text "これは日本" nonewline;ret="$x,$y,$ret"' ret=$'10,0,これは日本' + lines=3 cols=10 _ble_term_xenl=0 x=0 y=0 + ble/test 'ble/canvas/trace-text "これは日本" nonewline;ret="$x,$y,$ret"' ret=$'0,1,これは日本' + + # 改行は ^J と表示 + lines=1 cols=12 _ble_term_xenl=1 x=0 y=0 + ble/test $'ble/canvas/trace-text "あ\nい\nう" external-sgr;ret="$x,$y,$ret"' ret=$'10,0,あ^Jい^Jう' +) + ble/test/end-section diff --git a/lib/vim-airline.sh b/lib/vim-airline.sh index f389c455..95bebd2e 100644 --- a/lib/vim-airline.sh +++ b/lib/vim-airline.sh @@ -268,7 +268,8 @@ function ble/prompt/unit:{vim-airline-section}/update { ble/prompt/unit/add-hash '$_ble_lib_vim_airline_mode_data' ble/prompt/unit/add-hash "\$$ref_ps" local trace_opts=confine:relative:noscrc:face0="$face":ansi:measure-bbox:measure-gbox - LINES=1 COLUMNS=$cols ble/prompt/unit:{section}/update "$prefix" "${!ref_ps}" "$trace_opts" + local prompt_rows=1 prompt_cols=$cols # Note: cols は \q{lib/vim-airline} で設定される + ble/prompt/unit:{section}/update "$prefix" "${!ref_ps}" "$trace_opts" } function ble/prompt/unit:_ble_lib_vim_airline_section_a/update { ble/prompt/unit:{vim-airline-section}/update a; } function ble/prompt/unit:_ble_lib_vim_airline_section_b/update { ble/prompt/unit:{vim-airline-section}/update b; } @@ -355,6 +356,5 @@ function ble/prompt/backslash:lib/vim-airline { } bleopt keymap_vi_mode_show= -bleopt keymap_vi_mode_update_prompt=1 bleopt prompt_status_line='\q{lib/vim-airline}' bleopt prompt_status_align=$'justify=\r' diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md index 5ccb207d..843529f4 100644 --- a/memo/ChangeLog.md +++ b/memo/ChangeLog.md @@ -43,6 +43,7 @@ - util (`ble/gdict`): refactor `#D1569` 7732eed - vim-airline: support `bleopt vim_airline_theme` `#D1589` 0000000 - prompt: track dependencies and detect changes `#D1590` `#D1591` 0000000 + - prompt: preserve `LINES` and `COLUMNS` for custom sequences `#D1592` 0000000 - util, color: refactor configuration interfaces (`bleopt`, `blehook`, `ble-face`) `#D1568` c94d292 - color: support new face setting function `ble-face` - util (`bleopt`): support option `-r` and `-u` and wildcards in option names diff --git a/note.txt b/note.txt index d3eba554..08fdb6c5 100644 --- a/note.txt +++ b/note.txt @@ -4696,6 +4696,260 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2021-06-09 + + * vim-airline を blerc からロードする様にすると余分な行が表示される [#D1592] + + | 調べると \q{lib/vim-airline} の中で問題が発生している。更に調べると + | ble/prompt/unit:_ble_lib_vim_airline_mode/update の中の + | ble/history/get-entry により何かが出力されている。出力内容を調べるとエスケー + | プシーケンスを出力している。エスケープシーケンスの出処を調べる。 + | + | | ble-attach + | | ble/term/initialize + | | ble/term/test-DECSTBM + | | ESC7 + | | ESC[1;2r + | | ESC[2;1H + | | ESC[1B + | | ESC[6n + | | ESC[;r + | | ESC8 + | | ble/decode/attach + | | ESC[>c + | + | 上記の出力内容は単に buffer に残っていただけ。 + | これらは特に何も問題を起こさない。 + | 以下の内容が問題を起こしている。 + | + | | ESC(BESC[m^MESC[2KESC[1M + | | ESC(BESC[mESC[30C + | + | もっと分かり易く書くと以下の形になる。 + | + | SGR0 CR + | EL(2) DL(1) ... put-dl.draw + | LF SGR0 CUR(30) + | + | EL(2) DL(1) の組み合わせは put-dl.draw が使っている物である。put-dl.draw に + | 仕掛けて FUNCNAME[@] を出力してみると以下の結果になった。 + | + | | ble/canvas/put-dl.draw + | | ble/canvas/panel#set-height.draw + | | ble/canvas/panel/reallocate-height.draw + | | ble/edit/info/.render-content + | | ble/edit/info/show + | | ble/edit/info/immediate-show + | | ble-edit/history/history-message.hook + | | blehook/invoke + | | ble/history:bash/load + | | ble/history:bash/initialize + | | ble/history/initialize + | | ble/history/get-entry + | | ble/prompt/unit:_ble_lib_vim_airline_mode/update + | | ble/prompt/unit#update + | | ble/prompt/backslash:lib/vim-airline + | | ble/prompt/backslash:q + | | ble/function#try + | | ble/prompt/.process-backslash + | | ble/prompt/process-prompt-string + | | ble/prompt/.instantiate + | | ble/prompt/unit:{section}/update + | | ble/prompt/unit:_ble_prompt_status/update + | | ble/prompt/unit#update + | | ble/prompt/update + | | ble/textarea#render + | | ble/textarea#redraw + | | ble-attach + | | ble/base/attach-from-PROMPT_COMMAND + | | ble/function#lambda/0 + | + | つまり、ble-attach から呼び出したプロンプト再描画の中で vim-airline が呼び + | 出されて、その中での modified の判定の為に get-edited-entry が呼び出されて + | いるという事。get-edited-entry は内部で ble/edit/info/immediate-show を呼び + | 出して居て、結果として何らかの不都合が生じて計算がずれる。 + | + | a reject: 一つの可能性として DRAW_BUFF に出した出力が中途半端になっている事 + | によって問題が生じているのではないかと思ったが、DRAW_BUFF を覗いた感じだ + | と特に何も登録はされていない。なので出力のバッファリングが輻輳していると + | いう可能性は考えなくて良い。 + | + | b reject: 或いは buffer に既に入っている内容が問題になっている? と思ったが + | そうでもない。その場で buffer.flush して、get-edited-entry の出力だけ潰し + | ても特に問題は生じない。 + | + | c reject: 或いは端末に繋がっている時だけしか問題のある出力をしない可能性は + | あるだろうか。つまり e.log に出力された内容を今は観察しているが、実際には + | 端末に繋がっている時に限りもっと色々な出力をしている。具体的には非端末の + | 時にはble/history/initialize は info で何も表示しない可能性。一旦 + | get-edited-entry の直後で sleep を入れて何か表示されるのか確認してみる事 + | にする + | + | →特に何も表示されない。恐らく端末に繋がっているかどうかの違いで振る舞い + | が変わるという訳ではないと思われる。 + | + | →実際に非端末の出力先として 2> >(cat) を使った場合にも問題が再現する。と + | いう訳なので観察している出力で確かに問題が発生しているのだという事。 + | + | d reject: もう一つの可能性は後で遅延して履歴読み込みが完了した時に info を + | 削除する時に問題が生じているという可能性。 + | + | →これは関係ない。実際に get-edited-entry の stderr を潰せば問題は生じな + | くなっているし、その imbalance が生じる事によって表示が偶々正しくなってい + | るという様には考えがたい。 + | + | e reject: 或いは get-edited-entry を呼び出した直後に buffer に入っている内 + | 容が後になって問題を起こしている可能性? → 確認したが、get-edited-entry + | 直後には buffer は何も入っていない。これは関係ない。 + | + | f もう一つの可能性として全体更新が中途半端になっている事によって座標計算が + | ずれているのではないかという事。然し、問題が生じているのは ble-attach か + | ら直接 ble/textarea#redraw を呼び出した時であって、これは panel/render で + | はないので、textarea と info の描画は独立の筈である。 + | + | となって来ると、info から呼び出した set-height の実装か、或いは位置計算に問 + | 題が生じているという事になる気がする。出力内容と _ble_canvas_x,y の状態につ + | いて確認する必要がある。 + | + | | _ble_lib_vim_airline_mode + | | declare -- _ble_canvas_x="30" + | | declare -- _ble_canvas_y="0" + | | declare -- _ble_canvas_excursion="" + | | ^[(B^[[m^M^[[2K^[[1M + | | ^[(B^[[m^[[30Cdeclare -- _ble_canvas_x="30" + | | declare -- _ble_canvas_y="0" + | | declare -- _ble_canvas_excursion="" + | + | うーん。これを見る限りは canvas 的にはカーソル位置は動かしていないつもりな + | のである。改めてこのシーケンスがどの様に生成されているか確認する。 + | + | | _ble_lib_vim_airline_mode + | | declare -- _ble_canvas_x="30" + | | declare -- _ble_canvas_y="0" + | | declare -- _ble_canvas_excursion="" + | | declare -a _ble_canvas_panel_height=([0]="1" [1]="0" [2]="0") + | | [delta=-1,opts=] + | | ^[(B^[[m^M^[[2K^[[1M + | | ^[(B^[[m^[[30C[delta=0,opts=] + | | declare -- _ble_canvas_x="30" + | | declare -- _ble_canvas_y="0" + | | declare -- _ble_canvas_excursion="" + | | declare -a _ble_canvas_panel_height=([0]="0" [1]="0" [2]="0") + | + | うーん。どうやら panel#0 の高さが潰れてしまっている様子。然し、高さが潰れて + | しまっているからと言ってカーソルの位置が変わるのは変である。うーん。 + | set-height までは別に座標計算が変な事にはなっていない様だ。set-height を抜 + | けた後で座標位置を復元している箇所があって、其処で計算がずれているという事 + | の気がする。 + | + | うーん。分かった。以下の様な状態になっている。x=0 y=0 content=$'\n' になっ + | ている。content に改行が入っているのだから、本来は y=1 でなければならない筈 + | である。何故この様な内容が生成されるのか確認する必要がある。 + | + | declare -a _ble_edit_info=([0]="0" [1]="0" [2]=$'\n') + | + | 更に調べると ble/edit/info/.construct-content text 'loading history...' の + | 構築結果がその様になっている。 + | + | % 更に辿ると ble/canvas/trace-text がまるで動かなくなっている。何故。。。 + | % + | % x=0 y=0; ble/canvas/trace-text 'ABC'; echo "($x,$y)[$ret]" + | % + | % とすると x=0 y=0 ret=$'\n\n' 二重改行になってしまっている。これは大事。 + | % いつからこの様な事態になっていたのだろう。今まで気づかなかったのも不思 + | % 議である。というより、殆どの機能で着色を使っているので trace-text は余 + | % り使われてこなかったのである。更に遡って調べてみると v0.3.0 の時点で既 + | % に trace-text は動作していなかった様だ。0.2 系列では + | % ble-edit/info/.construct-text という関数で現在の実装とは全く異なる物凄 + | % く単純な実装だった。この時は勿論問題はなかった。 + | % + | % まとめると ble/canvas/trace-text は可也昔から壊れていた。v0.3.0 の時点 + | % で駄目。一方で v0.2 の段階ではその前身である + | % ble-edit/info/.construct-text だったが、これはとても単純な関数でまた問 + | % 題も存在しなかった…と思ったが微妙に関数の仕様を勘違いしていた。 + | % trace-text は領域の大きさを外部から与える必要があったのである。 + + 結局何が起こっていたのかというと、ble/edit/info/.construct-content に於いて、 + ble/edit/info/.initialize-size が lines=0 を返して、それに対して + ble/canvas/trace-text が変な振る舞いをしていたという事。 + + 問題が3つある。 + + x fixed: ble/canvas/trace-text は lines が限界に達しているのにも関わらず改 + 行を末尾に付加してしまう。これは個別に対応した。 + + x ok: 改行を付加したのにも関わらず y を増やしていない。これは trace-text を + ほぼ再実装した結果発生しなくなった。何故元の実装でこれが発生していたのか + は分からない。そもそも改行 \n ですら trace-text では ^J と表示される。 + + →これは分かった。ble/canvas/trace-text/.put-nl-if-eol が put-simple の中 + と終了時の2回呼び出されている。cols=0 の時には一回実行したとしてもまだ行 + 末にいると判定されるので二回実行されるのである。 + + x fixed: ble/canvas/trace-text を初期化する前に、何故か + ble/edit/info/.initialize-size が lines=0 を結果として与えている。 + + 中では ble/canvas/panel/layout/.get-available-height を呼び出している。 + + % 中で戻り値を確認すると ret=9730ret という謎の値が生成されている。と思っ + % たがこれは debug コードのミスだった。 + + 改めて調べるとこの時点で 0 が生成されている。 + + declare -a mins=([0]="1" [1]="0" [2]="0" [3]="0") + declare -a maxs=([0]="1" [1]="0" [2]="1" [3]="0") + declare -a heights=([0]="0" [1]="0" [2]="0" [3]="0") + declare -- index="2" + declare -- ret="0" + + うーん。この時点で maxs に LINES が設定されて欲しいが 1 になってしまって + いる。うーん。原因が分かった。プロンプトの処理を行っている最中は LINES + COLUMNS を通して描画範囲の大きさを指定しているが、これだと本来のレイアウ + ト処理に影響を与えてしまう。 + + 取り敢えずは ble/canvas/trace は引き続き LINES COLUMNS を参照する事にして + おいて、その外側の instantiate 等については LINES/COLUMNS は別変数経由で + 指定する事にする。 + + 書き換えた。これで現在 LINES= 及び COLUMNS= を設定している箇所は全て + ble/canvas/trace の呼び出しか、または ble/textmap#update の呼び出しに限ら + れる事となった。 + + x fixed: 何故 panel#0 の高さが潰れてしまうのか。本来は此処で高さを変更する + 必要はないのではないか。というより高さ 1 の儘であるべきなのではないのか。 + 特に ble/prompt/update の段階では。 + + これは LINES=1 を設定していた為に visible-bell 専用の行が引き算されて 0 + になってしまっているという事だろう。LINES=1 の時には visible-bell も表示 + しない様に修正する必要がある。もしくは visible-bell の表示方法を変更して、 + 即座に行送りにする。と思ったが、visible-bell を表示した時点で現在の表示内 + 容を保持する事ができないので、やはり LINES=1 の時には visible-bell は表示 + しない様に変更するのが適切だろう。 + + * done: この問題とは独立に get-edited-entry に於いて最新の値を参照している + 時には履歴をロードせずに済ませる様に実装する様にした方が良い。実装した。 + 取り敢えず vim-airline の modified はこれでもちゃんと動いている。 + + * done: trace-text のテストを拡充 + + x 2021-06-08 airline: ロード時に keymap_vi_mode_show=1 に再設定すると表示が + ずれてモード行の位置にプロンプトの残像が残ってしまう + + →これは #D1592 を修正したら再現しなくなった。 + + x 2021-06-08 airline: status 行を表示している時の空コマンド行による改行がス + ムーズではない。 + + →これも #D1592 の修正で再現しなくなった。LINES/COLUMNS によりレイアウト + 再構成が毎回走っていたという事なのだろうか。何れにしても空コマンド行によ + る改行で status line を出した儘にしているかどうかだけ、実装について確認す + るのが良い。 + + →確認した。textarea (panel#0) の再描画しかしていないので statusline 等に + ついてはその儘の筈。但しプロンプトの再計算が入るので結局再描画はされる様 + な気もしないでもない。うまく cache が働いていれば dirty にもならずに再描 + 画もなくそのまま前の表示が使われるのではないかという気がする。 + 2021-06-07 * prompt: [最適化] 依存関係追跡の整理・最適化 [#D1591] diff --git a/src/canvas.sh b/src/canvas.sh index 5381e096..373ca496 100644 --- a/src/canvas.sh +++ b/src/canvas.sh @@ -1636,59 +1636,58 @@ function ble/canvas/trace { ## function ble/canvas/trace-text/.put-simple { local nchar=$1 + ((nchar)) || return 0 - if ((y+(x+nchar)/colscols:x>=cols)&&(y++,x-=cols))) - else - # 画面をはみ出る場合 - flag_overflow=1 - out=$out${2::lines*cols-(y*cols+x)} - ((x=cols,y=lines-1)) - ble/canvas/trace-text/.put-nl-if-eol - fi + local nput=$((cols*lines-!_ble_term_xenl-(y*cols+x))) + ((nput>0)) || return 1 + ((nput>nchar)) && nput=$nchar + out=$out${2::nput} + ((x+=nput,y+=x/cols,x%=cols)) + ((_ble_term_xenl&&x==0&&(y--,x=cols))) + ((nput==nchar)); return $? } ## @fn x y cols out ; ble/canvas/trace-text/.put-atomic ( w char )+ ; x y out ## 指定した文字を out に追加しつつ、現在位置を更新します。 +## 範囲に収まり切らない時に失敗します。 function ble/canvas/trace-text/.put-atomic { local w=$1 c=$2 + # 収まらない時は skip + ((y*cols+x+w<=cols*lines-!_ble_term_xenl)) || return 1 + # その行に入りきらない文字は次の行へ (幅 w が2以上の文字) if ((x=lines)); then - # 画面に入らない時は表示しない - flag_overflow=1 - if [[ :$opts: == *:nonewline:* ]]; then - ble/string#reserve-prototype $((cols-x)) - out=$out${_ble_string_prototype::cols-x} - ((x=cols)) - else - out=$out$'\n' - ((y++,x=0)) - fi - return 0 + if [[ :$opts: == *:nonewline:* ]]; then + ble/string#reserve-prototype $((cols-x)) + out=$out${_ble_string_prototype::cols-x} + ((x=cols)) + else + out=$out$'\n' + ((y++,x=0)) fi - ble/string#reserve-prototype $((cols-x)) - out=$out${_ble_string_prototype::cols-x} - ((x=cols)) fi - out=$out$c + # w!=0 のとき行末にいたら次の行へ暗黙移動 + ((w&&x==cols&&(y++,x=0))) - # 移動 - if ((w>0)); then - ((x+=w)) - while ((_ble_term_xenl?x>cols:x>=cols)); do - ((y++,x-=cols)) - done + # 改行しても尚行内に収まらない時は ## で代用 + local limit=$((cols-(y+1==lines&&!_ble_term_xenl))) + if ((x+w>limit)); then + ble/string#reserve-prototype $((limit-x)) + local pad=${_ble_string_prototype::limit-x} + out=$out$sgr1${pad//?/'#'}$sgr0 + x=$limit + ((y+1=lines*cols)) && break + fi && ((y*cols+x=lines)) && flag_overflow=1 [[ ! $flag_overflow ]] } # Note: suppress LC_COLLATE errors #D1205 #D1262 #1341 #D1440 @@ -2336,7 +2332,7 @@ _ble_canvas_panel_height=(1 0 0) _ble_canvas_panel_focus= _ble_canvas_panel_vfill= _ble_canvas_panel_bottom= # 現在下部に居るかどうか -_ble_canvas_panel_tmargin=1 # for visible-bell +_ble_canvas_panel_tmargin='LINES!=1?1:0' # for visible-bell ## @fn ble/canvas/panel/layout/.extract-heights ## @arr[out] mins maxs @@ -2736,7 +2732,7 @@ function ble/canvas/panel/render { ## @fn ble/canvas/panel/ensure-terminal-top-line ## visible-bell で使う為 function ble/canvas/panel/ensure-tmargin.draw { - local tmargin=$_ble_canvas_panel_tmargin + local tmargin=$((_ble_canvas_panel_tmargin)) ((tmargin>LINES)) && tmargin=$LINES ((tmargin>0)) || return 0 diff --git a/src/edit.sh b/src/edit.sh index 6c05d79b..d9bf6703 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -1059,6 +1059,7 @@ function ble/prompt/.get-keymap-for-current-mode { ## @var[in,out] x1 x2 y1 y2 ## opts に measure-bbox を指定した時。 ## @var[in,out] "${_ble_prompt_cache_vars[@]}" +## @var[in,out] prompt_rows prompt_cols ## function ble/prompt/.instantiate { trace_hash= esc= x=0 y=0 g=0 lc=32 lg=0 @@ -1105,11 +1106,16 @@ function ble/prompt/.instantiate { # Note: "ESC k ... ESC \" 等を対象とするプロンプト文字列は trace 不要 x=0 y=0 g=0 lc=32 lg=0 esc=$expanded - elif trace_hash=$opts:$LINES,$COLUMNS:$expanded; [[ $trace_hash != "$trace_hash0" ]]; then + elif + local rows=${prompt_rows:-${LINES:-25}} + local cols=${prompt_cols:-${COLUMNS:-80}} + trace_hash=$opts:$rows,$cols:$expanded + [[ $trace_hash != "$trace_hash0" ]] + then local trace_opts=$opts:prompt [[ $bleopt_internal_suppress_bash_output ]] || trace_opts=$trace_opts:left-char x=0 y=0 g=0 lc=32 lg=0 - ble/canvas/trace "$expanded" "$trace_opts"; local traced=$ret + LINES=$rows COLUMNS=$cols ble/canvas/trace "$expanded" "$trace_opts"; local traced=$ret ((lc<0&&(lc=0))) esc=$traced return 0 @@ -1161,6 +1167,7 @@ function ble/prompt/unit:{section}/get { ## プロンプト文字列の処理のみを行います。 ## これは制御列など端末に出力しない内容を解析するのに使います。 ## +## @param[in] prompt_rows prompt_cols function ble/prompt/unit:{section}/update { local prefix=$1 ps=$2 opts=$3 @@ -1222,7 +1229,8 @@ function ble/prompt/unit:_ble_prompt_rps1/update { local cols=${COLUMNS-80} local ps1x=${_ble_prompt_ps1_data[3]} local ps1y=${_ble_prompt_ps1_data[4]} - LINES=$((ps1y+1)) ble/prompt/unit:{section}/update _ble_prompt_rps1 "$prompt_rps1" confine:relative:right:measure-gbox || return 1 + local prompt_rows=$((ps1y+1)) prompt_cols=$cols + ble/prompt/unit:{section}/update _ble_prompt_rps1 "$prompt_rps1" confine:relative:right:measure-gbox || return 1 local esc=${_ble_prompt_rps1_data[8]} width= if [[ $esc ]]; then @@ -1236,7 +1244,8 @@ function ble/prompt/unit:_ble_prompt_rps1/update { function ble/prompt/unit:_ble_prompt_xterm_title/update { ble/prompt/unit/add-hash '$bleopt_prompt_xterm_title' - LINES=1 ble/prompt/unit:{section}/update _ble_prompt_xterm_title "$bleopt_prompt_xterm_title" confine:no-trace || return 1 + local prompt_rows=1 + ble/prompt/unit:{section}/update _ble_prompt_xterm_title "$bleopt_prompt_xterm_title" confine:no-trace || return 1 local esc=${_ble_prompt_xterm_title_data[8]} [[ $esc ]] && esc=$'\e]0;'${esc//[! -~]/'#'}$'\a' @@ -1246,7 +1255,8 @@ function ble/prompt/unit:_ble_prompt_xterm_title/update { function ble/prompt/unit:_ble_prompt_screen_title/update { ble/prompt/unit/add-hash '$bleopt_prompt_screen_title' - LINES=1 ble/prompt/unit:{section}/update _ble_prompt_screen_title "$bleopt_prompt_screen_title" confine:no-trace || return 1 + local prompt_rows=1 + ble/prompt/unit:{section}/update _ble_prompt_screen_title "$bleopt_prompt_screen_title" confine:no-trace || return 1 local esc=${_ble_prompt_screen_title_data[8]} [[ $esc ]] && esc=$'\ek'${esc//[! -~]/'#'}$'\e\\' @@ -1256,7 +1266,8 @@ function ble/prompt/unit:_ble_prompt_screen_title/update { function ble/prompt/unit:_ble_prompt_term_status/update { ble/prompt/unit/add-hash '$bleopt_prompt_term_status' - LINES=1 ble/prompt/unit:{section}/update _ble_prompt_term_status "$bleopt_prompt_term_status" confine:no-trace || return 1 + local prompt_rows=1 + ble/prompt/unit:{section}/update _ble_prompt_term_status "$bleopt_prompt_term_status" confine:no-trace || return 1 local esc=${_ble_prompt_term_status_data[8]} if [[ $esc ]]; then @@ -1279,7 +1290,8 @@ function ble/prompt/unit:_ble_prompt_status/update { [[ $bleopt_prompt_status_align =~ $rex ]] && trace_opts=$trace_opts:$BASH_REMATCH - LINES=1 COLUMNS=$cols ble/prompt/unit:{section}/update _ble_prompt_status "$ps" "$trace_opts" || return 1 + local prompt_cols=1 prompt_cols=$cols + ble/prompt/unit:{section}/update _ble_prompt_status "$ps" "$trace_opts" || return 1 # tailor local esc=${_ble_prompt_status_data[8]} @@ -1395,8 +1407,11 @@ function ble/prompt/update { ((_ble_prompt_version++)) fi + # initialize variables ble/history/update-position local prompt_hashref_base='$_ble_prompt_version' + local prompt_rows=${LINES:-25} + local prompt_cols=${COLUMNS:-80} local "${_ble_prompt_cache_vars[@]/%/=}" # #D1570 OK ble/prompt/unit#update _ble_prompt_ps1 && dirty=1 @@ -1559,8 +1574,8 @@ function ble/edit/info/.render-content { ble/canvas/panel#clear.draw "$_ble_edit_info_panel" ble/canvas/panel#goto.draw "$_ble_edit_info_panel" ble/canvas/put.draw "$content" - ble/canvas/bflush.draw ((_ble_canvas_y+=y,_ble_canvas_x=x)) + ble/canvas/bflush.draw } _ble_edit_info_default=(0 0 "") @@ -3537,7 +3552,7 @@ function ble/widget/insert-arg.impl { ((index<0&&(index=0))) fi - local entry; ble/history/get-editted-entry "$index" + local entry; ble/history/get-edited-entry "$index" builtin history -s -- "$entry" local hist_expanded if ble-edit/hist_expanded.update '!!:'"$nth" && @@ -4366,7 +4381,7 @@ function ble/widget/forward-history-line.impl { return "$?" fi - local entry; ble/history/get-editted-entry "$index" + local entry; ble/history/get-edited-entry "$index" if [[ $entry == *$'\n'* ]]; then local ret; ble/string#count-char "$entry" $'\n' if ((rest<=ret)); then @@ -5076,6 +5091,8 @@ function ble-edit/exec/print-PS0 { if [[ $PS0 ]]; then local version=$COLUMNS,$_ble_edit_lineno,$_ble_history_count,$_ble_edit_CMD local prompt_hashref_base='$version' + local prompt_rows=${LINES:-25} + local prompt_cols=${COLUMNS:-80} local "${_ble_prompt_cache_vars[@]/%/=}" # #D1570 OK ble/prompt/unit#update _ble_prompt_ps10 ble/prompt/unit:{section}/get _ble_prompt_ps10 @@ -6219,12 +6236,12 @@ function ble-edit/history/goto { fi # store - ble/history/set-editted-entry "$index0" "$_ble_edit_str" + ble/history/set-edited-entry "$index0" "$_ble_edit_str" ble/history/onleave.fire # restore ble/history/set-index "$index1" - local entry; ble/history/get-editted-entry -v entry "$index1" + local entry; ble/history/get-edited-entry -v entry "$index1" ble-edit/content/reset "$entry" history # point @@ -6781,7 +6798,7 @@ function ble-edit/isearch/.next-history.fib { # 見付かった場合 # 一致範囲 beg-end を取得 - local str; ble/history/get-editted-entry -v str "$index" + local str; ble/history/get-edited-entry -v str "$index" if [[ $needle ]]; then if [[ $_ble_edit_isearch_dir == - ]]; then local prefix=${str%"$needle"*} @@ -7127,7 +7144,7 @@ function ble-edit/nsearch/.goto-match { elif [[ :$opts: == *:action=load:* ]]; then local old_index; ble/history/get-index -v old_index if ((index!=old_index)); then - local line; ble/history/get-editted-entry -v line "$index" + local line; ble/history/get-edited-entry -v line "$index" ble-edit/content/reset-and-check-dirty "$line" fi else diff --git a/src/history.sh b/src/history.sh index e7426a3a..8354b05a 100644 --- a/src/history.sh +++ b/src/history.sh @@ -1470,19 +1470,25 @@ function ble/history/set-index { ((${_ble_history_prefix:-_ble}_history_index=_ble_history_INDEX)) } function ble/history/get-entry { - ble/history/initialize local __var=entry [[ $1 == -v ]] && { __var=$2; shift 2; } - builtin eval "$__var=\${${_ble_history_prefix:-_ble}_history[\$1]}" + if [[ $_ble_history_prefix$_ble_history_load_done ]]; then + builtin eval -- "$__var=\${${_ble_history_prefix:-_ble}_history[\$1]}" + else + builtin eval -- "$__var=" + fi } -function ble/history/get-editted-entry { - ble/history/initialize +function ble/history/get-edited-entry { local __var=entry [[ $1 == -v ]] && { __var=$2; shift 2; } - builtin eval "$__var=\${${_ble_history_prefix:-_ble}_history_edit[\$1]}" + if [[ $_ble_history_prefix$_ble_history_load_done ]]; then + builtin eval -- "$__var=\${${_ble_history_prefix:-_ble}_history_edit[\$1]}" + else + builtin eval -- "$__var=\$_ble_edit_str" + fi } -## @fn ble/history/set-editted-entry index str -function ble/history/set-editted-entry { +## @fn ble/history/set-edited-entry index str +function ble/history/set-edited-entry { ble/history/initialize local index=$1 str=$2 local code=' diff --git a/src/util.sh b/src/util.sh index d6d2ecd3..acb8a673 100644 --- a/src/util.sh +++ b/src/util.sh @@ -5111,6 +5111,10 @@ function ble/term/visible-bell { local message=$1 opts=$2 message=${message:-$bleopt_vbell_default_message} + # Note: 1行しかない時は表示しない。0行の時は全てログに行くので出力する。空文 + # 字列の時は設定されていないだけなので表示する。 + ((LINES==1)) && return 0 + if ble/is-function ble/canvas/trace-text; then ble/term/visible-bell:canvas/init "$message" else