Unix write() 函数 (libc)

发布于 2024-09-19 02:09:15 字数 356 浏览 7 评论 0原文

我正在 Unix 中制作一个使用原始 tty 输入的 C 应用程序。

我正在对显示屏上的字符调用 write() ,但我想操纵光标:

ssize_t
write(int d, const void *buf, size_t nbytes);

我注意到如果 buf 的值为 8 (我的意思是 char tmp = 8,然后传递 &tmp),它将移动光标/指针在屏幕上向后移动。

我想知道在哪里可以找到所有代码,例如,我希望向前移动光标,但我似乎无法通过谷歌找到它。

请问是否有一个页面列出了 write() 函数的所有代码?

非常感谢你,

贾里

I am making a C application in Unix that uses raw tty input.

I am calling write() to characters on the display, but I want to manipulate the cursor:

ssize_t
write(int d, const void *buf, size_t nbytes);

I've noticed that if buf has the value 8 (I mean char tmp = 8, then passing &tmp), it will move the cursor/pointer backward on the screen.

I was wondering where I could find all the codes, for example, I wish to move the cursor forward but I cannot seem to find it via Google.

Is there a page that lists all the code for the write() function please?

Thank you very much,

Jary

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

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

发布评论

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

评论(3

姜生凉生 2024-09-26 02:09:15

8 只是退格键的 ascii 代码。您可以输入 man ascii 并查看所有值(我的手册页) Ubuntu 盒子有更友好的值名称)。如果您想做更复杂的事情,您可能需要查看像 ncurses 这样的库。

8 is just the ascii code for backspace. You can type man ascii and look at all the values (the man page on my Ubuntu box has friendlier names for the values). If you want to do more complicated things you may want to look at a library like ncurses.

ˇ宁静的妩媚 2024-09-26 02:09:15

您刚刚发现字符代码 8 是退格键 (control-H)。

您可能最好使用curses库来管理屏幕。但是,您可以通过使用 infocmp 反编译终端的 terminfo 条目来了解curses 知道哪些控制序列。格式不是特别容易理解,但是比较全面。另一种方法是找到终端手册,这往往相当困难。

例如,我使用的是彩色 Xterm 窗口; infocmp 表示:

#   Reconstructed via infocmp from file: /usr/share/terminfo/78/xterm-color
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,

包含有关方框绘制字符、功能键生成的代码序列、各种光标移动序列等信息。

您可以在以下位置找到有关 X/Open Curses (v4.2) 的更多信息HTML。然而,它已正式过时,已被 X/Open Curses v7 取代,您可以免费下载 PDF 版本。

You have just discovered that character code 8 is backspace (control-H).

You would probably be best off using the curses library to manage the screen. However, you can find out what control sequences curses knows about by using infocmp to decompile the terminfo entry for your terminal. The format isn't particularly easy to understand, but it is relatively comprehensive. The alternative is to find a manual for the terminal, which tends to be rather hard.

For instance, I'm using a color Xterm window; infocmp says:

#   Reconstructed via infocmp from file: /usr/share/terminfo/78/xterm-color
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,

That contains information about box drawing characters, code sequences generated by function keys, various cursor movement sequences, and so on.

You can find out more about X/Open Curses (v4.2) in HTML. However, that is officially obsolete, superseded by X/Open Curses v7, which you can download for free in PDF.

隐诗 2024-09-26 02:09:15

如果您使用 write 只是为了获得低级光标控制,我认为您使用了错误的工具来完成这项工作。许多类型的终端都有命令代码。例如,VT100 代码是 "\x1b[..." 形式的序列,但您最好使用 ncurses 这样的库,而不是发送原始代码。

If you're using write just so you have low-level cursor control, I think you are using the wrong tool for the job. There are command codes for many types of terminal. VT100 codes, for example, are sequences of the form "\x1b[...", but rather than sending raw codes, you'd be much better off using a library like ncurses.

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