pub struct ChatApp {Show 30 fields
pub agent_config: AgentConfig,
pub session: ChatSession,
pub input: String,
pub cursor_pos: usize,
pub mode: ChatMode,
pub scroll_offset: u16,
pub is_loading: bool,
pub model_list_state: ListState,
pub toast: Option<(String, bool, Instant)>,
pub stream_rx: Option<Receiver<StreamMsg>>,
pub streaming_content: Arc<Mutex<String>>,
pub msg_lines_cache: Option<MsgLinesCache>,
pub browse_msg_index: usize,
pub browse_scroll_offset: u16,
pub last_rendered_streaming_len: usize,
pub last_stream_render_time: Instant,
pub config_provider_idx: usize,
pub config_field_idx: usize,
pub config_editing: bool,
pub config_edit_buf: String,
pub config_edit_cursor: usize,
pub auto_scroll: bool,
pub theme: Theme,
pub archives: Vec<ChatArchive>,
pub archive_list_index: usize,
pub archive_default_name: String,
pub archive_custom_name: String,
pub archive_editing_name: bool,
pub archive_edit_cursor: usize,
pub restore_confirm_needed: bool,
}Expand description
TUI 应用状态
Fields§
§agent_config: AgentConfigAgent 配置
session: ChatSession当前对话会话
input: String输入缓冲区
cursor_pos: usize光标位置(字符索引)
mode: ChatMode当前模式
scroll_offset: u16消息列表滚动偏移
is_loading: bool是否正在等待 AI 回复
model_list_state: ListState模型选择列表状态
toast: Option<(String, bool, Instant)>Toast 通知消息 (内容, 是否错误, 创建时间)
stream_rx: Option<Receiver<StreamMsg>>用于接收后台流式回复的 channel
streaming_content: Arc<Mutex<String>>当前正在流式接收的 AI 回复内容(实时更新)
msg_lines_cache: Option<MsgLinesCache>消息渲染行缓存:(消息数, 最后一条消息内容hash, 气泡宽度) → 渲染好的行 避免每帧都重新解析 Markdown
browse_msg_index: usize消息浏览模式中选中的消息索引
browse_scroll_offset: u16浏览模式下当前消息内部的滚动偏移(相对于消息起始行,A/D 控制)
last_rendered_streaming_len: usize流式节流:上次实际渲染流式内容时的长度
last_stream_render_time: Instant流式节流:上次实际渲染流式内容的时间
config_provider_idx: usize配置界面:当前选中的 provider 索引
config_field_idx: usize配置界面:当前选中的字段索引
config_editing: bool配置界面:是否正在编辑某个字段
config_edit_buf: String配置界面:编辑缓冲区
config_edit_cursor: usize配置界面:编辑光标位置
auto_scroll: bool流式输出时是否自动滚动到底部(用户手动上滚后关闭,发送新消息或滚到底部时恢复)
theme: Theme当前主题
archives: Vec<ChatArchive>归档列表(缓存)
archive_list_index: usize归档列表选中索引
archive_default_name: String归档确认模式的默认名称
archive_custom_name: String归档确认模式的用户自定义名称
archive_editing_name: bool归档确认模式是否正在编辑名称
archive_edit_cursor: usize归档确认模式的光标位置
restore_confirm_needed: bool还原确认模式:是否需要确认当前会话有消息
Implementations§
Source§impl ChatApp
impl ChatApp
pub fn new() -> Self
Sourcepub fn switch_theme(&mut self)
pub fn switch_theme(&mut self)
切换到下一个主题
Sourcepub fn show_toast(&mut self, msg: impl Into<String>, is_error: bool)
pub fn show_toast(&mut self, msg: impl Into<String>, is_error: bool)
显示一条 toast 通知
Sourcepub fn tick_toast(&mut self)
pub fn tick_toast(&mut self)
清理过期的 toast
Sourcepub fn active_provider(&self) -> Option<&ModelProvider>
pub fn active_provider(&self) -> Option<&ModelProvider>
获取当前活跃的 provider
Sourcepub fn active_model_name(&self) -> String
pub fn active_model_name(&self) -> String
获取当前模型名称
Sourcepub fn build_api_messages(&self) -> Vec<ChatMessage>
pub fn build_api_messages(&self) -> Vec<ChatMessage>
构建发送给 API 的消息列表
Sourcepub fn send_message(&mut self)
pub fn send_message(&mut self)
发送消息(非阻塞,启动后台线程流式接收)
Sourcepub fn poll_stream(&mut self)
pub fn poll_stream(&mut self)
处理后台流式消息(在主循环中每帧调用)
Sourcepub fn clear_session(&mut self)
pub fn clear_session(&mut self)
清空对话
Sourcepub fn switch_model(&mut self)
pub fn switch_model(&mut self)
切换模型
Sourcepub fn scroll_down(&mut self)
pub fn scroll_down(&mut self)
向下滚动消息
Sourcepub fn start_archive_confirm(&mut self)
pub fn start_archive_confirm(&mut self)
开始归档确认流程
Sourcepub fn start_archive_list(&mut self)
pub fn start_archive_list(&mut self)
开始还原流程(加载归档列表)
Sourcepub fn do_archive(&mut self, name: &str)
pub fn do_archive(&mut self, name: &str)
执行归档
Sourcepub fn do_restore(&mut self)
pub fn do_restore(&mut self)
执行还原归档
Sourcepub fn do_delete_archive(&mut self)
pub fn do_delete_archive(&mut self)
删除选中的归档
Auto Trait Implementations§
impl Freeze for ChatApp
impl RefUnwindSafe for ChatApp
impl Send for ChatApp
impl !Sync for ChatApp
impl Unpin for ChatApp
impl UnsafeUnpin for ChatApp
impl UnwindSafe for ChatApp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more