xtd 1.0.0
Loading...
Searching...
No Matches
console.hpp
Go to the documentation of this file.
1
4#pragma once
9#include "console_color.hpp"
10#include "console_key_info.hpp"
12#include "event.hpp"
13#include "static.hpp"
14#include "types.hpp"
15#include "string.hpp"
16
18namespace xtd {
20 class environment;
22
37 class console final static_ {
38 public:
40
43 static std::ostream error;
48 static std::istream in;
53 static std::ostream out;
55
57
61 [[nodiscard]] static auto auto_flush_out() -> bool;
64 static auto auto_flush_out(bool value) -> void;
65
72 [[nodiscard]] static auto background_color() -> console_color;
80 static auto background_color(console_color color) -> void;
81
87 [[nodiscard]] static auto buffer_height() -> int32;
94 static auto buffer_height(int32 height) -> void;
95
101 [[nodiscard]] static auto buffer_width() -> int32;
108 static auto buffer_width(int32 width) -> void;
109
112 [[nodiscard]] static auto caps_lock() -> bool;
113
119 [[nodiscard]] static auto cursor_left() -> int32;
126 static auto cursor_left(int32 left) -> void;
127
133 [[nodiscard]] static auto cursor_size() -> int32;
140 static auto cursor_size(int32 size) -> void;
141
147 [[nodiscard]] static auto cursor_top() -> int32;
155 static auto cursor_top(int32 top) -> void;
156
162 [[nodiscard]] static auto cursor_visible() -> bool;
168 static auto cursor_visible(bool visible) -> void;
169
175 [[nodiscard]] static auto foreground_color() -> console_color;
182 static auto foreground_color(console_color color) -> bool;
183
199 [[nodiscard]] static auto input_code_page() -> int32;
215 static auto input_code_page(int32 code_page) -> void;
216
219 [[nodiscard]] static auto is_error_redirected() -> bool;
222 [[nodiscard]] static auto is_input_redirected() -> bool;
225 [[nodiscard]] static auto is_output_redirected() -> bool;
226
231 [[nodiscard]] static auto key_available() -> bool;
232
235 [[nodiscard]] static auto largest_window_height() -> int32;
238 [[nodiscard]] static auto largest_window_width() -> int32;
239
242 [[nodiscard]] static auto number_lock() -> bool;
243
259 [[nodiscard]] static auto output_code_page() -> int32;
275 static auto output_code_page(int32 code_page) -> void;
276
279 [[nodiscard]] static auto title() -> xtd::string;
282 static auto title(const xtd::string& title) -> void;
283
288 [[nodiscard]] static auto treat_control_c_as_input() -> bool;
294
297 [[nodiscard]] static auto window_height() -> int32;
300 static auto window_height(int32 height) -> void;
301
304 [[nodiscard]] static auto window_left() -> int32;
307 static auto window_left(int32 left) -> void;
308
311 [[nodiscard]] static auto window_top() ->int32;
314 static auto window_top(int32 top) -> void;
315
318 [[nodiscard]] static auto window_width() -> int32;
321 static auto window_width(int32 width) -> void;
323
325
338
340
347 static auto beep() -> void;
354 static auto beep(uint32 frequency, uint32 duration) -> void;
355
366 static auto clear() -> void;
367
372
376 [[nodiscard]] static auto open_standard_error() -> std::ostream;
380 [[nodiscard]] static auto open_standard_input() -> std::istream;
384 [[nodiscard]] static auto open_standard_output() -> std::ostream;
385
397 [[nodiscard]] static auto read() -> int32;
398
401 static auto read_key() -> console_key_info;
405 static auto read_key(bool intercept) -> console_key_info;
409 static auto read_key(const string& text) -> console_key_info;
414 static auto read_key(const string& text, bool intercept) -> console_key_info;
415
418 static auto read_line() -> xtd::string;
422 static auto read_line(bool intercept) -> xtd::string;
426 static auto read_line(const string& text) -> xtd::string;
431 static auto read_line(const string& text, bool intercept) -> xtd::string;
432
433 template<typename string_t>
434 static auto read_line(string_t text) -> xtd::string {return read_line(xtd::string(text), false);}
435 template<typename string_t>
436 static auto read_line(string_t text, bool intercept) -> xtd::string {return read_line(xtd::string(text), intercept);}
437
440 static auto reset_color() -> bool;
441
444 static auto reset_terminal_mode() -> void;
445
452 static auto set_cursor_position(int32 left, int32 top) -> void;
453
458 static auto set_error(const std::ostream& os) -> void;
463 static auto set_in(const std::istream& is) -> void;
468 static auto set_out(const std::ostream& os) -> void;
469
474 static auto set_window_position(int32 left, int32 top) -> void;
475
484 static auto set_window_size(int32 width, int32 height) -> void;
485
489 template<typename arg_t>
490 static auto write(arg_t&& value) -> void {write_(xtd::string::format("{}", value));}
491
493 template<typename type_t>
494 static auto write(std::initializer_list<type_t>&& il) -> void {write_(xtd::string::format("{}", il));}
496
501 template<typename ...args_t>
502 static auto write(const xtd::string& fmt, args_t&& ... values) -> void {write_(xtd::string::format(fmt, std::forward<args_t>(values)...));}
503
508 template<typename arg_t>
509 static auto write(const xtd::globalization::culture_info& culture, arg_t&& value) -> void {write_(xtd::string::format(culture, "{}", value));}
510
512 template<typename type_t>
513 static auto write(const xtd::globalization::culture_info& culture, std::initializer_list<type_t>&& il) -> void {write_(xtd::string::format(culture, "{}", il));}
515
521 template<typename ...args_t>
522 static auto write(const xtd::globalization::culture_info& culture, const xtd::string& fmt, args_t&& ... values) -> void {write_(xtd::string::format(culture, fmt, std::forward<args_t>(values)...));}
523
525 static auto write_line() -> void;
526
530 template<typename arg_t>
531 static auto write_line(arg_t&& value) -> void {write_line_(xtd::string::format("{}", value));}
532
534 template<typename type_t>
535 static auto write_line(const std::initializer_list<type_t>& il) -> void {write_line_(xtd::string::format("{}", il));}
537
542 template<typename ...args_t>
543 static auto write_line(const xtd::string& fmt, args_t&& ... values) -> void {write_line_(xtd::string::format(fmt, std::forward<args_t>(values)...));}
544
549 template<typename arg_t>
550 static auto write_line(const xtd::globalization::culture_info& culture, arg_t&& value) -> void {write_line_(xtd::string::format(culture, "{}", value));}
551
553 template<typename type_t>
554 static auto write_line(const xtd::globalization::culture_info& culture, const std::initializer_list<type_t>& il) -> void {write_line_(xtd::string::format(culture, "{}", il));}
556
562 template<typename ...args_t>
563 static auto write_line(const xtd::globalization::culture_info& culture, const xtd::string& fmt, args_t&& ... values) -> void {write_line_(xtd::string::format(culture, fmt, std::forward<args_t>(values)...));}
565
567 static auto __internal_rstc__() -> void;
569
570 private:
571 friend class xtd::environment;
572 [[nodiscard]] static auto on_cancel_key_press(int32 special_key) -> bool;
573 static auto register_cancel_key_press() -> void;
574
575 static auto write_(const string& value) -> void;
576 static auto write_line_(const string& value) -> void;
577 };
578}
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:37
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:336
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:43
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 write(const xtd::globalization::culture_info &culture, arg_t &&value) -> void
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:509
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:48
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:53
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 write_line(const xtd::globalization::culture_info &culture, arg_t &&value) -> void
Writes the text representation of the specified value, followed by the current line terminator,...
Definition console.hpp:550
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:531
static auto write(const xtd::globalization::culture_info &culture, 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:522
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:543
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:490
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:502
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 reset_terminal_mode() -> void
Resets terminale mode to default.
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 write_line(const xtd::globalization::culture_info &culture, 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:563
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:69
Represents an event.
Definition event.hpp:23
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition culture_info.hpp:42
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::globalization::culture_info 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
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
auto is(xtd::any value) -> bool
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:485
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:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:230
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.