Skip to content

Commit

Permalink
util.bgproc: fix use of "ble/util/idle" in bash-3
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 2, 2023
1 parent 4c6a477 commit 79a6bd4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
11 changes: 6 additions & 5 deletions docs/ChangeLog.md
Expand Up @@ -140,7 +140,8 @@
- sabbrev: support inline and linewise sabbre with `ble-sabbrev -il` `#D2012` 56208534
- complete: add `bleopt complete_source_sabbrev_{opts,ignore}` (motivated by mozirilla213) `#D2013` f95eb0cc `#D2016` 45c76746
- util.bgproc: separate `ble/util/bgproc` from `histdb` (motivated by bkerin) `#D2017` 7803305f
- menu-complete: support selection by index (requested by bkerin) `#D2023` xxxxxxxx
- util.bgproc: fix use of `ble/util/idle` in bash-3 `#D2026` xxxxxxxx
- menu-complete: support selection by index (requested by bkerin) `#D2023` b91b8bc8

## Changes

Expand Down Expand Up @@ -501,7 +502,7 @@
- main (`ble/bin/awk`): add workaround for macOS `awk-32` `#D1974` e2ec89c
- util.hook: workaround bash-5.2 bug of nested read by `WINCH` `#D1981` a5b10e8
- edit: always adjust the terminal states with `bind -x` (reported by linwaytin) `#D1983` 5d14cf1
- edit: restore `PS1` while processing `bind -x` (reported by adoyle-h) `#D2024` xxxxxxxx
- edit: restore `PS1` while processing `bind -x` (reported by adoyle-h) `#D2024` 2eadcd5b
- syntax: suppress brace expansions in designated array initialization in Bash 5.3 `#D1989` 1e7b884
- progcomp: work around slow `nix` completion `#D1997` 2c1aacf
- complete: suppress error messages from `_adb` (reported by mozirilla213) `#D2005` f2aa32b0
Expand Down Expand Up @@ -581,14 +582,14 @@
- util: add `ble/util/message` `#D2001` 2a524f34
- global: normalize bracket expressions to `_a-zA-Z` / `_a-zA-Z0-9` `#D2006` 41faa494
- global: fix leak variables `#D2018` 6f5604de
- edit: handle nested WINCH properly `#D2020` xxxxxxxx
- edit: handle nested WINCH properly `#D2020` a6b2c078

## Contrib

- prompt-git: detect staged changes `#D1718` 2b48e31
- prompt-git: fix a bug that information is not updated on reload `#D1732` 361e9c5
- config/execmark: show exit status in a separate line `#D1828` 4d24f84
- config/execmark: add names of exit statuses `#D2019` xxxxxxxx
- config/execmark: add names of exit statuses `#D2019` a6b2c078
- prompt-git: ignore untracked files in submodules `#D1829` 4d24f84
- integration/fzf
- fzf-completion: fix integration (reported by ferdinandyb) `#D1837` 12c022b
Expand Down Expand Up @@ -622,7 +623,7 @@
- histdb: fix `.timeout` not set for background `sqlite3` `#D1982` 20b42fa
- histdb: suppress color codes in the default `histdb_remarks` `#D1968` 20b42fa
- histdb: disable timeout of background processes in Bash 3.2 `#D1992` 20b42fa
- histdb: rewrite to use `ble/util/bgproc` `#D2017` xxxxxxxx
- histdb: rewrite to use `ble/util/bgproc` `#D2017` 7803305f
- integration: move `fzf` and `bash-preexec` integrations to subdir `#D1939` 86d9467

<!---------------------------------------------------------------------------->
Expand Down
15 changes: 10 additions & 5 deletions lib/util.bgproc.sh
Expand Up @@ -301,7 +301,7 @@ function ble/util/bgproc#stop/.kill {
##
function ble/util/bgproc#stop {
local prefix=$1
ble/util/idle.cancel "ble/util/bgproc#keepalive/.timeout $prefix"
ble/util/bgproc#keepalive/.cancel-timeout "$prefix"

local bgproc bgproc_fname
ble/util/restore-vars "${prefix}_" bgproc bgproc_fname
Expand Down Expand Up @@ -362,6 +362,11 @@ function ble/util/bgproc#keepalive/.timeout {
ble/util/bgproc#stop "$prefix"
}

function ble/util/bgproc#keepalive/.cancel-timeout {
local prefix=$1
ble/function#try ble/util/idle.cancel "ble/util/bgproc#keepalive/.timeout $prefix"
}

## @fn ble/util/bgproc#keepalive prefix
## Rest the timeout to stop the background process.
##
Expand All @@ -374,12 +379,12 @@ function ble/util/bgproc#keepalive {
((${#bgproc[@]})) || return 2
ble/util/bgproc/.alive || return 1

local timeout_proc="ble/util/bgproc#keepalive/.timeout $1"
ble/util/idle.cancel "$timeout_proc"
ble/util/bgproc#keepalive/.cancel-timeout "$prefix"
local ret
ble/opts#extract-last-optarg "${bgproc[3]}" timeout || return 0; local bgproc_timeout=$ret
if ((bgproc_timeout>0)); then
ble/util/idle.push --sleep="$bgproc_timeout" "$timeout_proc"
local timeout_proc="ble/util/bgproc#keepalive/.timeout $1"
ble/function#try ble/util/idle.push --sleep="$bgproc_timeout" "$timeout_proc"
fi
return 0
}
Expand All @@ -397,7 +402,7 @@ function ble/util/bgproc#close {

local prefix=${1}
blehook unload-="ble/util/bgproc#close $prefix"
ble/util/idle.cancel "ble/util/bgproc#keepalive/.timeout $prefix"
ble/util/bgproc#keepalive/.cancel-timeout "$prefix"

# When the callback function "ble/util/bgproc/onclose:PREFIX" is defined, we
# call the function before starting the closing process. However, we skip
Expand Down
20 changes: 19 additions & 1 deletion note.txt
Expand Up @@ -1995,6 +1995,7 @@ bash_tips

* sabbrev: suffix alias in Zsh (拡張子で実行形式を選択)
コマンド名補間も一緒に対応する必要がある。
つまり suffix alias がある時には対応する拡張子を持つファイルも候補に表示する。

* complete: 末尾に不完全な \ がある候補の specialchars フィルタリング?

Expand Down Expand Up @@ -2023,7 +2024,7 @@ bash_tips

https://www.webfx.com/tools/emoji-cheat-sheet/ に一覧がある。
然し、emoji リストの難点は思い出すのが大変という事。リストを表示できたら良いのだが。
例えば sabbrev -m 経由で挿入するというのが良いかもしれない。
例えば sabbrev -m 経由で挿入するというのが良いかもしれない。:: を使う。

* [保留] canvas/panel: 一旦 scroll buffer に行ったものを元に戻す可能性? (motivated by mozirilla213)

Expand Down Expand Up @@ -2054,6 +2055,10 @@ bash_tips
menu-completion や menu-complete backward 等の時には改めて開始するのではな
くて内部での補完候補の移動を行いたい気もする。

然しチェックするにしても全ての文字をチェックしていると大変である。と思った
が、UTF-8 decode や key decode 等の処理の重さなどを考えたら大した事ないとい
えば大したことない。

* menu-complete: suffix もメニュー選択時に表示する機能?
https://github.com/akinomyoga/ble.sh/discussions/297#discussioncomment-5159146

Expand Down Expand Up @@ -5852,6 +5857,11 @@ bash_tips
様々な形式で記録されている。取り敢えず一番簡単な対応として
nest に記録されている物を着色するというのが良さそうである。

2023-03-26 https://github.com/akinomyoga/ble.sh/discussions/308

対応する request が来た。うーん。もっと最近にも関連した考察をした気がするが、
メモに記録があるかどうかは覚えていない。

2018-07-29

* complete: メモ
Expand Down Expand Up @@ -6714,6 +6724,14 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2023-04-02

* bgproc: bash-3 で idle.cancel がないと表示される [#D2026]

実装を改めて確認してみたらそもそも bash-3 に対する考慮が全く入っていない。
然し、将来的に bash-3 でも idle を使える様にする可能性を考えると単にバージョ
ンで判定するのもよくない気がする。結局 function#try で調整する事にする。

2023-03-26

* menu-complete (linewise): 長い行がある時に表示が崩れる (reported by bkerin) [#D2025]
Expand Down

0 comments on commit 79a6bd4

Please sign in to comment.