aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 849ddea..93d9cb8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -197,8 +197,11 @@ impl Session {
let prompt = this.lock().unwrap().prompt.prompt().to_vec();
io::stdout().write_all(&prompt).unwrap();
let mut this = this.lock().unwrap();
- this.line.display_pre();
- this.line.display_post(b"");
+ if let Some(ti) = this.terminal_input.as_mut()
+ && let Some(pos) = ti.query_cursor_position()
+ {
+ this.line.set_begin_of_line(pos);
+ }
this.line.mark_dirty();
this.cohere().unwrap();
}
@@ -212,8 +215,6 @@ impl Session {
.cmd
.clone()
};
- io::stdout().write_all(&new).unwrap();
- io::stdout().flush().unwrap();
self.line.set_content(new).unwrap();
}
@@ -299,7 +300,6 @@ impl Session {
Ok(p) => p,
Err(_) => {
se.line.type_byte(b'\n').unwrap();
- print!("\r\n> ");
return;
}
};
@@ -340,23 +340,7 @@ impl Session {
/// do cleanup actions after a bunch of mutations.
fn cohere(&mut self) -> io::Result<()> {
- if self.line.is_dirty() {
- self.line.mark_clean();
-
- // overwrite line in terminal with syntax-highlighted line.
- if self.highlighter.enabled {
- let buf = self.line.into_bytes();
- let mut parser = parse::Cursor::new(&buf, parse::ParseMode::Completion);
- let _res = parse::Ast::parse(&mut parser);
- let mut stdout = io::stdout().lock();
- cursor::fmove_cursor(cursor::Direction::Left, self.line.left_len(), &mut stdout)?;
- self.highlighter
- .pretty_print(&buf, parser.highlights, &mut stdout)?;
- cursor::fmove_cursor(cursor::Direction::Left, self.line.right_len(), &mut stdout)?;
- stdout.flush()?;
- }
- }
-
+ self.line.highlight_syntax(&mut self.highlighter)?;
Ok(())
}
}