use serde::{Deserialize, Serialize};
use crate::{client::Opencode, error::OpencodeError};
pub type TuiAppendPromptResponse = bool;
pub type TuiOpenHelpResponse = bool;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct TuiAppendPromptParams {
pub text: String,
}
pub struct TuiResource<'a> {
client: &'a Opencode,
}
impl<'a> TuiResource<'a> {
pub(crate) const fn new(client: &'a Opencode) -> Self {
Self { client }
}
pub async fn append_prompt(
&self,
params: &TuiAppendPromptParams,
) -> Result<TuiAppendPromptResponse, OpencodeError> {
self.client.post("/tui/append-prompt", Some(params), None).await
}
pub async fn open_help(&self) -> Result<TuiOpenHelpResponse, OpencodeError> {
self.client.post::<TuiOpenHelpResponse, ()>("/tui/open-help", None, None).await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tui_append_prompt_params_round_trip() {
let params = TuiAppendPromptParams { text: "hello world".into() };
let json_str = serde_json::to_string(¶ms).unwrap();
assert!(json_str.contains(r#""text":"hello world"#));
let back: TuiAppendPromptParams = serde_json::from_str(&json_str).unwrap();
assert_eq!(params, back);
}
}