xtd 0.2.0
Loading...
Searching...
No Matches
console.hpp
Go to the documentation of this file.
1
4#pragma once
8#include "console_color.hpp"
11#include "event.hpp"
12#include "static.hpp"
13#include "types.hpp"
14#include "string.hpp"
15
17namespace xtd {
19 class environment;
21
36 class console final static_ {
37 public:
39
42 static std::ostream error;
47 static std::istream in;
52 static std::ostream out;
54
56
60 [[nodiscard]] static auto auto_flush_out() -> bool;
63 static auto auto_flush_out(bool value) -> void;
64
71 [[nodiscard]] static auto background_color() -> console_color;
79 static auto background_color(console_color color) -> void;
80
86 [[nodiscard]] static auto buffer_height() -> int32;
93 static auto buffer_height(int32 height) -> void;
94
100 [[nodiscard]] static auto buffer_width() -> int32;
107 static auto buffer_width(int32 width) -> void;
108
111 [[nodiscard]] static auto caps_lock() -> bool;
112
118 [[nodiscard]] static auto cursor_left() -> int32;
125 static auto cursor_left(int32 left) -> void;
126
132 [[nodiscard]] static auto cursor_size() -> int32;
139 static auto cursor_size(int32 size) -> void;
140
146 [[nodiscard]] static auto cursor_top() -> int32;
154 static auto cursor_top(int32 top) -> void;
155
161 [[nodiscard]] static auto cursor_visible() -> bool;
167 static auto cursor_visible(bool visible) -> void;
168
174 [[nodiscard]] static auto foreground_color() -> console_color;
181 static auto foreground_color(console_color color) -> bool;
182
198 [[nodiscard]] static auto input_code_page() -> int32;
214 static auto input_code_page(int32 code_page) -> void;
215
218 [[nodiscard]] static auto is_error_redirected() -> bool;
221 [[nodiscard]] static auto is_input_redirected() -> bool;
224 [[nodiscard]] static auto is_output_redirected() -> bool;
225
230 [[nodiscard]] static auto key_available() -> bool;
231
234 [[nodiscard]] static auto largest_window_height() -> int32;
237 [[nodiscard]] static auto largest_window_width() -> int32;
238
241 [[nodiscard]] static auto number_lock() -> bool;
242
258 [[nodiscard]] static auto output_code_page() -> int32;
274 static auto output_code_page(int32 code_page) -> void;
275
278 [[nodiscard]] static auto title() -> xtd::string;
281 static auto title(const xtd::string& title) -> void;
282
287 [[nodiscard]] static auto treat_control_c_as_input() -> bool;
293
296 [[nodiscard]] static auto window_height() -> int32;
299 static auto window_height(int32 height) -> void;
300
303 [[nodiscard]] static auto window_left() -> int32;
306 static auto window_left(int32 left) -> void;
307
310 [[nodiscard]] static auto window_top() ->int32;
313 static auto window_top(int32 top) -> void;
314
317 [[nodiscard]] static auto window_width() -> int32;
320 static auto window_width(int32 width) -> void;
322
324
337
339
346 static auto beep() -> void;
353 static auto beep(uint32 frequency, uint32 duration) -> void;
354
365 static auto clear() -> void;
366
371
375 [[nodiscard]] static auto open_standard_error() -> std::ostream;
379 [[nodiscard]] static auto open_standard_input() -> std::istream;
383 [[nodiscard]] static auto open_standard_output() -> std::ostream;
384
396 [[nodiscard]] static auto read() -> int32;
397
400 static auto read_key() -> console_key_info;
404 static auto read_key(bool intercept) -> console_key_info;
408 static auto read_key(const string& text) -> console_key_info;
413 static auto read_key(const string& text, bool intercept) -> console_key_info;
414
417 static auto read_line() -> xtd::string;
421 static auto read_line(bool intercept) -> xtd::string;
425 static auto read_line(const string& text) -> xtd::string;
430 static auto read_line(const string& text, bool intercept) -> xtd::string;
431
434 static auto reset_color() -> bool;
435
442 static auto set_cursor_position(int32 left, int32 top) -> void;
443
448 static auto set_error(const std::ostream& os) -> void;
453 static auto set_in(const std::istream& is) -> void;
458 static auto set_out(const std::ostream& os) -> void;
459
464 static auto set_window_position(int32 left, int32 top) -> void;
465
474 static auto set_window_size(int32 width, int32 height) -> void;
475
479 template<typename arg_t>
480 static auto write(arg_t&& value) -> void {write_(xtd::string::format("{}", value));}
481
483 template<typename type_t>
484 static auto write(std::initializer_list<type_t>&& il) -> void {write_(xtd::string::format("{}", il));}
486
491 template<typename ...args_t>
492 static auto write(const xtd::string& fmt, args_t&& ... values) -> void {write_(xtd::string::format(fmt, std::forward<args_t>(values)...));}
493
495 static auto write_line() -> void;
496
500 template<typename arg_t>
501 static auto write_line(arg_t&& value) -> void {write_line_(xtd::string::format("{}", value));}
502
504 template<typename type_t>
505 static auto write_line(const std::initializer_list<type_t>& il) -> void {write_line_(xtd::string::format("{}", il));}
507
512 template<typename ...args_t>
513 static auto write_line(const xtd::string& fmt, args_t&& ... values) -> void {write_line_(xtd::string::format(fmt, std::forward<args_t>(values)...));}
515
517 static auto __internal_rstc__() -> void;
519
520 private:
521 friend class xtd::environment;
522 [[nodiscard]] static auto on_cancel_key_press(int32 special_key) -> bool;
523 static auto register_cancel_key_press() -> void;
524
525 static auto write_(const string& value) -> void;
526 static auto write_line_(const string& value) -> void;
527 };
528}
Specifies the standard keys on a console.
Definition console_key_info.hpp:24
Represents the standard input, output, and error streams for console applications.
Definition console.hpp:36
static auto set_out(const std::ostream &os) -> void
Sets the out property to the specified std::ostream object.
static event< console, console_cancel_event_handler > cancel_key_press
Occurs when the Control modifier key (Ctrl) and either the ConsoleKey.C console key (C) or the Break ...
Definition console.hpp:335
static auto treat_control_c_as_input(bool treat_control_c_as_input) -> void
Sets a value indicating whether the combination of the Control modifier key and C console key (Ctrl+C...
static std::ostream error
Gets the error output stream. A std::basic_ostream<char_t> that represents the error output stream.
Definition console.hpp:42
static auto beep(uint32 frequency, uint32 duration) -> void
Plays the sound of a beep of a specified frequency and duration through the console speaker.
static auto cursor_left(int32 left) -> void
Sets the column position of the cursor within the buffer area.
static auto is_input_redirected() -> bool
Gets a value that indicates whether the input stream has been redirected from the standard input stre...
static auto background_color(console_color color) -> void
Sets the background color of the console.
static auto window_width(int32 width) -> void
Sets the width of the console window area.
static auto cursor_top(int32 top) -> void
Sets the row position of the cursor within the buffer area.
static auto set_window_position(int32 left, int32 top) -> void
Sets the position of the console window relative to the screen buffer.
static auto output_code_page(int32 code_page) -> void
Sets the code page the console uses to write output.
static auto title() -> xtd::string
Gets the title to display in the console title bar.
static auto read_key(const string &text, bool intercept) -> console_key_info
Obtains the next character or function key pressed by the user. The pressed key is optionally display...
static auto input_code_page() -> int32
Gets the code page the console uses to read input.
static auto foreground_color() -> console_color
Gets the foreground color of the console.
static auto foreground_color(console_color color) -> bool
Sets the foreground color of the console.
static auto caps_lock() -> bool
Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off.
static auto get_cursor_position() -> xtd::collections::generic::key_value_pair< int32, int32 >
Gets the position of the cursor.
static auto buffer_height() -> int32
Gets the height of the buffer area.
static auto cursor_size() -> int32
Gets or sets the height of the cursor within a character cell.
static auto read_line(const string &text, bool intercept) -> xtd::string
Reads the next line of characters from the standard input stream with specified invit text.
static auto read_line(const string &text) -> xtd::string
Reads the next line of characters from the standard input stream with specified invit text.
static auto largest_window_height() -> int32
Gets the largest possible number of console window rows, based on the current font and screen resolut...
static auto window_left() -> int32
Gets the left of the console window area.
static auto buffer_width(int32 width) -> void
Sets the width of the buffer area.
static auto input_code_page(int32 code_page) -> void
Sets the code page the console uses to read input.
static auto window_top(int32 top) -> void
Sets the top of the console window area.
static auto open_standard_output() -> std::ostream
Acquires the standard output stream.
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 auto read_line(bool intercept) -> xtd::string
Reads the next line of characters from the standard input stream.
static auto read_line() -> xtd::string
Reads the next line of characters from the standard input stream.
static auto window_top() -> int32
Gets the top of the console window area.
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 auto read_key(bool intercept) -> console_key_info
Obtains the next character or function key pressed by the user. The pressed key is optionally display...
static auto open_standard_input() -> std::istream
Acquires the standard input stream.
static auto largest_window_width() -> int32
Gets the largest possible number of console window columns, based on the current font and screen reso...
static auto write_line(arg_t &&value) -> void
Writes the text representation of the specified value, followed by the current line terminator,...
Definition console.hpp:501
static auto cursor_visible() -> bool
Gets a value indicating whether the cursor is visible.
static auto window_left(int32 left) -> void
Sets the left of the console window area.
static auto write_line(const xtd::string &fmt, args_t &&... values) -> void
Writes the text representation of the specified list of values, followed by the current line terminat...
Definition console.hpp:513
static auto set_in(const std::istream &is) -> void
Sets the int property to the specified std::istream object.
static auto is_error_redirected() -> bool
Gets a value that indicates whether the error output stream has been redirected from the standard err...
static auto window_height() -> int32
Gets the height of the console window area.
static auto open_standard_error() -> std::ostream
Acquires the standard error stream.
static auto set_cursor_position(int32 left, int32 top) -> void
Sets the position of the cursor.
static auto is_output_redirected() -> bool
Gets a value that indicates whether the output stream has been redirected from the standard output st...
static auto key_available() -> bool
Gets a value indicating whether a key press is available in the input stream.
static auto write(arg_t &&value) -> void
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:480
static auto auto_flush_out(bool value) -> void
Sets a value indicating whether the xtd::console::out will flush its buffer to the underlying stream ...
static auto output_code_page() -> int32
Gets the code page the console uses to write output.
static auto buffer_height(int32 height) -> void
Sets or sets the height of the buffer area.
static auto read() -> int32
Reads the next character from the standard input stream.
static auto background_color() -> console_color
Gets the background color of the console.
static auto cursor_top() -> int32
Gets the row position of the cursor within the buffer area.
static auto reset_color() -> bool
Sets the foreground and background console colors to their defaults.
static auto auto_flush_out() -> bool
Gets a value indicating whether the xtd::console::out will flush its buffer to the underlying stream ...
static auto cursor_left() -> int32
Gets the column position of the cursor within the buffer area.
static auto clear() -> void
Clears the console buffer and corresponding console window of display information.
static auto title(const xtd::string &title) -> void
Sets the title to display in the console title bar.
static auto set_window_size(int32 width, int32 height) -> void
Sets the height and width of the console window to the specified values.
static auto read_key() -> console_key_info
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static auto read_key(const string &text) -> console_key_info
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static auto write(const xtd::string &fmt, args_t &&... values) -> void
Writes the text representation of the specified list of values to the standard output stream using th...
Definition console.hpp:492
static auto window_height(int32 height) -> void
Sets the height of the console window area.
static auto write_line() -> void
Writes the current line terminator to the standard output stream using the specified format informati...
static auto treat_control_c_as_input() -> bool
Gets a value indicating whether the combination of the Control modifier key and C console key (Ctrl+C...
static auto cursor_size(int32 size) -> void
Sets the height of the cursor within a character cell.
static auto window_width() -> int32
Gets the width of the console window area.
static auto cursor_visible(bool visible) -> void
Sets a value indicating whether the cursor is visible.
static auto beep() -> void
Plays the sound of a beep through the console speaker.
static auto number_lock() -> bool
Gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off.
static auto buffer_width() -> int32
Gets the width of the buffer area.
static auto set_error(const std::ostream &os) -> void
Sets the error property to the specified std::ostream object.
The environment class.
Definition environment.hpp:68
Represents an event.
Definition event.hpp:21
Contains xtd::console_cancel_event_handler event handler.
Contains xtd::console_color enum class.
Contains xtd::console_key_info class.
Contains xtd::console_special_key enum class.
Contains xtd::event event.
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:38
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:484
console_color
Specifies constants that define foreground and background colors for the console.
Definition console_color.hpp:20
Contains xtd::collections::generic::key_value_pair <key_t, value_t> struct.
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::static_object class.
Contains xtd::io::stream_writer class.
Contains xtd::string alias.
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37
Contains xtd fundamental types.