libxr 1.0
Want to be the best embedded framework
|
终端类,实现一个基于 RamFS 的基本命令行接口 Terminal class implementing a basic command-line interface based on RamFS More...
#include <terminal.hpp>
Public Types | |
enum class | Mode : uint8_t { CRLF = 0 , LF = 1 , CR = 2 } |
终端换行模式 Line feed modes for the terminal More... | |
Public Member Functions | |
Terminal (LibXR::RamFS &ramfs, RamFS::Dir *current_dir=nullptr, ReadPort *read_port=STDIO::read_, WritePort *write_port=STDIO::write_, Mode MODE=Mode::CRLF) | |
终端构造函数,初始化文件系统、I/O 端口和当前目录 Constructor to initialize the terminal with file system, I/O ports, and current directory | |
void | LineFeed () |
执行换行操作 Performs a line feed operation | |
void | UpdateDisplayPosition () |
更新光标位置 Updates cursor position | |
bool | CanDisplayChar () |
检查是否可以显示字符 Checks if a character can be displayed | |
bool | CanDeleteChar () |
检查是否可以删除字符 Checks if a character can be deleted | |
void | AddCharToInputLine (char data) |
向输入行中添加字符,支持在光标位置插入 Adds a character to the input line, supports insertion at the cursor position | |
void | DisplayChar (char data) |
在终端上显示字符,并根据历史记录模式进行相应操作 Displays a character on the terminal and updates accordingly if history mode is active | |
void | RemoveCharFromInputLine () |
从输入行中删除字符,支持在光标位置删除 Removes a character from the input line, supports deletion at the cursor position | |
void | DeleteChar () |
处理删除字符操作,支持回退删除,并在历史模式下更新显示 Handles the delete character operation, supports backspace deletion, and updates display in history mode | |
void | ShowHeader () |
显示终端提示符,包括当前目录信息 Displays the terminal prompt, including the current directory information | |
void | ClearLine () |
清除当前行 Clears the current line | |
void | Clear () |
清除整个终端屏幕 Clears the entire terminal screen | |
void | ShowHistory () |
显示历史记录中的输入行,更新终端显示 Displays the input line from history and updates the terminal display | |
void | CopyHistoryToInputLine () |
将历史命令复制到输入行,并重置历史索引和光标偏移 Copies the history command to the input line and resets history index and cursor offset | |
void | AddHistory () |
将当前输入行添加到历史记录 Adds the current input line to the history | |
void | GetArgs () |
解析输入行,将其拆分为参数数组 Parses the input line and splits it into argument array | |
RamFS::Dir * | Path2Dir (char *path) |
将路径字符串解析为目录对象 Converts a path string into a directory object | |
RamFS::File * | Path2File (char *path) |
将路径字符串解析为文件对象 Converts a path string into a file object | |
void | ExecuteCommand () |
解析并执行输入的命令 Parses and executes the entered command | |
void | Parse (RawData &raw_data) |
解析输入数据流,将其转换为字符并处理 Parses the input data stream, converting it into characters and processing them | |
void | HandleAnsiCharacter (char data) |
解析输入数据流,将其转换为字符并处理 Parses the input data stream, converting it into characters and processing them | |
void | AutoComplete () |
实现命令自动补全,匹配目录或文件名 Implements command auto-completion by matching directories or file names | |
void | HandleControlCharacter (char data) |
处理控制字符,包括换行、删除、制表符等 Handles control characters such as newline, delete, and tab | |
void | HandleCharacter (char data) |
处理输入字符,根据类型调用相应的处理函数 Handles input characters, dispatching them to the appropriate handler | |
Static Public Member Functions | |
static void | ThreadFun (Terminal *term) |
终端线程函数,以独立线程方式持续驱动终端 Terminal thread function, continuously drives the terminal as an independent thread | |
static void | TaskFun (Terminal *term) |
终端任务函数,以定时器任务方式驱动终端 Terminal task function, drives the terminal using a scheduled task | |
Data Fields | |
ReadOperation::OperationPollingStatus | read_status_ |
WriteOperation::OperationPollingStatus | write_status_ |
const Mode | MODE |
终端换行模式 Terminal line feed mode | |
WriteOperation | write_op_ |
终端写操作 Terminal write operation | |
ReadPort * | read_ |
读取端口 Read port | |
WritePort * | write_ |
写入端口 Write port | |
RamFS & | ramfs_ |
关联的文件系统 Associated file system | |
char | read_buff_ [READ_BUFF_SIZE] |
读取缓冲区 Read buffer | |
RamFS::Dir * | current_dir_ |
当前目录 Current directory | |
uint8_t | flag_ansi_ = 0 |
ANSI 控制字符状态 ANSI control character state. | |
int | offset_ = 0 |
光标偏移 Cursor offset | |
Stack< char > | input_line_ |
输入行缓冲区 Input line buffer | |
char * | arg_tab_ [MAX_ARG_NUMBER] |
命令参数列表 Command argument list | |
size_t | arg_number_ = 0 |
参数数量 Number of arguments | |
Queue< LibXR::String< MAX_LINE_SIZE > > | history_ |
历史命令 History of commands | |
int | history_index_ = -1 |
当前历史索引 Current history index | |
bool | linefeed_flag_ = false |
换行标志 Line feed flag | |
Private Member Functions | |
char * | StrchrRev (char *str, char c) |
反向查找字符串中的特定字符 Finds a specific character in a string from the end | |
Static Private Attributes | |
static constexpr char | CLEAR_ALL [] |
清屏命令 Clear screen command | |
static constexpr char | CLEAR_LINE [] |
清除当前行命令 Clear current line command | |
static constexpr char | CLEAR_BEHIND [] |
清除光标后内容命令 Clear content after cursor command | |
static constexpr char | KEY_RIGHT [] = "\033[C" |
右箭头键 Right arrow key | |
static constexpr char | KEY_LEFT [] = "\033[D" |
左箭头键 Left arrow key | |
static constexpr char | KEY_SAVE [] = "\033[s" |
保存光标位置 Save cursor position | |
static constexpr char | KEY_LOAD [] = "\033[u" |
恢复光标位置 Restore cursor position | |
static constexpr char | DELETE_CHAR [] |
退格删除字符 Backspace delete character | |
终端类,实现一个基于 RamFS 的基本命令行接口 Terminal class implementing a basic command-line interface based on RamFS
READ_BUFF_SIZE | 读取缓冲区大小 Read buffer size |
MAX_LINE_SIZE | 最大输入行长度 Maximum input line size |
MAX_ARG_NUMBER | 最大参数数量 Maximum number of arguments |
MAX_HISTORY_NUMBER | 最大历史记录数量 Maximum number of command history records |
Definition at line 30 of file terminal.hpp.
|
strong |
终端换行模式 Line feed modes for the terminal
Enumerator | |
---|---|
CRLF | 回车换行 Carriage Return + Line Feed (\r |
LF | 仅换行 Line Feed ( |
CR | 仅回车 Carriage Return (\r) |
Definition at line 73 of file terminal.hpp.
|
inline |
终端构造函数,初始化文件系统、I/O 端口和当前目录 Constructor to initialize the terminal with file system, I/O ports, and current directory
ramfs | 关联的 RamFS 文件系统 Associated RamFS file system |
current_dir | 当前目录(默认为根目录)Current directory (default: root) |
read_port | 读取端口(默认使用标准输入)Read port (default: standard input) |
write_port | 写入端口(默认使用标准输出)Write port (default: standard output) |
MODE | 终端换行模式(默认 CRLF)Terminal line feed mode (default: CRLF) |
Definition at line 90 of file terminal.hpp.
|
inline |
向输入行中添加字符,支持在光标位置插入 Adds a character to the input line, supports insertion at the cursor position
data | 要添加的字符 The character to add |
Definition at line 178 of file terminal.hpp.
|
inline |
将当前输入行添加到历史记录 Adds the current input line to the history
Definition at line 350 of file terminal.hpp.
|
inline |
实现命令自动补全,匹配目录或文件名 Implements command auto-completion by matching directories or file names
Definition at line 627 of file terminal.hpp.
|
inline |
检查是否可以删除字符 Checks if a character can be deleted
Definition at line 171 of file terminal.hpp.
|
inline |
检查是否可以显示字符 Checks if a character can be displayed
Definition at line 164 of file terminal.hpp.
|
inline |
清除整个终端屏幕 Clears the entire terminal screen
Definition at line 307 of file terminal.hpp.
|
inline |
清除当前行 Clears the current line
Definition at line 301 of file terminal.hpp.
|
inline |
将历史命令复制到输入行,并重置历史索引和光标偏移 Copies the history command to the input line and resets history index and cursor offset
Definition at line 335 of file terminal.hpp.
|
inline |
处理删除字符操作,支持回退删除,并在历史模式下更新显示 Handles the delete character operation, supports backspace deletion, and updates display in history mode
Definition at line 248 of file terminal.hpp.
|
inline |
在终端上显示字符,并根据历史记录模式进行相应操作 Displays a character on the terminal and updates accordingly if history mode is active
data | 要显示的字符 The character to display |
Definition at line 197 of file terminal.hpp.
|
inline |
解析并执行输入的命令 Parses and executes the entered command
Definition at line 467 of file terminal.hpp.
|
inline |
解析输入行,将其拆分为参数数组 Parses the input line and splits it into argument array
Definition at line 365 of file terminal.hpp.
|
inline |
解析输入数据流,将其转换为字符并处理 Parses the input data stream, converting it into characters and processing them
raw_data | 输入的原始数据 Input raw data |
Definition at line 559 of file terminal.hpp.
|
inline |
处理输入字符,根据类型调用相应的处理函数 Handles input characters, dispatching them to the appropriate handler
data | 输入的字符 The input character |
Definition at line 824 of file terminal.hpp.
|
inline |
处理控制字符,包括换行、删除、制表符等 Handles control characters such as newline, delete, and tab
data | 输入的控制字符 The input control character |
Definition at line 774 of file terminal.hpp.
|
inline |
执行换行操作 Performs a line feed operation
Definition at line 130 of file terminal.hpp.
|
inline |
解析输入数据流,将其转换为字符并处理 Parses the input data stream, converting it into characters and processing them
raw_data | 输入的原始数据 Input raw data |
Definition at line 544 of file terminal.hpp.
|
inline |
将路径字符串解析为目录对象 Converts a path string into a directory object
path | 目录路径字符串 The directory path string |
Definition at line 391 of file terminal.hpp.
|
inline |
将路径字符串解析为文件对象 Converts a path string into a file object
path | 文件路径字符串 The file path string |
Definition at line 436 of file terminal.hpp.
|
inline |
从输入行中删除字符,支持在光标位置删除 Removes a character from the input line, supports deletion at the cursor position
Definition at line 230 of file terminal.hpp.
|
inline |
显示终端提示符,包括当前目录信息 Displays the terminal prompt, including the current directory information
Definition at line 281 of file terminal.hpp.
|
inline |
显示历史记录中的输入行,更新终端显示 Displays the input line from history and updates the terminal display
Definition at line 313 of file terminal.hpp.
|
inlineprivate |
反向查找字符串中的特定字符 Finds a specific character in a string from the end
str | 输入字符串 Input string |
c | 要查找的字符 Character to find |
Definition at line 54 of file terminal.hpp.
|
inlinestatic |
终端任务函数,以定时器任务方式驱动终端 Terminal task function, drives the terminal using a scheduled task
该函数用于以定时任务(或轮询方式)驱动终端,适用于资源受限的系统。 它不会持续运行,而是在定时器触发或系统任务调度时运行,执行一次数据读取和解析后返回。
This function drives the terminal using a scheduled task (or polling mode), making it suitable for resource-constrained systems. Unlike the thread-based approach, it only runs when scheduled (e.g., triggered by a timer) and processes available input data before returning.
Definition at line 890 of file terminal.hpp.
|
inlinestatic |
终端线程函数,以独立线程方式持续驱动终端 Terminal thread function, continuously drives the terminal as an independent thread
该函数用于以独立线程的方式驱动终端,持续从输入流读取数据并解析,适用于高实时性应用。 它会在循环中不断检查输入流的大小,并在数据可用时进行解析。
This function runs as a separate thread to continuously drive the terminal, reading and parsing input data in a loop. It is suitable for high real-time applications. It continuously checks the input stream size and processes data when available.
Definition at line 856 of file terminal.hpp.
|
inline |
更新光标位置 Updates cursor position
Definition at line 150 of file terminal.hpp.
size_t LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::arg_number_ = 0 |
参数数量 Number of arguments
Definition at line 121 of file terminal.hpp.
char* LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::arg_tab_[MAX_ARG_NUMBER] |
命令参数列表 Command argument list
Definition at line 120 of file terminal.hpp.
|
staticconstexprprivate |
清屏命令 Clear screen command
Definition at line 33 of file terminal.hpp.
|
staticconstexprprivate |
清除光标后内容命令 Clear content after cursor command
Definition at line 37 of file terminal.hpp.
|
staticconstexprprivate |
清除当前行命令 Clear current line command
Definition at line 35 of file terminal.hpp.
RamFS::Dir* LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::current_dir_ |
当前目录 Current directory
Definition at line 116 of file terminal.hpp.
|
staticconstexprprivate |
退格删除字符 Backspace delete character
Definition at line 43 of file terminal.hpp.
uint8_t LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::flag_ansi_ = 0 |
ANSI 控制字符状态 ANSI control character state.
Definition at line 117 of file terminal.hpp.
Queue<LibXR::String<MAX_LINE_SIZE> > LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::history_ |
历史命令 History of commands
Definition at line 122 of file terminal.hpp.
int LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::history_index_ = -1 |
当前历史索引 Current history index
Definition at line 123 of file terminal.hpp.
Stack<char> LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::input_line_ |
输入行缓冲区 Input line buffer
Definition at line 119 of file terminal.hpp.
|
staticconstexprprivate |
左箭头键 Left arrow key
Definition at line 40 of file terminal.hpp.
|
staticconstexprprivate |
恢复光标位置 Restore cursor position
Definition at line 42 of file terminal.hpp.
|
staticconstexprprivate |
右箭头键 Right arrow key
Definition at line 39 of file terminal.hpp.
|
staticconstexprprivate |
保存光标位置 Save cursor position
Definition at line 41 of file terminal.hpp.
bool LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::linefeed_flag_ = false |
换行标志 Line feed flag
Definition at line 124 of file terminal.hpp.
const Mode LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::MODE |
终端换行模式 Terminal line feed mode
Definition at line 109 of file terminal.hpp.
int LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::offset_ = 0 |
光标偏移 Cursor offset
Definition at line 118 of file terminal.hpp.
RamFS& LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::ramfs_ |
关联的文件系统 Associated file system
Definition at line 113 of file terminal.hpp.
ReadPort* LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::read_ |
读取端口 Read port
Definition at line 111 of file terminal.hpp.
char LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::read_buff_[READ_BUFF_SIZE] |
读取缓冲区 Read buffer
Definition at line 114 of file terminal.hpp.
ReadOperation::OperationPollingStatus LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::read_status_ |
Definition at line 106 of file terminal.hpp.
WritePort* LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::write_ |
写入端口 Write port
Definition at line 112 of file terminal.hpp.
WriteOperation LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::write_op_ |
终端写操作 Terminal write operation
Definition at line 110 of file terminal.hpp.
WriteOperation::OperationPollingStatus LibXR::Terminal< READ_BUFF_SIZE, MAX_LINE_SIZE, MAX_ARG_NUMBER, MAX_HISTORY_NUMBER >::write_status_ |
Definition at line 107 of file terminal.hpp.