|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
系统控制台单例类 更多...
#include <console.hpp>
类 | |
| struct | console_size |
| 控制台尺寸结构 更多... | |
Public 成员函数 | |
| void | flush () |
| 刷新输出缓冲区 | |
| void | print_string (const string &str) |
| 打印字符串 | |
| void | print_string (const string_view &view) |
| 打印字符串视图 | |
| void | print_string (const char *str) |
| 打印C风格字符串 | |
| string | read () |
| 读取输入(直到空白字符) | |
| string | readln () |
| 读取一行输入 | |
| char | read_char () |
| 读取单个字符 | |
| template<typename... Args> | |
| void | print (Args &&... args) |
| 打印任意类型的值 | |
| template<typename... Args> | |
| void | printf (const string_view fmt, Args &&... args) |
| 格式化打印 | |
| template<typename... Args> | |
| void | printc (const color &color, Args &&... args) |
| 带颜色的打印 | |
| template<typename... Args> | |
| void | printcf (const color &color, const string_view fmt, Args &&... args) |
| 带颜色的格式化打印 | |
| void | println () |
| 打印换行 | |
| template<typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0> | |
| void | println (Args &&... args) |
| 打印任意类型的值并换行 | |
| template<typename... Args> | |
| void | printfln (const string_view fmt, Args &&... args) |
| 格式化打印并换行 | |
| template<typename... Args> | |
| void | printcln (const color &color, Args &&... args) |
| 带颜色的打印并换行 | |
| template<typename... Args> | |
| void | printcfln (const color &color, const string_view fmt, Args &&... args) |
| 带颜色的格式化打印并换行 | |
| void | clear () |
| 清空屏幕 | |
| void | pause (string_view msg="Press any char to continue...") |
| 暂停并等待用户按键 | |
| bool | confirmation (string_view prompt="Are you sure? (y/n): ", char yes='y', char no='n') |
| 用户确认对话框 | |
| string | password (string_view prompt="Password: ", char mask=' *', bool show_length=false) |
| 密码输入 | |
| void | set_color (const integer32 &color) |
| 设置颜色(使用ANSI代码) | |
| void | set_color (const color &color, bool use_256_color=true) |
| 设置颜色 | |
| void | set_background_color (const color &color, bool use_256_color=true) |
| 设置背景色 | |
| void | reset_color () |
| 重置颜色 | |
| void | progress_bar (double percentage, int width=50, bool show_percentage=true, char fill_char='#', char empty_char=' ') |
| 显示进度条 | |
| void | set_cursor_position (int row, int column) |
| 设置光标位置 | |
| void | save_cursor_position () |
| 保存光标位置 | |
| void | restore_cursor_position () |
| 恢复光标位置 | |
| void | hide_cursor () |
| 隐藏光标 | |
| void | show_cursor () |
| 显示光标 | |
| NEFORCE_NODISCARD console_size | get_console_size () const |
| 获取控制台尺寸 | |
| NEFORCE_NODISCARD bool | is_terminal_resized () |
| 检查终端是否已调整大小 | |
| NEFORCE_NODISCARD bool | supports_colors () const |
| 检查是否支持颜色 | |
| NEFORCE_NODISCARD bool | supports_truecolor () const |
| 检查是否支持真彩色 | |
| NEFORCE_NODISCARD bool | supports_unicode () const |
| 检查是否支持Unicode | |
| NEFORCE_NODISCARD bool | is_interactive () const |
| 检查是否是交互式终端 | |
| NEFORCE_NODISCARD string | console_type () const |
| 获取终端类型 | |
| void | typewriter_print (string_view text, milliseconds delay_per_char=milliseconds(50), bool with_sound=false) |
| 打字机效果打印 | |
| void | typewriter_println (string_view text, milliseconds delay_per_char=milliseconds(50), bool with_sound=false) |
| 打字机效果打印并换行 | |
| void | beep () |
| 发出蜂鸣声 | |
| void | flash_screen () |
| 屏幕闪烁 | |
| void | notification (string_view message, milliseconds duration=milliseconds(2000), bool play_sound=true) |
| 显示通知 | |
| void | fade_in (string_view text, milliseconds duration=milliseconds(1000), const color &start_color=color::black(), const color &end_color=color::white()) |
| 淡入效果 | |
| void | fade_out (string_view text, milliseconds duration=milliseconds(1000), const color &start_color=color::white(), const color &end_color=color::black()) |
| 淡出效果 | |
| void | fade_in_out (string_view text, milliseconds in_duration=milliseconds(500), milliseconds hold_duration=milliseconds(1000), milliseconds out_duration=milliseconds(500)) |
| 淡入-保持-淡出效果 | |
静态 Public 成员函数 | |
| static sys_console & | instance () noexcept |
| 获取单例实例 | |
系统控制台单例类
提供了丰富的控制台输入输出功能,包括:
所有方法都是线程安全的。
在文件 console.hpp 第 59 行定义.
| bool sys_console::confirmation | ( | string_view | prompt = "Are you sure? (y/n): ", |
| char | yes = 'y', | ||
| char | no = 'n' ) |
用户确认对话框
| prompt | 提示信息 |
| yes | 确认字符 |
| no | 取消字符 |
| NEFORCE_NODISCARD string sys_console::console_type | ( | ) | const |
获取终端类型
| void sys_console::fade_in | ( | string_view | text, |
| milliseconds | duration = milliseconds(1000), | ||
| const color & | start_color = color::black(), | ||
| const color & | end_color = color::white() ) |
| void sys_console::fade_in_out | ( | string_view | text, |
| milliseconds | in_duration = milliseconds(500), | ||
| milliseconds | hold_duration = milliseconds(1000), | ||
| milliseconds | out_duration = milliseconds(500) ) |
淡入-保持-淡出效果
| text | 文本 |
| in_duration | 淡入时间 |
| hold_duration | 保持时间 |
| out_duration | 淡出时间 |
| void sys_console::fade_out | ( | string_view | text, |
| milliseconds | duration = milliseconds(1000), | ||
| const color & | start_color = color::white(), | ||
| const color & | end_color = color::black() ) |
| NEFORCE_NODISCARD console_size sys_console::get_console_size | ( | ) | const |
获取控制台尺寸
|
inlinestaticnoexcept |
| NEFORCE_NODISCARD bool sys_console::is_interactive | ( | ) | const |
检查是否是交互式终端
| NEFORCE_NODISCARD bool sys_console::is_terminal_resized | ( | ) |
检查终端是否已调整大小
| void sys_console::notification | ( | string_view | message, |
| milliseconds | duration = milliseconds(2000), | ||
| bool | play_sound = true ) |
显示通知
| message | 通知消息 |
| duration | 显示时长 |
| play_sound | 是否播放声音 |
| string sys_console::password | ( | string_view | prompt = "Password: ", |
| char | mask = ' *', | ||
| bool | show_length = false ) |
密码输入
| prompt | 提示信息 |
| mask | 掩码字符('\0'表示不显示) |
| show_length | 是否显示已输入长度 |
| console_exception | Windows中如果设置控制台模式失败 / Linux中如果进程被终止 |
| void sys_console::pause | ( | string_view | msg = "Press any char to continue..." | ) |
暂停并等待用户按键
| msg | 提示信息 |
|
inline |
| void sys_console::print_string | ( | const char * | str | ) |
打印C风格字符串
| str | 要打印的字符串 |
| void sys_console::print_string | ( | const string & | str | ) |
打印字符串
| str | 要打印的字符串 |
| void sys_console::print_string | ( | const string_view & | view | ) |
打印字符串视图
| view | 要打印的字符串 |
|
inline |
|
inline |
|
inline |
|
inline |
带颜色的打印并换行
| Args | 参数类型 |
| color | 颜色 |
| args | 打印参数 |
在文件 console.hpp 第 268 行定义.
引用了 forward() , 以及 to_string().
|
inline |
|
inline |
|
inline |
| void sys_console::progress_bar | ( | double | percentage, |
| int | width = 50, | ||
| bool | show_percentage = true, | ||
| char | fill_char = '#', | ||
| char | empty_char = ' ' ) |
显示进度条
| percentage | 进度百分比(0.0-100.0或0.0-1.0) |
| width | 进度条宽度 |
| show_percentage | 是否显示百分比 |
| fill_char | 填充字符 |
| empty_char | 空白字符 |
| string sys_console::read | ( | ) |
读取输入(直到空白字符)
| char sys_console::read_char | ( | ) |
读取单个字符
| string sys_console::readln | ( | ) |
读取一行输入
| void sys_console::set_background_color | ( | const color & | color, |
| bool | use_256_color = true ) |
设置背景色
| color | 颜色对象 |
| use_256_color | 是否使用256色模式 |
| void sys_console::set_color | ( | const color & | color, |
| bool | use_256_color = true ) |
设置颜色
| color | 颜色对象 |
| use_256_color | 是否使用256色模式 |
| void sys_console::set_color | ( | const integer32 & | color | ) |
设置颜色(使用ANSI代码)
| color | ANSI颜色代码 |
| void sys_console::set_cursor_position | ( | int | row, |
| int | column ) |
设置光标位置
| row | 行(从1开始) |
| column | 列(从1开始) |
| NEFORCE_NODISCARD bool sys_console::supports_colors | ( | ) | const |
检查是否支持颜色
| NEFORCE_NODISCARD bool sys_console::supports_truecolor | ( | ) | const |
检查是否支持真彩色
| NEFORCE_NODISCARD bool sys_console::supports_unicode | ( | ) | const |
检查是否支持Unicode
| void sys_console::typewriter_print | ( | string_view | text, |
| milliseconds | delay_per_char = milliseconds(50), | ||
| bool | with_sound = false ) |
打字机效果打印
| text | 要打印的文本 |
| delay_per_char | 每个字符的延迟 |
| with_sound | 是否伴随声音 |
| void sys_console::typewriter_println | ( | string_view | text, |
| milliseconds | delay_per_char = milliseconds(50), | ||
| bool | with_sound = false ) |
打字机效果打印并换行
| text | 要打印的文本 |
| delay_per_char | 每个字符的延迟 |
| with_sound | 是否伴随声音 |