简体   繁体   中英

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). When you execute it, the user shall see a cleared terminal area, like you try to create a new file using 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?
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.

To use the terminal in a more advanced way you have to use platform-specific methods, be them ioctl calls or VT* escape sequences. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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