How do shell text editors work?

I am new to programming, but I wondered how shell text editors such as vim, emacs, nano, etc., can control the command window. I am primarily a Windows programmer, so maybe it is different from * nix. As far as I know, you can only print text on the console and request input. How do text editors create a navigable, editable window in the command line environment?

+7
shell text-editor
07 Oct '08 at 16:27
source share
8 answers

Using libraries such as the following, which in turn use character escape sequences

 NAME
        ncurses - CRT screen handling and optimization package

 SYNOPSIS
        #include 

 DESCRIPTION
        The ncurses library routines give the user a terminal-independent 
 method of updating character screens with reasonable optimization.  This 
 implementation is '' new curses '' (ncurses) and is the approved replacement 
 for 4.4BSD classic curses, which has been discontinued.

 [... snip ....]

        The ncurses package supports: overall screen, window and pad 
 manipulation;  output to windows and pads;  reading terminal input;  control 
 over terminal and curses input and output options;  environment query 
 routines  color manipulation;  use of soft label keys;  terminfo capabilities; 
 and access to low-level terminal-manipulation routines.

+9
Oct 07 '08 at 16:33
source share

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

The longer answer: Doing things like jumping with the cursor or changing colors is done by printing special character sequences (called escape-secquences, since they start with the ESC character).

+5
07 Oct '08 at 16:29
source share

Learning about ncurses can be a good starting point.

+3
Oct 07 '08 at 16:28
source share

There is an old vt100 protocol based on the VT100 terminal. He used codes starting with escape to control the cursor position, color, clear the screen, etc.

This is also how you get color tips.

Google VT100 or "terminal exit codes"

edit: I Googled it for you: http://www.termsys.demon.co.uk/vtansi.htm

+3
Oct 07 '08 at 16:28
source share

You will also notice this if you type “edit” in the Windows command line console. This “feature” is not unique to Unix-like systems, although the concepts for managing the Windows console in this way are completely different on UNIX.

+3
07 Oct '08 at 16:33
source share

On Unix systems, the console window emulates an old serial terminal (usually VT100 ). You can print special control characters and escape sequences to move the cursor, change colors, and other special effects. There are libraries to help you handle the details; ncurses is the most popular.

The Windows API [Win32 Console API] ( http://msdn.microsoft.com/en-us/library/ms682073(VS.85%29.aspx) provides similar functionality, but in a different way.

+2
07 Oct '08 at 16:48
source share

Type "c: \ winnt \ system32 \ edit" or "c: \ windows \ system32 \ edit" at the command prompt and you will be shown a text editor on the command line.

People are mostly right about the ESC character that is used to control the command screen, but some older programs also write characters directly to the memory space used by the Windows command line screen.

To manage the command line window, you had to write your own window forms, input field, menu, etc. You would also have to wrap all this in a large event loop.

+2
Oct 07 '08 at 16:54
source share

An additional specification of the Windows command line, an application usually calls DOS or BIOS functions that do the same. Sometimes support for ANSI code is available, sometimes it is not (depending on the exact version of MS OS and whether it is configured to load it).

0
Oct 07 '08 at 16:38
source share



All Articles