xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
Static Public Attributes | Static Public Member Functions | List of all members
xtd::console Class Referencefinal

#include <console.h>

Definition

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

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.

Inherits xtd::static_object.

Static Public Attributes

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).
 
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.
 

Static Public Member Functions

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 void beep ()
 Plays the sound of a beep through the console speaker.
 
static void beep (uint32_t frequency, uint32_t duration)
 Plays the sound of a beep of a specified frequency and duration through the console speaker.
 
static int32_t buffer_height ()
 Gets the height of the buffer area.
 
static void buffer_height (int32_t height)
 Sets or sets the height of the buffer area.
 
static int32_t buffer_width ()
 Gets the width of the buffer area.
 
static void buffer_width (int32_t 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 void clear ()
 Clears the console buffer and corresponding console window of display information.
 
static int32_t cursor_left ()
 Gets the column position of the cursor within the buffer area.
 
static void cursor_left (int32_t left)
 Sets the column position of the cursor within the buffer area.
 
static int32_t cursor_size ()
 Gets or sets the height of the cursor within a character cell.
 
static void cursor_size (int32_t size)
 Sets the height of the cursor within a character cell.
 
static int32_t cursor_top ()
 Gets the row position of the cursor within the buffer area.
 
static void cursor_top (int32_t 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_t input_code_page ()
 Gets the code page the console uses to read input.
 
static bool input_code_page (int32_t 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_in_redirected ()
 Gets a value that indicates whether the input stream has been redirected from the standard input stream.
 
static bool is_out_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_t largest_window_height ()
 Gets the largest possible number of console window rows, based on the current font and screen resolution.
 
static int32_t 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 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_t output_code_page ()
 Gets the code page the console uses to write output.
 
static bool output_code_page (int32_t code_page)
 Sets the code page the console uses to write output.
 
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::ustring read_line ()
 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_t left, int32_t 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 xtd::ustring title ()
 Gets the title to display in the console title bar.
 
static void title (const xtd::ustring &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_t window_height ()
 Gets the height of the console window area.
 
static void window_height (int32_t height)
 Sets the height of the console window area.
 
static int32_t window_left ()
 Gets the left of the console window area.
 
static void window_left (int32_t left)
 Sets the left of the console window area.
 
static int32_t window_top ()
 Gets the top of the console window area.
 
static void window_top (int32_t top)
 Sets the top of the console window area.
 
static int32_t window_width ()
 Gets the width of the console window area.
 
static void window_width (int32 width)
 Sets the width of the console window area.
 
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::ustring &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::ustring &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

◆ background_color() [1/2]

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

Gets the background color of the console.

Returns
the background console_color.
Remarks
A get operation for a Windows-based application, in which a console does not exist, returns console_color::black.
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 console_color 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/xtd>
#include <vector>
using namespace std;
using namespace xtd;
int main() {
const vector logo = {
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 (size_t index = 0; index < logo.size(); ++index)
cout << (index == 0 || index == logo.size() - 1 ? " " : " ") << background_color(console_color::white) << foreground_color(console_color::dark_blue) << logo[index] << reset_color() << endl;
cout << foreground_color(console_color::dark_blue) << u8" Gammasoft " << endl;
cout << foreground_color(console_color::dark_gray) << u8" More than thirty years of passion for high technology especially in development" << endl;
cout << u8" (c++, c#, objective-c, ...)." << reset_color() << 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, ...).
static int32_t output_code_page()
Gets the code page the console uses to write output.
static console_color background_color()
Gets the background color of the console.
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 namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17

◆ 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.
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 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 console_color 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/xtd>
#include <vector>
using namespace std;
using namespace xtd;
int main() {
const vector logo = {
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 (size_t index = 0; index < logo.size(); ++index)
cout << (index == 0 || index == logo.size() - 1 ? " " : " ") << background_color(console_color::white) << foreground_color(console_color::dark_blue) << logo[index] << reset_color() << endl;
cout << foreground_color(console_color::dark_blue) << u8" Gammasoft " << endl;
cout << foreground_color(console_color::dark_gray) << u8" More than thirty years of passion for high technology especially in development" << endl;
cout << u8" (c++, c#, objective-c, ...)." << reset_color() << 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, ...).

◆ 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/xtd>
#include <thread>
using namespace std;
using namespace std::chrono;
using namespace std::this_thread;
using namespace xtd;
int main(int argc, char* argv[]) {
int x = 0;
//
if ((argc == 2) && (ustring::try_parse<int>(argv[1], x) == true) && ((x >= 1) && (x <= 9))) {
for (int i = 1; i <= x; i++) {
console::write_line("Beep number {}.", i);
sleep_for(milliseconds(100));
}
} 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 void beep()
Plays the sound of a beep through the console speaker.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
@ i
The I key.
@ x
The X key.

◆ beep() [2/2]

static void xtd::console::beep ( uint32_t  frequency,
uint32_t  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/xtd>
#include <chrono>
#include <vector>
#include <thread>
using namespace std;
using namespace std::this_thread;
using namespace xtd;
// 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;
// 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 vector<note>& tune) {
for (note n : tune) {
if (n.note_tone() == tone::rest)
sleep_for(chrono::milliseconds(static_cast<int>(n.note_duration())));
else
console::beep(static_cast<unsigned int>(n.note_tone()), static_cast<unsigned int>(n.note_duration()));
}
}
int main() {
// Declare the first few notes of the song, "Mary Had A Little Lamb".
vector mary = {
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);
}
@ none
Indicates that no style elements, such as leading or trailing white space, thousands separators,...
@ 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.

◆ buffer_height() [1/2]

static int32_t 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/xtd>
using namespace xtd;
int main() {
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_t buffer_height()
Gets the height of the buffer area.
static int32_t buffer_width()
Gets the width of the buffer area.

◆ buffer_height() [2/2]

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

Sets or sets the height of the buffer area.

Parameters
heightThe 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/xtd>
using namespace xtd;
int main() {
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_t 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/xtd>
using namespace xtd;
int main() {
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_t  width)
static

Sets the width of the buffer area.

Parameters
widthThe 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/xtd>
using namespace xtd;
int main() {
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.

◆ 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.
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/xtd>
using namespace xtd;
int orig_row = 0;
int orig_col = 0;
void write_at(const ustring& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
int main() {
// 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 void set_cursor_position(int32_t left, int32_t top)
Sets the position of the cursor.
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition: console.h:333
static void clear()
Clears the console buffer and corresponding console window of display information.
static int32_t cursor_left()
Gets the column position of the cursor within the buffer area.
static int32_t cursor_top()
Gets the row position of the cursor within the buffer area.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
@ s
The S key.
@ y
The Y key.

◆ cursor_left() [1/2]

static int32_t 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/xtd>
using namespace xtd;
int orig_row = 0;
int orig_col = 0;
void write_at(const ustring& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
int main() {
// 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_left() [2/2]

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

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.
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/xtd>
using namespace xtd;
int orig_row = 0;
int orig_col = 0;
void write_at(const ustring& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
int main() {
// 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_t 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.

◆ cursor_size() [2/2]

static void xtd::console::cursor_size ( int32_t  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.
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.

◆ cursor_top() [1/2]

static int32_t 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/xtd>
using namespace xtd;
int orig_row = 0;
int orig_col = 0;
void write_at(const ustring& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
int main() {
// 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_t  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.
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/xtd>
using namespace xtd;
int orig_row = 0;
int orig_col = 0;
void write_at(const ustring& s, int x, int y) {
console::set_cursor_position(orig_col + x, orig_row + y);
}
int main() {
// 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.

◆ 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.

◆ 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/xtd>
#include <vector>
using namespace std;
using namespace xtd;
int main() {
const vector logo = {
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 (size_t index = 0; index < logo.size(); ++index)
cout << (index == 0 || index == logo.size() - 1 ? " " : " ") << background_color(console_color::white) << foreground_color(console_color::dark_blue) << logo[index] << reset_color() << endl;
cout << foreground_color(console_color::dark_blue) << u8" Gammasoft " << endl;
cout << foreground_color(console_color::dark_gray) << u8" More than thirty years of passion for high technology especially in development" << endl;
cout << u8" (c++, c#, objective-c, ...)." << reset_color() << 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, ...).

◆ 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.
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/xtd>
#include <vector>
using namespace std;
using namespace xtd;
int main() {
const vector logo = {
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 (size_t index = 0; index < logo.size(); ++index)
cout << (index == 0 || index == logo.size() - 1 ? " " : " ") << background_color(console_color::white) << foreground_color(console_color::dark_blue) << logo[index] << reset_color() << endl;
cout << foreground_color(console_color::dark_blue) << u8" Gammasoft " << endl;
cout << foreground_color(console_color::dark_gray) << u8" More than thirty years of passion for high technology especially in development" << endl;
cout << u8" (c++, c#, objective-c, ...)." << reset_color() << 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_t 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.

◆ input_code_page() [2/2]

static bool xtd::console::input_code_page ( int32_t  code_page)
static

Sets the code page the console uses to read input.

Parameters
code_pageThe code page used to read console input.
Returns
true if the code page changed; otherwise false.

◆ 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_in_redirected()

static bool xtd::console::is_in_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_out_redirected()

static bool xtd::console::is_out_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.

Parameters
trueif 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_t 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_t 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.

◆ 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.

◆ output_code_page() [1/2]

static int32_t 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.

◆ output_code_page() [2/2]

static bool xtd::console::output_code_page ( int32_t  code_page)
static

Sets the code page the console uses to write output.

Parameters
code_pageThe code page used to write console output.
Returns
true if the code page changed; otherwise false.

◆ 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
ConsoleKeyInfo A ConsoleKeyInfo object that describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The ConsoleKeyInfo 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
ConsoleKeyInfo A ConsoleKeyInfo object that describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The ConsoleKeyInfo 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()

static xtd::ustring 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.

◆ 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_t  left,
int32_t  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.
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.

◆ title() [1/2]

static xtd::ustring 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::ustring 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_t 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_t  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_t 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_t  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_t 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_t  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_t 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.

◆ 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::ustring 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
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.

◆ 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::ustring 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
valuesValues to write,

Member Data Documentation

◆ 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.

◆ 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/xtd>
using namespace std;
using namespace xtd;
int main() {
istream& is = console::in;
ostream& os = console::out;
os << "Ola Mundo!" << endl;
os << "What is your name: ";
ustring name;
is >> name;
os << "Buenos Dias, " << name << endl;
}
// This code produces the following output:
//
// Ola Mundo!
// What is your name: James
// Buenos Dias, James!
static std::istream in
Gets the standard input stream. A std::basic_istream<char_t> that represents the standard input strea...
Definition: console.h:34
static std::ostream out
Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output str...
Definition: console.h:39
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:305

◆ 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/xtd>
using namespace std;
using namespace xtd;
int main() {
istream& is = console::in;
ostream& os = console::out;
os << "Ola Mundo!" << endl;
os << "What is your name: ";
ustring name;
is >> name;
os << "Buenos Dias, " << name << endl;
}
// This code produces the following output:
//
// Ola Mundo!
// What is your name: James
// Buenos Dias, James!

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