簡體   English   中英

SIGWINCH、bash、dash、tput 和 terminfo

[英]SIGWINCH, bash, dash, tput, and terminfo

我對tput和終端大小之間的交互有點困惑。 似乎tput的行為取決於調用它的 shell ,或者可能是 shell 負責更改終端設置,或者......什么。 為了減少問題,請考慮:

dash$ exec bash
bash$ trap 'echo winched' WINCH
bash$ tput cols
176
bash$ # changing terminal size now (after hitting return)
bash$ winched
bash$ winched
tput cols
150
bash$ exec dash
dash$ trap 'echo winched' WINCH
dash$ tput cols
150
dash$ # changing terminal size now (after hitting return)
dash$ tput cols
winched
150

在這里,在 bash 中,事情的表現(幾乎)符合預期(我說差不多,因為我不太確定 WINCH 處理程序為什么執行兩次),並且tput的 output 發生變化以匹配新的終端大小。 但是,當在 dash 中運行時,即使終端改變了大小, tput output 也不會改變。 另請注意,WINCH 處理程序似乎被破折號延遲,並且直到輸入下一個命令之后(但在它執行之前)才執行。 這里應該發生什么? tput是否關心 shell 在做什么? 絞盤是否相關? 我想問題是:

tput如何知道終端的大小?

另外,我不想過多地混淆 output,但是在示例的每個 shell 中,設置了 TERM 並且infocmp $TERM打印了似乎有效的 terminfo 描述。 (我認為,它給出任何 output 的事實表明它是有效數據!)

從描述中看不出來:

-T
表示終端類型。 通常這個選項是不必要的,因為默認值取自環境變量TERM 如果指定了-T ,則 shell 變量LINESCOLUMNS也將被忽略。

當前的tput調用use_envuse_tioctl用於-T選項:

20171007
    + modify "-T" option of clear and tput to call use_tioctl() to obtain
      the operating system's notion of the screensize if possible.

tput手冊頁有一個Terminal Size部分,其中更詳細。

此示例(使用 ncurses 6.1)按預期工作:

#!/bin/bash

trap "resize; tput cols; tput -T$TERM cols" WINCH

while true
do
        sleep 1
done

使用 ncurses 6.0,您會看到這種差異。 對於其他實現, ymmv

關於bash ,不久前討論過: tput cols 在腳本中無法正常工作(但 q/a 與-T選項沒有任何關系)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM