xtd_c - Reference Guide 0.2.0
console

Definition

Represents the standard input, output, and error streams for console applications.

Examples
The following example demonstrates how to read data from, and write data to, the standard input and output streams. Note that these streams can be redirected by using the set_in and set_out methods.

Enumerations

enum  xtd_console_color {
  xtd_console_color_black,
  xtd_console_color_dark_blue,
  xtd_console_color_dark_green,
  xtd_console_color_dark_cyan,
  xtd_console_color_dark_red,
  xtd_console_color_dark_magenta,
  xtd_console_color_dark_yellow,
  xtd_console_color_gray,
  xtd_console_color_dark_gray,
  xtd_console_color_blue,
  xtd_console_color_green,
  xtd_console_color_cyan,
  xtd_console_color_red,
  xtd_console_color_magenta,
  xtd_console_color_yellow,
  xtd_console_color_white
}
 Specifies constants that define foreground and background colors for the console. More...
 

Properties

xtd_console_color xtd_console_get_background_color ()
 Gets the background color of the console. More...
 
void xtd_console_set_background_color (xtd_console_color color)
 Sets the background color of the console. More...
 
int32_t xtd_console_get_buffer_height ()
 Gets the height of the buffer area. More...
 
void xtd_console_set_buffer_height (int32_t height)
 Sets or sets the height of the buffer area. More...
 
int32_t xtd_console_get_buffer_width ()
 Gets the width of the buffer area. More...
 
void xtd_console_set_buffer_width (int32_t width)
 Sets the width of the buffer area. More...
 
bool xtd_console_get_caps_lock ()
 Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off. More...
 
int32_t xtd_console_get_cursor_left ()
 Gets the column position of the cursor within the buffer area. More...
 
void xtd_console_set_cursor_left (int32_t left)
 Sets the column position of the cursor within the buffer area. More...
 
int32_t xtd_console_get_cursor_size ()
 Gets or sets the height of the cursor within a character cell. More...
 
void xtd_console_set_cursor_size (int32_t size)
 Sets the height of the cursor within a character cell. More...
 
int32_t xtd_console_get_cursor_top ()
 Gets the row position of the cursor within the buffer area. More...
 
void xtd_console_set_cursor_top (int32_t top)
 Sets the row position of the cursor within the buffer area. More...
 
bool xtd_console_get_cursor_visible ()
 Gets a value indicating whether the cursor is visible. More...
 
void xtd_console_set_cursor_visible (bool visible)
 Sets a value indicating whether the cursor is visible. More...
 
xtd_console_color xtd_console_get_foreground_color ()
 Gets the foreground color of the console. More...
 
void xtd_console_set_foreground_color (xtd_console_color color)
 Sets the foreground color of the console. More...
 

Methods

void xtd_console_write (const char *format,...)
 Writes the text representation of the specified list of values to the standard output stream using the specified format information. More...
 
void xtd_console_write_line (const char *format,...)
 Writes the text representation of the specified list of values, followed by the current line terminator, to the standard output stream using the specified format information. More...
 

Enumeration Type Documentation

◆ xtd_console_color

Specifies constants that define foreground and background colors for the console.

Library
xtd_c.core
Enumerator
xtd_console_color_black 

The color black.

xtd_console_color_dark_blue 

The color dark blue.

xtd_console_color_dark_green 

The color dark green.

xtd_console_color_dark_cyan 

The color dark cyan (dark blue-green).

xtd_console_color_dark_red 

The color dark red.

xtd_console_color_dark_magenta 

The color dark magenta (dark purplish-red).

xtd_console_color_dark_yellow 

The color dark yellow (ochre).

xtd_console_color_gray 

The color gray.

xtd_console_color_dark_gray 

The color dark gray.

xtd_console_color_blue 

The color blue.

xtd_console_color_green 

The color green.

xtd_console_color_cyan 

The color cyan (blue-green).

xtd_console_color_red 

The color red.

xtd_console_color_magenta 

The color magenta (purplish red).

xtd_console_color_yellow 

The color yellow.

xtd_console_color_white 

The color white.

Function Documentation

◆ xtd_console_get_background_color()

xtd_console_color xtd_console_get_background_color ( )

Gets the background color of the console.

Returns
the background xtd_console_color.
Library
xtd_c.core
Remarks
A get operation for a Windows-based application, in which a console does not exist, returns xtd_console_color_black.
Examples
The following example saves the values of the xtd_console_color enumeration to an array and stores the current values of the xtd_console_background_color and xtd_console_foreground_color properties to variables. It then changes the foreground color to each color in the xtd_console_color enumeration except to the color that matches the current background, and it changes the background color to each color in the xtd_console_color enumeration except to the color that matches the current foreground. (If the foreground color is the same as the background color, the text isn't visible.) Finally, it calls the xtd_console_reset_color method to restore the original console colors.

◆ xtd_console_get_buffer_height()

int32_t xtd_console_get_buffer_height ( )

Gets the height of the buffer area.

Returns
The current height, in rows, of the buffer area.
Library
xtd_c.core
Examples
This example demonstrates the buffer_height and buffer_width properties. The example reports the dimensions of an operating system window set to a buffer size of 300 rows and 85 columns.

◆ xtd_console_get_buffer_width()

int32_t xtd_console_get_buffer_width ( )

Gets the width of the buffer area.

Returns
The current width, in columns, of the buffer area.
Library
xtd_c.core
Examples
This example demonstrates the BufferHeight and buffer_width properties. The example reports the dimensions of an operating system window set to a buffer size of 300 rows and 85 columns.

◆ xtd_console_get_caps_lock()

bool xtd_console_get_caps_lock ( )

Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off.

Returns
true if CAPS LOCK is turned on; false if CAPS LOCK is turned off.
Library
xtd_c.core

◆ xtd_console_get_cursor_left()

int32_t xtd_console_get_cursor_left ( )

Gets the column position of the cursor within the buffer area.

Returns
The current position, in columns, of the cursor.
Library
xtd_c.core
Examples
This example demonstrates the cursor_left and cursor_top properties, and the set_cursor_position and clear methods. The example positions the cursor, which determines where the next write will occur, to draw a 5 character by 5 character rectangle using a combination of "+", "|", and "-" strings. Note that the rectangle could be drawn with fewer steps using a combination of other strings.

◆ xtd_console_get_cursor_size()

int32_t xtd_console_get_cursor_size ( )

Gets or sets the height of the cursor within a character cell.

Returns
The size of the cursor expressed as a percentage of the height of a character cell. The property value ranges from 1 to 100.
Library
xtd_c.core
Examples
This example demonstrates the cursor_size property. The example increases the size of the cursor each time any console key is pressed, then restores the cursor to its original size before terminating.

◆ xtd_console_get_cursor_top()

int32_t xtd_console_get_cursor_top ( )

Gets the row position of the cursor within the buffer area.

Returns
The current position, in rows, of the cursor.
Library
xtd_c.core
Examples
This example demonstrates the cursor_left and cursor_top properties, and the set_cursor_position and clear methods. The example positions the cursor, which determines where the next write will occur, to draw a 5 character by 5 character rectangle using a combination of "+", "|", and "-" strings. Note that the rectangle could be drawn with fewer steps using a combination of other strings.

◆ xtd_console_get_cursor_visible()

bool xtd_console_get_cursor_visible ( )

Gets a value indicating whether the cursor is visible.

Returns
true if the cursor is visible; otherwise, false.
Library
xtd_c.core
Examples
This example demonstrates the cursor_visible property. The example makes the cursor visible if the first column of input is a '+' character or invisible if the input is a '-' character.

◆ xtd_console_get_foreground_color()

xtd_console_color xtd_console_get_foreground_color ( )

Gets the foreground color of the console.

Returns
A console_color that specifies the foreground color of the console; that is, the color of each character that is displayed.
Library
xtd_c.core
Examples
The following example saves the values of the console_color enumeration to an array and stores the current values of the background_color and foreground_color properties to variables. It then changes the foreground color to each color in the ConsoleColor enumeration except to the color that matches the current background, and it changes the background color to each color in the console_color enumeration except to the color that matches the current foreground. (If the foreground color is the same as the background color, the text isn't visible.) Finally, it calls the reset_color method to restore the original console colors.

◆ xtd_console_set_background_color()

void xtd_console_set_background_color ( xtd_console_color  color)

Sets the background color of the console.

Parameters
colorA xtd_console_color that specifies the background color of the console; that is, the color that appears behind each character.
Library
xtd_c.core
Remarks
A change to the background_color method affects only output that is written to individual character cells after the background color is changed. To change the background color of the console window as a whole, set the BackgroundColor property and call the Clear method. The following example provides an illustration.
Examples
The following example saves the values of the xtd_console_color enumeration to an array and stores the current values of the xtd_console_background_color and xtd_console_foreground_color properties to variables. It then changes the foreground color to each color in the xtd_console_color enumeration except to the color that matches the current background, and it changes the background color to each color in the xtd_console_color enumeration except to the color that matches the current foreground. (If the foreground color is the same as the background color, the text isn't visible.) Finally, it calls the xtd_console_reset_color method to restore the original console colors.

◆ xtd_console_set_buffer_height()

void xtd_console_set_buffer_height ( int32_t  height)

Sets or sets the height of the buffer area.

Parameters
heightThe current height, in rows, of the buffer area.
Library
xtd_c.core
Examples
This example demonstrates the buffer_height and buffer_width properties. The example reports the dimensions of an operating system window set to a buffer size of 300 rows and 85 columns.

◆ xtd_console_set_buffer_width()

void xtd_console_set_buffer_width ( int32_t  width)

Sets the width of the buffer area.

Parameters
widthThe current width, in columns, of the buffer area.
Library
xtd_c.core
Examples
This example demonstrates the BufferHeight and buffer_width properties. The example reports the dimensions of an operating system window set to a buffer size of 300 rows and 85 columns.

◆ xtd_console_set_cursor_left()

void xtd_console_set_cursor_left ( int32_t  left)

Sets the column position of the cursor within the buffer area.

Parameters
leftThe current position, in columns, of the cursor.
Returns
true if cursor left changed; otherwise false.
Library
xtd_c.core
Examples
This example demonstrates the cursor_left and cursor_top properties, and the set_cursor_position and clear methods. The example positions the cursor, which determines where the next write will occur, to draw a 5 character by 5 character rectangle using a combination of "+", "|", and "-" strings. Note that the rectangle could be drawn with fewer steps using a combination of other strings.

◆ xtd_console_set_cursor_size()

void xtd_console_set_cursor_size ( int32_t  size)

Sets the height of the cursor within a character cell.

Parameters
sizeThe size of the cursor expressed as a percentage of the height of a character cell. The property value ranges from 1 to 100.
Library
xtd_c.core
Examples
This example demonstrates the cursor_size property. The example increases the size of the cursor each time any console key is pressed, then restores the cursor to its original size before terminating.

◆ xtd_console_set_cursor_top()

void xtd_console_set_cursor_top ( int32_t  top)

Sets the row position of the cursor within the buffer area.

Parameters
topThe current position, in rows, of the cursor.
Returns
true if cursor top changed; otherwise false.
Library
xtd_c.core
Examples
This example demonstrates the cursor_left and cursor_top properties, and the set_cursor_position and clear methods. The example positions the cursor, which determines where the next write will occur, to draw a 5 character by 5 character rectangle using a combination of "+", "|", and "-" strings. Note that the rectangle could be drawn with fewer steps using a combination of other strings.

◆ xtd_console_set_cursor_visible()

void xtd_console_set_cursor_visible ( bool  visible)

Sets a value indicating whether the cursor is visible.

Parameters
visibletrue if the cursor is visible; otherwise, false.
Library
xtd_c.core
Examples
This example demonstrates the cursor_visible property. The example makes the cursor visible if the first column of input is a '+' character or invisible if the input is a '-' character.

◆ xtd_console_set_foreground_color()

void xtd_console_set_foreground_color ( xtd_console_color  color)

Sets the foreground color of the console.

Parameters
colorA console_color that specifies the foreground color of the console; that is, the color of each character that is displayed.
Library
xtd_c.core
Examples
The following example saves the values of the console_color enumeration to an array and stores the current values of the background_color and foreground_color properties to variables. It then changes the foreground color to each color in the ConsoleColor enumeration except to the color that matches the current background, and it changes the background color to each color in the console_color enumeration except to the color that matches the current foreground. (If the foreground color is the same as the background color, the text isn't visible.) Finally, it calls the reset_color method to restore the original console colors.

◆ xtd_console_write()

void xtd_console_write ( const char *  format,
  ... 
)

Writes the text representation of the specified list of values to the standard output stream using the specified format information.

Parameters
formatA string format specifying how to interpret the data.
...Values to write,
Library
xtd_c.core

◆ xtd_console_write_line()

void xtd_console_write_line ( const char *  format,
  ... 
)

Writes the text representation of the specified list of values, followed by the current line terminator, to the standard output stream using the specified format information.

Parameters
formatA string format specifying how to interpret the data.
...Values to write,
Library
xtd_c.core