10#include "libxr_rw.hpp"
11#include "libxr_string.hpp"
13#include "semaphore.hpp"
57 for (
int i =
static_cast<int>(
len - 1); i >= 0; i--)
455 return dir->FindFile(name + 1);
513 return ErrorCode::OK;
546 char *buff =
static_cast<char *
>(
raw_data.addr_);
547 for (
size_t i = 0; i <
raw_data.size_; i++)
639 while (*
tmp !=
' ' && *
tmp !=
'\0')
700 return ErrorCode::OK;
730 if (ans_node ==
nullptr)
734 return ErrorCode::OK;
737 for (
size_t i = 0; i <
name_len; i++)
754 return ErrorCode::OK;
776 if (data !=
'\r' && data !=
'\n')
867 if ((*
term->read_)(buff, op) == ErrorCode::OK)
899 switch (
term->read_status_)
901 case ReadOperation::OperationPollingStatus::READY:
903 (*
term->read_)(buff, op);
905 case ReadOperation::OperationPollingStatus::RUNNING:
907 case ReadOperation::OperationPollingStatus::DONE:
914 (*
term->read_)(buff, op);
常量原始数据封装类。 A class for encapsulating constant raw data.
基于 BaseQueue 的泛型队列模板类 (Generic queue template class based on BaseQueue).
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
Data data_
存储的数据 (Stored data).
目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files...
File * FindFile(const char *name)
查找当前目录中的文件 Finds a file in the current directory
文件系统节点基类,所有文件和目录均继承自该类 Base class for file system nodes; all files and directories inherit from this
轻量级的内存文件系统,实现基本的文件、目录和设备管理 A lightweight in-memory file system implementing basic file,...
Dir root_
文件系统的根目录 Root directory of the file system
原始数据封装类。 A class for encapsulating raw data.
size_t size_
数据大小(字节)。 The size of the data (in bytes).
ReadPort class for handling read operations.
static ReadPort * read_
Read port instance. 读取端口。
static WritePort * write_
Write port instance. 写入端口。
信号量类,实现线程同步机制 Semaphore class implementing thread synchronization
线程安全的栈数据结构 / Thread-safe stack data structure
ErrorCode Delete(uint32_t index)
删除指定位置的数据 / Deletes data at a specified position
uint32_t EmptySize() const
获取栈的剩余可用空间 / Returns the remaining available space in the stack
ErrorCode Insert(const Data &data, uint32_t index)
在指定位置插入数据 / Inserts data at a specified position
void Reset()
重置栈 / Resets the stack
ErrorCode Push(const Data &data)
向栈中推入数据 / Pushes data onto the stack
ErrorCode Pop(Data &data)
从栈中弹出数据 / Pops data from the stack
uint32_t Size() const
获取栈中当前元素数量 / Returns the number of elements currently in the stack
A fixed-length string class with safe operations.
终端类,实现一个基于 RamFS 的基本命令行接口 Terminal class implementing a basic command-line interface based on RamFS
bool CanDisplayChar()
检查是否可以显示字符 Checks if a character can be displayed
RamFS::Dir * Path2Dir(char *path)
将路径字符串解析为目录对象 Converts a path string into a directory object
char * arg_tab_[MAX_ARG_NUMBER]
命令参数列表 Command argument list
void HandleAnsiCharacter(char data)
解析输入数据流,将其转换为字符并处理 Parses the input data stream, converting it into characters and processing them
Queue< LibXR::String< MAX_LINE_SIZE > > history_
历史命令 History of commands
void UpdateDisplayPosition()
更新光标位置 Updates cursor position
static constexpr char KEY_LEFT[]
左箭头键 Left arrow key
size_t arg_number_
参数数量 Number of arguments
uint8_t flag_ansi_
ANSI 控制字符状态 ANSI control character state.
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,...
void AutoComplete()
实现命令自动补全,匹配目录或文件名 Implements command auto-completion by matching directories or file names
void HandleCharacter(char data)
处理输入字符,根据类型调用相应的处理函数 Handles input characters, dispatching them to the appropriate handler
void HandleControlCharacter(char data)
处理控制字符,包括换行、删除、制表符等 Handles control characters such as newline, delete, and tab
WriteOperation write_op_
终端写操作 Terminal write operation
bool CanDeleteChar()
检查是否可以删除字符 Checks if a character can be deleted
static constexpr char KEY_LOAD[]
恢复光标位置 Restore cursor position
char read_buff_[READ_BUFF_SIZE]
读取缓冲区 Read buffer
int history_index_
当前历史索引 Current history index
RamFS & ramfs_
关联的文件系统 Associated file system
char * StrchrRev(char *str, char c)
反向查找字符串中的特定字符 Finds a specific character in a string from the end
int offset_
光标偏移 Cursor offset
void ClearLine()
清除当前行 Clears the current line
void CopyHistoryToInputLine()
将历史命令复制到输入行,并重置历史索引和光标偏移 Copies the history command to the input line and resets history index and cu...
void AddHistory()
将当前输入行添加到历史记录 Adds the current input line to the history
void DisplayChar(char data)
在终端上显示字符,并根据历史记录模式进行相应操作 Displays a character on the terminal and updates accordingly if history mode...
ReadPort * read_
读取端口 Read port
RamFS::File * Path2File(char *path)
将路径字符串解析为文件对象 Converts a path string into a file object
static constexpr char CLEAR_LINE[]
清除当前行命令 Clear current line command
void ShowHistory()
显示历史记录中的输入行,更新终端显示 Displays the input line from history and updates the terminal display
static constexpr char DELETE_CHAR[]
退格删除字符 Backspace delete character
static constexpr char CLEAR_ALL[]
清屏命令 Clear screen command
void LineFeed()
执行换行操作 Performs a line feed operation
void Clear()
清除整个终端屏幕 Clears the entire terminal screen
void RemoveCharFromInputLine()
从输入行中删除字符,支持在光标位置删除 Removes a character from the input line, supports deletion at the cursor position
WritePort * write_
写入端口 Write port
static constexpr char CLEAR_BEHIND[]
清除光标后内容命令 Clear content after cursor command
static void TaskFun(Terminal *term)
终端任务函数,以定时器任务方式驱动终端 Terminal task function, drives the terminal using a scheduled task
void GetArgs()
解析输入行,将其拆分为参数数组 Parses the input line and splits it into argument array
void Parse(RawData &raw_data)
解析输入数据流,将其转换为字符并处理 Parses the input data stream, converting it into characters and processing them
void ShowHeader()
显示终端提示符,包括当前目录信息 Displays the terminal prompt, including the current directory information
RamFS::Dir * current_dir_
当前目录 Current directory
Stack< char > input_line_
输入行缓冲区 Input line buffer
static constexpr char KEY_SAVE[]
保存光标位置 Save cursor position
static void ThreadFun(Terminal *term)
终端线程函数,以独立线程方式持续驱动终端 Terminal thread function, continuously drives the terminal as an independent thr...
void ExecuteCommand()
解析并执行输入的命令 Parses and executes the entered command
void DeleteChar()
处理删除字符操作,支持回退删除,并在历史模式下更新显示 Handles the delete character operation, supports backspace deletion,...
Mode
终端换行模式 Line feed modes for the terminal
@ CR
仅回车 Carriage Return (\r)
@ CRLF
回车换行 Carriage Return + Line Feed (\r )
bool linefeed_flag_
换行标志 Line feed flag
const Mode MODE
终端换行模式 Terminal line feed mode
static constexpr char KEY_RIGHT[]
右箭头键 Right arrow key
void AddCharToInputLine(char data)
向输入行中添加字符,支持在光标位置插入 Adds a character to the input line, supports insertion at the cursor position
WritePort class for handling write operations.
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto max(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最大值
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值