mod.rs - icy_draw - [fork] icy_draw is the successor to mystic draw.
HTML git clone https://git.drkhsh.at/icy_draw.git
DIR Log
DIR Files
DIR Refs
DIR README
---
mod.rs (1523B)
---
1 use codepages::tables::{CP437_TO_UNICODE, UNICODE_TO_CP437};
2
3 use super::BufferParser;
4 use crate::{AttributedChar, Buffer, CallbackAction, Caret, EngineResult, UnicodeConverter, BEL, BS, CR, FF, LF};
5 #[derive(Default)]
6 pub struct Parser {}
7
8 #[cfg(test)]
9 mod tests;
10
11 #[derive(Default)]
12 pub struct CP437Converter {}
13
14 impl UnicodeConverter for CP437Converter {
15 fn convert_from_unicode(&self, ch: char, _font_page: usize) -> char {
16 if let Some(tch) = UNICODE_TO_CP437.get(&ch) {
17 *tch as char
18 } else {
19 ch
20 }
21 }
22
23 fn convert_to_unicode(&self, attributed_char: AttributedChar) -> char {
24 match CP437_TO_UNICODE.get(attributed_char.ch as usize) {
25 Some(out_ch) => *out_ch,
26 _ => attributed_char.ch,
27 }
28 }
29 }
30
31 impl BufferParser for Parser {
32 fn print_char(&mut self, buf: &mut Buffer, current_layer: usize, caret: &mut Caret, ch: char) -> EngineResult<CallbackAction> {
33 match ch {
34 '\x00' | '\u{00FF}' => {
35 caret.reset_color_attribute();
36 }
37 BEL => {
38 return Ok(CallbackAction::Beep);
39 }
40 LF => return Ok(caret.lf(buf, current_layer)),
41 FF => caret.ff(buf, current_layer),
42 CR => caret.cr(buf),
43 BS => caret.bs(buf, current_layer),
44 '\x7F' => caret.del(buf, current_layer),
45 _ => buf.print_value(current_layer, caret, ch as u16),
46 }
47 Ok(CallbackAction::NoUpdate)
48 }
49 }