Skip to content

Commit

Permalink
wip: to split
Browse files Browse the repository at this point in the history
  • Loading branch information
gwen-lg committed Oct 23, 2024
1 parent cba9940 commit f0fd697
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/glyph_asker_term.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ocs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f0fd697

Please sign in to comment.