pub trait ConversationView: Send + 'static {
Show 17 methods
// Required methods
fn add_user_message(&mut self, content: String);
fn add_assistant_message(&mut self, content: String);
fn add_system_message(&mut self, content: String);
fn append_streaming(&mut self, text: &str);
fn complete_streaming(&mut self);
fn discard_streaming(&mut self);
fn is_streaming(&self) -> bool;
fn add_tool_message(
&mut self,
tool_use_id: &str,
display_name: &str,
display_title: &str,
);
fn update_tool_status(&mut self, tool_use_id: &str, status: ToolStatus);
fn scroll_up(&mut self);
fn scroll_down(&mut self);
fn enable_auto_scroll(&mut self);
fn render(
&mut self,
frame: &mut Frame<'_>,
area: Rect,
theme: &Theme,
pending_status: Option<&str>,
);
fn step_spinner(&mut self);
fn save_state(&self) -> Box<dyn Any + Send>;
fn restore_state(&mut self, state: Box<dyn Any + Send>);
fn clear(&mut self);
}Expand description
Trait for conversation/chat display widgets.
This trait is separate from the Widget trait - a ConversationView may also implement Widget, but this trait focuses specifically on conversation display functionality.
§Session State
ConversationView supports saving and restoring state for session switching:
save_state()returns an opaque state objectrestore_state()restores from a previously saved stateclear()resets the view while preserving configuration
§Example Implementation
impl ConversationView for MyChatView {
fn add_user_message(&mut self, content: String) {
self.messages.push(Message::user(content));
}
// ... implement other methods
}Required Methods§
Sourcefn add_user_message(&mut self, content: String)
fn add_user_message(&mut self, content: String)
Add a user message to the conversation
Sourcefn add_assistant_message(&mut self, content: String)
fn add_assistant_message(&mut self, content: String)
Add an assistant message to the conversation
Sourcefn add_system_message(&mut self, content: String)
fn add_system_message(&mut self, content: String)
Add a system message to the conversation
Sourcefn append_streaming(&mut self, text: &str)
fn append_streaming(&mut self, text: &str)
Append text to the current streaming response
Sourcefn complete_streaming(&mut self)
fn complete_streaming(&mut self)
Complete the streaming response and finalize it as a message
Sourcefn discard_streaming(&mut self)
fn discard_streaming(&mut self)
Discard the streaming buffer without saving (used on cancel)
Sourcefn is_streaming(&self) -> bool
fn is_streaming(&self) -> bool
Check if currently streaming a response
Sourcefn add_tool_message(
&mut self,
tool_use_id: &str,
display_name: &str,
display_title: &str,
)
fn add_tool_message( &mut self, tool_use_id: &str, display_name: &str, display_title: &str, )
Add a tool execution message
Sourcefn update_tool_status(&mut self, tool_use_id: &str, status: ToolStatus)
fn update_tool_status(&mut self, tool_use_id: &str, status: ToolStatus)
Update the status of a tool message
Sourcefn scroll_down(&mut self)
fn scroll_down(&mut self)
Scroll down by the implementation’s scroll step
Sourcefn enable_auto_scroll(&mut self)
fn enable_auto_scroll(&mut self)
Enable auto-scroll and scroll to bottom (called when user submits a message)
Sourcefn render(
&mut self,
frame: &mut Frame<'_>,
area: Rect,
theme: &Theme,
pending_status: Option<&str>,
)
fn render( &mut self, frame: &mut Frame<'_>, area: Rect, theme: &Theme, pending_status: Option<&str>, )
Render the conversation view
§Arguments
frame- The ratatui frame to render toarea- The area to render withintheme- The current themepending_status- Optional pending status message (e.g., “running tools…”)
Sourcefn step_spinner(&mut self)
fn step_spinner(&mut self)
Advance the spinner animation (called periodically during activity)
Sourcefn save_state(&self) -> Box<dyn Any + Send>
fn save_state(&self) -> Box<dyn Any + Send>
Save the current state for session switching
Returns an opaque state object that can be restored later.
Sourcefn restore_state(&mut self, state: Box<dyn Any + Send>)
fn restore_state(&mut self, state: Box<dyn Any + Send>)
Restore state from a previously saved state
If the state cannot be downcast to the expected type, this is a no-op.