use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use super::types::{
BufferId, BufferInfo, CursorInfo, ModeInfo, ScreenFormat, ScreenInfo, SelectionInfo,
WindowInfo, WireLayoutInfo, WireRect, WireWindowId,
};
pub type StateCursorResult = CursorInfo;
pub type StateModeResult = ModeInfo;
pub type StateSelectionResult = SelectionInfo;
pub type StateScreenResult = ScreenInfo;
pub type StateLayoutResult = WireLayoutInfo;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StateWindowContentResult {
pub window_id: WireWindowId,
pub bounds: WireRect,
pub format: ScreenFormat,
pub content: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StateOptionsResult {
pub options: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScreenContentResult {
pub width: u16,
pub height: u16,
pub format: ScreenFormat,
pub content: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BufferListResult {
pub buffers: Vec<BufferInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BufferContentResult {
pub content: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BufferOpenResult {
pub buffer_id: BufferId,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WindowsResult {
pub windows: Vec<WindowInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct OkResult {
#[serde(default = "default_ok")]
pub ok: bool,
}
const fn default_ok() -> bool {
true
}
impl OkResult {
#[must_use]
pub const fn new() -> Self {
Self { ok: true }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModuleInfo {
pub id: String,
pub name: String,
pub version: String,
pub state: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
pub is_static: bool,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub dependencies: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModuleListResult {
pub modules: Vec<ModuleInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModuleLoadResult {
pub module: ModuleInfo,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum KeyStatus {
Executed,
Pending,
NotFound,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InputKeysResult {
pub ok: bool,
pub status: KeyStatus,
}
impl InputKeysResult {
#[must_use]
pub const fn executed() -> Self {
Self {
ok: true,
status: KeyStatus::Executed,
}
}
#[must_use]
pub const fn pending() -> Self {
Self {
ok: true,
status: KeyStatus::Pending,
}
}
#[must_use]
pub const fn not_found() -> Self {
Self {
ok: true,
status: KeyStatus::NotFound,
}
}
}
#[cfg(test)]
#[path = "results_tests.rs"]
mod tests;