Manpage of Console::Console
Those functions should also make possible a port of the Unix's curses library; if there is anyone interested (and/or willing to contribute) to this project, e-mail me. Thank you.
Example:
$CONSOLE->Alloc();
Example:
$attr = $CONSOLE->Attr();
$CONSOLE->Attr($FG_YELLOW | $BG_BLUE);
Example:
$LINK->Close();
Example:
$CONSOLE->Cls();
$CONSOLE->Cls($FG_WHITE | $BG_GREEN);
Example:
($x, $y, $size, $visible) = $CONSOLE->Cursor();
# Get position only
($x, $y) = $CONSOLE->Cursor();
$CONSOLE->Cursor(40, 13, 50, 1);
# Set position only
$CONSOLE->Cursor(40, 13);
# Set size and visibility without affecting position
$CONSOLE->Cursor(-1, -1, 50, 1);
Example:
$CONSOLE->Display();
Example:
$CONSOLE->FillAttr($FG_BLACK | $BG_BLACK, 80*25, 0, 0);
Example:
$CONSOLE->FillChar("X", 80*25, 0, 0);
Example:
$CONSOLE->Flush();
Example:
$CONSOLE->Free();
CTRL_BREAK_EVENT
CTRL_C_EVENT
they signal, respectively, the pressing of Control + Break and of Control + C; if not specified, it defaults to CTRL_C_EVENT. processgroup is the pid of a process sharing the same console. If omitted, it defaults to 0 (the current process), which is also the only meaningful value that you can pass to this function. Returns "undef" on errors, a nonzero value on success.
Example:
# break this script now
$CONSOLE->GenerateCtrlEvent();
Example:
$events = $CONSOLE->GetEvents();
See also: "Attr", "Cursor", "Size", "Window", "MaxWindow".
Example:
@info = $CONSOLE->Info();
print "Cursor at $info[3], $info[4].\n";
This method will return "undef" on errors. Note that the events returned are depending on the input "Mode" of the console; for example, mouse events are not intercepted unless ENABLE_MOUSE_INPUT is specified. See also: "GetEvents", "InputChar", "Mode", "PeekInput", "WriteInput".
Example:
@event = $CONSOLE->Input();
Example:
$key = $CONSOLE->InputChar(1);
Example:
$codepage = $CONSOLE->InputCP();
$CONSOLE->InputCP(437);
# you may want to use the non-instanciated form to avoid confuzion :)
$codepage = Win32::Console::InputCP();
Win32::Console::InputCP(437);
Example:
($maxCol, $maxRow) = $CONSOLE->MaxWindow();
ENABLE_LINE_INPUT
ENABLE_ECHO_INPUT
ENABLE_PROCESSED_INPUT
ENABLE_WINDOW_INPUT
ENABLE_MOUSE_INPUT
ENABLE_PROCESSED_OUTPUT
ENABLE_WRAP_AT_EOL_OUTPUT
For more informations on the meaning of those flags, please refer to the ``Microsoft's Documentation''.
Example:
$mode = $CONSOLE->Mode();
$CONSOLE->Mode(ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT);
Example:
print "Your mouse has ", $CONSOLE->MouseButtons(), " buttons.\n";
STD_OUTPUT_HANDLE
STD_ERROR_HANDLE
STD_INPUT_HANDLE
The second form, instead, creates a console screen buffer in memory, which you can access for reading and writing as a normal console, and then redirect on the standard output (the screen) with "Display". In this case, you can specify one or both of the following values for accessmode:
GENERIC_READ
GENERIC_WRITE
which are the permissions you will have on the created buffer, and one or both of the following values for sharemode:
FILE_SHARE_READ
FILE_SHARE_WRITE
which affect the way the console can be shared. If you don't specify any of those parameters, all 4 flags will be used.
Example:
$STDOUT = new Win32::Console(STD_OUTPUT_HANDLE);
$STDERR = new Win32::Console(STD_ERROR_HANDLE);
$STDIN = new Win32::Console(STD_INPUT_HANDLE);
$BUFFER = new Win32::Console();
$BUFFER = new Win32::Console(GENERIC_READ | GENERIC_WRITE);
Example:
$codepage = $CONSOLE->OutputCP();
$CONSOLE->OutputCP(437);
# you may want to use the non-instanciated form to avoid confuzion :)
$codepage = Win32::Console::OutputCP();
Win32::Console::OutputCP(437);
Example:
@event = $CONSOLE->PeekInput();
Example:
$colors = $CONSOLE->ReadAttr(80*25, 0, 0);
Example:
$chars = $CONSOLE->ReadChar(80*25, 0, 0);
Example:
$rect = $CONSOLE->ReadRect(0, 0, 80, 25);
Example:
# scrolls the screen 10 lines down, filling with black spaces
$CONSOLE->Scroll(0, 0, 80, 25, 0, 10, " ", $FG_BLACK | $BG_BLACK);
STD_INPUT_HANDLE
STD_OUTPUT_HANDLE
STD_ERROR_HANDLE
Returns "undef" on errors, a nonzero value on success.
Example:
$CONSOLE->Select(STD_OUTPUT_HANDLE);
Example:
($x, $y) = $CONSOLE->Size();
$CONSOLE->Size(80, 25);
Example:
$title = $CONSOLE->Title();
$CONSOLE->Title("This is a title");
Example:
($left, $top, $right, $bottom) = $CONSOLE->Window();
$CONSOLE->Window(1, 0, 0, 80, 50);
Example:
$CONSOLE->Write("Hello, world!");
Example:
$CONSOLE->WriteAttr($attrs, 0, 0);
# note the use of chr()...
$attrs = chr($FG_BLACK | $BG_WHITE) x 80;
$CONSOLE->WriteAttr($attrs, 0, 0);
Example:
$CONSOLE->WriteChar("Hello, worlds!", 0, 0);
Example:
$CONSOLE->WriteInput(@event);
Example:
$CONSOLE->WriteRect($rect, 0, 0, 80, 25);
BACKGROUND_BLUE
BACKGROUND_GREEN
BACKGROUND_INTENSITY
BACKGROUND_RED
CAPSLOCK_ON
CONSOLE_TEXTMODE_BUFFER
ENABLE_ECHO_INPUT
ENABLE_LINE_INPUT
ENABLE_MOUSE_INPUT
ENABLE_PROCESSED_INPUT
ENABLE_PROCESSED_OUTPUT
ENABLE_WINDOW_INPUT
ENABLE_WRAP_AT_EOL_OUTPUT
ENHANCED_KEY
FILE_SHARE_READ
FILE_SHARE_WRITE
FOREGROUND_BLUE
FOREGROUND_GREEN
FOREGROUND_INTENSITY
FOREGROUND_RED
LEFT_ALT_PRESSED
LEFT_CTRL_PRESSED
NUMLOCK_ON
GENERIC_READ
GENERIC_WRITE
RIGHT_ALT_PRESSED
RIGHT_CTRL_PRESSED
SCROLLLOCK_ON
SHIFT_PRESSED
STD_INPUT_HANDLE
STD_OUTPUT_HANDLE
STD_ERROR_HANDLE
Additionally, the following variables can be used:
$FG_BLACK
$FG_BLUE
$FG_LIGHTBLUE
$FG_RED
$FG_LIGHTRED
$FG_GREEN
$FG_LIGHTGREEN
$FG_MAGENTA
$FG_LIGHTMAGENTA
$FG_CYAN
$FG_LIGHTCYAN
$FG_BROWN
$FG_YELLOW
$FG_GRAY
$FG_WHITE
$BG_BLACK
$BG_BLUE
$BG_LIGHTBLUE
$BG_RED
$BG_LIGHTRED
$BG_GREEN
$BG_LIGHTGREEN
$BG_MAGENTA
$BG_LIGHTMAGENTA
$BG_CYAN
$BG_LIGHTCYAN
$BG_BROWN
$BG_YELLOW
$BG_GRAY
$BG_WHITE
$ATTR_NORMAL
$ATTR_INVERSE
ATTR_NORMAL is set to gray foreground on black background (DOS's standard colors).
http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/sys/src/conchar.htm
A reference of the available functions is at:
http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/sys/src/conchar_34.htm
This is distributed under the terms of Larry Wall's Artistic License.