Commit d53e951c authored by Ticki's avatar Ticki

Work on the status bar

parent ecc743fb
......@@ -20,7 +20,7 @@ The bug causing these two bugs, is localised to be in position.rs. It resolves b
6) Now go one down
7) You'll end up on e, even though it should be d
- [ ] Crashes when:
- [x] Crashes when:
1) Write abc on line 1
2) Press o to go to the next line
3) Go to normal mode
......@@ -28,4 +28,4 @@ The bug causing these two bugs, is localised to be in position.rs. It resolves b
5) Type text
6) Out of bound (index) error
- [ ] When typing the first char in a line in normal insert mode, it wont go to the next char.
- [x] When typing the first char in a line in normal insert mode, it wont go to the next char.
......@@ -168,7 +168,14 @@ impl Editor {
self.goto(p);
}
},
_ => {},
Char(c) => {
self.status_bar.msg = format!("Unknown command: {}", c);
self.redraw_status_bar();
}
_ => {
self.status_bar.msg = format!("Unknown command");
self.redraw_status_bar();
},
},
Primitive(Insert(opt)) => {
self.insert(cmd.key, opt);
......
......@@ -64,6 +64,14 @@ impl Editor {
}
}
self.redraw_status_bar();
self.window.sync();
}
pub fn redraw_status_bar(&mut self) {
let h = self.window.height();
let w = self.window.width();
let mode = self.cursor().mode;
self.window.rect(0, h as isize - 18 - {
if mode == Mode::Primitive(PrimitiveMode::Prompt) {
18
......@@ -72,20 +80,14 @@ impl Editor {
}
}, w, 18, Color::rgba(74, 74, 74, 255));
for (n, c) in (if self.status_bar.mode.len() > w / (8 * 4) {
self.status_bar.mode.chars().take(w / (8 * 4) - 5).chain(vec!['.', '.', '.']).collect::<Vec<_>>()
} else {
self.status_bar.mode.chars().collect()
}).into_iter().enumerate() {
self.window.char(n as isize * 8, h as isize - 16 - 1 - {
if mode == Mode::Primitive(PrimitiveMode::Prompt) {
16 + 1 + 1
} else {
0
}
}, c, Color::WHITE);
}
let sb_mode = self.status_bar.mode.clone();
status_bar(self, sb_mode, 0, 4);
let sb_file = self.status_bar.file.clone();
status_bar(self, sb_file, 1, 4);
let sb_cmd = self.status_bar.cmd.clone();
status_bar(self, sb_cmd, 2, 4);
let sb_msg = self.status_bar.msg.clone();
status_bar(self, sb_msg, 3, 4);
for (n, c) in self.prompt.chars().enumerate() {
self.window.char(n as isize * 8, h as isize - 16 - 1, c, Color::WHITE);
......@@ -95,6 +97,29 @@ impl Editor {
}
}
fn status_bar(editor: &mut Editor, text: String, a: usize, b: usize) {
let h = editor.window.height();
let w = editor.window.width();
let (x, y) = editor.pos();
let mode = editor.cursor().mode;
for (n, c) in (if text.len() > w / (8 * b) {
text.chars().take(w / (8 * b) - 5).chain(vec!['.', '.', '.']).collect::<Vec<_>>()
} else {
text.chars().collect()
}).into_iter().enumerate() {
editor.window.char(((w * a) / b) as isize + (n as isize * 8), h as isize - 16 - 1 - {
if mode == Mode::Primitive(PrimitiveMode::Prompt) {
16 + 1 + 1
} else {
0
}
}, c, Color::WHITE);
}
}
/// The statubar (showing various info about the current state of the editor)
pub struct StatusBar {
/// The current mode
......@@ -114,7 +139,7 @@ impl StatusBar {
mode: "Normal".to_string(),
file: String::new(),
cmd: String::new(),
msg: String::new(),
msg: "Welcome to Sodium!".to_string(),
}
}
}
......@@ -23,7 +23,15 @@ impl Editor {
None
}
},
_ => None,
Char(c) => {
self.status_bar.msg = format!("Motion not defined: '{}'", c);
self.redraw_status_bar();
None
},
_ => {
self.status_bar.msg = format!("Motion not defined");
None
},
}
}
/// Convert an instruction to a motion (new coordinate) (unbounded)
......
......@@ -38,6 +38,8 @@ impl Editor {
.unwrap_or(Event::new())
.to_option() {
if k.pressed {
self.status_bar.cmd.push(k.character);
self.redraw_status_bar();
return k.character;
}
}
......@@ -54,9 +56,12 @@ impl Editor {
let mut shift = false;
let mut key = Key::Null;
self.status_bar.cmd = String::new();
// self.status_bar.cmd = String::new();
loop {
if let EventOption::Key(k) = self.window.poll().unwrap_or(Event::new()).to_option() {
let c = k.character;
match c {
'\0' => {
......@@ -79,6 +84,9 @@ impl Editor {
}
}
_ => if k.pressed {
self.status_bar.cmd.push(c);
self.redraw_status_bar();
match self.cursor().mode {
Mode::Primitive(_) => {
key = Key::Char(c);
......@@ -131,7 +139,8 @@ impl Editor {
n
//return Inst(if unset { Parameter::Null } else { Parameter::Int(n) }, Key::Char(c));
}
}
};
// self.status_bar.cmd.push(c);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment