xtd 0.2.0
console.h
Go to the documentation of this file.
1 #pragma once
5 #include "io/stream_writer.h"
7 #include "console_color.h"
8 #include "console_key_info.h"
9 #include "console_special_key.h"
10 #include "event.h"
11 #include "static.h"
12 #include "types.h"
13 #include "ustring.h"
14 
16 namespace xtd {
18  class environment;
20 
33  class console final static_ {
34  public:
36 
39  static std::ostream error;
44  static std::istream in;
49  static std::ostream out;
51 
53 
57  static bool auto_flush_out();
60  static void auto_flush_out(bool value);
61 
76  static void background_color(console_color color);
77 
83  static int32 buffer_height();
90  static void buffer_height(int32 height);
91 
97  static int32 buffer_width();
104  static void buffer_width(int32 width);
105 
108  static bool caps_lock();
109 
115  static int32 cursor_left();
122  static void cursor_left(int32 left);
123 
129  static int32 cursor_size();
136  static void cursor_size(int32 size);
137 
143  static int32 cursor_top();
151  static void cursor_top(int32 top);
152 
158  static bool cursor_visible();
164  static void cursor_visible(bool visible);
165 
178  static bool foreground_color(console_color color);
179 
182  static int32 input_code_page();
186  static bool input_code_page(int32 code_page);
187 
190  static bool is_error_redirected();
193  static bool is_input_redirected();
196  static bool is_output_redirected();
197 
202  static bool key_available();
203 
206  static int32 largest_window_height();
209  static int32 largest_window_width();
210 
213  static bool number_lock();
214 
217  static int32 output_code_page();
221  static bool output_code_page(int32 code_page);
222 
225  static xtd::ustring title();
228  static void title(const xtd::ustring& title);
229 
234  static bool treat_control_c_as_input();
240 
243  static int32 window_height();
246  static void window_height(int32 height);
247 
250  static int32 window_left();
253  static void window_left(int32 left);
254 
257  static int32 window_top();
260  static void window_top(int32 top);
261 
264  static int32 window_width();
267  static void window_width(int32 width);
269 
271 
284 
286 
293  static void beep();
300  static void beep(uint32 frequency, uint32 duration);
301 
312  static void clear();
313 
317  static std::pair<int32, int32> get_cursor_position();
318 
322  static std::ostream open_standard_error();
326  static std::istream open_standard_input();
330  static std::ostream open_standard_output();
331 
343  static int32 read();
344 
347  static console_key_info read_key();
351  static console_key_info read_key(bool intercept);
352 
355  static xtd::ustring read_line();
359  static xtd::ustring read_line(bool intercept);
360 
363  static bool reset_color();
364 
371  static void set_cursor_position(int32 left, int32 top);
372 
377  static void set_error(const std::ostream& os);
382  static void set_in(const std::istream& is);
387  static void set_out(const std::ostream& os);
388 
393  static void set_window_position(int32 left, int32 top);
394 
403  static void set_window_size(int32 width, int32 height);
404 
408  template<typename arg_t>
409  static void write(arg_t&& value) {write_(xtd::ustring::format("{}", value));}
410 
412  template<typename type_t>
413  static void write(std::initializer_list<type_t>&& il) {write_(xtd::ustring::format("{}", il));}
415 
419  template<typename ... args_t>
420  static void write(const xtd::ustring& fmt, args_t&& ... values) {write_(xtd::ustring::format(fmt, std::forward<args_t>(values)...));}
421 
423  static void write_line();
424 
428  template<typename arg_t>
429  static void write_line(arg_t&& value) {write_line_(xtd::ustring::format("{}", value));}
430 
432  template<typename type_t>
433  static void write_line(const std::initializer_list<type_t>& il) {write_line_(xtd::ustring::format("{}", il));}
435 
439  template<typename ... args_t>
440  static void write_line(const xtd::ustring& fmt, args_t&& ... values) {write_line_(xtd::ustring::format(fmt, std::forward<args_t>(values)...));}
442 
443  private:
444  friend class xtd::environment;
445  static bool on_cancel_key_press(int32 special_key);
446  static void register_cancel_key_press();
447 
448  static void write_(const ustring& value);
449  static void write_line_(const ustring& value);
450  };
451 }
static bool is_input_redirected()
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:33
static void set_cursor_position(int32 left, int32 top)
Sets the position of the cursor.
Contains xtd fundamental types.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static int32 buffer_height()
Gets the height of the buffer area.
static bool auto_flush_out()
Gets a value indicating whether the xtd::console::out will flush its buffer to the underlying stream ...
Contains xtd::io::stream_writer class.
static int32 window_width()
Gets the width of the console window area.
Contains xtd::console_color enum class.
static bool reset_color()
Sets the foreground and background console colors to their defaults.
static int32 window_left()
Gets the left of the console window area.
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 instantiated (constructors...
Definition: static.h:37
static int32 input_code_page()
Gets the code page the console uses to read input.
static int32 largest_window_height()
Gets the largest possible number of console window rows, based on the current font and screen resolut...
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 output_code_page()
Gets the code page the console uses to write output.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
static int32 window_top()
Gets the top of the console window area.
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 th...
Definition: console.h:420
Contains xtd::console_key_info class.
static void set_window_position(int32 left, int32 top)
Sets the position of the console window relative to the screen buffer.
static void write_line(arg_t &&value)
Writes the text representation of the specified value, followed by the current line terminator...
Definition: console.h:429
static void clear()
Clears the console buffer and corresponding console window of display information.
static std::ostream error
Gets the error output stream. A std::basic_ostream<char_t> that represents the error output stream...
Definition: console.h:39
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:44
static int32 cursor_left()
Gets the column position of the cursor within the buffer area.
console_color
Specifies constants that define foreground and background colors for the console. ...
Definition: console_color.h:19
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 list of values, followed by the current line terminat...
Definition: console.h:440
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition: console.h:409
static int32 cursor_top()
Gets the row position of the cursor within the buffer area.
Specifies the standard keys on a console.
Definition: console_key_info.h:22
static xtd::ustring read_line()
Reads the next line of characters from the standard input stream.
Contains xtd::ustring class.
static int32 cursor_size()
Gets or sets the height of the cursor within a character cell.
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 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 buffer_width()
Gets the width of the buffer area.
static std::istream open_standard_input()
Acquires the standard input stream.
static console_color background_color()
Gets the background color of the console.
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
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:744
static int32 read()
Reads the next character from the standard input stream.
static int32 window_height()
Gets the height of the console window area.
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 bool is_error_redirected()
Gets a value that indicates whether the error output stream has been redirected from the standard err...
static bool cursor_visible()
Gets a value indicating whether the cursor is visible.
static bool is_output_redirected()
Gets a value that indicates whether the output stream has been redirected from the standard output st...
The environment class.
Definition: environment.h:71
static void set_window_size(int32 width, int32 height)
Sets the height and width of the console window to the specified values.
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
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 std::pair< int32, int32 > get_cursor_position()
Gets the position of the cursor.
size_t size
Represents a size of any object in bytes.
Definition: types.h:195
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:282
static bool number_lock()
Gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off...
static int32 largest_window_width()
Gets the largest possible number of console window columns, based on the current font and screen reso...
static std::ostream out
Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output str...
Definition: console.h:49
static void set_error(const std::ostream &os)
Sets the error property to the specified std::ostream object.
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:335