12#include "libxr_rw.hpp"
14#include "semaphore.hpp"
31template <
size_t READ_BUFF_SIZE = 32,
size_t MAX_LINE_SIZE = READ_BUFF_SIZE,
32 size_t MAX_ARG_NUMBER = 5,
size_t MAX_HISTORY_NUMBER = 5>
39 using HistoryLine = std::array<char, MAX_LINE_SIZE + 1>;
48 static constexpr char CLEAR_ALL[] =
50 static constexpr char CLEAR_LINE[] =
52 static constexpr char CLEAR_BEHIND[] =
54 static constexpr char KEY_RIGHT[] =
"\033[C";
55 static constexpr char KEY_LEFT[] =
"\033[D";
56 static constexpr char KEY_SAVE[] =
"\033[s";
57 static constexpr char KEY_LOAD[] =
59 static constexpr char DELETE_CHAR[] =
68 char* StrchrRev(
char* str,
char c)
70 auto len = strlen(str);
71 for (
int i =
static_cast<int>(len - 1); i >= 0; i--)
117 ASSERT(read_port !=
nullptr);
118 ASSERT(write_port !=
nullptr);
119 ASSERT(read_port->Readable());
120 ASSERT(write_port->Writable());
172#include "display.hpp"
178#include "command.hpp"
互斥锁类,提供线程同步机制 Mutex class providing thread synchronization mechanisms.
基于 QueueBase 的泛型队列模板类。 Generic queue template class based on QueueBase.
目录节点片段 / Directory-node fragment
轻量级内存文件系统 / Lightweight in-memory file system
基于 SPSC 字节队列的读端口 / Read endpoint backed by an SPSC byte queue.
static LibXR::WritePort::Stream * write_stream_
可选的外部托管写流 / Optional externally owned write stream.
static LibXR::Mutex * write_mutex_
写入端口互斥锁 / Write port mutex.
static ReadPort * read_
读取端口 / Read port instance.
static WritePort * write_
写入端口 / Write port instance.
线程安全的栈数据结构 / Thread-safe stack data structure
基于 RamFS 的命令行终端 / Command-line terminal backed by RamFS.
std::atomic< ReadOperation::OperationPollingStatus > read_status_
读完成方发布、轮询入口读取的状态 / Read completion status used by the polling entry.
char * arg_tab_[MAX_ARG_NUMBER]
命令参数列表 / Command argument list
WritePort * write_port_
写入端口 / Write port
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)
初始化终端的文件系统和读写端口 / Initialize the terminal filesystem and ports.
bool line_truncated_
当前输入行丢弃过超长字符 / Characters beyond MAX_LINE_SIZE were dropped
std::atomic< WriteOperation::OperationPollingStatus > write_status_
写完成方发布的轮询状态 / Polling status published by write completion.
char linefeed_char_
上一个换行字符 / Previous line feed character
ReadPort * read_port_
读取端口 / Read port
WriteOperation write_op_
终端写操作 / Terminal write operation
Queue< HistoryLine > history_
历史命令 / History of commands
char read_buff_[READ_BUFF_SIZE]
读取缓冲区 / Read buffer
int history_index_
当前历史索引 / Current history index
RamFS & ramfs_
关联的文件系统 / Associated file system
WritePort::Stream write_stream_
写入流 / Write stream
int offset_
光标偏移 / Cursor offset
LibXR::Mutex * write_mutex_
写入端口互斥锁 / Write port mutex
RamFS::Dir * current_dir_
当前目录 / Current directory
Stack< char > input_line_
输入行缓冲区 / Input line buffer
size_t request_read_size_
本轮计划读取的字节数 / Byte count requested for the current read attempt.
Mode
终端换行模式 / Terminal line ending mode.
@ CR
仅回车 / Carriage Return (\r)
@ CRLF
回车换行 / Carriage Return + Line Feed (\r\n)
bool linefeed_flag_
CRLF 抑制标志 / CRLF suppression flag.
const Mode MODE
终端换行模式 / Terminal line feed mode
合并多次写入的流接口 / Stream interface for batched writes.
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
终端线程与轮询入口 / Thread and polling entry points for Terminal.
LibXR 命名空间 / LibXR namespace.