历史记录 - 控制屏幕在适当位置滚动文本(向上箭头 -> 在适当位置/相同位置循环显示命令)

发布于 2024-10-30 16:34:37 字数 303 浏览 0 评论 0原文

当您滚动浏览历史记录时,文本会根据提示发生变化。我已经查看了所涉及的结构,但还没有足够深入地研究源代码,以找出它如何更改屏幕上的文本而不更改其上面的所有文本(提示符,已打印出的过去文本。)

它不能只是清除屏幕并重新打印所有内容,而仅在提示后进行微小的更改 - 那样效率非常低。他们是如何做到这一点的?

这可能听起来很愚蠢,但我尝试打印一个退格字符,这会导致将光标移动到提示中,当您键入时,它只会写在提示上方。

我只是不明白他们如何打印文本并更改它或循环浏览文本。

如果有人知道这是如何完成的,我将非常感激。

谢谢

When you scroll through the history the text changes at the prompt. I've looked at the structures involved but haven't looked deep enough in the source code to find out how it changes the text on the screen without changing all the text above it (the prompt, past text that has been printed out.)

It can't just clear the screen and reprint everything out with only the minor change after the prompt-- that would just be so inefficient. How do they do this?

It probably sounds really dumb, but I tried printing a backspace character which results in moving the cursor into the prompt in which when you type it just writes over top of the prompt.

I just can't figure how they print out text and change it or cycle through text in place.

If anyone knows how this is done I would really appreciate it.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-11-06 16:34:37

bash 使用 GNU readline 来执行此操作。它最终是 terminfo 库的包装器(来自 System V 或 ncurses),其目的是使用终端描述来弄清楚如何进行这些更新。如果终端类型未知或声明不正确,您会发现要么最终得到垃圾,要么所有漂亮的就地更新都消失了。

终端描述看起来像

xterm-color|nxterm|generic color xterm,
        am, km, mir, msgr, xenl,
        colors#8, cols#80, it#8, lines#24, ncv@, pairs#64,
        acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, bold=\E[1m, clear=\E[H\E[2J, cr=^M,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
        dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, ed=\E[J,
        el=\E[K, enacs=\E)0, home=\E[H, ht=^I, hts=\EH, il=\E[%p1%dL,
        il1=\E[L, ind=^J,
        is2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, kbs=^H,
        kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
        kdch1=\E[3~, kf1=\E[11~, kf10=\E[21~, kf11=\E[23~,
        kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, kf15=\E[28~,
        kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, kf19=\E[33~,
        kf2=\E[12~, kf20=\E[34~, kf3=\E[13~, kf4=\E[14~,
        kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
        kfnd=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~,
        kslt=\E[4~, meml=\El, memu=\Em, op=\E[m, rc=\E8, rev=\E[7m,
        ri=\EM, rmacs=^O, rmcup=\E[2J\E[?47l\E8, rmir=\E[4l,
        rmkx=\E[?1l\E>, rmso=\E[m, rmul=\E[m,
        rs2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, sc=\E7,
        setab=\E[4%p1%dm, setaf=\E[3%p1%dm, sgr0=\E[m, smacs=^N,
        smcup=\E7\E[?47h, smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m,
        smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
        u8=\E[?1;2c, u9=\E[c,

并描述了如何进行各种屏幕更新、可用的功能和操作键以及它们发送的内容以及特殊的终端行为(画线字符、颜色和其他形式的突出显示、是否可以在线的中间等)。通常,您不需要理解它,除非设置错误或者您喜欢高级终端黑客技术。 (如果您确实想理解它,请从terminfo(5)和其他curses/ncurses/开始terminfo 文档。如果不出意外,您将学习如何制作真正精美的 shell 提示。)

bash uses the GNU readline library to do this. It's ultimately a wrapper over the terminfo library (from System V or the ncurses library), whose purpose is to use terminal descriptions to figure out how to do those updates. If the terminal type is unknown or declared incorrectly, you'll notice that you either end up with garbage or all the pretty in-place updates go away.

A terminal description looks something like

xterm-color|nxterm|generic color xterm,
        am, km, mir, msgr, xenl,
        colors#8, cols#80, it#8, lines#24, ncv@, pairs#64,
        acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, bold=\E[1m, clear=\E[H\E[2J, cr=^M,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
        dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, ed=\E[J,
        el=\E[K, enacs=\E)0, home=\E[H, ht=^I, hts=\EH, il=\E[%p1%dL,
        il1=\E[L, ind=^J,
        is2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, kbs=^H,
        kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
        kdch1=\E[3~, kf1=\E[11~, kf10=\E[21~, kf11=\E[23~,
        kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, kf15=\E[28~,
        kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, kf19=\E[33~,
        kf2=\E[12~, kf20=\E[34~, kf3=\E[13~, kf4=\E[14~,
        kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
        kfnd=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~,
        kslt=\E[4~, meml=\El, memu=\Em, op=\E[m, rc=\E8, rev=\E[7m,
        ri=\EM, rmacs=^O, rmcup=\E[2J\E[?47l\E8, rmir=\E[4l,
        rmkx=\E[?1l\E>, rmso=\E[m, rmul=\E[m,
        rs2=\E[m\E[?7h\E[4l\E>\E7\E[r\E[?1;3;4;6l\E8, sc=\E7,
        setab=\E[4%p1%dm, setaf=\E[3%p1%dm, sgr0=\E[m, smacs=^N,
        smcup=\E7\E[?47h, smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m,
        smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, u7=\E[6n,
        u8=\E[?1;2c, u9=\E[c,

and describes how to do various screen updates, what function and action keys are available and what they send, and special terminal behaviors (line-drawing characters, colors and other forms of highlighting, whether it can insert characters in the middle of a line, etc.). You don't need to understand it, usually, unless something is set up wrong or you're into advanced terminal hackery. (If you do want to understand it, start with terminfo(5) and the other curses/ncurses/terminfo documentation. If nothing else, you'll learn how to make really fancy shell prompts.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文