Ereigniszustellung und Hostgrenzen korrigieren und Change archivieren
This commit is contained in:
@@ -86,7 +86,33 @@ impl Host for TerminalHost {
|
||||
self.start.elapsed().as_millis() as u64
|
||||
}
|
||||
|
||||
fn warten(&mut self, deadline_ms: Option<u64>) -> Option<Ereignis> {
|
||||
loop {
|
||||
if let Some(e) = self.next_event(false) {
|
||||
return Some(e);
|
||||
}
|
||||
let timeout = match deadline_ms {
|
||||
Some(deadline) => {
|
||||
let rest = deadline.saturating_sub(self.jetzt_ms());
|
||||
if rest == 0 {
|
||||
return None;
|
||||
}
|
||||
Duration::from_millis(rest.min(10))
|
||||
}
|
||||
None => Duration::from_millis(10),
|
||||
};
|
||||
// Begrenzt warten, damit auch SIGINT/SIGTERM ohne Terminaltaste
|
||||
// abgeholt werden. Die VM kennt dieses Backend-Intervall nicht.
|
||||
if event::poll(timeout).is_err() {
|
||||
return Some(Ereignis::Ende);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn next_event(&mut self, blockierend: bool) -> Option<Ereignis> {
|
||||
if blockierend {
|
||||
return self.warten(None);
|
||||
}
|
||||
loop {
|
||||
// Signale vor dem Terminal: sie liegen schon an, wenn wir hier
|
||||
// ankommen, und ein blockierendes `read` wuerde sie liegenlassen.
|
||||
@@ -181,7 +207,7 @@ fn taste_zu_ereignis(k: KeyEvent) -> Option<Ereignis> {
|
||||
KeyCode::Enter => taste::ENTER.to_string(),
|
||||
KeyCode::Backspace => taste::BACKSPACE.to_string(),
|
||||
KeyCode::Esc => taste::ESC.to_string(),
|
||||
KeyCode::Tab => taste::TAB.to_string(),
|
||||
KeyCode::Tab | KeyCode::BackTab => taste::TAB.to_string(),
|
||||
// Sondertasten in der Kodierung des Vorbilds: Nullzeichen + Kennung.
|
||||
KeyCode::F(n @ 1..=10) => taste::sonder(58 + n),
|
||||
KeyCode::Home => taste::sonder(71),
|
||||
@@ -197,7 +223,7 @@ fn taste_zu_ereignis(k: KeyEvent) -> Option<Ereignis> {
|
||||
_ => return None,
|
||||
};
|
||||
let mut shift = 0u8;
|
||||
if k.modifiers.contains(KeyModifiers::SHIFT) {
|
||||
if k.modifiers.contains(KeyModifiers::SHIFT) || k.code == KeyCode::BackTab {
|
||||
shift |= umschalt::SHIFT;
|
||||
}
|
||||
if k.modifiers.contains(KeyModifiers::CONTROL) {
|
||||
@@ -213,6 +239,16 @@ fn taste_zu_ereignis(k: KeyEvent) -> Option<Ereignis> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn backtab_ist_tab_mit_shift_auch_ohne_modifier() {
|
||||
for modifiers in [KeyModifiers::NONE, KeyModifiers::SHIFT, KeyModifiers::ALT] {
|
||||
assert_eq!(
|
||||
taste_zu_ereignis(KeyEvent::new(KeyCode::BackTab, modifiers)),
|
||||
taste_zu_ereignis(KeyEvent::new(KeyCode::Tab, modifiers | KeyModifiers::SHIFT))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zeichentaste_wird_zu_inkey_form() {
|
||||
let k = KeyEvent::new(KeyCode::Char('a'), KeyModifiers::NONE);
|
||||
|
||||
Reference in New Issue
Block a user