use crate::chat_send::SendTarget;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CurrentRecipient {
None,
Handle { handle: String, id: Option<String> },
Id(String),
}
impl CurrentRecipient {
pub fn from_args(to: Option<&str>, to_id: Option<&str>) -> Self {
if let Some(handle) = to.filter(|h| !h.is_empty()) {
CurrentRecipient::Handle {
handle: handle.to_string(),
id: None,
}
} else if let Some(id) = to_id.filter(|i| !i.is_empty()) {
CurrentRecipient::Id(id.to_string())
} else {
CurrentRecipient::None
}
}
pub fn prompt(&self) -> String {
match self {
CurrentRecipient::None => "User? > ".to_string(),
CurrentRecipient::Handle { handle, .. } => format!("[{handle}] > "),
CurrentRecipient::Id(id) => format!("[{id}] > "),
}
}
pub fn target(&self) -> Option<SendTarget> {
match self {
CurrentRecipient::None => None,
CurrentRecipient::Handle { handle, .. } => Some(SendTarget::Handle(handle.clone())),
CurrentRecipient::Id(id) => Some(SendTarget::Id(id.clone())),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChatInput {
Empty,
Exit,
Switch { prefix: String },
Send { text: String },
}
pub fn parse_input(line: &str) -> ChatInput {
let trimmed = line.trim();
if trimmed.is_empty() {
ChatInput::Empty
} else if trimmed == "!exit" {
ChatInput::Exit
} else if let Some(prefix) = trimmed.strip_prefix('/') {
ChatInput::Switch {
prefix: prefix.trim().to_string(),
}
} else {
ChatInput::Send {
text: trimmed.to_string(),
}
}
}