Skip to main content

ConversationView

Trait ConversationView 

Source
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 object
  • restore_state() restores from a previously saved state
  • clear() 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§

Source

fn add_user_message(&mut self, content: String)

Add a user message to the conversation

Source

fn add_assistant_message(&mut self, content: String)

Add an assistant message to the conversation

Source

fn add_system_message(&mut self, content: String)

Add a system message to the conversation

Source

fn append_streaming(&mut self, text: &str)

Append text to the current streaming response

Source

fn complete_streaming(&mut self)

Complete the streaming response and finalize it as a message

Source

fn discard_streaming(&mut self)

Discard the streaming buffer without saving (used on cancel)

Source

fn is_streaming(&self) -> bool

Check if currently streaming a response

Source

fn add_tool_message( &mut self, tool_use_id: &str, display_name: &str, display_title: &str, )

Add a tool execution message

Source

fn update_tool_status(&mut self, tool_use_id: &str, status: ToolStatus)

Update the status of a tool message

Source

fn scroll_up(&mut self)

Scroll up by the implementation’s scroll step

Source

fn scroll_down(&mut self)

Scroll down by the implementation’s scroll step

Source

fn enable_auto_scroll(&mut self)

Enable auto-scroll and scroll to bottom (called when user submits a message)

Source

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 to
  • area - The area to render within
  • theme - The current theme
  • pending_status - Optional pending status message (e.g., “running tools…”)
Source

fn step_spinner(&mut self)

Advance the spinner animation (called periodically during activity)

Source

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.

Source

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.

Source

fn clear(&mut self)

Clear conversation content while preserving configuration

This resets messages, streaming state, and scroll position, but keeps settings like title, theme configuration, and renderers.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§