Skip to content

Commit f5beceb

Browse files
committed
refactor: refine debug log for process kevent
1 parent a4ed77a commit f5beceb

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/editor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ fn collect_new_phrases(intervals: &[Interval], symbols: &[Symbol]) -> Vec<(Vec<S
783783

784784
impl BasicEditor for Editor {
785785
fn process_keyevent(&mut self, key_event: KeyboardEvent) -> EditorKeyBehavior {
786-
debug!("process_keyevent: {:?}", key_event);
786+
debug!("process {}", key_event);
787787
self.shared.estimate.tick();
788788
// reset?
789789
self.shared.notice_buffer.clear();

src/input.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Input handling modules
22
3+
use std::fmt::Display;
4+
35
use keycode::Keycode;
46
use keysym::Keysym;
57

@@ -142,6 +144,43 @@ impl KeyboardEvent {
142144
}
143145
}
144146

147+
impl Display for KeyboardEvent {
148+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
149+
write!(f, "#KeyboardEvent(")?;
150+
write!(f, ":code {}", self.code.0)?;
151+
write!(f, " :ksym {}", self.ksym.0)?;
152+
if self.ksym.is_unicode() {
153+
write!(f, " :char '{}'", self.ksym.to_unicode())?;
154+
}
155+
if self.state != 0 {
156+
write!(f, " :state '")?;
157+
if self.is_state_on(KeyState::Control) {
158+
write!(f, "c")?;
159+
}
160+
if self.is_state_on(KeyState::Shift) {
161+
write!(f, "s")?;
162+
}
163+
if self.is_state_on(KeyState::Alt) {
164+
write!(f, "a")?;
165+
}
166+
if self.is_state_on(KeyState::Super) {
167+
write!(f, "S")?;
168+
}
169+
if self.is_state_on(KeyState::CapsLock) {
170+
write!(f, "C")?;
171+
}
172+
if self.is_state_on(KeyState::NumLock) {
173+
write!(f, "N")?;
174+
}
175+
if self.is_state_on(KeyState::Release) {
176+
write!(f, "R")?;
177+
}
178+
}
179+
write!(f, ")")?;
180+
Ok(())
181+
}
182+
}
183+
145184
#[derive(Clone, Copy, Debug)]
146185
pub struct KeyboardEventBuilder {
147186
evt: KeyboardEvent,

0 commit comments

Comments
 (0)