Skip navigation links

Package ca.randolf.fx.textmode

TextRegion is a high-performance pixel-perfect JavaFX text-mode region that accurately resembles the look-and-feel of Unix and DOS screens that were popular in the 1980s.  In particular, the font's appearance has been accurately re-created, the cursor's behaviour has been implemented with the utmost attention to function and timing, and has support for both AVATAR (AVT/0+) and ANSI code sequences.  New features are also introduced to modernize this extensive implementation of text mode, such as support for full RGB colour support with transparency (RGBA).

See: Description

Package ca.randolf.fx.textmode Description

TextRegion is a high-performance pixel-perfect JavaFX text-mode region that accurately resembles the look-and-feel of Unix and DOS screens that were popular in the 1980s.  In particular, the font's appearance has been accurately re-created, the cursor's behaviour has been implemented with the utmost attention to function and timing, and has support for both AVATAR (AVT/0+) and ANSI code sequences.  New features are also introduced to modernize this extensive implementation of text mode, such as support for full RGB colour support with transparency (RGBA).

Acronyms used throughout this document
  • ASCII = American Standard Code for Information Interchange
  • ANSI = Advanced Numeric Screen Instruction
    • ANSI (standard) = American National Standards Institute
  • API = Application Programming Interface
  • AVATAR = Advanced Video Attribute Terminal Assembler and Recreator
    • AVT = Advanced Video Terminal
  • BBS = Bulletin Board System
  • CPU = Central Processing Unit
    • GPU = Graphics Processing Unit
  • DOS = Disk Operating System
  • GUI = Graphical User Interface
  • I/O = Input/Output
  • JVM = Java Virtual Machine
  • MB = MegaByte (1 MegaByte = 1,048,576 bytes, a.k.a., 2^20 bytes)
  • OS = Operating System
  • PC = Personal Computer
    • AT = Advanced Technology
    • PS/2 = Personal System/2
    • XT = eXtra Technology
  • RAM = Random Access Memory
  • RGB = Red Green Blue
    • ARGB = Alpha Red Green Blue
    • BGRA = Blue Green Red Alpha
    • RGBA = Reg Green Blue Alpha
  • SQL = Structured Query Language
  • UTF-8 = Universal Transformation Format-8 (character encoding)
  • VGA = Video Graphics Array

The thread-safe design of TextRegion makes it possible for multiple threads to update it simultaneously because all commands and text output sent to it are queued to ensure atomic operations occur in the order in which they were injected.  Further to that, Transactions are also supported which make it easy to arrange an assortment of commands and text output before committing the transaction for injection into the TextRegion without losing its place in the queue.

Perceptions

When people see a text mode screen, such as that presented by TextRegion, they often assume that they're using a DOS application.  This is due to the fact that a text mode interface was used by the vast majority of DOS applications.

However, "text mode" is not equivilant to "DOS" and there are also many non-DOS applications that utilize text mode (such as the FAR Manager at http://www.farmanager.com/, which we assume was inspired by the Norton Commander, an advanced and famously popular file management system for DOS that was an essential tool for many computer users).

Capabilities

Extended ASCII is supported.  Unicode, UTF-8, etc., is not at this time (but provisions have been included in the internal design to simplify adding support for it in the future), so if you need to support other languages that aren't possible with the standard Extended ASCII character set, then TextRegion probably won't satisfy your requirements (if there is sufficient demand and support for it, and free fonts are available for inclusion, I am interested in updating this class accordingly).

For ASCII art, ASCII games, text-mode interfaces, etc., TextRegion is very well-suited.  TextRegion also supports blinking and underlining attributes, and custom (RGB) colours with transparency support (RGBA), for which more details are available in the "Features" section (below).

Text output is designed to be handled in the most efficient manner.  All queued command sets that alter attributes, write to the TextRegion, etc., are processed on the secret JavaFX background thread as they become ready.  Also, the use of primitive data types eliminates unnecessary memory and processor overhead incurred by the Object-wrapped variants of these types, which is particularly important for loops that draw characters, pixel-by-pixel, and manipulate groups of screen memory for scrolling and other such operations.

History

Some of the main reasons that text-mode applications disappeared, which were primarily architectural challenges imposed by DOS, included a variety of limitations:

The most notable aspect was the popularization of the GUI (Graphical User Interface), but not so much for reasons of practicality (because support for it required more powerful hardware) or because it looked attractive (in fact it tended to look very ugly and unfriendly with all the single-colour pixel patterns and shades of grey, and the small assortment of icons that were built with {at the time} limited numbers of colours, that all resided on top of bland colour schemes that were set up by default on the majority of the GUI-centric Operating Systems {after colours were introduced in the later versions}), but because it was well marketed to software developers and users in a way that emphasized that it was where the future of computing was headed.

This over-emphasis by marketers turned out to be a great success for the GUI, and although it, for the most-part, ended text-mode development, most of the ASCII art and ANSI art enthusiasts weren't discouraged and all the hardware manufacturers continue to support it to this day not only because there is so much software that still needs it (such as the BIOS interface), but also because it's so simple to implement.  Text mode is extremely useful, and even Apple is finding that they can no longer continue to avoid it (they were the only vendor I'm aware of who manufactured computer hardware that had absolutely no text mode support {it started in graphics mode first, immediately after the power was switched on, displaying Apple's famous MacOS logo, icons, etc., prior to booting the Operating System}, until within the first decade after the turn of the century; c. year 2000).

Evolution - 1st generation text mode

The first generation of text mode was very simple, and was compatible with line printers (a.k.a., basic dot matrix printers), and later evolved to what I refer to as "second-generation text mode."

Functional control characters that could move the cursor's position (the most common provided tabulation, home position, and line feed support), clearing the screen, implementing the BackSpace key's function, etc., were essential aspects of the basic text-mode interface.

Some vendors ventured forth with a few additions that eventually became common-place on most platforms as well, most notably Unix, but those basic few mentioned in the previous paragraph were the only ones that were supported with actual consistency.

Evolution - 2nd generation text mode

The second generation introduced underlining, high-intensity (bold), and blinking effects, which were initially popular on monochrome (no colour) displays and various types of mainframe terminals.  Some manufacturers made some significant enhancements to the feature-set, most notably IBM who added a 26th row to the bottom of the screen to display a small variety of some really nice looking non-standard characters to indicate the status for various actions/activities (note that TextRegion has built-in support for more than 256 characters, so this feature can be supported eventually).

The second generation also introduced 16 colours, with a background colour that could be set independently from the character colour.  This, combined with the Extended ASCII characters, turned out to be a wonderful feature for ASCII art creators who wanted to use colours.  With this colour came those who then wanted to take ASCII art into the 8-bit realm, and thus ANSI art was born due to the ubiquitous deployment of ANSI among users of BBSs (Bulletin Board Systems), which were the mainstream electronic communications medium to the introduction of the internet to the general public in the 1990s.

Unix environments contributed tremendously to text mode and were especially notable for the flexible screen sizing capabilities, some of which was made available to DOS users later on.  Certain video card manufacturers, such as ATi, also pioneered support for some exotic text mode screen sizes that included hundreds of rows and columns (albeit with very small fonts) that also yielded better performance than using graphics mode to accomplish the same screen output (the newer high-performance video cards that were produced less than a decade later completely overcame this graphics mode performance challenge due to the inclusion of graphics card processors for which even later generations were referred to as GPUs, which is a variant of the acronym "CPU").

Evolution - 3nd generation text mode

Thanks to Java, the aforementioned limits are also not a hinderance, so the potential future of feature-rich text-mode applications and games is very promising.  TextRegion takes text-mode screen technology to a new level with features like per-character transparency (Unix is known for providing a uniform transparency level only) which greatly simplifies the creation of "viewports" that reveal portions of background graphics (this could be used in text-mode platform game development with a background that scrolls or changes in other ways).  In a future version I would like to expand TextRegion's support for more than 256 characters with an easy means of drawing custom characters on-the-fly.

The features introduced by TextRegion (documented below) evolves text mode into its 3rd generation of progress.  Aside from per-character transparency and support for characters beyond the 8-bit realm, there is also multi-processor/thread and database-like transaction support that make it a very capable JavaFX Region Node.

Features

My hope, with these new features, is that a blizzard of new text-mode games that utilize TextRegion will increasily become available.  I would love to recieve a letter or an eMail about any text-mode games (or applications of any type) that use TextRegion so that I many link to it from some of my web sites.  In particular, I'd love to promote any educational games and applications.

I would also like to see interest from hardware manufacturers wanting to support this implementation of text-mode with the new features I've added, natively with their video cards.  Whether they implement it with an embedded JVM (this is likely the best and easiest approach because it will require far less programming and can be updated easily), or directly in hardware (I can even help with implementation design and testing).

Text mode font
The font is based on the native font used on the original VGA and SuperVGA video adapters of XT, PC, and PS/2 computers.  It is a fixed-size font that is commonly referred to as the CP437 (Code Page 437) font where every character has the same width and height in pixels, and also includes the original standard Extended ASCII characters (8-bit altogether with the 8th bit set).

This is a specialized font used to implement text mode because Java doesn't support using any of the text modes natively supported by nearly all video hardware when specifying a custom graphics mode, and store it internally in the form of arrays of points to be drawn on the screen (this results in a small savings in memory, and uses fewer CPU cycles to draw characters than a typical TrueType Font).

The standard Extended ASCII (or "8-bit ASCII") character values range from 0 through 255.  These "Extended" characters (values above 127) are essential to good user-friendly text-mode interface designs because they include, in particular, mathematical symbols and line-drawing characters (plus some language-specific letters with accents, umluts, etc.) that aid in presenting information to the user in a manner that's easier for audiences to understand.

Flashing cursor
The cursor flashes in the same manner as text mode, and helps to re-create the look-and-feel of actual text mode.  It can be disabled at will, and its shape can be changed.

Two specific commands for disabling and enabling the cursor are also provided.  Since the implementation of this feature was different on early text-mode computers, many of which didn't have this feautre at all (so the work-around was to change the size of the cursor to make it invisible, although this was also problematic because rules for setting the cursor size were also inconsistent due to competing vendors interpreting these numbers differently).

Per-character foreground/text colours
The foreground/text colours may be specified for every character (the most recent colour setting is used when not specified).

Additionally, colours may be specified by providing RGB (or RGBA) colour values.  This feature, which is not supported by the standard older first-evolution and second-evolution text modes, is unique to TextRegion.

Per-character background colours
The background colours may be specified for every character (the most recent colour setting is used when not specified).

Normally there are only 8 possible background colours unless a special flag is set to extend this to 16 (this flag was primarily intended to disable blinking text).  TextRegion supports all 16 background colours without the need to set a special flag.

Additionally, colours may be specified by providing RGB (or RGBA) colour values.  This feature, which is not supported by the standard older first-evolution and second-evolution text modes, is unique to TextRegion.

Transparency attribute
For each character, the background can be set to be fully transparent.  Whatever was drawn immediately behind each transparent charater will be visible, and will appear behind the foreground text character.  This is particularly useful for:

  • Implementing text menus that float in front of another screen (e.g., drop-down menus)
  • Revealing graphics that are positioned behind the text screen (e.g., to create the appearance that graphics are inside a box comprised of Extended ASCII line drawing characters)
  • A viewport in a video game, to create the illusion that your user is looking out of a window of a moving room as scenery scrolls by (e.g., looking out the window from inside a space ship, and seeing stars plus the occasional planet passing by)

For more detailed control over transparency, which is provided with advanced alpha-blending techniques, TextRegion supports the use of custom RGBA colours for backround and/or foreground colours, which makes it possible to appear partially blended with whatever is in the background.

The flashing cursor always incorporates the alpha-blending setting of the character it obscures.

Additionally, colours may be specified by providing RGB (or RGBA) colour values.  This feature, which is not supported by the standard older first-evolution and second-evolution text modes, is unique to TextRegion.

Blinking attribute
Any text character can be set to blink.

In text mode, all characters that blink do so at precisely the same moment, and at a rate that [hopefully] isn't bothersome.  Much effort was expended to ensure that TextRegion simulates this effect well, and so the speed of the blinking was chosen with great care.

Underlining attribute
Any character may be displayed with an underline.

This feature was available on monochrome displays because certain colours indicated when text should appear underlined (this approach was a good one because colours were differentiated in a useful way; this is also the reason some DOS applications prompted the user as to whether they were using a colour display {a different colour scheme would be used for non-colour displays to prevent underlining from being displayed inappropriately}).

Although underlining was only really available on monocrhome displays, TextRegion supports this feature without compromising colour selection options.

Strike-through attribute
Any character may be displayed with a strike-through line, which is drawn horizontally across the middle.

This feature, which is not supported by the standard older first-evolution and second-evolution text modes, is unique to TextRegion.

JavaFX integration
This class extends JavaFX's Region object, which means that it can be seamlessly integrated into any JavaFX Parent container, and be positioned accordingly.

The transparency features for backgrounds make it easy to display ASCII text within your applications, without interfering with the style and background behind it.  One example of such an application is a hexadecimal file editor that shows all the binary characters on one side of the screen using a TextRegion object that doesn't need to obscure any characters by a period (as most editors that support hexadecimal editing mode normally do).

Thread-safety
Multiple threads may operate on TextRegion simultaneously, altering its attributes, cursor position, etc., without problems.  The developer, Randolf Richardson, has extensive experience programming threads, threadgroups, processes, locks, semaphores, etc., and has a thorough understanding of the many problems that can arise from incorrectly sharing resouces in busy, high affinity multi-threading contexts.

A low-overhead thread-safe queing system is used to ensure that every aspect of screen I/O is processed in the intended order, and without conflict or unneccesary complexity.  This simplifies the reliable, high-performance implementation of a feature-rich command-set, which leads to greater flexibility for multi-threaded application development.

Transactions
Interactions with the TextRegion can be grouped into sets of transactions to prevent settings change and text output collisions, which can result in unintended combinations of text and colour, cursor movements, etc.

Transactions are a very useful concept that has a proven track record due to heavy use in enterprise-class SQL servers such as PostgreSQL and Oracle.  The TextRegion transactions start with the begin() method call, and are ended with either the commit() or rollback() method calls, similarly to SQL transactions.

Any number of transactions are permitted within any transaction, but do note that nothing will appear on the screen until the root (first/initial) transaction in the hierarchy is finally committed.

A transaction is written to the screen when commit() is called, and not when the transaction was started, unless the point in time when the transaction was started is still in the queue (then the transaction will appear to have been inserted at that point instead).  The commitNow() method will always add the transaction to the end of the queue regardless of whether its starting point is still in the queue (effectively moving the transaction to the end, like the "end of the line" in a bank).

Skip navigation links