Build prompt line

This commit is contained in:
daa 2017-11-19 23:13:06 +03:00
parent f58e398c48
commit 519c279c8d

View File

@ -13,6 +13,7 @@ pub struct Level {
impl Level { impl Level {
const COLUMNS_STEP: u64 = 50; const COLUMNS_STEP: u64 = 50;
const ROWS_STEP: u64 = 10;
pub fn from( pub fn from(
content: Vec<(HashMap<String, Value>, String)>, content: Vec<(HashMap<String, Value>, String)>,
@ -23,21 +24,33 @@ impl Level {
level: u64, level: u64,
) -> Self { ) -> Self {
//TODO: double width chars //TODO: double width chars
//TODO: multiline prompt
let prompt = prompt_lines(firstc, prompt, indent);
let content: Vec<(Attrs, Vec<char>)> = content let content: Vec<(Attrs, Vec<char>)> = content
.iter() .iter()
.map(|c| (Attrs::from_value_map(&c.0), c.1.chars().collect())) .map(|c| (Attrs::from_value_map(&c.0), c.1.chars().collect()))
.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 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 } Level { model }
} }
} }
fn prompt_lines(firstc: String, prompt: String, indent: u64) -> Vec<Vec<char>> {
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 { pub struct CmdLine {
popover: gtk::Popover, popover: gtk::Popover,
levels: Vec<Level>, levels: Vec<Level>,