Build prompt line

This commit is contained in:
daa 2017-11-19 23:13:06 +03:00
parent f58e398c48
commit 519c279c8d
1 changed files with 16 additions and 3 deletions

View File

@ -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, Value>, 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<char>)> = 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<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 {
popover: gtk::Popover,
levels: Vec<Level>,