nui 0.0.1

Experimental neovim RPC for UI clients
Documentation
use rmpv::Value;

use super::ParseError;

#[derive(Debug)]
pub struct HighlightAttributeDefine {
    pub id: i64,
    pub rgb: Option<Vec<(String, String)>>,
    pub cterm: Option<Vec<(String, String)>>,
    pub info: Option<i64>,
}

impl TryFrom<&Vec<Value>> for HighlightAttributeDefine {
    type Error = ParseError;

    fn try_from(values: &Vec<Value>) -> Result<Self, Self::Error> {
        dbg!(&values);

        Ok(Self {
            id: 1,
            rgb: None,
            cterm: None,
            info: None,
        })
    }
}

#[derive(Debug)]
pub struct HighlightGroupSet {
    pub name: String,
    pub hl_id: i64,
}

impl TryFrom<&Vec<Value>> for HighlightGroupSet {
    type Error = ParseError;

    fn try_from(values: &Vec<Value>) -> Result<Self, Self::Error> {
        dbg!(&values);

        Ok(Self {
            name: String::from("test"),
            hl_id: 1,
        })
    }
}

#[derive(Debug)]
pub struct GridLineCell {
    pub text: String,
    pub hl_id: Option<i64>,
    pub repeat: Option<i64>,
}

impl TryFrom<&Value> for GridLineCell {
    type Error = ParseError;

    fn try_from(value: &Value) -> Result<Self, Self::Error> {
        let cell = value.as_array().unwrap();
        let text = cell.get(0).unwrap().as_str().unwrap().to_owned();
        let hl_id = match cell.get(1) {
            Some(value) => Some(value.as_i64().unwrap()),
            None => None,
        };
        let repeat = match cell.get(2) {
            Some(value) => Some(value.as_i64().unwrap()),
            None => None,
        };

        Ok(Self {
            text,
            hl_id,
            repeat,
        })
    }
}

#[derive(Debug)]
pub struct GridLine {
    pub grid: i64,
    pub row: i64,
    pub column_start: i64,
    pub cells: Vec<GridLineCell>,
}

impl TryFrom<&Vec<Value>> for GridLine {
    type Error = ParseError;

    fn try_from(value: &Vec<Value>) -> Result<Self, Self::Error> {
        let grid = value.get(0).unwrap().as_i64().unwrap();
        let row = value.get(1).unwrap().as_i64().unwrap();
        let column_start = value.get(2).unwrap().as_i64().unwrap();
        let cells = value.get(3).unwrap().as_array().unwrap().into_iter();

        let mut parsed_cells = Vec::<GridLineCell>::with_capacity(cells.len());
        for cell in cells {
            if let Ok(cell) = GridLineCell::try_from(cell) {
                parsed_cells.push(cell);
            }
        }

        Ok(GridLine {
            grid,
            row,
            column_start,
            cells: parsed_cells,
        })
    }
}

#[derive(Debug)]
pub struct GridClear {
    pub grid: i64,
}

impl TryFrom<&Vec<Value>> for GridClear {
    type Error = ParseError;

    fn try_from(values: &Vec<Value>) -> Result<Self, Self::Error> {
        todo!();
    }
}

#[derive(Debug)]
pub struct GridDestroy {
    pub grid: i64,
}

impl TryFrom<&Vec<Value>> for GridDestroy {
    type Error = ParseError;

    fn try_from(values: &Vec<Value>) -> Result<Self, Self::Error> {
        todo!();
    }
}

#[derive(Debug)]
pub struct GridResize {
    pub grid: i64,
    pub width: i64,
    pub height: i64,
}

impl TryFrom<&Vec<Value>> for GridResize {
    type Error = ParseError;

    fn try_from(value: &Vec<Value>) -> Result<Self, Self::Error> {
        todo!()
    }
}

#[derive(Debug)]
pub struct GridCursorGoto {
    pub grid: i64,
    pub row: i64,
    pub column: i64,
}

impl TryFrom<&Vec<Value>> for GridCursorGoto {
    type Error = ParseError;

    fn try_from(value: &Vec<Value>) -> Result<Self, Self::Error> {
        todo!()
    }
}

#[derive(Debug)]
pub struct GridScroll {
    pub grid: i64,
    pub top: i64,
    pub bottom: i64,
    pub left: i64,
    pub right: i64,
    pub rows: i64,
    pub columns: i64,
}

impl TryFrom<&Vec<Value>> for GridScroll {
    type Error = ParseError;

    fn try_from(value: &Vec<Value>) -> Result<Self, Self::Error> {
        todo!()
    }
}