Text UI: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
m linkfix
m Bot: Replace deprecated source tag with syntaxhighlight
 
(27 intermediate revisions by 19 users not shown)
Line 1:
A text<b>Text userUser interfaceInterface</b> or <b>TUI</b> is a user interface where by all output is presented in the form of text, in contrast with a [[GUI|Graphical UI]] that uses graphics along with text to display output.
 
== Popularity and Use ==
Back in the DOS days before GUIs were widespread, almost all applications used some sort of text UI. Some of these were simple, showing a menu or unmovable panels, but others included a fully featured windowing system, like the [https://en.wikipedia.org/wiki/Turbo_Pascal Turbo Pascal IDE] or the MS-DOS edit application (you can't tell from the screenshot on the wiki, but file windows were actually resizable and movable and they were stacked).
With the rise of graphical UI's, text based user interfaces still remain practical in hobbyist operating system projects, as they are the most easier type of interface to implement, and are still in use in larger and commerical operating systems where a graphical user interface is unneccesary, for example, in large servers. A text user interface is also easy for quickly outputing results or debug data, and inputing commands to test new features, rather than writing complicated graphical applications.
 
With the rise of graphical UI's, text based user interfaces still remain practical in hobbyist operating system projects, as they are the most easiereasy type of interface to implement, and are still in use in larger and commericalcommercial operating systems where a graphical user interface is unneccesaryunnecessary, for example, in large servers. A text user interface is also easy for quickly outputingoutputting results or debug data, and inputing commands to test new features, rather than writing complicated graphical applications.
 
These days text based UI is mostly used over pseudo-ttys, using [[Terminals|VT escape sequences]] rather than direct VGA buffers. Most notable examples are Midnight Commander (a Linux clone of the Norton Commander under DOS), and [https://vtm.netxs.online/ VTM] (a fully featured desktop environment). The biggest advantage of these UIs that they can be used over simple tty-based SSH tunnels, no additional protocol needed. Details on curses based text interfaces are out of the scope of this page, which only focuses on [[VGA Hardware|VGA]] buffer text interfaces.
 
== Input ==
Input in a text user interface primarily involves the use of a [[Command_Line|command line]] [[shell]], usually through entering commands via a [[keyboard]]. Other methods do exist, such as text-based menus that can scroll up and down, and prompts asking a user to press a specific key for a specific event to occur.
 
== Video Mode ==
The most used VGA video mode for a text UI is [[text mode]], or"VGA mode 03". This is the most commonly used, as it allows direct memory access to a linear address containing each character and it'sits associated attributes. TextVGA mode 03 provides a text interface 80 characters wide and 25 characters lines per screen, although on modern computers [[Drawing In a Linear Framebuffer]] is preferrable, and often mandatory.
 
== Video Memory ==
In textVGA mode 03, the linear text buffer is located in physical at 0xB8000. Reading and writing to and from this address will provide direct manipulation of on screen text. To access a particular character on the screen from X and Y coordinates is simple using the following formula:
 
position = (y_position * characters_per_line) + x_position;
 
Each character takes up two bytes of space in memory. The first byte is split into two segments, the forecolour, and the backcolour. The second byte is a nan 8-bit ASCII value of the character to print.
 
== Colours ==
 
Each character has a colorcolour Bytebyte. This colorcolour Bytebyte is split up in forecolour and backcolour.<br>
 
The layout of the byte, using the standard colour palette:
The Colorbyte layout:
<pre>
Bit 76543210
||||||||
|||||^^^-forecolourfore colour
||||^----forecolourfore colour bright bit
|^^^-----backcolourback colour
^--------backcolourback colour bright bit OR enables blinking Text
</pre>
 
Its easy to write theto ColorBL, the NiblesColour Nibbles(4Bit), in a Hex Value. <br>
For Example:<br>
0x01 sets the background to Blackblack and the forecolourfore colour to Blueblue<br>
0x10 sets the background to Blueblue and the forecolourfore colour to Blackblack <br>
0x11 sets both to blue.
The default display colours set by the [[BIOS]] upon booting are 0x070x0F: 0 (black) for the background and 7 (White) + 8 (Bright) for the foreground.<br>
<br>
 
In text mode 0, the following standard colour palletepalette is avaliableavailable for use:. You can change this palette with VGA commands.
 
{| border="1" cellspacing="0"
! Number
Line 53 ⟶ 56:
| Black
| 0+8=8
| style="background: #808080555555" |
| Dark Gray
|-
| 1
| style="background: #0000c00000AA" |
| Blue
| 1+8=9
| style="background: #0000ff5555FF" |
| Light Blue
|-
| 2
| style="background: #00c00000AA00" |
| Green
| 2+8=A
| style="background: #00ff0055FF55" |
| Light Green
|-
| 3
| style="background: #00c0c000AAAA" |
| Cyan
| 3+8=B
| style="background: #00ffff55FFFF" |
| Light Cyan
|-
| 4
| style="background: #c00000AA0000" |
| Red
| 4+8=C
| style="background: #ff0000FF5555" |
| Light Red
|-
| 5
| style="background: #c000c0AA00AA" |
| Magenta
| 65+8=D
| style="background: #ff00ffFF55FF" |
| Light Magenta
|-
| 6
| style="background: #c08000AA5500" |
| Brown
| 6*+8=E
| style="background: #ffff00FFFF00" |
| Yellow
|-
| 7
| style="background: #c0c0c0AAAAAA" |
| Light Gray
| 7+8=F
| style="background: #ffffffFFFFFF" |
| White
|-
Line 108 ⟶ 111:
 
== Example Console Class ==
A heavily documented and easy to understand example of a text console class is taken from Brandon's Kernel Tutorial, avaliableavailable at http://osdever.net/bkerndev/Docs/printing.htm
 
== C Code for Print a Character ==
The following C code will print a character at X and Y coordinates:
 
<syntaxhighlight lang="c">
<pre>
void WriteCharacter(unsigned char c, unsigned char forecolour, unsigned char backcolour, int x, int y)
{
unsigned shortuint16_t attrib = (backcolour << 4) | (forecolour & 0x0F);
volatile unsigned shortuint16_t * where;
where = (volatile uint16_t *)0xB8000 + (y * 80 + x) ;
*where = c | (attrib << 8);
}
</syntaxhighlight>
</pre>
 
== Scrolling ==
Line 127 ⟶ 130:
 
== Virtual Terminals ==
Virtual terminals are much the same as physical screens, but instead of writing to the linear text buffer referring to the screen, text is written to a linear text buffer stored in memory. Each virtual terminal has it's own text buffer, and the terminal currently being displayed on screen has it's buffer copied into the video buffer to display on screen. Having more than one virtual text buffer has other advantages, such as only having parts of multiple bufferbuffers being outputedoutput onto the screen at the same time.
 
== Buffering Data ==
When working with a text-based interface, writing text directly into the video memory may eventually begin to create issues, especially when handling keyboard input, processing input from menus or dealing with multiple text mode consoles. This problem can usually be overcome by writing characters and colour data into a separate buffer (unparsed), and periodically flushing the buffer to the screen. There are multiple ways to implement a text buffer; a simple solution might feature a flat block of memory in which text and colour bytes are stored before being copied to the screen, though more a more advanced approach may include a per-line buffer, planar-buffer or a system of tracking updated lines or portions of the screen.
 
==See Also==
* [[VGA Hardware]]
* [[Text Mode Cursor]]
 
===External Links===
* [https://vtm.netxs.online/ VTM] Text-based Desktop Environment that uses curses and VT codes
 
[[Category:OSText theoryUI]]
[[Category:Video]]