diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 3b82c6a..c46ed4b 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -13,6 +13,7 @@ pub struct Level { impl Level { const COLUMNS_STEP: u64 = 50; + const ROWS_STEP: u64 = 10; pub fn from( content: Vec<(HashMap, String)>, @@ -23,21 +24,33 @@ impl Level { level: u64, ) -> Self { //TODO: double width chars - //TODO: multiline prompt + let prompt = prompt_lines(firstc, prompt, indent); let content: Vec<(Attrs, Vec)> = content .iter() .map(|c| (Attrs::from_value_map(&c.0), c.1.chars().collect())) .collect(); - let width = content.iter().map(|c| c.1.len()).count() as u64 + indent + 1/*firstc*/; + let width = (content.iter().map(|c| c.1.len()).count() + prompt.last().map_or(0, |p| p.len())) as u64; let columns = ((width / Level::COLUMNS_STEP) + 1) * Level::COLUMNS_STEP; + let rows = ((prompt.len() as u64 / Level::ROWS_STEP) + 1) * Level::ROWS_STEP; + + let model = UiModel::new(rows, columns); - let model = UiModel::new(1, columns); Level { model } } } +fn prompt_lines(firstc: String, prompt: String, indent: u64) -> Vec> { + if !firstc.is_empty() { + vec![firstc.chars().chain((0..indent).map(|_| ' ')).collect()] + } else if !prompt.is_empty() { + prompt.lines().map(|l| l.chars().collect()).collect() + } else { + vec![] + } +} + pub struct CmdLine { popover: gtk::Popover, levels: Vec,