1

In this question I'm asking of one specific bit of functionality of readline:

The Readline library includes additional functions to maintain a list of previously-entered command lines, to recall and perhaps reedit those lines

Now on Windows with Visual Studio you ain't need no stinking readline. You can use fgets and arrow keys will happily recall what you typed previously. Of course you can edit these too.

On linux the very same code (fgets in a loop ) does not work like this. Up arrow is shown as ^[[A and left and right arrows also does not allow you navigating the line as shown by experiment and also described here.

My question is, what part of Windows makes the editing possible?

I think it can be either conhost.exe or how fgets, et al, are implemented. Somehow I suspect that it's the former. In any case, I'd like to know how exactly it works if it's documented anywhere, etc. For example, what other keys, apart from arrows have a special meaning and processed differently instead of being returned as par of the buffer fgets writes to.

Community
  • 1
  • 1
Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158
  • 2
    I *think* this is logically handled by the console device, and only happens when the console device is in [cooked mode](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx). The implementation details are subject to change, but yes, I'd guess it actually happens inside `conhost.exe` in current versions of Windows. I'm pretty sure it isn't part of the C runtime library, i.e., nothing to do with `fgets`. – Harry Johnston Apr 02 '17 at 02:37

1 Answers1

1

The documentation for DOSKEY lists the special keys.

I am not aware of any documentation explaining that in 32-bit Windows this functionality is built into the console and that doskey.exe is merely an interface to it. However, it is easy to confirm that this functionality does not depend on the running console application using the C runtime library or having been launched from the command-line shell.

It is a reasonable guess that the actual code implementing this feature lives inside conhost.exe on current versions of Windows, but of course that's an implementation detail, subject to change without notice. From the programmer's perspective, all that matters is that DOSKEY functionality is present on any console window, and is available whenever the application is in cooked mode.

Note that cooked mode is the default setting. Therefore, console applications will have DOSKEY functionality unless the application specifically disables it.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158