编写"真正的"交互式终端程序如vim,HTOP,...在C / C ++没有的ncurses [英] Writing a "real" interactive terminal program like vim, htop, ... in C/C++ without ncurses

查看:272
本文介绍了编写"真正的"交互式终端程序如vim,HTOP,...在C / C ++没有的ncurses的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有,我不想使用的ncurses ,因为我想学习如何
  终端的作品,有乐趣的编程对我自己。 :)它不
  一定要随身携带,它在Linux上的xterm基于终端仿真器只工作。

No, I don't want to use ncurses, because I want to learn how the terminal works and have fun programming it on my own. :) It doesn't have to be portable, it has to work on linux xterm-based terminal emulators only.

我想要做的就是编程像HTOP和vim是一个交互式终端的应用是什么。我的意思是不是看起来像箱子或设置的颜色,这是平凡人物的输出;也使内容配合到窗口大小。我需要的是

What I want to do is programming an interactive terminal application like htop and vim are. What I mean is not the output of characters which look like boxes or setting colors, this is trivial; also to make the content fit to the window size. What I need is


  1. 如何让鼠标交互像点击一个字符,滚动鼠标滚轮(当鼠标在一个特定的字符)来实现滚动[修改:在终端当然模拟器],以及

  1. how to get mouse interactions like clicking on a character and scrolling the mouse wheel (when the mouse is at a specific character) to implement scrolling [ in a terminal emulator of course], and

如何完全保存和恢复父进程的输出和输出单独我的打印,所以留给我的应用程序只是命令后,我进入了壳应该在那里运行HTOP并再次狭路相逢时,它像:没有什么是从该应用程序可见了

how to completely save and restore the output of the parent process and seperate my printing from its output, so after leaving my application nothing but the command I entered in the shell should be there, like when running htop and quitting it again: nothing is visible from this application anymore.

我真的不希望使用ncurses的。不过,当然,如果你知道哪些ncurses的一部分是负责这些工作,欢迎您告诉我,在源$ C ​​$ C我能找到它,所以我会研究一下。

I really don't want to use ncurses. But of course, if you know which part of ncurses is responsible for these tasks, you're welcome to tell me where in the source code I can find it, so I will study it.

推荐答案

我有点困惑。你说一个&ldquo的;终端应用程序&rdquo ;,
像vim;终端应用没有得到鼠标事件,并且不
响应于鼠标

I'm a bit confused. You speak of a “terminal application”, like vim; terminal applications don't get mouse events, and don't respond to the mouse.

如果你谈论的是真正的终端应用,在运行
的xterm ,最重要的考虑需要注意的是,许多便携性
问题涉及的终端,而不是操作系统。终端控制
通过发送不同的转义序列。哪些做什么取决于终端上; ANSI转义codeS现在相当wides $ P $垫,但是,请参见 HTTP: //en.wikipedia.org/wiki/ANSI_escape_$c$c 。这些通常是由的xterm 理解,例如。

If you're talking about real terminal applications, which run in an xterm, the important think to note is that many of the portability issues concern the terminal, and not the OS. The terminal is controlled by sending different escape sequences. Which ones do what depend on the terminal; the ANSI escape codes are now fairly widespread, however, see http://en.wikipedia.org/wiki/ANSI_escape_code. These are generally understood by xterm, for example.

您可能要输出的附加序列在开始和结束时进入和离开“全屏”的模式;这是必要的的xterm

You may have to output an additional sequence at the start and at the end to enter and leave “full screen” mode; this is necessary for xterm.

最后,你必须做一些特殊的输入/输出电平,以确保您的输出驱动器中不添加任何字符(例如将一个简单的LF到CRLF),并确保输入不回显,是透明的,并立即返回。在Linux下,这是使用的ioctl完成。 (再次提醒,不要忘了,当你完成恢复它。)

Finally, you'll have to do something special at the input/output level to ensure that your output driver doesn't add any characters (e.g. convert a simple LF into a CRLF), and ensure that input doesn't echo, is transparent, and returns immediately. Under Linux, this is done using ioctl. (Again, don't forget to restore it when you finish.)

这篇关于编写"真正的"交互式终端程序如vim,HTOP,...在C / C ++没有的ncurses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆