xtd 0.2.0
Loading...
Searching...
No Matches
xtd::console Class Referencefinal
Inheritance diagram for xtd::console:
xtd::static_object

Definition

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

Header
#include <xtd/console>
Namespace
xtd
Library
xtd.core
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
console::write("Hello ");
console::write("Enter your name: ");
string name = console::read_line();
console::write("Good day, ");
}
// This code produces the following output :
//
// Hello World!
// Enter your name: James
// Good day, James!
static xtd::string read_line()
Reads the next line of characters from the standard input stream.
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
#include <xtd/console>
#include <xtd/environment>
using namespace xtd;
auto main() -> int {
auto& is = console::in;
auto& os = console::out;
os << "Ola Mundo!" << environment::new_line;
os << "What is your name: ";
auto name = string::empty_string;
is >> name;
os << "Buenos Dias, " << name << environment::new_line;
}
// This code produces the following output :
//
// Ola Mundo!
// What is your name: James
// Buenos Dias, James!
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.hpp:124
static std::istream in
Gets the standard input stream. A std::basic_istream<char_t> that represents the standard input strea...
Definition console.hpp:47
static std::ostream out
Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output str...
Definition console.hpp:52
static xtd::string new_line() noexcept
Gets the newline string defined for this environment.
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:365
Examples
generic_list.cpp, and generic_list4.cpp.

Public Fields

static std::ostream error
 Gets the error output stream. A std::basic_ostream<char_t> that represents the error output stream.
 
static std::istream in
 Gets the standard input stream. A std::basic_istream<char_t> that represents the standard input stream.
 
static std::ostream out
 Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output stream.
 

Public Static Events

static event< console, console_cancel_event_handlercancel_key_press
 Occurs when the Control modifier key (Ctrl) and either the ConsoleKey.C console key (C) or the Break key are pressed simultaneously (Ctrl+C or Ctrl+Break).
 

Public Static Properties

static bool auto_flush_out ()
 Gets a value indicating whether the xtd::console::out will flush its buffer to the underlying stream after every call to xtd::console::write and xtd::console::write_line.
 
static void auto_flush_out (bool value)
 Sets a value indicating whether the xtd::console::out will flush its buffer to the underlying stream after every call to xtd::console::write and xtd::console::write_line.
 
static console_color background_color ()
 Gets the background color of the console.
 
static void background_color (console_color color)
 Sets the background color of the console.
 
static int32 buffer_height ()
 Gets the height of the buffer area.
 
static void buffer_height (int32 height)
 Sets or sets the height of the buffer area.
 
static int32 buffer_width ()
 Gets the width of the buffer area.
 
static void buffer_width (int32 width)
 Sets the width of the buffer area.
 
static bool caps_lock ()
 Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off.
 
static int32 cursor_left ()
 Gets the column position of the cursor within the buffer area.
 
static void cursor_left (int32 left)
 Sets the column position of the cursor within the buffer area.
 
static int32 cursor_size ()
 Gets or sets the height of the cursor within a character cell.
 
static void cursor_size (int32 size)
 Sets the height of the cursor within a character cell.
 
static int32 cursor_top ()
 Gets the row position of the cursor within the buffer area.
 
static void cursor_top (int32 top)
 Sets the row position of the cursor within the buffer area.
 
static bool cursor_visible ()
 Gets a value indicating whether the cursor is visible.
 
static void cursor_visible (bool visible)
 Sets a value indicating whether the cursor is visible.
 
static console_color foreground_color ()
 Gets the foreground color of the console.
 
static bool foreground_color (console_color color)
 Sets the foreground color of the console.
 
static int32 input_code_page ()
 Gets the code page the console uses to read input.
 
static void input_code_page (int32 code_page)
 Sets the code page the console uses to read input.
 
static bool is_error_redirected ()
 Gets a value that indicates whether the error output stream has been redirected from the standard error stream.
 
static bool is_input_redirected ()
 Gets a value that indicates whether the input stream has been redirected from the standard input stream.
 
static bool is_output_redirected ()
 Gets a value that indicates whether the output stream has been redirected from the standard output stream.
 
static bool key_available ()
 Gets a value indicating whether a key press is available in the input stream.
 
static int32 largest_window_height ()
 Gets the largest possible number of console window rows, based on the current font and screen resolution.
 
static int32 largest_window_width ()
 Gets the largest possible number of console window columns, based on the current font and screen resolution.
 
static bool number_lock ()
 Gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off.
 
static int32 output_code_page ()
 Gets the code page the console uses to write output.
 
static void output_code_page (int32 code_page)
 Sets the code page the console uses to write output.
 
static xtd::string title ()
 Gets the title to display in the console title bar.
 
static void title (const xtd::string &title)
 Sets the title to display in the console title bar.
 
static bool treat_control_c_as_input ()
 Gets a value indicating whether the combination of the Control modifier key and C console key (Ctrl+C) is treated as ordinary input or as an interruption that is handled by the operating system.
 
static void treat_control_c_as_input (bool treat_control_c_as_input)
 Sets a value indicating whether the combination of the Control modifier key and C console key (Ctrl+C) is treated as ordinary input or as an interruption that is handled by the operating system.
 
static int32 window_height ()
 Gets the height of the console window area.
 
static void window_height (int32 height)
 Sets the height of the console window area.
 
static int32 window_left ()
 Gets the left of the console window area.
 
static void window_left (int32 left)
 Sets the left of the console window area.
 
static int32 window_top ()
 Gets the top of the console window area.
 
static void window_top (int32 top)
 Sets the top of the console window area.
 
static int32 window_width ()
 Gets the width of the console window area.
 
static void window_width (int32 width)
 Sets the width of the console window area.
 

Public Static Methods

static void beep ()
 Plays the sound of a beep through the console speaker.
 
static void beep (uint32 frequency, uint32 duration)
 Plays the sound of a beep of a specified frequency and duration through the console speaker.
 
static void clear ()
 Clears the console buffer and corresponding console window of display information.
 
static xtd::collections::generic::key_value_pair< int32, int32get_cursor_position ()
 Gets the position of the cursor.
 
static std::ostream open_standard_error ()
 Acquires the standard error stream.
 
static std::istream open_standard_input ()
 Acquires the standard input stream.
 
static std::ostream open_standard_output ()
 Acquires the standard output stream.
 
static int32 read ()
 Reads the next character from the standard input stream.
 
static console_key_info read_key ()
 Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.
 
static console_key_info read_key (bool intercept)
 Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window.
 
static xtd::string read_line ()
 Reads the next line of characters from the standard input stream.
 
static xtd::string read_line (bool intercept)
 Reads the next line of characters from the standard input stream.
 
static bool reset_color ()
 Sets the foreground and background console colors to their defaults.
 
static void set_cursor_position (int32 left, int32 top)
 Sets the position of the cursor.
 
static void set_error (const std::ostream &os)
 Sets the error property to the specified std::ostream object.
 
static void set_in (const std::istream &is)
 Sets the int property to the specified std::istream object.
 
static void set_out (const std::ostream &os)
 Sets the out property to the specified std::ostream object.
 
static void set_window_position (int32 left, int32 top)
 Sets the position of the console window relative to the screen buffer.
 
static void set_window_size (int32 width, int32 height)
 Sets the height and width of the console window to the specified values.
 
template<typename arg_t >
static void write (arg_t &&value)
 Writes the text representation of the specified value to the standard output stream.
 
template<typename ... args_t>
static void write (const xtd::string &fmt, args_t &&... values)
 Writes the text representation of the specified list of values to the standard output stream using the specified format information.
 
static void write_line ()
 Writes the current line terminator to the standard output stream using the specified format information.
 
template<typename arg_t >
static void write_line (arg_t &&value)
 Writes the text representation of the specified value, followed by the current line terminator, to the standard output stream.
 
template<typename ... args_t>
static void write_line (const xtd::string &fmt, args_t &&... values)
 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.
 

Member Function Documentation

◆ auto_flush_out() [1/2]

static bool xtd::console::auto_flush_out ( )
static

Gets a value indicating whether the xtd::console::out will flush its buffer to the underlying stream after every call to xtd::console::write and xtd::console::write_line.

Returns
true to force xtd::console::out to flush its buffer; otherwise, false. The default value is true.

◆ auto_flush_out() [2/2]

static void xtd::console::auto_flush_out ( bool  value)
static

Sets a value indicating whether the xtd::console::out will flush its buffer to the underlying stream after every call to xtd::console::write and xtd::console::write_line.

Parameters
valuetrue to force xtd::console::out to flush its buffer; otherwise, false. The default value is true.

◆ background_color() [1/2]

static console_color xtd::console::background_color ( )
static

Gets the background color of the console.

Returns
the background xtd::console_color.
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.
#include <xtd/collections/generic/list>
#include <xtd/console>
using namespace xtd;
using namespace xtd::collections::generic;
auto main() -> int {
const auto logo = list {
u8"████████████████████████████████████████████████████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████",
u8"███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████",
u8"██████████████████████████ ▀████ ▀█████████████████████████",
u8"███████████ ▐ ▀▀ ▐ ██████████",
u8"█████████ ▐ ███ ▌▐ ███ ▐ █████████",
u8"█████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████",
u8"█████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████",
u8"█████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████",
u8"█████████ █████████",
u8"█████████ █▄ ▌ █████████",
u8"█████████ ▌▀▀▄ ▄██ █████████",
u8"█████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████",
u8"█████████ ▐ ▄█ █████████",
u8"█████████ █ ▄█ █████████",
u8"█████████ ▀▄ █▀ █████████",
u8"█████████ ▀▄▄▄▄██▀ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"██████████████████████████████████████████████████████████████████",
};
for (auto index = 0ul; index < logo.size(); ++index) {
console::write(index == 0 || index == logo.size() - 1 ? " " : " ");
console::write(logo[index]);
}
console::write_line(u8" Gammasoft ");
console::write_line(u8" More than thirty years of passion for high technology especially in development");
console::write_line(u8" (c++, c#, objective-c, ...).");
}
// This code produces the following output with colors :
//
// ████████████████████████████████████████████████████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████
// ███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████
// ██████████████████████████ ▀████ ▀█████████████████████████
// ███████████ ▐ ▀▀ ▐ ██████████
// █████████ ▐ ███ ▌▐ ███ ▐ █████████
// █████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████
// █████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████
// █████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████
// █████████ █████████
// █████████ █▄ ▌ █████████
// █████████ ▌▀▀▄ ▄██ █████████
// █████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████
// █████████ ▐ ▄█ █████████
// █████████ █ ▄█ █████████
// █████████ ▀▄ █▀ █████████
// █████████ ▀▄▄▄▄██▀ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// ██████████████████████████████████████████████████████████████████
// Gammasoft
// More than thirty years of passion for high technology especially in development
// (c++, c#, objective-c, ...).
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
static console_color background_color()
Gets the background color of the console.
static int32 output_code_page()
Gets the code page the console uses to write output.
static console_color foreground_color()
Gets the foreground color of the console.
static bool reset_color()
Sets the foreground and background console colors to their defaults.
@ dark_blue
The color dark blue.
@ dark_gray
The color dark gray.
@ white
The color white.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:15

◆ background_color() [2/2]

static void xtd::console::background_color ( console_color  color)
static

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.
Exceptions
xtd::argument_exceptionThe color specified in a set operation is not a valid member of xtd::console_color.
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.
#include <xtd/collections/generic/list>
#include <xtd/console>
using namespace xtd;
using namespace xtd::collections::generic;
auto main() -> int {
const auto logo = list {
u8"████████████████████████████████████████████████████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████",
u8"███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████",
u8"██████████████████████████ ▀████ ▀█████████████████████████",
u8"███████████ ▐ ▀▀ ▐ ██████████",
u8"█████████ ▐ ███ ▌▐ ███ ▐ █████████",
u8"█████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████",
u8"█████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████",
u8"█████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████",
u8"█████████ █████████",
u8"█████████ █▄ ▌ █████████",
u8"█████████ ▌▀▀▄ ▄██ █████████",
u8"█████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████",
u8"█████████ ▐ ▄█ █████████",
u8"█████████ █ ▄█ █████████",
u8"█████████ ▀▄ █▀ █████████",
u8"█████████ ▀▄▄▄▄██▀ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"██████████████████████████████████████████████████████████████████",
};
for (auto index = 0ul; index < logo.size(); ++index) {
console::write(index == 0 || index == logo.size() - 1 ? " " : " ");
console::write(logo[index]);
}
console::write_line(u8" Gammasoft ");
console::write_line(u8" More than thirty years of passion for high technology especially in development");
console::write_line(u8" (c++, c#, objective-c, ...).");
}
// This code produces the following output with colors :
//
// ████████████████████████████████████████████████████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████
// ███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████
// ██████████████████████████ ▀████ ▀█████████████████████████
// ███████████ ▐ ▀▀ ▐ ██████████
// █████████ ▐ ███ ▌▐ ███ ▐ █████████
// █████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████
// █████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████
// █████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████
// █████████ █████████
// █████████ █▄ ▌ █████████
// █████████ ▌▀▀▄ ▄██ █████████
// █████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████
// █████████ ▐ ▄█ █████████
// █████████ █ ▄█ █████████
// █████████ ▀▄ █▀ █████████
// █████████ ▀▄▄▄▄██▀ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// ██████████████████████████████████████████████████████████████████
// Gammasoft
// More than thirty years of passion for high technology especially in development
// (c++, c#, objective-c, ...).

◆ buffer_height() [1/2]

static int32 xtd::console::buffer_height ( )
static

Gets the height of the buffer area.

Returns
The current height, in rows, of the buffer area.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
console::write_line("The current buffer height is {} rows.", console::buffer_height());
console::write_line("The current buffer width is {} columns.", console::buffer_width());
}
// This code produces the following output :
//
// The current buffer height is 300 rows.
// The current buffer width is 85 columns.
static int32 buffer_height()
Gets the height of the buffer area.
static int32 buffer_width()
Gets the width of the buffer area.

◆ buffer_height() [2/2]

static void xtd::console::buffer_height ( int32  height)
static

Sets or sets the height of the buffer area.

Parameters
heightThe current height, in rows, of the buffer area.
Exceptions
xtd::argument_out_of_range_exceptionThe value in a set operation is less than or equal to zero.
-or-
The value in a set operation is greater than or equal to xtd::int16_object::max_value.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
console::write_line("The current buffer height is {} rows.", console::buffer_height());
console::write_line("The current buffer width is {} columns.", console::buffer_width());
}
// This code produces the following output :
//
// The current buffer height is 300 rows.
// The current buffer width is 85 columns.

◆ buffer_width() [1/2]

static int32 xtd::console::buffer_width ( )
static

Gets the width of the buffer area.

Returns
The current width, in columns, of the buffer area.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
console::write_line("The current buffer height is {} rows.", console::buffer_height());
console::write_line("The current buffer width is {} columns.", console::buffer_width());
}
// This code produces the following output :
//
// The current buffer height is 300 rows.
// The current buffer width is 85 columns.

◆ buffer_width() [2/2]

static void xtd::console::buffer_width ( int32  width)
static

Sets the width of the buffer area.

Parameters
widthThe current width, in columns, of the buffer area.
Exceptions
xtd::argument_out_of_range_exceptionThe value in a set operation is less than or equal to zero.
-or-
The value in a set operation is greater than or equal to xtd::int16_object::max_value.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
console::write_line("The current buffer height is {} rows.", console::buffer_height());
console::write_line("The current buffer width is {} columns.", console::buffer_width());
}
// This code produces the following output :
//
// The current buffer height is 300 rows.
// The current buffer width is 85 columns.

◆ caps_lock()

static bool xtd::console::caps_lock ( )
static

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.

◆ cursor_left() [1/2]

static int32 xtd::console::cursor_left ( )
static

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

Returns
The current position, in columns, of the cursor.
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.
#include <xtd/console>
using namespace xtd;
auto orig_row = 0;
auto orig_col = 0;
void write_at(const string& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
auto main() -> int {
// Clear the screen, then save the top and left coordinates.
orig_row = console::cursor_top();
orig_col = console::cursor_left();
// Draw the left side of a 5x5 rectangle, from top to bottom.
write_at("+", 0, 0);
write_at("|", 0, 1);
write_at("|", 0, 2);
write_at("|", 0, 3);
write_at("+", 0, 4);
// Draw the bottom side, from left to right.
write_at("-", 1, 4); // shortcut: write_at("---", 1, 4)
write_at("-", 2, 4); // ...
write_at("-", 3, 4); // ...
write_at("+", 4, 4);
// Draw the right side, from bottom to top.
write_at("|", 4, 3);
write_at("|", 4, 2);
write_at("|", 4, 1);
write_at("+", 4, 0);
// Draw the top side, from right to left.
write_at("-", 3, 0); // shortcut: write_at("---", 1, 0)
write_at("-", 2, 0); // ...
write_at("-", 1, 0); // ...
//
write_at("All done!", 0, 6);
}
// This code produces the following output :
//
// +---+
// | |
// | |
// | |
// +---+
//
// All done!
static int32 cursor_top()
Gets the row position of the cursor within the buffer area.
static void clear()
Clears the console buffer and corresponding console window of display information.
static void set_cursor_position(int32 left, int32 top)
Sets the position of the cursor.
static int32 cursor_left()
Gets the column position of the cursor within the buffer area.
@ s
The S key.
@ y
The Y key.
@ x
The X key.

◆ cursor_left() [2/2]

static void xtd::console::cursor_left ( int32  left)
static

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

Parameters
leftThe current position, in columns, of the cursor.
Exceptions
xtd::argument_out_of_range_exceptionThe value in a set operation is less than zero
-or-
The value in a set operation is greater than or equal to xtd::console::buffer_width.
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.
#include <xtd/console>
using namespace xtd;
auto orig_row = 0;
auto orig_col = 0;
void write_at(const string& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
auto main() -> int {
// Clear the screen, then save the top and left coordinates.
orig_row = console::cursor_top();
orig_col = console::cursor_left();
// Draw the left side of a 5x5 rectangle, from top to bottom.
write_at("+", 0, 0);
write_at("|", 0, 1);
write_at("|", 0, 2);
write_at("|", 0, 3);
write_at("+", 0, 4);
// Draw the bottom side, from left to right.
write_at("-", 1, 4); // shortcut: write_at("---", 1, 4)
write_at("-", 2, 4); // ...
write_at("-", 3, 4); // ...
write_at("+", 4, 4);
// Draw the right side, from bottom to top.
write_at("|", 4, 3);
write_at("|", 4, 2);
write_at("|", 4, 1);
write_at("+", 4, 0);
// Draw the top side, from right to left.
write_at("-", 3, 0); // shortcut: write_at("---", 1, 0)
write_at("-", 2, 0); // ...
write_at("-", 1, 0); // ...
//
write_at("All done!", 0, 6);
}
// This code produces the following output :
//
// +---+
// | |
// | |
// | |
// +---+
//
// All done!

◆ cursor_size() [1/2]

static int32 xtd::console::cursor_size ( )
static

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.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto m0 = "This example increments the cursor size from 1% to 100%:\n";
auto m1 = "Cursor size = {0}%. (Press any key to continue...)";
auto sizes = { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
auto save_cursor_size = console::cursor_size();
for (auto size : sizes) {
}
console::cursor_size(save_cursor_size);
}
// This code produces the following output :
//
// This example increments the cursor size from 1% to 100%:
//
// Cursor size = 1%. (Press any key to continue...)
// Cursor size = 10%. (Press any key to continue...)
// Cursor size = 20%. (Press any key to continue...)
// Cursor size = 30%. (Press any key to continue...)
// Cursor size = 40%. (Press any key to continue...)
// Cursor size = 50%. (Press any key to continue...)
// Cursor size = 60%. (Press any key to continue...)
// Cursor size = 70%. (Press any key to continue...)
// Cursor size = 80%. (Press any key to continue...)
// Cursor size = 90%. (Press any key to continue...)
// Cursor size = 100%. (Press any key to continue...)
static int32 cursor_size()
Gets or sets the height of the cursor within a character cell.
static console_key_info read_key()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23

◆ cursor_size() [2/2]

static void xtd::console::cursor_size ( int32  size)
static

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.
Exceptions
xtd::argument_out_of_range_exceptionThe value specified in a set operation is less than 1 or greater than 100.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto m0 = "This example increments the cursor size from 1% to 100%:\n";
auto m1 = "Cursor size = {0}%. (Press any key to continue...)";
auto sizes = { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
auto save_cursor_size = console::cursor_size();
for (auto size : sizes) {
}
console::cursor_size(save_cursor_size);
}
// This code produces the following output :
//
// This example increments the cursor size from 1% to 100%:
//
// Cursor size = 1%. (Press any key to continue...)
// Cursor size = 10%. (Press any key to continue...)
// Cursor size = 20%. (Press any key to continue...)
// Cursor size = 30%. (Press any key to continue...)
// Cursor size = 40%. (Press any key to continue...)
// Cursor size = 50%. (Press any key to continue...)
// Cursor size = 60%. (Press any key to continue...)
// Cursor size = 70%. (Press any key to continue...)
// Cursor size = 80%. (Press any key to continue...)
// Cursor size = 90%. (Press any key to continue...)
// Cursor size = 100%. (Press any key to continue...)

◆ cursor_top() [1/2]

static int32 xtd::console::cursor_top ( )
static

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

Returns
The current position, in rows, of the cursor.
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.
#include <xtd/console>
using namespace xtd;
auto orig_row = 0;
auto orig_col = 0;
void write_at(const string& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
auto main() -> int {
// Clear the screen, then save the top and left coordinates.
orig_row = console::cursor_top();
orig_col = console::cursor_left();
// Draw the left side of a 5x5 rectangle, from top to bottom.
write_at("+", 0, 0);
write_at("|", 0, 1);
write_at("|", 0, 2);
write_at("|", 0, 3);
write_at("+", 0, 4);
// Draw the bottom side, from left to right.
write_at("-", 1, 4); // shortcut: write_at("---", 1, 4)
write_at("-", 2, 4); // ...
write_at("-", 3, 4); // ...
write_at("+", 4, 4);
// Draw the right side, from bottom to top.
write_at("|", 4, 3);
write_at("|", 4, 2);
write_at("|", 4, 1);
write_at("+", 4, 0);
// Draw the top side, from right to left.
write_at("-", 3, 0); // shortcut: write_at("---", 1, 0)
write_at("-", 2, 0); // ...
write_at("-", 1, 0); // ...
//
write_at("All done!", 0, 6);
}
// This code produces the following output :
//
// +---+
// | |
// | |
// | |
// +---+
//
// All done!

◆ cursor_top() [2/2]

static void xtd::console::cursor_top ( int32  top)
static

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.
Exceptions
xtd::argument_out_of_range_exceptionThe value in a set operation is less than zero
-or-
The value in a set operation is greater than or equal to xtd::console::buffer_height.
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.
#include <xtd/console>
using namespace xtd;
auto orig_row = 0;
auto orig_col = 0;
void write_at(const string& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
auto main() -> int {
// Clear the screen, then save the top and left coordinates.
orig_row = console::cursor_top();
orig_col = console::cursor_left();
// Draw the left side of a 5x5 rectangle, from top to bottom.
write_at("+", 0, 0);
write_at("|", 0, 1);
write_at("|", 0, 2);
write_at("|", 0, 3);
write_at("+", 0, 4);
// Draw the bottom side, from left to right.
write_at("-", 1, 4); // shortcut: write_at("---", 1, 4)
write_at("-", 2, 4); // ...
write_at("-", 3, 4); // ...
write_at("+", 4, 4);
// Draw the right side, from bottom to top.
write_at("|", 4, 3);
write_at("|", 4, 2);
write_at("|", 4, 1);
write_at("+", 4, 0);
// Draw the top side, from right to left.
write_at("-", 3, 0); // shortcut: write_at("---", 1, 0)
write_at("-", 2, 0); // ...
write_at("-", 1, 0); // ...
//
write_at("All done!", 0, 6);
}
// This code produces the following output :
//
// +---+
// | |
// | |
// | |
// +---+
//
// All done!

◆ cursor_visible() [1/2]

static bool xtd::console::cursor_visible ( )
static

Gets a value indicating whether the cursor is visible.

Returns
true if the cursor is visible; otherwise, false.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto m1 = "\nThe cursor is {0}.\nType any text then press Enter. "
"Type '+' in the first column to show \n"
"the cursor, '-' to hide the cursor, "
"or lowercase 'x' to quit:"_s;
auto save_cursor_visibile = console::cursor_visible();
auto save_cursor_size = console::cursor_size();
console::cursor_visible(true); // Initialize the cursor to visible.
console::cursor_size(100); // Emphasize the cursor.
while (true) {
console::write_line(m1, ((console::cursor_visible() == true) ? "VISIBLE" : "HIDDEN"));
if (string::is_empty(s) == false) {
if (s[0] == '+')
else if (s[0] == '-')
else if (s[0] == 'x')
break;
}
}
console::cursor_visible(save_cursor_visibile);
console::cursor_size(save_cursor_size);
}
// This code produces the following output. Note that these results
// cannot depict cursor visibility. You must run the example to see the
// cursor behavior:
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// The quick brown fox
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// -
//
// The cursor is HIDDEN.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// jumps over
//
// The cursor is HIDDEN.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// +
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// the lazy dog.
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// x
bool is_empty() const noexcept
Indicates whether this basic_string is an empty basic_string ("").
Definition basic_string.hpp:1511
static bool cursor_visible()
Gets a value indicating whether the cursor is visible.

◆ cursor_visible() [2/2]

static void xtd::console::cursor_visible ( bool  visible)
static

Sets a value indicating whether the cursor is visible.

Parameters
visibletrue if the cursor is visible; otherwise, false.
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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto m1 = "\nThe cursor is {0}.\nType any text then press Enter. "
"Type '+' in the first column to show \n"
"the cursor, '-' to hide the cursor, "
"or lowercase 'x' to quit:"_s;
auto save_cursor_visibile = console::cursor_visible();
auto save_cursor_size = console::cursor_size();
console::cursor_visible(true); // Initialize the cursor to visible.
console::cursor_size(100); // Emphasize the cursor.
while (true) {
console::write_line(m1, ((console::cursor_visible() == true) ? "VISIBLE" : "HIDDEN"));
if (string::is_empty(s) == false) {
if (s[0] == '+')
else if (s[0] == '-')
else if (s[0] == 'x')
break;
}
}
console::cursor_visible(save_cursor_visibile);
console::cursor_size(save_cursor_size);
}
// This code produces the following output. Note that these results
// cannot depict cursor visibility. You must run the example to see the
// cursor behavior:
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// The quick brown fox
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// -
//
// The cursor is HIDDEN.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// jumps over
//
// The cursor is HIDDEN.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// +
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// the lazy dog.
//
// The cursor is VISIBLE.
// Type any text then press Enter. Type '+' in the first column to show
// the cursor, '-' to hide the cursor, or lowercase 'x' to quit:
// x

◆ foreground_color() [1/2]

static console_color xtd::console::foreground_color ( )
static

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.
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.
#include <xtd/collections/generic/list>
#include <xtd/background_color>
#include <xtd/foreground_color>
#include <xtd/reset_color>
using namespace xtd;
using namespace xtd::collections;
auto main() -> int {
const auto logo = generic::list {
u8"████████████████████████████████████████████████████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████",
u8"███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████",
u8"██████████████████████████ ▀████ ▀█████████████████████████",
u8"███████████ ▐ ▀▀ ▐ ██████████",
u8"█████████ ▐ ███ ▌▐ ███ ▐ █████████",
u8"█████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████",
u8"█████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████",
u8"█████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████",
u8"█████████ █████████",
u8"█████████ █▄ ▌ █████████",
u8"█████████ ▌▀▀▄ ▄██ █████████",
u8"█████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████",
u8"█████████ ▐ ▄█ █████████",
u8"█████████ █ ▄█ █████████",
u8"█████████ ▀▄ █▀ █████████",
u8"█████████ ▀▄▄▄▄██▀ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"██████████████████████████████████████████████████████████████████",
};
for (auto index = 0ul; index < logo.size(); ++index)
std::cout << (index == 0 || index == logo.size() - 1 ? " " : " ") << background_color(console_color::white) << foreground_color(console_color::dark_blue) << logo[index] << reset_color() << std::endl;
std::cout << foreground_color(console_color::dark_blue) << " Gammasoft " << std::endl;
std::cout << foreground_color(console_color::dark_gray) << " More than thirty years of passion for high technology especially in development" << std::endl;
std::cout << " (c++, c#, objective-c, ...)." << reset_color() << std::endl;
}
// This code produces the following output with colors :
//
// ████████████████████████████████████████████████████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████
// ███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████
// ██████████████████████████ ▀████ ▀█████████████████████████
// ███████████ ▐ ▀▀ ▐ ██████████
// █████████ ▐ ███ ▌▐ ███ ▐ █████████
// █████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████
// █████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████
// █████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████
// █████████ █████████
// █████████ █▄ ▌ █████████
// █████████ ▌▀▀▄ ▄██ █████████
// █████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████
// █████████ ▐ ▄█ █████████
// █████████ █ ▄█ █████████
// █████████ ▀▄ █▀ █████████
// █████████ ▀▄▄▄▄██▀ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// ██████████████████████████████████████████████████████████████████
// Gammasoft
// More than thirty years of passion for high technology especially in development
// (c++, c#, objective-c, ...).
Represent background color output manipulator class.
Definition background_color.hpp:24
Represent foreground color output manipulator class.
Definition foreground_color.hpp:20
Represent reset color output manipulator class.
Definition reset_color.hpp:20
console_color
Specifies constants that define foreground and background colors for the console.
Definition console_color.hpp:20
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:12

◆ foreground_color() [2/2]

static bool xtd::console::foreground_color ( console_color  color)
static

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.
Exceptions
xtd::argument_exceptionThe color specified in a set operation is not a valid member of xtd::console_color.
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.
#include <xtd/collections/generic/list>
#include <xtd/background_color>
#include <xtd/foreground_color>
#include <xtd/reset_color>
using namespace xtd;
using namespace xtd::collections;
auto main() -> int {
const auto logo = generic::list {
u8"████████████████████████████████████████████████████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████",
u8"███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████████████████████████████████████████████████",
u8"██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████",
u8"███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████",
u8"██████████████████████████ ▀████ ▀█████████████████████████",
u8"███████████ ▐ ▀▀ ▐ ██████████",
u8"█████████ ▐ ███ ▌▐ ███ ▐ █████████",
u8"█████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████",
u8"█████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████",
u8"█████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████",
u8"█████████ █████████",
u8"█████████ █▄ ▌ █████████",
u8"█████████ ▌▀▀▄ ▄██ █████████",
u8"█████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████",
u8"█████████ ▐ ▄█ █████████",
u8"█████████ █ ▄█ █████████",
u8"█████████ ▀▄ █▀ █████████",
u8"█████████ ▀▄▄▄▄██▀ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"█████████ █████████",
u8"██████████████████████████████████████████████████████████████████",
};
for (auto index = 0ul; index < logo.size(); ++index)
std::cout << (index == 0 || index == logo.size() - 1 ? " " : " ") << background_color(console_color::white) << foreground_color(console_color::dark_blue) << logo[index] << reset_color() << std::endl;
std::cout << foreground_color(console_color::dark_blue) << " Gammasoft " << std::endl;
std::cout << foreground_color(console_color::dark_gray) << " More than thirty years of passion for high technology especially in development" << std::endl;
std::cout << " (c++, c#, objective-c, ...)." << reset_color() << std::endl;
}
// This code produces the following output with colors :
//
// ████████████████████████████████████████████████████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░██████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ██████████████████████████████░░░░░░░░░░░░░░░░░░░░░░████░░████████████
// ███████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████▀▄▄▄▄▀███████▀▄▄▄▄▀█████████████████████████
// ███████████████████████████▀▀▀▀███████▀▀▀▀▀███████████████████████████
// ██████████████████████████ ▀████ ▀█████████████████████████
// ███████████ ▐ ▀▀ ▐ ██████████
// █████████ ▐ ███ ▌▐ ███ ▐ █████████
// █████████ ▐ █▄▄▌ ▌▐ ▐▄▄█ ▐ █████████
// █████████ ▐▄ ▀▀ ▄▀ ▀▄ ▀▀ ▄▀ █████████
// █████████ ▀▀▄▄▀ ▀▀▄▄▀ █████████
// █████████ █████████
// █████████ █▄ ▌ █████████
// █████████ ▌▀▀▄ ▄██ █████████
// █████████ ▐ ▀▀▄▄▄▄▄▄█▀ █▌ █████████
// █████████ ▐ ▄█ █████████
// █████████ █ ▄█ █████████
// █████████ ▀▄ █▀ █████████
// █████████ ▀▄▄▄▄██▀ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// █████████ █████████
// ██████████████████████████████████████████████████████████████████
// Gammasoft
// More than thirty years of passion for high technology especially in development
// (c++, c#, objective-c, ...).

◆ input_code_page() [1/2]

static int32 xtd::console::input_code_page ( )
static

Gets the code page the console uses to read input.

Returns
The code page used to read console input.
Exceptions
xtd::io::io_exceptionAn error occurred during the execution of this operation.
Remarks
The following table lists the encodings supported by xtd.
Code page Name Display name
1200 utf-16 Unicode
1201 utf-16BE Unicode (Big endian)
12000 utf-32 Unicode (UTF-32)
12001 utf-32BE Unicode (UTF-32 Big endian)
20127 us-ascii US-ASCII
28591 iso-8859-1 Western European (ISO)
65000 utf-7 Unicode (UTF-7)
65001 utf-8 Unicode (UTF-8)

◆ input_code_page() [2/2]

static void xtd::console::input_code_page ( int32  code_page)
static

Sets the code page the console uses to read input.

Parameters
code_pageThe code page used to read console input.
Exceptions
xtd::io::io_exceptionAn error occurred during the execution of this operation.
Remarks
The following table lists the encodings supported by xtd.
Code page Name Display name
1200 utf-16 Unicode
1201 utf-16BE Unicode (Big endian)
12000 utf-32 Unicode (UTF-32)
12001 utf-32BE Unicode (UTF-32 Big endian)
20127 us-ascii US-ASCII
28591 iso-8859-1 Western European (ISO)
65000 utf-7 Unicode (UTF-7)
65001 utf-8 Unicode (UTF-8)

◆ is_error_redirected()

static bool xtd::console::is_error_redirected ( )
static

Gets a value that indicates whether the error output stream has been redirected from the standard error stream.

Parameters
trueif error output is redirected; otherwise, false.

◆ is_input_redirected()

static bool xtd::console::is_input_redirected ( )
static

Gets a value that indicates whether the input stream has been redirected from the standard input stream.

Parameters
trueif input is redirected; otherwise, false.

◆ is_output_redirected()

static bool xtd::console::is_output_redirected ( )
static

Gets a value that indicates whether the output stream has been redirected from the standard output stream.

Parameters
trueif output is redirected; otherwise, false.

◆ key_available()

static bool xtd::console::key_available ( )
static

Gets a value indicating whether a key press is available in the input stream.

Returns
true if a key press is available; otherwise, false.
Remarks
The key_available method is returned immediately; that is, the key_available method does not block input until a key press is available.
Use the key_available method in conjunction with only the read_key method, not the read or read_line methods

◆ largest_window_height()

static int32 xtd::console::largest_window_height ( )
static

Gets the largest possible number of console window rows, based on the current font and screen resolution.

Parameters
Theheight of the largest possible console window measured in rows.

◆ largest_window_width()

static int32 xtd::console::largest_window_width ( )
static

Gets the largest possible number of console window columns, based on the current font and screen resolution.

Parameters
Thewidth of the largest possible console window measured in columns.

◆ number_lock()

static bool xtd::console::number_lock ( )
static

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

Parameters
trueif NUM LOCK is turned on; false if NUM LOCK is turned off.

◆ output_code_page() [1/2]

static int32 xtd::console::output_code_page ( )
static

Gets the code page the console uses to write output.

Returns
The code page used to write console output.
Exceptions
xtd::io::io_exceptionAn error occurred during the execution of this operation.
Remarks
The following table lists the encodings supported by xtd.
Code page Name Display name
1200 utf-16 Unicode
1201 utf-16BE Unicode (Big endian)
12000 utf-32 Unicode (UTF-32)
12001 utf-32BE Unicode (UTF-32 Big endian)
20127 us-ascii US-ASCII
28591 iso-8859-1 Western European (ISO)
65000 utf-7 Unicode (UTF-7)
65001 utf-8 Unicode (UTF-8)

◆ output_code_page() [2/2]

static void xtd::console::output_code_page ( int32  code_page)
static

Sets the code page the console uses to write output.

Parameters
code_pageThe code page used to write console output.
Exceptions
xtd::io::io_exceptionAn error occurred during the execution of this operation.
Remarks
The following table lists the encodings supported by xtd.
Code page Name Display name
1200 utf-16 Unicode
1201 utf-16BE Unicode (Big endian)
12000 utf-32 Unicode (UTF-32)
12001 utf-32BE Unicode (UTF-32 Big endian)
20127 us-ascii US-ASCII
28591 iso-8859-1 Western European (ISO)
65000 utf-7 Unicode (UTF-7)
65001 utf-8 Unicode (UTF-8)

◆ title() [1/2]

static xtd::string xtd::console::title ( )
static

Gets the title to display in the console title bar.

Returns
The string to be displayed in the title bar of the console. The maximum length of the title string is 24500 characters.

◆ title() [2/2]

static void xtd::console::title ( const xtd::string title)
static

Sets the title to display in the console title bar.

Parameters
titleThe string to be displayed in the title bar of the console. The maximum length of the title string is 24500 characters.

◆ treat_control_c_as_input() [1/2]

static bool xtd::console::treat_control_c_as_input ( )
static

Gets a value indicating whether the combination of the Control modifier key and C console key (Ctrl+C) is treated as ordinary input or as an interruption that is handled by the operating system.

Returns
true if Ctrl+C is treated as ordinary input; otherwise, false.
Remarks
If the value of the treat_control_c_as_input property is false and Ctrl+C is pressed, the pressed keys are not stored in the input buffer and the operating system terminates the currently executing process. This is the default value.
Warning
Use this property judiciously because setting it to true has such a dramatic effect. Most users expect Ctrl+C to terminate a console application. If you disable the effect of Ctrl+C, the user must remember to use Ctrl+Break to terminate the application, which is a less familiar key combination.

◆ treat_control_c_as_input() [2/2]

static void xtd::console::treat_control_c_as_input ( bool  treat_control_c_as_input)
static

Sets a value indicating whether the combination of the Control modifier key and C console key (Ctrl+C) is treated as ordinary input or as an interruption that is handled by the operating system.

Parameters
treat_control_c_as_inputtrue if Ctrl+C is treated as ordinary input; otherwise, false.
Remarks
If the value of the treat_control_c_as_input property is false and Ctrl+C is pressed, the pressed keys are not stored in the input buffer and the operating system terminates the currently executing process. This is the default value.
Warning
Use this property judiciously because setting it to true has such a dramatic effect. Most users expect Ctrl+C to terminate a console application. If you disable the effect of Ctrl+C, the user must remember to use Ctrl+Break to terminate the application, which is a less familiar key combination.

◆ window_height() [1/2]

static int32 xtd::console::window_height ( )
static

Gets the height of the console window area.

Returns
The height of the console window measured in rows.

◆ window_height() [2/2]

static void xtd::console::window_height ( int32  height)
static

Sets the height of the console window area.

Parameters
heightThe height of the console window measured in rows.

◆ window_left() [1/2]

static int32 xtd::console::window_left ( )
static

Gets the left of the console window area.

Returns
The left of the console window measured in columns.

◆ window_left() [2/2]

static void xtd::console::window_left ( int32  left)
static

Sets the left of the console window area.

Parameters
leftThe left of the console window measured in columns.

◆ window_top() [1/2]

static int32 xtd::console::window_top ( )
static

Gets the top of the console window area.

Returns
The top of the console window measured in rows.

◆ window_top() [2/2]

static void xtd::console::window_top ( int32  top)
static

Sets the top of the console window area.

Parameters
topThe top of the console window measured in rows.

◆ window_width() [1/2]

static int32 xtd::console::window_width ( )
static

Gets the width of the console window area.

Returns
The width of the console window measured in columns.

◆ window_width() [2/2]

static void xtd::console::window_width ( int32  width)
static

Sets the width of the console window area.

Parameters
widthThe width of the console window measured in columns.

◆ beep() [1/2]

static void xtd::console::beep ( )
static

Plays the sound of a beep through the console speaker.

Remarks
By default, the beep plays at a frequency of 800 hertz for a duration of 200 milliseconds
Examples
The following example demonstrates the beep method. The example accepts a number from 1 through 9 as a command line argument, and plays the beep that number of times.
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/int32_object>
using namespace xtd;
using namespace xtd::threading;
auto main(int argc, char* argv[]) -> int {
auto x = 0;
//
if ((argc == 2) && (int32_object::try_parse(argv[1], x) == true) && ((x >= 1) && (x <= 9))) {
for (auto i = 1; i <= x; ++i) {
console::write_line("Beep number {}.", i);
thread::sleep(100_ms);
}
} else
console::write_line("Usage: Enter the number of times (between 1 and 9) to beep.");
}
// This code produces the following output if 3 is entered on command line:
//
// Beep number 1.
// Beep number 2.
// Beep number 3.
static bool try_parse(const xtd::string &value, type_t &result) noexcept
Converts the string to its type_t equivalent. A return value indicates whether the conversion succeed...
Definition box.hpp:133
static void beep()
Plays the sound of a beep through the console speaker.
@ i
The I key.
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:11

◆ beep() [2/2]

static void xtd::console::beep ( uint32  frequency,
uint32  duration 
)
static

Plays the sound of a beep of a specified frequency and duration through the console speaker.

Parameters
frequencyThe frequency of the beep, ranging from 37 to 32767 hertz
durationThe duration of the beep measured in milliseconds
Examples
This example demonstrates the beep method by playing the first few notes of a song through the console speaker.
#include <xtd/collections/generic/list>
#include <xtd/threading/thread>
#include <xtd/as>
#include <xtd/console>
using namespace xtd;
using namespace xtd::collections::generic;
// Define the frequencies of notes in an octave, as well as
// silence (rest).
enum class tone {
rest = 0,
g_below_c = 196,
a = 220,
a_sharp = 233,
b = 247,
c = 262,
c_sharp = 277,
d = 294,
d_sharp = 311,
e = 330,
f = 349,
f_sharp = 370,
g = 392,
g_sharp = 415,
};
// Define the duration of a note in units of milliseconds.
enum class duration {
none = 0,
whole = 1600,
half = whole / 2,
quarter = half / 2,
eighth = quarter / 2,
sixteenth = eighth / 2,
};
// Define a note as a frequency (tone) and the amount of
// time (duration) the note plays.
struct note final {
private:
tone tone_val = tone::rest;
duration dur_val = duration::none;
public:
// Define a constructor to create a specific note.
note(tone frequency, duration time) : tone_val(frequency), dur_val(time) {}
note() = default;
note(const note& note) = default;
note& operator=(const note& note) = default;
bool operator ==(const note& rhs) const noexcept {return tone_val == rhs.tone_val && dur_val == rhs.dur_val;}
// Define properties to return the note's tone and duration.
tone note_tone() const noexcept {return tone_val;}
duration note_duration() const noexcept {return dur_val;}
};
// Play the notes in a song.
void play(const list<note>& tune) {
for (auto n : tune) {
if (n.note_tone() == tone::rest)
threading::thread::sleep(as<int>(n.note_duration()));
else
console::beep(as<unsigned int>(n.note_tone()), as<unsigned int>(n.note_duration()));
}
}
auto main() -> int {
// Declare the first few notes of the song, "Mary Had A Little Lamb".
auto mary = list {
note(tone::b, duration::quarter),
note(tone::a, duration::quarter),
note(tone::g_below_c, duration::quarter),
note(tone::a, duration::quarter),
note(tone::b, duration::quarter),
note(tone::b, duration::quarter),
note(tone::b, duration::half),
note(tone::a, duration::quarter),
note(tone::a, duration::quarter),
note(tone::a, duration::half),
note(tone::b, duration::quarter),
note(tone::d, duration::quarter),
note(tone::d, duration::half)
};
// Play the song
play(mary);
}
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
@ none
No modifier key.
@ a
The A key.
@ c
The C key.
@ n
The N key.
@ d
The D key.
@ f
The F key.
@ b
The B key.
@ play
The Play key.
@ g
The G key.
@ e
The E key.

◆ clear()

static void xtd::console::clear ( )
static

Clears the console buffer and corresponding console window of display information.

Remarks
Using the clear method is equivalent invoking the MS-DOS cls command in the command prompt window.
When the Clear method is called, the cursor automatically scrolls to the top-left corner of the window and the contents of the screen buffer are set to blanks using the current foreground background colors.
Examples
The following example uses the clear method to clear the console before it executes a loop, prompts the user to select a foreground and background color and to enter a string to display. If the user chooses not to exit the program, the console's original foreground and background colors are restored and the Clear method is called again before re-executing the loop.
#include <xtd/collections/generic/list>
#include <xtd/char32_object>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::collections::generic;
namespace console_clear_example {
class program {
public:
// The main entry point for the application.
static auto main(const argument_collection& args) {
// Save colors so they can be restored when use finishes input.
auto dft_fore_color = console::foreground_color();
auto dft_back_color = console::background_color();
auto continue_flag = true;
console::clear();
do {
auto new_fore_color = console_color::white;
auto new_back_color = console_color::black;
auto fore_color_selection = get_key_press("Select Text Color (B for Blue, R for Red, Y for Yellow): ", list<char32_t> { 'B', 'R', 'Y' });
switch (fore_color_selection) {
case 'B':
case 'b': new_fore_color = console_color::dark_blue; break;
case 'R':
case 'r': new_fore_color = console_color::dark_red; break;
case 'Y':
case 'y': new_fore_color = console_color::dark_yellow; break;
}
auto back_color_selection = get_key_press("Select Background Color (W for White, G for Green, M for Magenta): ", list<char32_t> { 'W', 'G', 'M' });
switch (back_color_selection) {
case 'W':
case 'w': new_back_color = console_color::white; break;
case 'G':
case 'g': new_back_color = console_color::green; break;
case 'M':
case 'm': new_back_color = console_color::magenta; break;
}
console::write_line();
console::write("Enter a message to display: ");
string text_to_display = console::read_line();
console::write_line();
console::foreground_color(new_fore_color);
console::background_color(new_back_color);
console::write_line(text_to_display);
console::write_line();
if (char32_object::to_upper(get_key_press("Display another message (Y/N): ", list<char32_t> { 'Y', 'N' })) == 'N')
continue_flag = false;
// Restore the default settings and clear the screen.
console::foreground_color(dft_fore_color);
console::background_color(dft_back_color);
console::clear();
} while (continue_flag);
}
private:
static char32_t get_key_press(const string& msg, const list<char32_t>& valid_chars) {
auto key_pressed = console_key_info {};
auto valid = false;
console::write_line();
do {
console::write(msg);
key_pressed = console::read_key();
console::write_line();
if (std::find(valid_chars.begin(), valid_chars.end(), char32_object::to_upper(key_pressed.key_char())) != valid_chars.end())
valid = true;
} while (!valid);
return key_pressed.key_char();
}
};
}
startup_(console_clear_example::program::main);
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:204
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.hpp:315
Specifies the standard keys on a console.
Definition console_key_info.hpp:24
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:175
The example relies on a get_key_press method to validate the user's selection of a foreground and background color.
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.
#include <xtd/console>
using namespace xtd;
auto orig_row = 0;
auto orig_col = 0;
void write_at(const string& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
auto main() -> int {
// Clear the screen, then save the top and left coordinates.
orig_row = console::cursor_top();
orig_col = console::cursor_left();
// Draw the left side of a 5x5 rectangle, from top to bottom.
write_at("+", 0, 0);
write_at("|", 0, 1);
write_at("|", 0, 2);
write_at("|", 0, 3);
write_at("+", 0, 4);
// Draw the bottom side, from left to right.
write_at("-", 1, 4); // shortcut: write_at("---", 1, 4)
write_at("-", 2, 4); // ...
write_at("-", 3, 4); // ...
write_at("+", 4, 4);
// Draw the right side, from bottom to top.
write_at("|", 4, 3);
write_at("|", 4, 2);
write_at("|", 4, 1);
write_at("+", 4, 0);
// Draw the top side, from right to left.
write_at("-", 3, 0); // shortcut: write_at("---", 1, 0)
write_at("-", 2, 0); // ...
write_at("-", 1, 0); // ...
//
write_at("All done!", 0, 6);
}
// This code produces the following output :
//
// +---+
// | |
// | |
// | |
// +---+
//
// All done!

◆ get_cursor_position()

static xtd::collections::generic::key_value_pair< int32, int32 > xtd::console::get_cursor_position ( )
static

Gets the position of the cursor.

Returns
The column and row position of the cursor.
Remarks
Columns are numbered from left to right starting at 0. Rows are numbered from top to bottom starting at 0.

◆ open_standard_error()

static std::ostream xtd::console::open_standard_error ( )
static

Acquires the standard error stream.

Returns
The standard error stream.
Remarks
This method can be used to reacquire the standard error stream after it has been changed by the set_error method.

◆ open_standard_input()

static std::istream xtd::console::open_standard_input ( )
static

Acquires the standard input stream.

Returns
The standard input stream.
Remarks
This method can be used to reacquire the standard input stream after it has been changed by the set_int method.

◆ open_standard_output()

static std::ostream xtd::console::open_standard_output ( )
static

Acquires the standard output stream.

Returns
The standard output stream.
Remarks
This method can be used to reacquire the standard output stream after it has been changed by the set_output method.

◆ read()

static int32 xtd::console::read ( )
static

Reads the next character from the standard input stream.

Returns
int32 The next character from the input stream, or negative one (-1) if there are currently no more characters to be read
Remarks
The Read method blocks its return while you type input characters; it terminates when you press the Enter key.
Pressing Enter appends a platform-dependent line termination sequence to your input (for example, Windows appends a carriage return-linefeed sequence).
Subsequent calls to the Read method retrieve your input one character at a time. After the final character is retrieved, Read blocks its return again and the cycle repeats.
Note that you will not get a property value of -1 unless you perform one of the following actions: simultaneously press the Control modifier key and Z console key (CTRL+Z),
which signals the end-of-file condition; press an equivalent key that signals the end-of-file condition, such as the F6 function key in Windows; or redirect the input stream to a source,
such as a text file, that has an actual end-of-file character.
Example
The following example demonstrates the Read method.
#include <xtd/char_object>
#include <xtd/console>
#include <xtd/convert>
using namespace xtd;
auto main() -> int {
auto m1 = "\nType a string of text then press Enter. "
"Type '+' anywhere in the text to quit:\n";
auto m2 = "Character '{0}' is hexadecimal 0x{1:x4}.";
auto m3 = "Character is hexadecimal 0x{0:x4}.";
auto ch = U'0';
//
do {
auto x = console::read();
try {
if (ch == 0x0a)
} else
} catch (const overflow_exception& e) {
console::write_line("{0} Value read = {1}.", e.message(), x);
}
} while (ch != '+');
}
// This code produces the following output :
//
// Type a string of text then press Enter. Type '+' anywhere in the text to quit:
//
// The quick brown fox.
// Character 'T' is hexadecimal 0x0054.
// Character 'h' is hexadecimal 0x0068.
// Character 'e' is hexadecimal 0x0065.
// Character is hexadecimal 0x0020.
// Character 'q' is hexadecimal 0x0071.
// Character 'u' is hexadecimal 0x0075.
// Character 'i' is hexadecimal 0x0069.
// Character 'c' is hexadecimal 0x0063.
// Character 'k' is hexadecimal 0x006b.
// Character is hexadecimal 0x0020.
// Character 'b' is hexadecimal 0x0062.
// Character 'r' is hexadecimal 0x0072.
// Character 'o' is hexadecimal 0x006f.
// Character 'w' is hexadecimal 0x0077.
// Character 'n' is hexadecimal 0x006e.
// Character is hexadecimal 0x0020.
// Character 'f' is hexadecimal 0x0066.
// Character 'o' is hexadecimal 0x006f.
// Character 'x' is hexadecimal 0x0078.
// Character '.' is hexadecimal 0x002e.
// Character is hexadecimal 0x000d.
// Character is hexadecimal 0x000a.
//
// Type a string of text then press Enter. Type '+' anywhere in the text to quit:
//
// ^Z
// Value was either too large or too small for a character. Value read = -1.
//
// Type a string of text then press Enter. Type '+' anywhere in the text to quit:
//
// +
// Character '+' is hexadecimal 0x002b.
static bool is_white_space(type_t c) noexcept
Indicates whether the specified Unicode character is categorized as white space.
Definition box_char.hpp:187
static constexpr type_t min_value
Represents the smallest possible value of type_t. This field is constant.
Definition box_integer.hpp:70
static int32 read()
Reads the next character from the standard input stream.
static char32 to_char32(std::any value)
Convert std::any to char32.
The exception that is thrown when an arithmetic, casting, or conversion operation in a checked contex...
Definition overflow_exception.hpp:19

◆ read_key() [1/2]

static console_key_info xtd::console::read_key ( )
static

Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.

Returns
xtd::console_key_info A xtd::console_key_info object that describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The xtd::console_key_info object also describes, in a bitwise combination of ConsoleModifiers values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key.

◆ read_key() [2/2]

static console_key_info xtd::console::read_key ( bool  intercept)
static

Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window.

Parameters
interceptDetermines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false
Returns
xtd::console_key_info A xtd::console_key_info object that describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The xtd::console_key_info object also describes, in a bitwise combination of ConsoleModifiers values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key.

◆ read_line() [1/2]

static xtd::string xtd::console::read_line ( )
static

Reads the next line of characters from the standard input stream.

Returns
The next line of characters from the input stream, or "" if no more lines are available.

◆ read_line() [2/2]

static xtd::string xtd::console::read_line ( bool  intercept)
static

Reads the next line of characters from the standard input stream.

Parameters
interceptDetermines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false
Returns
The next line of characters from the input stream, or "" if no more lines are available.

◆ reset_color()

static bool xtd::console::reset_color ( )
static

Sets the foreground and background console colors to their defaults.

Remarks
The foreground and background colors are restored to the colors that existed when the current process began. For more information, see the foreground_color and background_color properties.

◆ set_cursor_position()

static void xtd::console::set_cursor_position ( int32  left,
int32  top 
)
static

Sets the position of the cursor.

Parameters
leftThe column position of the cursor. Columns are numbered from left to right starting at 0.
topThe row position of the cursor. Rows are numbered from top to bottom starting at 0.
Exceptions
xtd::argument_out_of_range_exceptionThe left in a set operation is less than zero
-or-
The left in a set operation is greater than or equal to xtd::console::buffer_width
-or-
the top in a set operation is less than zero
-or-
The topo in a set operation is greater than or equal to xtd::console::buffer_height.
Remarks
Use the set_cursor_position method to specify where the next write operation in the console window is to begin. If the specified cursor position is outside the area that is currently visible in the console window, the window origin changes automatically to make the cursor visible.
The cursor automatically moves to the next character position each time a character is written to the console window. If the cursor is at the bottom right character position of the console window, the next write operation causes the console window to scroll so the cursor remains visible. If you want to write a character to the bottom right character position without causing the console window to scroll, use the move_buffer_area method to move a character to that position.

◆ set_error()

static void xtd::console::set_error ( const std::ostream &  os)
static

Sets the error property to the specified std::ostream object.

Parameters
osA stream that is the new standard error output.
Remarks
By default, the error property is set to the standard error output stream.
A std::ostream that encapsulates a std::ofstream can be used to send error messages to a file.

◆ set_in()

static void xtd::console::set_in ( const std::istream &  is)
static

Sets the int property to the specified std::istream object.

Parameters
osA stream that is the new standard input.
Remarks
By default, the in property is set to the standard input stream.
A std::istream that encapsulates a std::ifstream can be used to receiver input from a file.

◆ set_out()

static void xtd::console::set_out ( const std::ostream &  os)
static

Sets the out property to the specified std::ostream object.

Parameters
osA stream that is the new standard output.
Remarks
By default, the out property is set to the standard output stream.
A std::ostream that encapsulates a std::ofstream can be used to send output to a file.

◆ set_window_position()

static void xtd::console::set_window_position ( int32  left,
int32  top 
)
static

Sets the position of the console window relative to the screen buffer.

Parameters
leftThe column position of the upper left corner of the console window.
topThe row position of the upper left corner of the console window.
Exceptions
xtd::argument_out_of_range_exceptionThe left in a set operation is less than zero
-or-
The left in a set operation is greater than or equal to xtd::console::buffer_width
-or-
the top in a set operation is less than zero
-or-
The topo in a set operation is greater than or equal to xtd::console::buffer_height.

◆ set_window_size()

static void xtd::console::set_window_size ( int32  width,
int32  height 
)
static

Sets the height and width of the console window to the specified values.

Parameters
widthThe width of the console window measured in columns.
heightThe height of the console window measured in rows.
Exceptions
xtd::argument_out_of_range_exceptionwidth or height is less than or equal to zero.
-or-
width plus WindowLeft or height plus WindowTop is greater than or equal to xtd::int16_object.max_value.
-or-
width or height is greater than the largest possible window width or height for the current screen resolution and console font.
Examples
This example demonstrates the SetWindowSize method, and the WindowWidth and WindowHeight properties. You must run the example to see the full effect of changing the console window size. The example reports the dimensions of a console window set to 85 columns and 43 rows, then waits for a key press. When any key is pressed, the dimensions of the console window are halved, the new dimensions are reported, and the example waits for another key press. Finally, when any key is pressed the console window is restored to its original dimensions and the example terminates.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto orig_width = 0, width = 0;
auto orig_height = 0, height = 0;
auto m1 = "The current window width is {0}, and the current window height is {1}.";
auto m2 = "The new window width is {0}, and the new window height is {1}.";
auto m4 = " (Press any key to continue...)";
//
// Step 1: Get the current window dimensions.
//
orig_width = console::window_width();
orig_height = console::window_height();
//
// Step 2: Cut the window to 1/4 its original size.
//
width = orig_width / 2;
height = orig_height / 2;
console::set_window_size(width, height);
//
// Step 3: Restore the window to its original size.
//
console::set_window_size(orig_width, orig_height);
// This code produces the following output :
//
// The current window width is 100, and the current window height is 60.
// (Press any key to continue...)
// The new window width is 50, and the new window height is 30.
// (Press any key to continue...)
// The current window width is 100, and the current window height is 60.
static int32 window_height()
Gets the height of the console window area.
static void set_window_size(int32 width, int32 height)
Sets the height and width of the console window to the specified values.
static int32 window_width()
Gets the width of the console window area.

◆ write() [1/2]

template<typename arg_t >
static void xtd::console::write ( arg_t &&  value)
inlinestatic

Writes the text representation of the specified value to the standard output stream.

Template Parameters
arg_tThe type of the value to write.
Parameters
valueThe value to write,

◆ write() [2/2]

template<typename ... args_t>
static void xtd::console::write ( const xtd::string fmt,
args_t &&...  values 
)
inlinestatic

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

Template Parameters
...args_tTypes of the values to write.
Parameters
fmtA composite format string.
valuesValues to write,

◆ write_line() [1/3]

static void xtd::console::write_line ( )
static

Writes the current line terminator to the standard output stream using the specified format information.

Examples
css_reader.cpp, date_time_add.cpp, date_time_add_days.cpp, date_time_days_in_month.cpp, date_time_subtract.cpp, environment.cpp, strings.cpp, and uri.cpp.

◆ write_line() [2/3]

template<typename arg_t >
static void xtd::console::write_line ( arg_t &&  value)
inlinestatic

Writes the text representation of the specified value, followed by the current line terminator, to the standard output stream.

Template Parameters
arg_tThe type of the value to write.
Parameters
valueThe value to write,

◆ write_line() [3/3]

template<typename ... args_t>
static void xtd::console::write_line ( const xtd::string fmt,
args_t &&...  values 
)
inlinestatic

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.

Template Parameters
...args_tTypes of the values to write.
Parameters
fmtA composite format string.
valuesValues to write,

Member Data Documentation

◆ error

std::ostream xtd::console::error
static

Gets the error output stream. A std::basic_ostream<char_t> that represents the error output stream.

◆ in

std::istream xtd::console::in
static

Gets the standard input stream. A std::basic_istream<char_t> that represents the standard input stream.

Examples
The following sample illustrates the use of the in property.
#include <xtd/console>
#include <xtd/environment>
using namespace xtd;
auto main() -> int {
auto& is = console::in;
auto& os = console::out;
os << "Ola Mundo!" << environment::new_line;
os << "What is your name: ";
auto name = string::empty_string;
is >> name;
os << "Buenos Dias, " << name << environment::new_line;
}
// This code produces the following output :
//
// Ola Mundo!
// What is your name: James
// Buenos Dias, James!

◆ out

std::ostream xtd::console::out
static

Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output stream.

Examples
The following sample illustrates the use of the out property.
#include <xtd/console>
#include <xtd/environment>
using namespace xtd;
auto main() -> int {
auto& is = console::in;
auto& os = console::out;
os << "Ola Mundo!" << environment::new_line;
os << "What is your name: ";
auto name = string::empty_string;
is >> name;
os << "Buenos Dias, " << name << environment::new_line;
}
// This code produces the following output :
//
// Ola Mundo!
// What is your name: James
// Buenos Dias, James!
Examples
event.cpp.

◆ cancel_key_press

event<console, console_cancel_event_handler> xtd::console::cancel_key_press
static

Occurs when the Control modifier key (Ctrl) and either the ConsoleKey.C console key (C) or the Break key are pressed simultaneously (Ctrl+C or Ctrl+Break).

Remarks
This event is used in conjunction with xtd::console_cancel_event_handler and xtd::console_cancel_event_args. The cancel_key_press event enables a console application to intercept the Ctrl+C signal so the event handler can decide whether to continue executing or terminate.
For more information about handling events, see Handling and Raising Events.
When the user presses either Ctrl+C or Ctrl+Break, the cancel_key_press event is fired and the application's console_cancel_event_handler event handler is executed. The event handler is passed a console_cancel_event_args object that has two useful properties:
  • special_key, which allows you to determine whether the handler was invoked as a result of the user pressing Ctrl+C (the property value is console_special_key::control_c) or Ctrl+Break (the property value is console_special_key.control_break).
  • Cancel, which allows you to determine how to your application should respond to the user pressing Ctrl+C or Ctrl+Break. By default, the cancel property is false, which causes program execution to terminate when the event handler exits. Changing its property to true specifies that the application should continue to execute.
Note
If your application has simple requirements, you can use the treat_control_c_as_input property instead of this event. By setting this property to false, you can ensure that your application always exits if the user presses Ctrl+C. By setting it to true, you can ensure that pressing Ctrl+C will not terminate the application.
Warning
The xtd::signal::interrupt and xtd::console_special_key::control_c use the same signal (SIGINT).
The xtd::signal::interrupt and xtd::console_special_key::control_c can be cancelled with xtd::environment::cancel_signal event or xtd::console::cancel_key_press event. Both of these events are called when SIGINT is raised.

The documentation for this class was generated from the following file: