How do shell text editors work?

2019-04-07 09:06发布

I'm fairly new at programming, but I've wondered how shell text editors such as vim, emacs, nano, etc are able to control the command-line window. I'm primarily a Windows programmer, so maybe it's different on *nix. As far as I know, it's only possible to print text to a console, and ask for input. How do text editors create a navigable, editable window in a command line environment?

8条回答
狗以群分
2楼-- · 2019-04-07 09:38

You will also notice this if you type "edit" in a Windows command line console. This "feature" is not unique to unix-like systems, though the concepts for manipulating the windows console in that way are quite different to in unix.

查看更多
神经病院院长
3楼-- · 2019-04-07 09:40

Short answer: there are libraries for it (like curses, slang).

Longer answer: doing things like jumping around with the cursor or changing colors are done by printing special character sequences (called escape-secquences, because they start with the ESC character).

查看更多
登录 后发表回答