Skip to main content

ChatApp

Struct ChatApp 

Source
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: AgentConfig

Agent 配置

§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

Source

pub fn new() -> Self

Source

pub fn switch_theme(&mut self)

切换到下一个主题

Source

pub fn show_toast(&mut self, msg: impl Into<String>, is_error: bool)

显示一条 toast 通知

Source

pub fn tick_toast(&mut self)

清理过期的 toast

Source

pub fn active_provider(&self) -> Option<&ModelProvider>

获取当前活跃的 provider

Source

pub fn active_model_name(&self) -> String

获取当前模型名称

Source

pub fn build_api_messages(&self) -> Vec<ChatMessage>

构建发送给 API 的消息列表

Source

pub fn send_message(&mut self)

发送消息(非阻塞,启动后台线程流式接收)

Source

pub fn poll_stream(&mut self)

处理后台流式消息(在主循环中每帧调用)

Source

pub fn clear_session(&mut self)

清空对话

Source

pub fn switch_model(&mut self)

切换模型

Source

pub fn scroll_up(&mut self)

向上滚动消息

Source

pub fn scroll_down(&mut self)

向下滚动消息

Source

pub fn start_archive_confirm(&mut self)

开始归档确认流程

Source

pub fn start_archive_list(&mut self)

开始还原流程(加载归档列表)

Source

pub fn do_archive(&mut self, name: &str)

执行归档

Source

pub fn do_restore(&mut self)

执行还原归档

Source

pub fn do_delete_archive(&mut self)

删除选中的归档

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,