From 19771dbd1324126908939f6da98a35899f990e75 Mon Sep 17 00:00:00 2001 From: Justine Date: Sun, 25 Dec 2022 17:27:59 +0100 Subject: [PATCH] Felche gauche en cours --- src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1ff5d25..34e59d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ pub mod shell { use termion::event::Key; use termion::input::TermRead; use termion::raw::IntoRawMode; - use termion::color; + use termion::{color, cursor, cursor::DetectCursorPos}; use unicode_segmentation::UnicodeSegmentation; mod history; @@ -292,6 +292,20 @@ pub mod shell { write!(stdout, "{}", mycommand); }, + Key::Left => { + //La taille du prompt est incorrecte à cause des couleurs ! + let pr_length = prompt.chars().count(); + let curs_pos = stdout.cursor_pos().unwrap().0; + if usize::from(curs_pos) > pr_length { + write!(stdout, "1{:?}/2{}-{}", curs_pos, pr_length, cursor::Left(10)); + stdout.flush(); + } + }, + + Key::Right => { + print!("{}", cursor::Right(1)); + } + _ => (), }