Skip to content

Commit

Permalink
prompt: support "status line"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 20, 2021
1 parent a56873f commit cca1cbc
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 52 deletions.
1 change: 1 addition & 0 deletions README-ja_JP.md
Expand Up @@ -288,6 +288,7 @@ ble-color-setface menu_filter_input fg=16,bg=229
ble-color-setface vbell reverse
ble-color-setface vbell_erase bg=252
ble-color-setface vbell_flash fg=green,reverse
ble-color-setface prompt_status_line fg=231,bg=240

# 構文着色の設定
ble-color-setface syntax_default none
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -279,6 +279,7 @@ ble-color-setface menu_filter_input fg=16,bg=229
ble-color-setface vbell reverse
ble-color-setface vbell_erase bg=252
ble-color-setface vbell_flash fg=green,reverse
ble-color-setface prompt_status_line fg=231,bg=240

# syntax highlighting
ble-color-setface syntax_default none
Expand Down
14 changes: 12 additions & 2 deletions blerc
Expand Up @@ -146,20 +146,29 @@
#bleopt prompt_rps1_transient=''


## The following settings specifies the content of terminal titles and status
## The following settings specify the content of terminal titles and status
## lines. "prompt_xterm_title" specifies the terminal title which can be set
## by "OSC 0 ; ... BEL". "prompt_screen_title" is effective inside terminal
## multiplexers such as GNU screen and tmux and specifies the window title of
## the terminal multiplexer which can be set by "ESC k ... ST".
## "prompt_status_line" is only effective when terminfo entries "tsl" and "fsl"
## "prompt_term_status" is only effective when terminfo entries "tsl" and "fsl"
## (or termcap entries "ts" and "ds") are available, and specifies the content
## of the status line which can be set by the terminfo entries. When each
## setting has non-empty value, the content of corresponding title or status
## line is replaced just before PS1 is shown.

#bleopt prompt_xterm_title=
#bleopt prompt_screen_title=
#bleopt prompt_term_status=


## The following settings control the status line. "prompt_status_line"
## specifies the content of the status line. If its value is empty, the status
## line is not shown. "prompt_status_align" controls the position of the
## content in the status line.

#bleopt prompt_status_line=
#bleopt prompt_status_align=left


## "prompt_eol_mark" specifies the contents of the mark used to indicate the
Expand Down Expand Up @@ -545,6 +554,7 @@
# ble-color-setface vbell reverse
# ble-color-setface vbell_erase bg=252
# ble-color-setface vbell_flash fg=green,reverse
# ble-color-setface prompt_status_line fg=231,bg=240

# ble-color-setface syntax_default none
# ble-color-setface syntax_command fg=brown
Expand Down
7 changes: 7 additions & 0 deletions lib/init-term.sh
Expand Up @@ -80,6 +80,13 @@ function ble/init:term/initialize {
_ble_term_xenl=0
ble/init:term/register-varname _ble_term_xenl

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

# tab width
_ble_term_it=8
if [[ $_ble_term_tput ]]; then
Expand Down
10 changes: 7 additions & 3 deletions make_command.sh
Expand Up @@ -438,13 +438,17 @@ function sub:show-contrib {
sort | uniq -c | sort -rn > "$cache_contrib_github"
fi

echo "Contributions (from GitHub Issues/PRs)"
cat "$cache_contrib_github"

echo "Contributions (from memo.txt)"
sed -En 's/^ \* .*\([^()]+ by ([^()]+)\).*/\1/p' memo/done.txt note.txt |
sort | uniq -c | sort -rn

echo "Contributions (from ChangeLog.md)"
sed -n 's/.*([^()]* by \([^()]*\)).*/\1/p' memo/ChangeLog.md |
sort | uniq -c | sort -rn
echo

echo "Contributions (from GitHub Issues/PRs)"
cat "$cache_contrib_github"
}

#------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion memo/ChangeLog.md
Expand Up @@ -13,6 +13,7 @@
- edit (`{kill,copy}-region-or`): fix unconditionally combined kills/copies (reported by 3ximus) `#D1447` 1631751
- canvas: update emoji database and support `bleopt emoji_version` (motivated by endorfina) `#D1454` d1f8c27
- canvas, edit: support `bleopt info_display` (suggested by 0neGuyDev) `#D1458` 69228fa
- prompt: support `bleopt prompt_status_{line,align}` and `face prompt_status_line` `#D1462` 0000000

## Changes

Expand All @@ -21,9 +22,10 @@
- edit: preserve the state of `READLINE_{LINE,POINT,MARK}` `#D1437` 8379d4a
- edit: change default behavior of <kbd>C-w</kbd> and <kbd>M-w</kbd> to operate on backward words `#D1448` 47a3301
- syntax (`layer:syntax/word`): perform pathname expansions in background subshells (motivated by 3ximus) `#D1449` 13e7bdd
- syntax (`simple-word/is-simple-noglob`): suppress error messages on expansions `#D1461` 0000000
- syntax (`simple-word/is-simple-noglob`): suppress error messages on expansions `#D1461` a56873f
- complete: perform pathname expansions in subshells (motivated by 3ximus) `#D1450` d511896
- complete: support `bleopt complete_timeout_compvar` to time out pathname expansions for `COMP_WORDS` / `COMP_LINE` `#D1457` cc2881a
- prompt: rename `bleopt prompt_{status_line => term_status}` `#D1462` 0000000

## Fixes

Expand Down
14 changes: 7 additions & 7 deletions memo/done.txt
Expand Up @@ -2656,7 +2656,7 @@

2020-08-06

* fzf の設定でエラーが発生する (reported by @tigger04) [#D1372]
* fzf の設定でエラーが発生する (reported by tigger04) [#D1372]
https://github.com/akinomyoga/ble.sh/issues/60

bind '"...": fzf-file-widget' の様に -x を
Expand Down Expand Up @@ -2761,7 +2761,7 @@

2020-08-04

* textarea: vi-mode strings がある時の計算がおかしい (reported by @tigger04) [#D1371]
* textarea: vi-mode strings がある時の計算がおかしい (reported by tigger04) [#D1371]
https://github.com/akinomyoga/ble.sh/issues/60

先ず、再現するかどうかを確認する必要がある。
Expand Down Expand Up @@ -31395,7 +31395,7 @@

2018-03-15

* 単語着色の問題 (2017-11-26 reported by @cmplsetofB) [#D0686]
* 単語着色の問題 (2017-11-26 reported by cmplstofB) [#D0686]

これについては項目が既にあるかと思ったが今探してみた所なかった。
恐らく以下の項目が実装途中で放棄されているので、
Expand Down Expand Up @@ -33875,7 +33875,7 @@

現状では問題ないが、やはり後々のためにちゃんと安全な方法で split する事にする。直した。

* edit: history 初期化で先頭行に行く [reported by @cmplstofB] [#D0634]
* edit: history 初期化で先頭行に行く (reported by cmplstofB) [#D0634]

> 起動直後に履歴を遡る (というより ^P を押下する) と一番始めの履歴にまで戻ってしまいます。

Expand All @@ -33885,7 +33885,7 @@
どうやら history で出力される履歴番号は printf %5d で出力されている為に、
履歴項目の数が 5 桁より小さい時には先頭にスペースが入るのだ。

* complete: failglob 時の問題 (3) [reported by @cmplstofB] [#D0633]
* complete: failglob 時の問題 (3) (reported by cmplstofB) [#D0633]

> コマンドに glob が含まれている場合などはいいのですが,
> 存在しないパスを補完しようとすると不具合が発生します。
Expand Down Expand Up @@ -34016,7 +34016,7 @@
- 更に、compgen に内容が含まれていたとしても空行がある場合には、それを除く様に変更した。
- ble/util/assign-array も調整した。

* highlight: failglob でエラーメッセージが出る [reported by @cmplstofB] [#D0630]
* highlight: failglob でエラーメッセージが出る (reported by cmplstofB) [#D0630]

> コマンドラインで $ l* と入力すると bash: 一致しません: l* という
> エラーメッセージらしい表示が入力位置の右隣に発生し,続く入力が妨げられます。
Expand All @@ -34040,7 +34040,7 @@

- done: あと、パス名展開に失敗したらその単語をエラー着色するようにする。

* keymap/vi (cmap): C-d で終了してしまうバグ [reported by @cmplstofB] [#D0629]
* keymap/vi (cmap): C-d で終了してしまうバグ (reported by cmplstofB) [#D0629]

> たとえコマンドラインに文字があっても終了してしまいます。

Expand Down
35 changes: 35 additions & 0 deletions note.txt
Expand Up @@ -3813,6 +3813,41 @@ bash_tips

2021-02-03

* edit: status line に対応しても良いのではないか [#D1462]

→改めて確認してみた所、prompt_status_line という設定が既に存在していた。

? terminfo tsl/fsl に対応している TERMは存在するのか

これは terminfo の tsl fsl を使って何かを表示する物だが、実のところ
tsl/fsl に対応している TERM はなかなかない。少なくとも screen, xterm は違
う。

* tmux の term entry には tsl/fsl が存在しているが、シーケンスを見るとこ
れは prompt_xterm_title と同じ OSC であって間違っている。terminfo の説
明を読む限りに於いては、tsl/fsl は端末の特別な行で内部ではエスケープシー
ケンスなども普通に使える物と見られる。という事を考えると、tmux の様に振
る舞うのは間違っている気がする。

* cygwin も tmux と同様である。但し、OSC 0 ; ではなくて OSC ; になってい
る。0 は省略可能という事なのだろう。

* kterm には \e[?E\e[?..T ... \e[?F という物が登録されている。
* aixterm は \e[?..T ... \e[?F
* aixterm は \e[?..T ... \e[?F

うーん。何れにしても最近の端末エミュレータに存在する様な物ではない気がする
ので、取り敢えず prompt_status_line は ble.sh の新しい機能の為に使う事にし
てしまって良い。

既存の tsl/fsl によるタイトルは別名の設定にする事にする。
prompt_terminfo_status という名前にでもするか。terminfo だけでなく termcap
にも存在するようだから、prompt_termcap_status の方が良いのかもしれない。或
いは、prompt_term_status にするか。

* status line の区別がやはり付きにくい。背景色を設定できる様にしても良いのではないだろうか。
元々 trace にその様な機能があった様な気がする。改めて確認する。なかったので新しく実装した。

* syntax: echo ${!_} と入力すると誤った代入ですというエラーメッセージが表示される [#D1461]
そもそも "${!_}" を実行しようとするとエラーメッセージが出るが、
これが着色等の際に発生するのは良くない。何処で発生しているのか確認する必要がある。
Expand Down
43 changes: 30 additions & 13 deletions src/canvas.sh
Expand Up @@ -532,6 +532,9 @@ function ble/canvas/bflush.draw {
## ANSI制御シーケンスではなく現在の端末のシーケンスとして
## 制御機能SGRを解釈します。
##
## g0
## 背景色・既定属性として用いる属性値を指定します。
##
## @var[in,out] DRAW_BUFF[]
## ble/canvas/trace.draw の出力先の配列です。
## @var[out] ret
Expand Down Expand Up @@ -569,6 +572,17 @@ function ble/canvas/bflush.draw {
## それ以外はカーソル位置の変更は行いません。
##

function ble/canvas/trace/.put-sgr.draw {
local ret g=$1
if ((g==0)); then
ble/canvas/put.draw "$opt_sgr0"
else
ble/color/g#compose "$opt_g0" "$g"
ble/color/g2sgr "$g"
ble/canvas/put.draw "$ret"
fi
}

## @fn ble/canvas/trace/.goto x1 y1
## @var[in,out] x y
## Note: lc lg の面倒は呼び出し元で見る。
Expand Down Expand Up @@ -608,8 +622,7 @@ function ble/canvas/trace/.decsc {
ble/canvas/put.draw "$_ble_term_sc"
}
function ble/canvas/trace/.decrc {
local ret; ble/color/g2sgr "${trace_decsc[2]}" # g を明示的に復元。
ble/canvas/put.draw "$ret"
ble/canvas/trace/.put-sgr.draw "${trace_decsc[2]}" # g を明示的に復元。
if [[ :$opts: == *:noscrc:* ]]; then
ble/canvas/put-move.draw $((trace_decsc[0]-x)) $((trace_decsc[1]-y))
else
Expand All @@ -627,8 +640,7 @@ function ble/canvas/trace/.scosc {
ble/canvas/put.draw "$_ble_term_sc"
}
function ble/canvas/trace/.scorc {
local ret; ble/color/g2sgr "$g" # g は変わらない様に。
ble/canvas/put.draw "$ret"
ble/canvas/trace/.put-sgr.draw "$g" # g は変わらない様に。
if [[ :$opts: == *:noscrc:* ]]; then
ble/canvas/put-move.draw $((trace_scosc[0]-x)) $((trace_scosc[1]-y))
else
Expand Down Expand Up @@ -675,7 +687,7 @@ function ble/canvas/trace/.SGR {
local param=$1 seq=$2 specs i iN
if [[ ! $param ]]; then
g=0
ble/canvas/put.draw "$_ble_term_sgr0"
ble/canvas/put.draw "$opt_sgr0"
return 0
fi

Expand All @@ -686,9 +698,7 @@ function ble/canvas/trace/.SGR {
ble/color/read-sgrspec "$param" ansi
fi

local ret
ble/color/g2sgr "$g"
ble/canvas/put.draw "$ret"
ble/canvas/trace/.put-sgr.draw "$g"
}
function ble/canvas/trace/.process-csi-sequence {
local seq=$1 seq1=${1:2} rex
Expand Down Expand Up @@ -854,7 +864,7 @@ function ble/canvas/trace/.impl {

# Note: 文字符号化方式によっては対応する文字が存在しない可能性がある。
# その時は st='\u009C' になるはず。2文字以上のとき変換に失敗したと見做す。
local ret
local ret rex
ble/util/c2s 156; local st=$ret # œ (ST)
((${#st}>=2)) && st=

Expand All @@ -865,6 +875,13 @@ function ble/canvas/trace/.impl {
[[ :$opts: != *:left-char:* ]] && local lc=32 lg=0
local opt_terminfo=; [[ :$opts: == *:terminfo:* ]] && opt_terminfo=1

local opt_g0= opt_sgr0=$_ble_term_sgr0
if rex=':g0=([^:]+):'; [[ :$opts: =~ $rex ]]; then
opt_g0=${BASH_REMATCH[1]}
ble/color/g2sgr "$opt_g0"; opt_sgr0=$ret
ble/canvas/put.draw "$opt_sgr0"
fi

# constants
local cols=${COLUMNS:-80} lines=${LINES:-25}
local it=${bleopt_tab_width:-$_ble_term_it} xenl=$_ble_term_xenl
Expand Down Expand Up @@ -1764,8 +1781,8 @@ _ble_canvas_panel_tmargin=1 # for visible-bell
function ble/canvas/panel/layout/.extract-heights {
local i n=${#_ble_canvas_panel_class[@]}
for ((i=0;i<n;i++)); do
local height
"${_ble_canvas_panel_class[i]}#panel::getHeight" "$i"
local height=0:0
ble/function#try "${_ble_canvas_panel_class[i]}#panel::getHeight" "$i"
mins[i]=${height%:*}
maxs[i]=${height#*:}
done
Expand Down Expand Up @@ -1866,9 +1883,9 @@ function ble/canvas/panel/goto-bottom-dock.draw {
if [[ ! $_ble_canvas_panel_bottom ]]; then
_ble_canvas_panel_bottom=1
ble/canvas/excursion-start.draw
ble/canvas/goto.draw 0 $((LINES-1)) # 一番下の行に移動
ble/canvas/put-cup.draw "$LINES" 0 # 一番下の行に移動
ble/arithmetic/sum "${_ble_canvas_panel_height[@]}"
((_ble_canvas_y=ret-1))
((_ble_canvas_x=0,_ble_canvas_y=ret-1))
fi
}
function ble/canvas/panel/goto-top-dock.draw {
Expand Down
4 changes: 4 additions & 0 deletions src/color.sh
Expand Up @@ -223,6 +223,10 @@ function ble/color/g#append {
((g&=~(_ble_color_gflags_BgMask|_ble_color_gflags_BgIndexed)))
((g|=g2))
}
function ble/color/g#compose {
g=$1; shift
local g2; for g2; do ble/color/g#append "$g2"; done
}


## @fn ble/color/gspec2g gspec
Expand Down

0 comments on commit cca1cbc

Please sign in to comment.