TBMANLIB_ConsoleCore Package
Author: woeoio.
The TBMANLIB_ConsoleCore contributed package is a library for the console of a twinBASIC program. Its class cConsole writes text in 16 colours, reads lines, single keys and passwords, moves the cursor, switches the console to UTF-8 and to the escape-sequence mode, and has a full-screen mode in which a program draws into an in-memory grid, cConsoleBuffer, and receives key, mouse and window-size events. The module mConsoleStyle builds the escape sequences for colours, text styles and cursor movement, and has helpers that align, shorten and wrap text. This section documents version 0.0.0.0, published on TWINSERV on 1 February 2026 with no licence declared. The package describes itself as “TBMAN: Modern console library with UTF-8, colors, and full-screen support”.
The library is built on the Windows console functions of kernel32.dll. The package TBMANLIB_ConsoleComponents, by the same author, is a set of text-interface components that draw into the buffer of this package.
Note
The tools that check this documentation’s samples run a sample and compare what it prints with Debug.Print. They cannot yet read what a program writes to a console, or send it keys and mouse events. So the samples on these pages are compiled, and what they show on the console has not been checked by running them. Statements about console output, keys and the mouse follow the package’s source, and will be checked once the tools can capture a console.
Dim con As New cConsole
con.EnableUTF8
con.EnableVirtualTerminal
con.Title = "Demo"
con.WriteLineColored "Hello, world", ConsoleColor.Green
con.WriteAt 0, 2, mConsoleStyle.Bold & "Bold text" & mConsoleStyle.Reset
con.WriteLine
con.Restore
Warning
Several members of version 0.0.0.0 do not do what their names suggest. ReadKey never returns in a program that has no console input, and a comparison of a key with a member of ConsoleKey is true for the wrong key. Defects in version 0.0.0.0 lists them with the pages that describe them.
- Which project it needs
- What the package offers
- Defects in version 0.0.0.0
- Classes and modules
- Declarations of the Windows API
- See Also
Which project it needs
The package works on the standard input, output and error handles that Windows gives a program, and the members that read or draw reach Windows through them. It is meant for a console application: a project with Is Console Application set to Yes, which the Standard EXE (Console App) template does, as Console Applications describes. Add the package as Importing a package from TWINSERV describes.
A program with no console can create a cConsole, and the buffer of the full-screen mode then works as an in-memory grid, but nothing is shown and the members that wait for a key never return. Without a console lists what each member does in that case. When the output of a console program is redirected to a file or a pipe, the write members write nothing; see Redirected input and output.
What the package offers
- Text output. WriteTo, WriteLine, WriteF with numbered placeholders, the coloured variants, WriteAt at a position, and WriteError for the standard error handle.
- Input. ReadLine, ReadKey, ReadKeyTimeout, ReadPassword, and tests for pending input.
- Console state. Colours, the cursor, the title, the code pages, the escape-sequence mode and the size, and Restore, which puts the state of the console back as it was.
- Full-screen mode. EnterFullScreenMode, ProcessEvents with handlers for keys, the mouse and the window size, and Refresh, which writes the changed part of the buffer in one call.
- The buffer. cConsoleBuffer draws characters, lines, boxes and filled rectangles, copies and scrolls regions, and keeps a dirty rectangle so that Flush writes only what changed.
- Escape sequences. mConsoleStyle returns the sequences for 16, 256 and 24-bit colours, bold, underline and the other styles, cursor movement, clearing, scrolling and the alternate screen, and constants for box-drawing, block, arrow and symbol characters.
Defects in version 0.0.0.0
- ReadKey and ReadPassword never return when the program has no console input.
- The key codes of ConsoleKey are not the virtual-key codes that ReadKey and the key handler return, except for Enter, Escape, Space, Backspace and Tab.
- KeyAvailable is true for any input event, including a key release.
- WriteColored, WriteLineColored and WriteAtColored default the background to black, and leave the console in Gray on Black.
- Refresh draws at the top of the screen buffer, which is out of sight when the window shows another part of it, and draws nothing after a WriteAt with a negative column or row.
- OnResize is given the size of the screen buffer, not of the window.
- OnCtrlEvent adds a handler that is never removed, and none of the four handler properties can be cleared.
- ScrollRegion of the buffer moves a region by less than the distance asked for when the region is near the top or left edge of the buffer.
- RepeatStr repeats only the first character of its string, and StripAnsi removes text after some sequences.
- Of the types in Types, ConsoleTextStyle, ConsoleMode, ConsoleEventType, ConsoleEventInfo and the delegates ConsoleTimerCallback and ConsoleRenderCallback are not used by any member.
Classes and modules
- cConsole – writes and reads text, controls the cursor, colours and modes of the console, and runs the full-screen mode
- cConsoleBuffer – a grid of characters and colours in memory, written to the console in one call
- mConsoleStyle – escape sequences for colours, styles and cursor movement, text helpers and drawing characters
- Types – the enumerations, the structures such as ConsoleRect and ConsoleKeyInfo, and the handler types
Declarations of the Windows API
A fifth public module, mConsoleAPI, has no page of its own, since a program does not need it, but a project that references the package can use its members. It declares 51 functions of kernel32.dll, user32.dll and oleaut32.dll: the console functions that cConsole calls and others, such as AllocConsole, FreeConsole, AttachConsole and CreateConsoleScreenBuffer, and the general functions Sleep, GetTickCount, GetAsyncKeyState, SetTimer and KillTimer. It also declares 12 structures (among them COORD, SMALL_RECT, CHAR_INFO, INPUT_RECORD and RECT), 47 constants for modes, events, code pages and key states, and five helper functions: MakeCOORD and MakeDWORD pack two 16-bit values into a Long, LoWord and HiWord take them out, and ColorAttribute combines a text and a background ConsoleColor into a console attribute. All these names are public, so they are visible in a project that references the package.
See Also
- cConsole class – the console
- cConsoleBuffer class – the screen buffer of the full-screen mode
- TBMANLIB_ConsoleComponents package – progress bars, charts, panels, layouts and a data grid that draw into the buffer
- Console Applications – the project type that the package is made for
- Importing a package from TWINSERV – adding a published package to a project