use rmpv::{Value, ValueRef};
use crate::{error::CallError, neovim::Neovim, rpc::handler::Handler, uioptions::UiAttachOptions};
impl<H: Handler> Neovim<H> {
pub async fn ui_attach(
&self,
width: i64,
height: i64,
opts: UiAttachOptions<'_>,
) -> Result<(), Box<CallError>> {
let opts = opts.into_value();
let args = (width, height, &opts);
self.request("nvim_ui_attach", args).await??;
Ok(())
}
pub async fn get_api_info(&self) -> Result<Vec<Value>, Box<CallError>> {
match self.request("nvim_get_api_info", ()).await?? {
Value::Array(values) => Ok(values),
value => Err(Box::new(CallError::WrongValueType(value))),
}
}
pub async fn request_input(&self, keys: &str) -> Result<i64, Box<CallError>> {
let value = self.request("nvim_input", &ValueRef::from(keys)).await??;
i64::try_from(value).map_err(|value| Box::new(CallError::WrongValueType(value)))
}
#[inline]
pub async fn notify_input(&self, keys: &str) -> Result<(), Box<CallError>> {
self.notify("nvim_input", keys).await
}
#[inline]
pub async fn out_write(&self, str: &str) -> Result<(), Box<CallError>> {
self.notify("nvim_out_write", str).await
}
#[inline]
pub async fn err_write(&self, str: &str) -> Result<(), Box<CallError>> {
self.notify("nvim_err_write", str).await
}
#[inline]
pub async fn err_writeln(&self, str: &str) -> Result<(), Box<CallError>> {
self.notify("nvim_err_writeln", str).await
}
#[inline]
pub async fn ui_set_focus(&self, gained: bool) -> Result<(), Box<CallError>> {
self.notify("nvim_ui_set_focus", gained).await
}
#[inline]
pub async fn ui_try_resize(&self, width: i64, height: i64) -> Result<(), Box<CallError>> {
let args = (width, height);
self.notify("nvim_ui_try_resize", args).await
}
pub async fn cmd(
&self,
cmd: ValueRef<'_>,
opts: ValueRef<'_>,
) -> Result<String, Box<CallError>> {
let value = self.request("nvim_cmd", (&cmd, &opts)).await??;
String::try_from(value).map_err(|value| Box::new(CallError::WrongValueType(value)))
}
}