Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
76
akode-rs/tui/src/activation_key_guard.rs
Normal file
76
akode-rs/tui/src/activation_key_guard.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
//! Keep a held activation key from triggering another action.
|
||||
//!
|
||||
//! Terminals with enhanced keyboard reporting distinguish a held `Repeat` from a fresh `Press`.
|
||||
//! A view transition on a press-only terminal can use a bounded window to block ambiguous presses.
|
||||
|
||||
use crate::key_hint::KeyBinding;
|
||||
use crossterm::event::KeyEventKind;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
const INITIAL_GUARD: Duration = Duration::from_secs(/*secs*/ 1);
|
||||
const LEGACY_REPEAT_GUARD: Duration = Duration::from_secs(/*secs*/ 1);
|
||||
|
||||
pub(crate) enum ActivationKeySuppression {
|
||||
ViewTransition,
|
||||
ReportedRepeats,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct ActivationKeyGuard {
|
||||
key: KeyBinding,
|
||||
block_until: Instant,
|
||||
legacy_repeat_fallback: bool,
|
||||
active: bool,
|
||||
}
|
||||
|
||||
impl ActivationKeyGuard {
|
||||
pub(crate) fn new_at(key: KeyBinding, now: Instant, reported_repeats_only: bool) -> Self {
|
||||
Self {
|
||||
key,
|
||||
block_until: now.checked_add(INITIAL_GUARD).unwrap_or(now),
|
||||
legacy_repeat_fallback: !reported_repeats_only,
|
||||
active: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn consume(&mut self, key: KeyBinding, kind: KeyEventKind) -> bool {
|
||||
self.consume_at(key, kind, Instant::now())
|
||||
}
|
||||
|
||||
fn consume_at(&mut self, key: KeyBinding, kind: KeyEventKind, now: Instant) -> bool {
|
||||
if !self.active {
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.key.is_same_physical_key(key) {
|
||||
if kind == KeyEventKind::Release {
|
||||
self.active = false;
|
||||
return true;
|
||||
}
|
||||
// Without the legacy fallback, only a reported Repeat is treated as held.
|
||||
if !self.legacy_repeat_fallback && kind == KeyEventKind::Press {
|
||||
self.active = false;
|
||||
return false;
|
||||
}
|
||||
if kind == KeyEventKind::Repeat || now <= self.block_until {
|
||||
let repeat_until = now.checked_add(LEGACY_REPEAT_GUARD).unwrap_or(now);
|
||||
self.block_until = self.block_until.max(repeat_until);
|
||||
return true;
|
||||
}
|
||||
self.active = false;
|
||||
} else if matches!(kind, KeyEventKind::Press | KeyEventKind::Repeat) {
|
||||
self.active = false;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub(crate) fn is_active(self) -> bool {
|
||||
self.active
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "activation_key_guard_tests.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user