简体   繁体   English

如何在原始输入模式下发送终端转义序列?

[英]How can I send terminal escape sequences in raw input mode?

I have a program that uses a terminal in raw mode and I want to move the cursor around. 我有一个在原始模式下使用终端的程序,我想移动光标。 Where can I find the escape sequence for this and how can I send it to the terminal from inside my c program? 在哪里可以找到此转义序列,以及如何从c程序内部将其发送到终端?

Here's what I currently have: 这是我目前拥有的:

char code[4];
code[0] = 27;
code[1] = 91;
code[2] = '*';
code[3] = 'D';
write(1, code, 4);

If you want control of the full screen then you should look at the ncurses library. 如果要控制全屏,则应查看ncurses库。 This is a simple library for full screen console programs that contains among other things 这是用于全屏控制台程序的简单库,其中包含其他内容

  • Full screen positioning of text 全屏文字定位
  • Use of the full keyboard including function keys, insert/delete etc 使用全键盘,包括功能键,插入/删除等
  • Use of attributes for colouring, highlighting of text etc 使用属性为文本上色,突出显示等

您希望使用termcap来获取此信息,因为它取决于用户所处的终端类型,因此会有所不同。

I would suggest you look hard at the curses or ncurses libraries, and plan to use one or the other rather than roll your own. 我建议您仔细看一下cursesncurses库,并计划使用其中一个而不是自己动手。 You should aim to use the terminfo system of terminal descriptions rather than the older termcap system. 您应该旨在使用终端描述的terminfo系统,而不是较旧的termcap系统。 See also the O'Reilly books " Termcap and Terminfo " and my favourite title (mainly because I seem to spend a lot of time cursing when programming) " Progamming With Curses ". 另请参阅O'Reilly的书籍“ Termcap和Terminfo ”和我最喜欢的书名(主要是因为编程时我似乎花费了大量时间在咒骂)“ 用诅咒编程”。 (However, that book is ancient - 1986 - and there are other more recent books on the same subject which would probably be better choices; I still love the title, though.) (但是,那本书是古老的-1986年-还有其他关于同一主题的其他较新的书籍可能是更好的选择;不过,我还是很喜欢书名。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM