aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-03-18 15:34:00 +0000
committerAkshay <[email protected]>2021-03-18 15:34:00 +0000
commit68bd6c2dfb0ed593c5e6deebe1d9753db90f03e1 (patch)
treeca3f173addd185172acb2c915501c812dedc1384 /src/app.rs
parentdf95b239e78121ddf4314d47e1c20dad626752fb (diff)
render cursor to command box, add readline keybinds
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/app.rs b/src/app.rs
index 9ba93f4..3571436 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,7 +1,7 @@
1use crate::{ 1use crate::{
2 bitmap::{MapPoint, Pixmap}, 2 bitmap::{MapPoint, Pixmap},
3 command::CommandBox, 3 command::CommandBox,
4 consts::colors::*, 4 consts::{colors::*, FONT_PATH},
5 dither, rect, 5 dither, rect,
6 symmetry::Symmetry, 6 symmetry::Symmetry,
7 undo::{ModifyRecord, OpKind, Operation, UndoStack}, 7 undo::{ModifyRecord, OpKind, Operation, UndoStack},
@@ -352,6 +352,20 @@ impl<'ctx> AppState<'ctx> {
352 BLACK, 352 BLACK,
353 (0, winsize_y - cmd_height), 353 (0, winsize_y - cmd_height),
354 ); 354 );
355
356 self.canvas.set_draw_color(PINK);
357 let mut font = self.ttf_context.load_font(FONT_PATH, 17).unwrap();
358 font.set_style(sdl2::ttf::FontStyle::NORMAL);
359 font.set_hinting(sdl2::ttf::Hinting::Mono);
360 let prev_text = &self.command_box.text[..self.command_box.cursor];
361 let prev_text_dim = font.size_of_latin1(prev_text.as_bytes()).unwrap();
362 let cursor = rect!(
363 prev_text_dim.0,
364 winsize_y - cmd_height + 2,
365 2,
366 cmd_height - 4
367 );
368 self.canvas.fill_rect(cursor).unwrap();
355 } 369 }
356 370
357 fn draw_mouse(&mut self) { 371 fn draw_mouse(&mut self) {
@@ -641,7 +655,9 @@ impl<'ctx> AppState<'ctx> {
641 } 655 }
642 } 656 }
643 if let Event::KeyDown { 657 if let Event::KeyDown {
644 keycode: Some(k), .. 658 keycode: Some(k),
659 keymod,
660 ..
645 } = event 661 } = event
646 { 662 {
647 match k { 663 match k {
@@ -651,9 +667,16 @@ impl<'ctx> AppState<'ctx> {
651 Keycode::Right => self.command_box.forward(), 667 Keycode::Right => self.command_box.forward(),
652 Keycode::Up => self.command_box.hist_prev(), 668 Keycode::Up => self.command_box.hist_prev(),
653 Keycode::Down => self.command_box.hist_next(), 669 Keycode::Down => self.command_box.hist_next(),
654 Keycode::Return => { 670 _ if keymod == Mod::LCTRLMOD => match k {
655 self.eval_command(); 671 Keycode::A => self.command_box.cursor_start(),
656 } 672 Keycode::E => self.command_box.cursor_end(),
673 Keycode::F => self.command_box.forward(),
674 Keycode::B => self.command_box.backward(),
675 Keycode::K => self.command_box.delete_to_end(),
676 Keycode::U => self.command_box.delete_to_start(),
677 _ => (),
678 },
679 Keycode::Return => self.eval_command(),
657 Keycode::Escape => { 680 Keycode::Escape => {
658 self.command_box.clear(); 681 self.command_box.clear();
659 self.mode = Mode::Draw; 682 self.mode = Mode::Draw;