简体   繁体   English

如何使用c在终端上实现“文本编辑器”样式界面

[英]How to implement a “text editor” style interface on terminal using c

I'm not trying to make a text editor yet. 我还没有尝试制作文本编辑器。 What I want to do now is simpler. 我现在想做的更简单。 It will be a command line tool (either Linux or windows). 它将是一个命令行工具(Linux或Windows)。 When you execute it, the user shall see a cleared terminal area, like you try to create a new file using vi. 当您执行它时,用户应该看到一个已清除的终端区域,就像您尝试使用vi创建新文件一样。
The user can then type in some pre-defined command. 然后,用户可以键入一些预定义的命令。 Question: how to define where the user inputs? 问题:如何定义用户输入的位置? Say like what vi does, at the bottom of the terminal screen? 像终端屏幕底部的vi那样说?
According to the command the user typed in, some info or figure will be shown/drawn on the screen. 根据用户输入的命令,将在屏幕上显示/绘制一些信息或图形。
The user can type in command at any time, the result will be output immediately. 用户可以随时输入命令,结果将立即输出。

The difficulty for me is how to implement such an input/output interface. 对我来说困难的是如何实现这样的输入/输出接口。 Comment if there is anything not clear. 评论是否有任何不清楚的地方。

The C standard "per se" doesn't define anything for this task, for what it is concerned the terminal is "just like a file" - two (three counting stderr) streams of data, that's it. C标准“本身”没有为此任务定义任何内容,因为它关注的是终端“就像一个文件” - 两个(三个计数stderr)数据流,就是这样。

To use the terminal in a more advanced way you have to use platform-specific methods, be them ioctl calls or VT* escape sequences. 要以更高级的方式使用终端,您必须使用特定于平台的方法,无论是ioctl调用还是VT *转义序列。 But more probably you'd better use a higher level library that handles all the low-level fuss and lets you focus on more important stuff, the classical one is ncurses . 但更可能你最好使用更高级别的库来处理所有低级别的烦恼,让你专注于更重要的东西,经典的是ncurses

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

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