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#include <tuple>
17
19namespace xtd {
21 class environment;
23
38 class console final static_ {
39 public:
41
44 static std::ostream error;
49 static std::istream in;
54 static std::ostream out;
56
58
62 [[nodiscard]] static auto auto_flush_out() -> bool;
65 static auto auto_flush_out(bool value) -> void;
66
73 [[nodiscard]] static auto background_color() -> console_color;
76 [[nodiscard]] static auto background_color_rgb() {
77 struct rgb {
78 byte r;
79 byte g;
80 byte b;
81 };
82 auto [_, r, g, b] = argb_from_uint32(background_color_uint32());
83 return rgb {r, g, b};
84 }
85
87 [[nodiscard]] static auto background_color_uint32() -> xtd::uint32;
95 static auto background_color(console_color color) -> void;
101 static auto background_color(xtd::byte r, xtd::byte g, xtd::byte b) -> void;
106 static auto background_color(xtd::uint32 color) -> void;
107
113 [[nodiscard]] static auto buffer_height() -> int32;
120 static auto buffer_height(int32 height) -> void;
121
127 [[nodiscard]] static auto buffer_width() -> int32;
134 static auto buffer_width(int32 width) -> void;
135
138 [[nodiscard]] static auto caps_lock() -> bool;
139
145 [[nodiscard]] static auto cursor_left() -> int32;
152 static auto cursor_left(int32 left) -> void;
153
159 [[nodiscard]] static auto cursor_size() -> int32;
166 static auto cursor_size(int32 size) -> void;
167
173 [[nodiscard]] static auto cursor_top() -> int32;
181 static auto cursor_top(int32 top) -> void;
182
188 [[nodiscard]] static auto cursor_visible() -> bool;
194 static auto cursor_visible(bool visible) -> void;
195
201 [[nodiscard]] static auto foreground_color() -> console_color;
204 [[nodiscard]] static auto foreground_color_rgb() {
205 struct rgb {
206 byte r;
207 byte g;
208 byte b;
209 };
210 auto [_, r, g, b] = argb_from_uint32(foreground_color_uint32());
211 return rgb {r, g, b};
212 }
213
215 [[nodiscard]] static auto foreground_color_uint32() -> xtd::uint32;
222 static auto foreground_color(console_color color) -> bool;
228 static auto foreground_color(xtd::byte r, xtd::byte g, xtd::byte b) -> void;
233 static auto foreground_color(xtd::uint32 color) -> void;
234
250 [[nodiscard]] static auto input_code_page() -> int32;
266 static auto input_code_page(int32 code_page) -> void;
267
270 [[nodiscard]] static auto is_ansi_escape_sequence_supported() noexcept -> bool;
271
274 [[nodiscard]] static auto is_error_redirected() -> bool;
277 [[nodiscard]] static auto is_input_redirected() -> bool;
280 [[nodiscard]] static auto is_output_redirected() -> bool;
281
286 [[nodiscard]] static auto key_available() -> bool;
287
290 [[nodiscard]] static auto largest_window_height() -> int32;
293 [[nodiscard]] static auto largest_window_width() -> int32;
294
297 [[nodiscard]] static auto number_lock() -> bool;
298
314 [[nodiscard]] static auto output_code_page() -> int32;
330 static auto output_code_page(int32 code_page) -> void;
331
334 [[nodiscard]] static auto title() -> xtd::string;
337 static auto title(const xtd::string& title) -> void;
338
343 [[nodiscard]] static auto treat_control_c_as_input() -> bool;
349
352 [[nodiscard]] static auto window_height() -> int32;
355 static auto window_height(int32 height) -> void;
356
359 [[nodiscard]] static auto window_left() -> int32;
362 static auto window_left(int32 left) -> void;
363
366 [[nodiscard]] static auto window_top() ->int32;
369 static auto window_top(int32 top) -> void;
370
373 [[nodiscard]] static auto window_width() -> int32;
376 static auto window_width(int32 width) -> void;
378
380
393
395
402 static auto beep() -> void;
409 static auto beep(uint32 frequency, uint32 duration) -> void;
410
421 static auto clear() -> void;
422
426 [[nodiscard]] static auto get_cursor_position() -> xtd::collections::generic::key_value_pair<int32, int32>;
427
431 [[nodiscard]] static auto open_standard_error() -> std::ostream;
435 [[nodiscard]] static auto open_standard_input() -> std::istream;
439 [[nodiscard]] static auto open_standard_output() -> std::ostream;
440
452 [[nodiscard]] static auto read() -> int32;
453
460 static auto read_key(bool intercept) -> console_key_info;
464 static auto read_key(const string& text) -> console_key_info;
469 static auto read_key(const string& text, bool intercept) -> console_key_info;
470
473 static auto read_line() -> xtd::string;
477 static auto read_line(bool intercept) -> xtd::string;
481 static auto read_line(const string& text) -> xtd::string;
486 static auto read_line(const string& text, bool intercept) -> xtd::string;
487
488 template<typename string_t>
489 static auto read_line(string_t text) -> xtd::string {return read_line(xtd::string(text), false);}
490 template<typename string_t>
491 static auto read_line(string_t text, bool intercept) -> xtd::string {return read_line(xtd::string(text), intercept);}
492
495 static auto reset_color() -> bool;
496
499 static auto reset_terminal_mode() -> void;
500
507 static auto set_cursor_position(int32 left, int32 top) -> void;
508
513 static auto set_error(const std::ostream& os) -> void;
518 static auto set_in(const std::istream& is) -> void;
523 static auto set_out(const std::ostream& os) -> void;
524
529 static auto set_window_position(int32 left, int32 top) -> void;
530
539 static auto set_window_size(int32 width, int32 height) -> void;
540
544 template<typename arg_t>
545 static auto write(arg_t&& value) -> void {write_(xtd::string::format("{}", value));}
546
548 template<typename type_t>
549 static auto write(std::initializer_list<type_t>&& il) -> void {write_(xtd::string::format("{}", il));}
551
556 template<typename ...args_t>
557 static auto write(const xtd::string& fmt, args_t&& ... values) -> void {write_(xtd::string::format(fmt, std::forward<args_t>(values)...));}
558
563 template<typename arg_t>
564 static auto write(const xtd::globalization::culture_info& culture, arg_t&& value) -> void {write_(xtd::string::format(culture, "{}", value));}
565
567 template<typename type_t>
568 static auto write(const xtd::globalization::culture_info& culture, std::initializer_list<type_t>&& il) -> void {write_(xtd::string::format(culture, "{}", il));}
570
576 template<typename ...args_t>
577 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)...));}
578
580 static auto write_line() -> void;
581
585 template<typename arg_t>
586 static auto write_line(arg_t&& value) -> void {write_line_(xtd::string::format("{}", value));}
587
589 template<typename type_t>
590 static auto write_line(const std::initializer_list<type_t>& il) -> void {write_line_(xtd::string::format("{}", il));}
592
597 template<typename ...args_t>
598 static auto write_line(const xtd::string& fmt, args_t&& ... values) -> void {write_line_(xtd::string::format(fmt, std::forward<args_t>(values)...));}
599
604 template<typename arg_t>
605 static auto write_line(const xtd::globalization::culture_info& culture, arg_t&& value) -> void {write_line_(xtd::string::format(culture, "{}", value));}
606
608 template<typename type_t>
609 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));}
611
617 template<typename ...args_t>
618 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)...));}
620
622 static auto __internal_rstc__() -> void;
624
625 private:
626 friend class xtd::environment;
627 [[nodiscard]] static auto argb_from_uint32(xtd::uint32 value) noexcept -> std::tuple<xtd::byte, xtd::byte, xtd::byte, xtd::byte> {return std::make_tuple(static_cast<xtd::byte>(255), static_cast<xtd::byte>((value & 0x00FF0000) >> 16), static_cast<xtd::byte>((value & 0x0000FF00) >> 8), static_cast<xtd::byte>(value & 0x000000FF));}
628 [[nodiscard]] static auto on_cancel_key_press(int32 special_key) -> bool;
629 static auto register_cancel_key_press() -> void;
630
631 static auto write_(const string& value) -> void;
632 static auto write_line_(const string& value) -> void;
633 };
634}
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:38
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:391
static std::ostream error
Gets the error output stream. A std::basic_ostream<char_t> that represents the error output stream.
Definition console.hpp:44
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 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:564
static auto title() -> xtd::string
Gets the title to display in the console title bar.
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 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 foreground_color_rgb()
Gets the foreground color of the console.
Definition console.hpp:204
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 is_ansi_escape_sequence_supported() noexcept -> bool
Gets a value indicating whether a ANSI escape sequence is supported.
static auto background_color(xtd::uint32 color) -> void
Sets the background color of the console.
static auto open_standard_output() -> std::ostream
Acquires the standard output stream.
static auto foreground_color_uint32() -> xtd::uint32
Gets the foreground color of the console.
static auto background_color_uint32() -> xtd::uint32
Gets the background color of the console.
static std::istream in
Gets the standard input stream. A std::basic_istream<char_t> that represents the standard input strea...
Definition console.hpp:49
static auto foreground_color(xtd::uint32 color) -> void
Sets the foreground color of the console.
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:54
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:605
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:586
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:577
static auto cursor_visible() -> bool
Gets a value indicating whether the cursor is visible.
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:598
static auto set_in(const std::istream &is) -> void
Sets the int property to the specified std::istream object.
static auto background_color_rgb()
Gets the background color of the console.
Definition console.hpp:76
static auto background_color(xtd::byte r, xtd::byte g, xtd::byte b) -> void
Sets the background color of the console.
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:545
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 foreground_color(xtd::byte r, xtd::byte g, xtd::byte b) -> void
Sets the foreground color of the console.
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 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 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:557
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:618
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:71
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.
auto() -> void
Signals a breakpoint to an attached debugger.
Definition debugger.hpp:75
Contains xtd::event event.
xtd::delegate< void(console_cancel_event_args &e)> console_cancel_event_handler
Represents the method that will handle the cancel_key_press event of a xtd::console.
Definition console_cancel_event_handler.hpp:24
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
std::uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
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
@ r
The R key.
Definition console_key.hpp:122
@ b
The B key.
Definition console_key.hpp:90
@ g
The G key.
Definition console_key.hpp:100
Contains xtd::collections::generic::key_value_pair <key_t, value_t> struct.
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:14
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:213
Contains xtd::static_object class.
Contains xtd::io::stream_writer class.
Contains xtd::string alias.
Contains xtd fundamental types.