Mengfei Murphy
Mengfei Murphy

Reputation: 1089

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.

Upvotes: 0

Views: 933

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126787

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.

Upvotes: 2

Related Questions