Unit DConsole

Classes

TAttr -
TAttrManager -
TColorConsole -
TConsole -
TFixedFont - forward declaration

Functions

Exchange -
FillInt -
Register - Since we've manipulated the DC directly, and the canvas may think its current objects are still selected, we should force the canvas to deselect all GDI objects

Types

PIntArray
TCMScrollBy
TConsoleLineBreak
TConsoleOption
TConsoleOptions
TIntArray
TProcessControlCodes

Constants

CM_ScrollBy
CM_TrackCursor

Variables


Functions


procedure Exchange(var X,Y: Pointer);


procedure FillInt(var Buf; Count: Cardinal; Value: Integer);


procedure Register;

Since we've manipulated the DC directly, and the canvas may think its current objects are still selected, we should force the canvas to deselect all GDI objects

Types


PIntArray = ^TIntArray

TCMScrollBy = record
Msg : Cardinal;
dx : Integer;
dy : Longint;
end;

TConsoleLineBreak = (CRLF, CR, LF);
CR/LF translation. CRLF = no translation CR = on CR add LF LF = on LF add CR
TConsoleOption = (coAutoTracking, coCheckEOF, coCheckBreak,
    coFulltimeCursor, coLazyWrite, coStdInput, coStdOutput, coFixedPitchOnly);

TConsoleOptions = set of TConsoleOption

TIntArray = array [0..0] of Integer;

TProcessControlCodes = procedure (Sender: TConsole;
				    Buffer: PChar; Count: Cardinal) of object

Constants

CM_ScrollBy = wm_User + 101

CM_TrackCursor = wm_User + 100

TConsole TConsole implements a WinCRT-like control for routing text file I/O (readlns and writelns) to a scrollable window. A text cursor can be positioned using X,Y text coordinates. TConsole is not intended to be a text editor, merely a TTY text output device. TConsole does not store its text buffers when it is streamed. Max display text in 16 bit applications is 64k (rows * columns <= 64k); in 32 bit applications, the only capacity limit is system memory. You can set the TConsole font name, style or other properties, but only fixed-pitch fonts should be used. TConsole can be extended to support text color attributes and multiple fonts, and can support multiple terminal emulation command decoders (like ANSI-BBS or DEC VT-100). TConsole supports keyboard input via the Pascal standard input functions ReadKey, Keypressed, and Readln. Note that the modal nature of Readln (execution doesn't return until EOL is received) is problematic. Only one outstanding Console Readln operation is supported for the entire application. Calling readln while another readln is pending (eg Readln on a button click) will raise an exception. TConsole provides a performance option called toLazyWrite. With this option turned off, each write operation to the Console is immediately displayed on the screen. With toLazyWrite turned on, screen updating is delayed slightly so that multiple text changes can be displayed in one Paint operation. Despite the 'lazy' name, this consolidation results in dramatically better display performance - a factor of 10 to 100 times faster than writing each little piece of text immediately. toLazyWrite is enabled by default. The public ScrollTo and TrackCursor methods don't use toLazyWrite, nor do the ReadKey or ReadBuf routines. When these routines modify the display or text buffer, the Console is updated immediately. The coFixedPitchOnly option, True by default, determines whether the console component raises an exception when a font which is not marked as fixed pitch is assigned to the component. Many off-brand truetype fonts which have a uniform character width are incorrectly marked as proportional fonts. By setting coFixedPitchOnly to false, you can now use those fonts in the console components. Using proportional fonts in a console component is not advised; it's very ugly. TColorConsole TColorConsole implements support for multiple text color attributes. The Console's font properties determine the text color, background color, font, style, etc of the display text. Text foreground color is Console.Font.Color; text background is Console.Font.BkColor. Set the Console's font properties, then writeln to the Console's text file and that text will be displayed with those attributes. In 16 bit applications, TColorConsole has the following capacity limits: Max display text is 32k. (rows * cols <= 32k). Max unique text attribute sets: 16k. (unique = font+color+bkcolor) In 32 bit applications, the only limit is system memory. Memory consumption is roughly 5 bytes per display text character cell: an 80 x 25 color console will use 80 x 25 = 2000 bytes for the text buffer plus 80 x 25 x 4 = 8000 bytes for the cell attribute buffer. Each unique text attribute set uses 36 bytes of memory. Text attribute sets are maintained in a pool. Each attr set is released when the last char in the display buffer using that set is overwritten with different attributes. Multiple fonts are supported, but the cell height and width of the fonts must be the same. That is, you can output text in Courier New 10pt, Courier New 10pt Bold, and Lucida Sans Monospace 10pt Italic all on the same screen. If the Console's font size is changed, that size change is applied to all fonts used by the Console control and the control is repainted. Fonts of the same height often have different widths. When a wider font is selected into the Console control, the character cell dimensions for all the text is enlarged to accommodate the wider font. Characters of narrower fonts will be spaced further apart to maintain column alignment. This rarely looks appealing, so take it easy on the fonts. TrueType fonts (like Courier New) tend to work better than bitmap fonts (like Courier). TConsole's output routines Most of the time, you'll use a text file to write data to the Console window. To make the component intercept all output written to stdout (ie anything that calls write or writeln without a file handle), include the coStdOutput flag in the component's Options property. Only one component in the application can intercept stdout. coStdOutput is disabled by default. For more specialized work, such as extending these objects or adding terminal emulation processor methods, you can use some of TConsole's specialized output routines. WriteChar Calls WriteCodedBuf to output one character using the current font/color attributes. WriteString Calls WriteCodedBuf to output the characters in the string using the current font/color attributes. WriteCodedBuf Passes control to the ProcessControlCodes method pointer if it is assigned. If the pointer is not assigned, WriteBuf is called instead. WriteCodedBuf is called by the internal text file device driver (Write and Writeln), WriteChar, and WriteString. Your ProcessControlCodes routine should parse the buffer to find and execute complex display formatting control codes and command sequences embedded in the data stream (such as ANSI terminal codes). ProcessControlCodes is an event so that it can be reassigned dynamically at runtime - for example, to switch from ANSI emulation to Wyse terminal emulation. Control code processing methods have full responsibility for displaying the actual text - they should parse their control codes, set the cursor position or font/color attributes as needed, and then call WriteChar, WriteString, or WriteFill as necessary to display the actual text (without codes). If you determine that a text buffer contains no special codes for your ProcessControlCodes event to handle, you can pass the text buffer to DefaultProcessControlCodes to perform the normal WriteBuf text processing on the buffer. This will save you some work in your event handler. WriteFill Replicates a single character (or space) N times starting from text coordinate X,Y and flowing down the page. All the replicated chars are displayed with the currently selected font and color attributes. The copy count can be any length up to (rows * cols). TColorConsole overrides this method to add additional color support. WriteBuf This is an internal (protected) mid-level method to process simple text file formatting codes. It scans the data stream for special characters (Carriage return, Linefeed, Backspace, Bell), wraps text at the right margin, and calls WriteBlock or WriteFill for actual output. WriteBlock This is an internal (protected) low-level method to output a string of characters. WriteBlock assumes the string parameter has been stripped of all special characters and is guaranteed to contain no more than one line of text (length <= Cols - Cursor.X). All the characters in the string are displayed with the currently selected font and color attributes. TColorConsole overrides this method to add additional color support.

Variables