winpty/agent/Win32Console.h
Ryan Prichard ac76cbcc20 Initial checkin of improved console input handling.
* Generate Ctrl-C events by calling GenerateConsoleCtrlEvent.

   I noticed that calls to this routine don't behave exactly the same as
   a real Ctrl-C keypress.  In Python, pressing Ctrl-C immediately
   displays a new "KeyboardInterrupt" line.  Calling
   GenerateConsoleCtrlEvent has no immediate effect, but after pressing
   Enter, Python displays a stack trace where a KeyboardInterrupt was
   raised.  After some testing, I suspect the issue is that a real Ctrl-C
   keypress interrupts a blocking console read, but
   GenerateConsoleCtrlEvent does not.

   I also tried synthesizing Ctrl-C using (a) PostMessage with
   WM_{CHAR,KEYDOWN}, and (b) SendInput.  I couldn't get either to work.

 * Recognize ESC sequences.  The set of recognized sequences is ad hoc.

 * Recognize UTF-8-encoded characters and convert them to UTF-16.

 * The code currently uses a timeout to differentiate between pressing ESC
   and pressing a key that generates an ESC sequence.  I have a theory that
   I can use the "Device Status Report" ESC sequences to avoid this
   timeout.
2012-03-19 21:30:16 -07:00

44 lines
939 B
C++

#ifndef WIN32CONSOLE_H
#define WIN32CONSOLE_H
#include <windows.h>
#include "Coord.h"
#include "SmallRect.h"
class Win32Console
{
public:
Win32Console();
~Win32Console();
HANDLE conin();
HANDLE conout();
HWND hwnd();
void postCloseMessage();
// Buffer and window sizes.
Coord bufferSize();
SmallRect windowRect();
void resizeBuffer(const Coord &size);
void moveWindow(const SmallRect &rect);
void reposition(const Coord &bufferSize, const SmallRect &windowRect);
// Cursor.
Coord cursorPosition();
void setCursorPosition(const Coord &point);
// Input stream.
void writeInput(const INPUT_RECORD *ir, int count=1);
bool processedInputMode();
// Screen content.
void read(const SmallRect &rect, CHAR_INFO *data);
void write(const SmallRect &rect, const CHAR_INFO *data);
private:
HANDLE m_conin;
HANDLE m_conout;
};
#endif // WIN32CONSOLE_H