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.
console.h
Go to the documentation of this file.
1 #pragma once
6 #include "console_color.h"
7 #include "console_key_info.h"
8 #include "console_special_key.h"
9 #include "event.h"
10 #include "static.h"
11 #include "types.h"
12 #include "ustring.h"
13 
15 namespace xtd {
26  class console final static_ {
27  public:
29  static std::ostream error;
34  static std::istream in;
39  static std::ostream out;
40 
48 
62  static void background_color(console_color color);
63 
69  static void beep();
76  static void beep(uint32_t frequency, uint32_t duration);
77 
83  static int32_t buffer_height();
89  static void buffer_height(int32_t height);
90 
96  static int32_t buffer_width();
102  static void buffer_width(int32_t width);
103 
106  static bool caps_lock();
107 
118  static void clear();
119 
125  static int32_t cursor_left();
132  static void cursor_left(int32_t left);
133 
139  static int32_t cursor_size();
145  static void cursor_size(int32_t size);
146 
152  static int32_t cursor_top();
159  static void cursor_top(int32_t top);
160 
166  static bool cursor_visible();
172  static void cursor_visible(bool visible);
173 
185  static bool foreground_color(console_color color);
186 
189  static int32_t input_code_page();
193  static bool input_code_page(int32_t code_page);
194 
197  static bool is_error_redireted();
200  static bool is_in_redireted();
203  static bool is_out_redireted();
204 
209  static bool key_available();
210 
213  static int32_t largest_window_height();
216  static int32_t largest_window_width();
217 
220  static bool number_lock();
221 
225  static std::ostream open_standard_error();
229  static std::istream open_standard_input();
233  static std::ostream open_standard_output();
234 
237  static int32_t output_code_page();
241  static bool output_code_page(int32_t code_page);
242 
245  static xtd::ustring read_line();
249  static console_key_info read_key();
254  static console_key_info read_key(bool intercept);
255 
258  static bool reset_color();
259 
265  static void set_cursor_position(int32_t left, int32_t top);
266 
271  static void set_error(const std::ostream& os);
276  static void set_in(const std::istream& is);
281  static void set_out(const std::ostream& os);
282 
285  static xtd::ustring title();
288  static void title(const xtd::ustring& title);
289 
294  static bool treat_control_c_as_input();
300 
303  static int32_t window_height();
306  static void window_height(int32_t height);
307 
310  static int32_t window_left();
313  static void window_left(int32_t left);
314 
317  static int32_t window_top();
320  static void window_top(int32_t top);
321 
324  static int32_t window_width();
327  static void window_width(int32 width);
328 
332  template<typename arg_t>
333  static void write(arg_t&& value) {write_(xtd::ustring::format("{}", value));}
334 
336  template<typename type_t>
337  static void write(std::initializer_list<type_t>&& il) {write_(xtd::ustring::format("{}", il));}
339 
343  template<typename ... args_t>
344  static void write(const xtd::ustring& fmt, args_t&& ... values) {write_(xtd::ustring::format(fmt, std::forward<args_t>(values)...));}
345 
347  static void write_line();
348 
352  template<typename arg_t>
353  static void write_line(arg_t&& value) {write_line_(xtd::ustring::format("{}", value));}
354 
356  template<typename type_t>
357  static void write_line(const std::initializer_list<type_t>& il) {write_line_(xtd::ustring::format("{}", il));}
359 
363  template<typename ... args_t>
364  static void write_line(const xtd::ustring& fmt, args_t&& ... values) {write_line_(xtd::ustring::format(fmt, std::forward<args_t>(values)...));}
365 
367  static void __internal_cancel_key_press__(xtd::console_cancel_event_args& e);
369  private:
370  static void write_(const ustring& value);
371  static void write_line_(const ustring& value);
372  };
373 }
static bool is_in_redireted()
Gets a value that indicates whether the input stream has been redirected from the standard input stre...
Contains xtd::static_object class.
Represents the standard input, output, and error streams for console applications.
Definition: console.h:26
Contains xtd fundamental types.
static void set_cursor_position(int32_t left, int32_t top)
Sets the position of the cursor.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Contains xtd::console_color enum class.
static bool reset_color()
Sets the foreground and background console colors to their defaults.
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...
#define static_
This keyword is use to represent a static object. A static object can&#39;t be instancied (constructors a...
Definition: static.h:38
static int32_t input_code_page()
Gets the code page the console uses to read input.
static int32_t cursor_size()
Gets or sets the height of the cursor within a character cell.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static std::ostream open_standard_error()
Acquires the standard error stream.
static int32_t buffer_width()
Gets the width of the buffer area.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
static void write(const xtd::ustring &fmt, args_t &&... values)
Writes the text representation of the specified listt of values to the standard output stream using t...
Definition: console.h:344
static int32_t output_code_page()
Gets the code page the console uses to write output.
Contains xtd::console_key_info class.
int32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
static void write_line(arg_t &&value)
Writes the text representation of the specified value, followed by the current line terminator...
Definition: console.h:353
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 std::ostream error
Gets the error output stream. A std::basic_ostream<char_t> that represents the error output stream...
Definition: console.h:29
Contains xtd::console_special_key enum class.
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 int32_t largest_window_width()
Gets the largest possible number of console window columns, based on the current font and screen reso...
static int32_t window_top()
Gets the top of the console window area.
console_color
Specifies constants that define foreground and background colors for the console. ...
Definition: console_color.h:17
Represents an event.
Definition: event.h:21
static void write_line(const xtd::ustring &fmt, args_t &&... values)
Writes the text representation of the specified listt of values, followed by the current line termina...
Definition: console.h:364
Provides data for the console::cancel_key_press event. This class cannot be inherited.
Definition: console_cancel_event_args.h:18
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition: console.h:333
Specifies the standard keys on a console.
Definition: console_key_info.h:20
static xtd::ustring read_line()
Reads the next line of characters from the standard input stream.
static bool is_out_redireted()
Gets a value that indicates whether the output stream has been redirected from the standard output st...
Contains xtd::ustring class.
static console_key_info read_key()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static void set_in(const std::istream &is)
Sets the int property to the specified std::istream object.
static int32_t window_height()
Gets the height of the console window area.
static void beep()
Plays the sound of a beep through the console speaker.
static bool caps_lock()
Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off...
static int32_t largest_window_height()
Gets the largest possible number of console window rows, based on the current font and screen resolut...
static std::istream open_standard_input()
Acquires the standard input stream.
static console_color background_color()
Gets the background color of the console.
static std::ostream open_standard_output()
Acquires the standard output stream.
Contains xtd::event event.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
static bool key_available()
Gets a value indicating whether a key press is available in the input stream.
static xtd::ustring title()
Gets the title to display in the console title bar.
static int32_t window_width()
Gets the width of the console window area.
static bool cursor_visible()
Gets a value indicating whether the cursor is visible.
static console_color foreground_color()
Gets the foreground color of the console.
static void set_out(const std::ostream &os)
Sets the out property to the specified std::ostream object.
Contains xtd::console_cancel_event_handler event handler.
static int32_t cursor_top()
Gets the row position of the cursor within the buffer area.
static bool is_error_redireted()
Gets a value that indicates whether the error output stream has been redirected from the standard err...
size_t size
Represents a size of any object in bytes.
Definition: types.h:171
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.h:47
static bool number_lock()
Gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off...
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
static int32_t buffer_height()
Gets the height of the buffer area.
static void set_error(const std::ostream &os)
Sets the error property to the specified std::ostream object.
static int32_t window_left()
Gets the left of the console window area.