aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 902f939..3e5ff55 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,4 +1,4 @@
1use crate::consts::FONT_PATH; 1use crate::{consts::FONT_PATH, lisp::error::LispError, message::Message};
2use sdl2::{ 2use sdl2::{
3 keyboard::{Keycode, Mod}, 3 keyboard::{Keycode, Mod},
4 pixels::Color, 4 pixels::Color,
@@ -26,7 +26,10 @@ pub fn draw_text<S: AsRef<str>>(
26 let mut font = ttf_context.load_font(FONT_PATH, 17).unwrap(); 26 let mut font = ttf_context.load_font(FONT_PATH, 17).unwrap();
27 font.set_style(sdl2::ttf::FontStyle::NORMAL); 27 font.set_style(sdl2::ttf::FontStyle::NORMAL);
28 font.set_hinting(sdl2::ttf::Hinting::Mono); 28 font.set_hinting(sdl2::ttf::Hinting::Mono);
29 let surface = font.render(text.as_ref()).blended(color).unwrap(); 29 let surface = font
30 .render(if text.is_empty() { " " } else { text.as_ref() })
31 .blended(color)
32 .unwrap();
30 let texture = texture_creator 33 let texture = texture_creator
31 .create_texture_from_surface(&surface) 34 .create_texture_from_surface(&surface)
32 .unwrap(); 35 .unwrap();
@@ -43,3 +46,12 @@ pub fn is_copy_event(keycode: Option<Keycode>, keymod: Mod) -> bool {
43pub fn is_paste_event(keycode: Option<Keycode>, keymod: Mod) -> bool { 46pub fn is_paste_event(keycode: Option<Keycode>, keymod: Mod) -> bool {
44 keycode == Some(Keycode::V) && (keymod == Mod::LCTRLMOD || keymod == Mod::RCTRLMOD) 47 keycode == Some(Keycode::V) && (keymod == Mod::LCTRLMOD || keymod == Mod::RCTRLMOD)
45} 48}
49
50pub fn handle_error(err: LispError, src: &str) -> Message {
51 let mut message = Message::new();
52 match err {
53 LispError::Parse(p) => message.set_error(p.display(&src)),
54 eval_err => message.set_error(eval_err.to_string()),
55 }
56 message
57}