Starting point for special char processing

This commit is contained in:
daa 2018-02-27 22:51:23 +03:00
parent 4eb025ba91
commit c339a27481
4 changed files with 49 additions and 11 deletions

View File

@ -27,6 +27,11 @@ impl Level {
//TODO: double width chars render, also note in text wrapping //TODO: double width chars render, also note in text wrapping
//TODO: im //TODO: im
pub fn insert(&mut self, c: &str, shift: bool, render_state: &shell::RenderState) {
self.model_layout.insert(c, shift);
self.update_preferred_size(render_state);
}
pub fn replace_from_ctx(&mut self, ctx: &CmdLineContext, render_state: &shell::RenderState) { pub fn replace_from_ctx(&mut self, ctx: &CmdLineContext, render_state: &shell::RenderState) {
let content = ctx.get_lines(); let content = ctx.get_lines();
self.replace_line(&content.lines, false); self.replace_line(&content.lines, false);
@ -79,9 +84,7 @@ impl Level {
.map(|line_chars| { .map(|line_chars| {
line_chars line_chars
.iter() .iter()
.map(|c| { .map(|c| (Some(Attrs::from_value_map(&c.0)), c.1.chars().collect()))
(Some(Attrs::from_value_map(&c.0)), c.1.chars().collect())
})
.collect() .collect()
}) })
.collect() .collect()
@ -254,7 +257,6 @@ impl State {
} }
impl cursor::CursorRedrawCb for State { impl cursor::CursorRedrawCb for State {
fn queue_redraw_cursor(&mut self) { fn queue_redraw_cursor(&mut self) {
self.queue_redraw_cursor(); self.queue_redraw_cursor();
} }
@ -323,6 +325,26 @@ impl CmdLine {
} }
} }
pub fn special_char(
&self,
render_state: &shell::RenderState,
c: String,
shift: bool,
level: u64,
) {
let mut state = self.state.borrow_mut();
if let Some(level) = state.levels.get_mut((level - 1) as usize) {
level.insert(&c, shift, render_state);
level.update_cache(&*render_state);
} else {
error!("Level {} does not exists", level);
}
state.request_area_size();
state.drawing_area.queue_draw()
}
pub fn hide_level(&mut self, level_idx: u64) { pub fn hide_level(&mut self, level_idx: u64) {
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
@ -350,16 +372,13 @@ impl CmdLine {
state.request_area_size(); state.request_area_size();
} }
pub fn block_append(&mut self, content: &Vec<(HashMap<String, Value>, String)>) { pub fn block_append(&mut self, content: &Vec<(HashMap<String, Value>, String)>) {
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
let render_state = state.render_state.clone(); let render_state = state.render_state.clone();
{ {
let attr_content = content let attr_content = content
.iter() .iter()
.map(|c| { .map(|c| (Some(Attrs::from_value_map(&c.0)), c.1.chars().collect()))
(Some(Attrs::from_value_map(&c.0)), c.1.chars().collect())
})
.collect(); .collect();
let block = state.block.as_mut().unwrap(); let block = state.block.as_mut().unwrap();
@ -441,9 +460,7 @@ impl CmdLineContext {
fn get_lines(&self) -> LineContent { fn get_lines(&self) -> LineContent {
let content_line: Vec<(Option<Attrs>, Vec<char>)> = self.content let content_line: Vec<(Option<Attrs>, Vec<char>)> = self.content
.iter() .iter()
.map(|c| { .map(|c| (Some(Attrs::from_value_map(&c.0)), c.1.chars().collect()))
(Some(Attrs::from_value_map(&c.0)), c.1.chars().collect())
})
.collect(); .collect();
let (prompt_offset, prompt_lines) = prompt_lines(&self.firstc, &self.prompt, self.indent); let (prompt_offset, prompt_lines) = prompt_lines(&self.firstc, &self.prompt, self.indent);

View File

@ -95,6 +95,8 @@ pub trait RedrawEvents {
fn cmdline_block_hide(&mut self) -> RepaintMode; fn cmdline_block_hide(&mut self) -> RepaintMode;
fn cmdline_pos(&mut self, pos: u64, level: u64) -> RepaintMode; fn cmdline_pos(&mut self, pos: u64, level: u64) -> RepaintMode;
fn cmdline_special_char(&mut self, c: String, shift: bool, level: u64) -> RepaintMode;
} }
pub trait GuiApi { pub trait GuiApi {
@ -323,6 +325,7 @@ pub fn call(
"cmdline_hide" => call!(ui->cmdline_hide(args: uint)), "cmdline_hide" => call!(ui->cmdline_hide(args: uint)),
"cmdline_block_hide" => ui.cmdline_block_hide(), "cmdline_block_hide" => ui.cmdline_block_hide(),
"cmdline_pos" => call!(ui->cmdline_pos(args: uint, uint)), "cmdline_pos" => call!(ui->cmdline_pos(args: uint, uint)),
"cmdline_special_char" => call!(ui->cmdline_special_char(args: str, bool, uint)),
_ => { _ => {
warn!("Event {}({:?})", method, args); warn!("Event {}({:?})", method, args);
RepaintMode::Nothing RepaintMode::Nothing

View File

@ -1197,6 +1197,12 @@ impl RedrawEvents for State {
self.cmd_line.pos(&*render_state, pos, level); self.cmd_line.pos(&*render_state, pos, level);
RepaintMode::Nothing RepaintMode::Nothing
} }
fn cmdline_special_char(&mut self, c: String, shift: bool, level: u64) -> RepaintMode {
let render_state = self.render_state.borrow();
self.cmd_line.special_char(&*render_state, c, shift, level);
RepaintMode::Nothing
}
} }
impl CursorRedrawCb for State { impl CursorRedrawCb for State {

View File

@ -58,6 +58,18 @@ impl ModelLayout {
} }
} }
pub fn insert(&mut self, c: &str, shift: bool) {
if c.is_empty() {
return;
}
if shift {
//TODO: insert special char
} else {
self.model.put(c.chars().next().unwrap(), false, None);
}
}
/// Wrap all lines into model /// Wrap all lines into model
/// ///
/// returns actual width /// returns actual width