Unix write() 函数 (libc)
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
您刚刚发现字符代码 8 是退格键 (control-H)。
您可能最好使用curses库来管理屏幕。但是,您可以通过使用
infocmp
反编译终端的 terminfo 条目来了解curses 知道哪些控制序列。格式不是特别容易理解,但是比较全面。另一种方法是找到终端手册,这往往相当困难。例如,我使用的是彩色 Xterm 窗口;
infocmp
表示:包含有关方框绘制字符、功能键生成的代码序列、各种光标移动序列等信息。
您可以在以下位置找到有关 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: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.
如果您使用
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.