diff --git a/kkdisp/src/component.rs b/kkdisp/src/component.rs index 3728ec6..0e11984 100644 --- a/kkdisp/src/component.rs +++ b/kkdisp/src/component.rs @@ -11,6 +11,27 @@ pub enum Component { Bg(Color), } +impl Component { + fn make_for_line( + comp: Vec, + line: usize, + offset: usize, + ) -> String { + comp.into_iter() + .map(|c| match c { + Component::X(x) => termion::cursor::Goto( + (x + offset) as u16, + line as u16, + ) + .into(), + Component::String(s) => s, + Component::Fg(c) => c.fg(), + Component::Bg(c) => c.bg(), + }) + .collect() + } +} + impl PartialEq for Component { fn eq(&self, other: &Self) -> bool { match self { @@ -131,11 +152,34 @@ impl PartialEq for Instruction { } impl Instruction { - pub fn make( + pub fn make_lines( self, - (term_width, term_height): (u16, u16), - ) -> String { - todo!() + line_width: usize, + height_left: usize, + ) -> Vec { + if height_left == 0 { + return vec![]; + } + match self { + Instruction::FixedHeight(next, lines, wdg) => { + let mut offset = 0; + let wdg = wdg.into_iter().map(|wdg| { + let width = wdg.want_width.abs_size(line_width); + (width, wdg) + }); + (0..lines).zip(wdg).map(|(line_index, (width, widget))|{ + todo!(); + }) + let xxx = + next.make_lines(line_width, height_left - lines); + todo!() + } + Instruction::End => todo!(), + } + // let xxx = (0..term_height).map(|index| { + // todo!(); + // }); + // todo!() } pub fn start() -> Self { diff --git a/kkdisp/src/token.rs b/kkdisp/src/token.rs index c155093..638dd3f 100644 --- a/kkdisp/src/token.rs +++ b/kkdisp/src/token.rs @@ -76,7 +76,7 @@ impl Token { Self::Bg(Box::new(self), c) } - fn with_width(self, width: usize) -> Vec { + pub fn with_width(self, width: usize) -> Vec { match self { Token::String(t, s) => vec![Component::String(s)] .into_iter()