xtd.console - Reference Guide  0.0.1
Modern c++17 library to manage terminal on Windows, macOS and Linux.
basic_console.hpp
Go to the documentation of this file.
1 #pragma once
4 #include "__get_err_rdbuf.hpp"
5 #include "__get_in_rdbuf.hpp"
6 #include "__get_out_rdbuf.hpp"
7 #include "__opaque_console.hpp"
8 #include <xtd/strings>
9 
11 namespace xtd {
18  template<class Char>
19  class basic_console final {
20  public:
22  static std::basic_ostream<Char> error;
23 
28  static std::basic_istream<Char> in;
29 
34  static std::basic_ostream<Char> out;
35 
37  basic_console() = delete;
39 
46  static console_color background_color() noexcept {return __opaque_console::background_color();}
47 
55  static bool background_color(console_color color) noexcept {return __opaque_console::background_color(color);}
56 
62  static void beep() noexcept {beep(800, 200);}
63 
71  static bool beep(unsigned int frequency, unsigned int duration) noexcept {return __opaque_console::beep(frequency, duration);}
72 
78  static int buffer_height() noexcept {return __opaque_console::buffer_height();}
79 
86  static bool buffer_height(int height) noexcept {return __opaque_console::buffer_height(height);}
87 
93  static int buffer_width() noexcept {return __opaque_console::buffer_width();}
94 
100  static bool buffer_width(int width) noexcept {return __opaque_console::buffer_width(width);}
101 
104  static bool caps_lock() noexcept {return __opaque_console::caps_lock();}
105 
116  static bool clear() noexcept {return __opaque_console::clear();}
117 
123  static int cursor_left() noexcept {return __opaque_console::cursor_left();}
124 
131  static bool cursor_left(int left) noexcept {return set_cursor_position(left, cursor_top());}
132 
138  static int cursor_size() noexcept {return __opaque_console::cursor_size();}
139 
146  static void cursor_size(int size) noexcept {__opaque_console::cursor_size(size);}
147 
153  static int cursor_top() noexcept {return __opaque_console::cursor_top();}
154 
161  static bool cursor_top(int top) noexcept {return set_cursor_position(cursor_left(), top);}
162 
168  static bool cursor_visible() noexcept {return __opaque_console::cursor_visible();}
169 
175  static void cursor_visible(bool visible) noexcept {__opaque_console::cursor_visible(visible);}
176 
182  static console_color foreground_color() noexcept {return __opaque_console::foreground_color();}
183 
189  static bool foreground_color(console_color color) noexcept {return __opaque_console::foreground_color(color);}
190 
193  static int input_code_page() noexcept {return __opaque_console::input_code_page();}
194 
198  static bool input_code_page(int code_page) noexcept {return __opaque_console::input_code_page(code_page);}
199 
202  static bool is_error_redireted() noexcept {return error.rdbuf() != __get_err_rdbuf<Char>();}
203 
206  static bool is_in_redireted() noexcept {return in.rdbuf() != __get_in_rdbuf<Char>();}
207 
210  static bool is_out_redireted() noexcept {return out.rdbuf() != __get_out_rdbuf<Char>();}
211 
215  static std::basic_ostream<Char> open_standard_error() noexcept {return std::basic_ostream<Char>(__get_err_rdbuf<Char>());}
216 
220  static std::basic_istream<Char> open_standard_input() noexcept {return std::basic_istream<Char>(__get_in_rdbuf<Char>());}
221 
225  static std::basic_ostream<Char> open_standard_output() noexcept {return std::basic_ostream<Char>(__get_out_rdbuf<Char>());}
226 
229  static int output_code_page() noexcept {return __opaque_console::output_code_page();}
230 
234  static bool output_code_page(int code_page) noexcept {return __opaque_console::output_code_page(code_page);}
235 
236  static std::basic_string<Char> read_line() noexcept {
237  std::basic_string<Char> result;
238  in >> result;
239  return result;
240  }
241 
242  static bool reset_color() noexcept {return __opaque_console::reset_color();}
243 
244  static bool set_cursor_position(int left, int top) noexcept {return __opaque_console::set_cursor_position(left, top);}
245 
246  static void set_error(const std::ostream& os) noexcept {error.rdbuf(os.rdbuf());}
247 
248  static void set_in(const std::istream& is) noexcept {in.rdbuf(is.rdbuf());}
249 
250  static void set_out(const std::ostream& os) noexcept {out.rdbuf(os.rdbuf());}
251 
252  static std::map<int, console_special_key> signal_keys() noexcept {return __opaque_console::signal_keys();}
253 
254  static int window_height() noexcept {return __opaque_console::window_height();}
255 
256  static int window_left() noexcept {return __opaque_console::window_left();}
257 
258  static int window_top() noexcept {return __opaque_console::window_top();}
259 
260  static int window_width() noexcept {return __opaque_console::window_width();}
261 
262  template<typename Arg>
263  static void write(Arg&& arg) noexcept {out << arg;}
264 
265  template<typename ... Args>
266  static void write(const std::basic_string<Char>& fmt, Args&& ... args) noexcept {out << strings::format(fmt, std::forward<Args>(args)...);}
267 
268  static void write_line() noexcept {out << std::endl;}
269 
270  template<typename Arg>
271  static void write_line(Arg&& arg) noexcept {out << arg << std::endl;}
272 
273  template<typename ... Args>
274  static void write_line(const std::basic_string<Char>& fmt, Args&& ... args) noexcept {out << strings::format(fmt, std::forward<Args>(args)...) << std::endl;}
275  };
276 
278  template<class Char>
279  std::basic_ostream<Char> basic_console<Char>::error {__get_err_rdbuf<Char>()};
280  template<class Char>
281  std::basic_istream<Char> basic_console<Char>::in {__get_in_rdbuf<Char>()};
282  template<class Char>
283  std::basic_ostream<Char> basic_console<Char>::out {__get_out_rdbuf<Char>()};
285 }
static bool cursor_left(int left) noexcept
Sets the column position of the cursor within the buffer area.
Definition: basic_console.hpp:131
static bool beep(unsigned int frequency, unsigned int duration) noexcept
Plays the sound of a beep of a specified frequency and duration through the console speaker...
Definition: basic_console.hpp:71
static void cursor_visible(bool visible) noexcept
Sets a value indicating whether the cursor is visible.
Definition: basic_console.hpp:175
static std::basic_ostream< Char > error
Gets the error output stream. A std::basic_ostream<Char> that represents the error output stream...
Definition: basic_console.hpp:22
static bool caps_lock() noexcept
Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off...
Definition: basic_console.hpp:104
console_color
Specifies constants that define foreground and background colors for the console. ...
Definition: console_color.hpp:10
The xtd namespace contains all fundamental classes to access console.
Definition: background_color.hpp:7
static std::basic_istream< Char > in
Gets the standard input stream. A std::basic_istream<Char> that represents the standard input stream...
Definition: basic_console.hpp:28
static bool cursor_top(int top) noexcept
Sets the row position of the cursor within the buffer area.
Definition: basic_console.hpp:161
static int cursor_size() noexcept
Gets or sets the height of the cursor within a character cell.
Definition: basic_console.hpp:138
static int input_code_page() noexcept
Gets the code page the console uses to read input.
Definition: basic_console.hpp:193
static bool clear() noexcept
Clears the console buffer and corresponding console window of display information.
Definition: basic_console.hpp:116
static bool input_code_page(int code_page) noexcept
Sets the code page the console uses to read input.
Definition: basic_console.hpp:198
static void beep() noexcept
Plays the sound of a beep through the console speaker.
Definition: basic_console.hpp:62
static int buffer_width() noexcept
Gets the width of the buffer area.
Definition: basic_console.hpp:93
static bool is_out_redireted() noexcept
Gets a value that indicates whether the output stream has been redirected from the standard output st...
Definition: basic_console.hpp:210
static bool is_in_redireted() noexcept
Gets a value that indicates whether the input stream has been redirected from the standard input stre...
Definition: basic_console.hpp:206
static bool output_code_page(int code_page) noexcept
Sets the code page the console uses to write output.
Definition: basic_console.hpp:234
static console_color background_color() noexcept
Gets the background color of the console.
Definition: basic_console.hpp:46
static bool foreground_color(console_color color) noexcept
Sets the foreground color of the console.
Definition: basic_console.hpp:189
Represent reset color output manipulator class.
Definition: reset_color.hpp:10
static std::basic_ostream< Char > open_standard_error() noexcept
Acquires the standard error stream.
Definition: basic_console.hpp:215
static bool cursor_visible() noexcept
Gets a value indicating whether the cursor is visible.
Definition: basic_console.hpp:168
Represents the standard input, output, and error streams for console applications.
Definition: basic_console.hpp:19
static std::basic_istream< Char > open_standard_input() noexcept
Acquires the standard input stream.
Definition: basic_console.hpp:220
static bool buffer_width(int width) noexcept
Sets the width of the buffer area.
Definition: basic_console.hpp:100
static int buffer_height() noexcept
Gets the height of the buffer area.
Definition: basic_console.hpp:78
static void cursor_size(int size) noexcept
Sets the height of the cursor within a character cell.
Definition: basic_console.hpp:146
static bool is_error_redireted() noexcept
Gets a value that indicates whether the error output stream has been redirected from the standard err...
Definition: basic_console.hpp:202
static std::basic_ostream< Char > out
Gets the standard output stream. A std::basic_ostream<Char> that represents the standard output strea...
Definition: basic_console.hpp:34
static bool buffer_height(int height) noexcept
Gets or sets the height of the buffer area.
Definition: basic_console.hpp:86
static std::basic_ostream< Char > open_standard_output() noexcept
Acquires the standard output stream.
Definition: basic_console.hpp:225
static console_color foreground_color() noexcept
Gets the foreground color of the console.
Definition: basic_console.hpp:182
static int output_code_page() noexcept
Gets the code page the console uses to write output.
Definition: basic_console.hpp:229
The CapsLock key.
static int cursor_left() noexcept
Gets the column position of the cursor within the buffer area.
Definition: basic_console.hpp:123
static int cursor_top() noexcept
Gets the row position of the cursor within the buffer area.
Definition: basic_console.hpp:153
static bool background_color(console_color color) noexcept
Sets the background color of the console.
Definition: basic_console.hpp:55