use reovim_kernel::api::v1::{BufferId, Position, WindowId};
use super::Selection;
pub trait WindowApi: Send {
fn active_window(&self) -> Option<WindowId>;
fn cursor_position(&self) -> Option<Position>;
fn window_count(&self) -> usize;
fn window_buffer(&self, window: WindowId) -> Option<BufferId>;
fn create_window(&mut self, buffer: Option<BufferId>) -> WindowId;
fn close_window(&mut self, window: WindowId) -> Result<(), WindowError>;
fn focus_window(&mut self, window: WindowId) -> Result<(), WindowError>;
fn set_window_buffer(&mut self, window: WindowId, buffer: BufferId) -> Result<(), WindowError>;
fn set_active_selection(&mut self, selection: Option<Selection>);
fn active_selection(&self) -> Option<&Selection>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WindowError {
NotFound(WindowId),
CannotCloseLastWindow,
BufferNotFound(BufferId),
}
impl std::fmt::Display for WindowError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotFound(id) => write!(f, "window not found: {id:?}"),
Self::CannotCloseLastWindow => write!(f, "cannot close last window"),
Self::BufferNotFound(id) => write!(f, "buffer not found: {id:?}"),
}
}
}
impl std::error::Error for WindowError {}
#[cfg(test)]
#[path = "tests/window.rs"]
mod tests;