From f0fd69741f5653858ba6bc14c980b53b8492ff74 Mon Sep 17 00:00:00 2001 From: Gwen Lg Date: Thu, 17 Oct 2024 14:30:20 +0200 Subject: [PATCH] wip: to split --- src/glyph_asker_term.rs | 22 +++++++++++++++++----- src/ocs.rs | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/glyph_asker_term.rs b/src/glyph_asker_term.rs index d4cdb6b..2ddd025 100644 --- a/src/glyph_asker_term.rs +++ b/src/glyph_asker_term.rs @@ -1,6 +1,6 @@ use crate::ocs::{GlyphCharAsker, GlyphResult, Piece}; -use compact_str::ToCompactString; -use crossterm::event::{self, KeyCode, KeyEventKind}; +use compact_str::CompactString; +use crossterm::event::{self, KeyCode, KeyEventKind, KeyModifiers}; use image::{DynamicImage, GrayImage, Pixel, Rgb, RgbImage}; use ratatui::{prelude::Backend, Terminal}; use ratatui_image::{picker::Picker, StatefulImage}; @@ -68,11 +68,23 @@ where //frame.render_widget(msg, frame.area()); }) .unwrap(); + let mut characters = CompactString::default(); loop { - if let event::Event::Key(key) = event::read().unwrap() { - if key.kind == KeyEventKind::Press { + let event = event::read().unwrap(); + if let event::Event::Key(key) = event { + if key.modifiers.intersects(KeyModifiers::CONTROL) { + match key.code { + KeyCode::Char('c') => { + return GlyphResult::Abort; + } + _ => { + // Ignore other key if Ctrl is pressed} + } + } + } else if key.kind == KeyEventKind::Press { if let KeyCode::Char(char) = key.code { - let characters = char.to_compact_string(); + characters.push(char); + } else if key.code == KeyCode::Enter { return GlyphResult::Char(characters); } } diff --git a/src/ocs.rs b/src/ocs.rs index f5a33cf..42db4a5 100644 --- a/src/ocs.rs +++ b/src/ocs.rs @@ -202,6 +202,7 @@ impl ImagePieces { // test to get character for glyph let mut text = String::new(); self.lines.iter().try_for_each(|line| { + assert!(line.pieces.len() == line.spaces.len()); let line_base_y = line.base_y.unwrap(); line.pieces .iter()