ui: split out the app struct into a new ui mod
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use async_openai::types::chat::{ChatCompletionRequestAssistantMessage, ChatCompletionRequestAssistantMessageContent, ChatCompletionRequestMessage, ChatCompletionRequestSystemMessage, ChatCompletionRequestSystemMessageContent, ChatCompletionRequestUserMessage, ChatCompletionRequestUserMessageContent};
|
||||
use ratatui::style::{self, Style};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -11,6 +12,47 @@ pub enum ConversationEntry {
|
||||
SystemMessage(String)
|
||||
}
|
||||
|
||||
impl ConversationEntry {
|
||||
pub fn prefix(&self) -> Option<&str> {
|
||||
match self {
|
||||
ConversationEntry::Eva(_) => Some("Eva: "),
|
||||
ConversationEntry::User(_) => Some("Argee: "),
|
||||
ConversationEntry::ShipComputer(_) => Some("Ship Computer: "),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prefix_style(&self) -> Style {
|
||||
match self {
|
||||
ConversationEntry::Eva(_) => Style::new().fg(style::Color::Cyan),
|
||||
ConversationEntry::User(_) => Style::new().fg(style::Color::Magenta),
|
||||
ConversationEntry::ShipComputer(_) => Style::new().fg(style::Color::Green),
|
||||
ConversationEntry::StageDirection(_) => Style::new().fg(style::Color::Yellow),
|
||||
ConversationEntry::SystemMessage(_) => Style::new().fg(style::Color::DarkGray),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn text_style(&self) -> Style {
|
||||
match self {
|
||||
ConversationEntry::StageDirection(_) => Style::new().fg(style::Color::Yellow),
|
||||
ConversationEntry::SystemMessage(_) => Style::new().fg(style::Color::DarkGray),
|
||||
_ => Style::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for ConversationEntry {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
ConversationEntry::Eva(text) => text,
|
||||
ConversationEntry::ShipComputer(text) => text,
|
||||
ConversationEntry::StageDirection(text) => text,
|
||||
ConversationEntry::SystemMessage(text) => text,
|
||||
ConversationEntry::User(text) => text
|
||||
}.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<ChatCompletionRequestMessage> for ConversationEntry {
|
||||
fn try_into(self) -> Result<ChatCompletionRequestMessage, Self::Error> {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user