MonkOS  v0.1
A simple 64-bit operating system (x86_64)
tty.h File Reference

Teletype (console) screen text manipulation routines. More...

#include <core.h>
#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct  screenpos_t
 tty screen text position. More...
 

Macros

#define MAX_TTYS   4
 The number of available virtual consoles. More...
 

Typedefs

typedef enum textcolor textcolor_t
 

Enumerations

Functions

void tty_init ()
 Initialize all virtual consoles. More...
 
void tty_activate (int id)
 Activate the requested virtual console. More...
 
void tty_set_textcolor (int id, textcolor_t fg, textcolor_t bg)
 Set the foreground and background colors used to display text on the virtual console. More...
 
void tty_set_textcolor_fg (int id, textcolor_t fg)
 Set the foreground color used to display text on the virtual console. More...
 
void tty_set_textcolor_bg (int id, textcolor_t bg)
 Set the background color used to display text on the virtual console. More...
 
textcolor_t tty_get_textcolor_fg (int id)
 Get the foreground color used to display text on the virtual console. More...
 
textcolor_t tty_get_textcolor_bg (int id)
 Get the background color used to display text on the virtual console. More...
 
void tty_clear (int id)
 Clear the virtual console screen's contents using the current text background color. More...
 
void tty_setpos (int id, screenpos_t pos)
 Set the position of the cursor on the virtual console. More...
 
void tty_getpos (int id, screenpos_t *pos)
 Get the current position of the cursor on the virtual console. More...
 
void tty_print (int id, const char *str)
 Output a null-terminated string to the virtual console using the console's current text color and screen position. More...
 
void tty_printc (int id, char ch)
 Output a single character to the virtual console using the console's current text color and screen position. More...
 
int tty_printf (int id, const char *format,...)
 Output a printf-formatted string to the virtual console using the console's current text color and screen position. More...
 

Detailed Description

Teletype (console) screen text manipulation routines.

Definition in file tty.h.


Data Structure Documentation

struct screenpos

tty screen text position.

Definition at line 52 of file tty.h.

Data Fields
uint8_t x x position in range [0:79].
uint8_t y y position in range [0:24].

Macro Definition Documentation

#define MAX_TTYS   4

Typedef Documentation

typedef enum textcolor textcolor_t

Definition at line 46 of file tty.h.

Enumeration Type Documentation

enum textcolor

Color values used for tty text.

Enumerator
TEXTCOLOR_BLACK 
TEXTCOLOR_BLUE 
TEXTCOLOR_GREEN 
TEXTCOLOR_CYAN 
TEXTCOLOR_RED 
TEXTCOLOR_MAGENTA 
TEXTCOLOR_BROWN 
TEXTCOLOR_LTGRAY 
TEXTCOLOR_GRAY 
TEXTCOLOR_LTBLUE 
TEXTCOLOR_LTGREEN 
TEXTCOLOR_LTCYAN 
TEXTCOLOR_LTRED 
TEXTCOLOR_LTMAGENTA 
TEXTCOLOR_YELLOW 
TEXTCOLOR_WHITE 

Definition at line 26 of file tty.h.

Function Documentation

void tty_init ( )

Initialize all virtual consoles.

This function must be called before any other console functions can be used.

Definition at line 89 of file tty.c.

Referenced by kmain().

void tty_activate ( int  id)

Activate the requested virtual console.

The virtual console's buffer is immediately displayed on the screen.

Parameters
[in]idVirtual tty id (0-3).

Definition at line 107 of file tty.c.

Referenced by isr_fatal().

void tty_set_textcolor ( int  id,
textcolor_t  fg,
textcolor_t  bg 
)

Set the foreground and background colors used to display text on the virtual console.

Parameters
[in]idVirtual tty id (0-3).
[in]fgForeground color.
[in]bgBackground color.

Definition at line 122 of file tty.c.

Referenced by isr_fatal(), and kmain().

void tty_set_textcolor_fg ( int  id,
textcolor_t  fg 
)

Set the foreground color used to display text on the virtual console.

Parameters
[in]idVirtual tty id (0-3).
[in]fgForeground color.

Definition at line 132 of file tty.c.

void tty_set_textcolor_bg ( int  id,
textcolor_t  bg 
)

Set the background color used to display text on the virtual console.

Parameters
[in]idVirtual tty id (0-3).
[in]bgBackground color.

Definition at line 143 of file tty.c.

textcolor_t tty_get_textcolor_fg ( int  id)

Get the foreground color used to display text on the virtual console.

Parameters
[in]idVirtual tty id (0-3).
Returns
Foreground color.

Definition at line 154 of file tty.c.

Referenced by tty_set_textcolor_bg().

textcolor_t tty_get_textcolor_bg ( int  id)

Get the background color used to display text on the virtual console.

Parameters
[in]idVirtual tty id (0-3).
Returns
Background color.

Definition at line 164 of file tty.c.

Referenced by tty_set_textcolor_fg().

void tty_clear ( int  id)

Clear the virtual console screen's contents using the current text background color.

Parameters
[in]idVirtual tty id (0-3).

Definition at line 174 of file tty.c.

Referenced by isr_fatal(), and kmain().

void tty_setpos ( int  id,
screenpos_t  pos 
)

Set the position of the cursor on the virtual console.

Text written to the console after this function will be located at the requested screen position.

Parameters
[in]idVirtual tty id (0-3).
[in]posThe screen position of the cursor.

Definition at line 194 of file tty.c.

void tty_getpos ( int  id,
screenpos_t *  pos 
)

Get the current position of the cursor on the virtual console.

Parameters
[in]idVirtual tty id (0-3).
[out]posA pointer to a screenpos_t to receive the position.

Definition at line 209 of file tty.c.

void tty_print ( int  id,
const char *  str 
)

Output a null-terminated string to the virtual console using the console's current text color and screen position.

A newline character (\n) causes the screen position to be updated as though a carriage return and line feed were performed.

To change the foreground color on the fly without having to call a console function, you may use the escape sequence \033[x], where x is a single character representing the foreground color to use for all following text. If x is a hexadecimal digit, then it represents one of the 16 textcolor codes. If x is '-', then it represents the console's original foreground color setting.

To change the background color on the fly, use the escape sequence \033{x}. The meaning of x is the same as with the foreground color escape sequence.

Parameters
[in]idVirtual tty id (0-3).
[in]strThe null-terminated string to be printed.

Definition at line 343 of file tty.c.

Referenced by cmd_display_apic(), cmd_display_help(), cmd_display_pcie(), cmd_switch_to_keycodes(), command_prompt(), dump_context(), isr_breakpoint(), kmain(), and tty_printf().

void tty_printc ( int  id,
char  ch 
)

Output a single character to the virtual console using the console's current text color and screen position.

See tty_print for further details.

Parameters
[in]idVirtual tty id (0-3).
[in]chThe character to be printed.

Definition at line 357 of file tty.c.

Referenced by command_run().

int tty_printf ( int  id,
const char *  format,
  ... 
)

Output a printf-formatted string to the virtual console using the console's current text color and screen position.

See tty_print for further details.

Parameters
[in]idVirtual tty id (0-3).
[in]formatThe null-terminated format string used to format the text to be printed.
[in]...Variable arguments list to be initialized with va_start.
Returns
The number of characters written to the console.

Definition at line 372 of file tty.c.

Referenced by cmd_display_apic(), cmd_display_help(), cmd_display_pcie(), command_exec(), dump_context(), isr_fatal(), keycode_run(), and probe_function().