~animations~

This commit is contained in:
Zacharias-Brohn
2025-12-15 23:31:42 +01:00
parent 567c403912
commit f304fd18a8
6 changed files with 612 additions and 35 deletions
+61
View File
@@ -3,6 +3,24 @@
use crate::keyboard::{query_response, KeyboardState};
use crate::vt_parser::{CsiParams, Handler, Parser};
/// Commands that the terminal can send to the application.
/// These are triggered by special escape sequences from programs like Neovim.
#[derive(Clone, Debug, PartialEq)]
pub enum TerminalCommand {
/// Navigate to a neighboring pane in the given direction.
/// Triggered by OSC 51;navigate;<direction> ST
NavigatePane(Direction),
}
/// Direction for pane navigation.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Direction {
Up,
Down,
Left,
Right,
}
/// A single cell in the terminal grid.
#[derive(Clone, Copy, Debug)]
pub struct Cell {
@@ -467,6 +485,9 @@ pub struct Terminal {
parser: Option<Parser>,
/// Performance timing stats (for debugging).
pub stats: ProcessingStats,
/// Command queue for terminal-to-application communication.
/// Commands are added by OSC handlers and consumed by the application.
command_queue: Vec<TerminalCommand>,
}
impl Terminal {
@@ -523,6 +544,7 @@ impl Terminal {
line_pool,
parser: Some(Parser::new()),
stats: ProcessingStats::default(),
command_queue: Vec::new(),
}
}
@@ -570,6 +592,13 @@ impl Terminal {
self.dirty_lines = [0u64; 4];
}
/// Take all pending commands from the queue.
/// Returns an empty Vec if no commands are pending.
#[inline]
pub fn take_commands(&mut self) -> Vec<TerminalCommand> {
std::mem::take(&mut self.command_queue)
}
/// Get the dirty lines bitmap (for passing to shm).
#[inline]
pub fn get_dirty_lines(&self) -> u64 {
@@ -1336,6 +1365,38 @@ impl Handler for Terminal {
}
}
}
// OSC 51 - ZTerm custom commands
// Format: OSC 51;command;args ST
// Currently supported:
// OSC 51;navigate;up/down/left/right ST - Navigate to neighboring pane
51 => {
if parts.len() >= 2 {
if let Ok(command) = std::str::from_utf8(parts[1]) {
match command {
"navigate" => {
if parts.len() >= 3 {
if let Ok(direction_str) = std::str::from_utf8(parts[2]) {
let direction = match direction_str {
"up" => Some(Direction::Up),
"down" => Some(Direction::Down),
"left" => Some(Direction::Left),
"right" => Some(Direction::Right),
_ => None,
};
if let Some(dir) = direction {
log::debug!("OSC 51: Navigate {:?}", dir);
self.command_queue.push(TerminalCommand::NavigatePane(dir));
}
}
}
}
_ => {
log::debug!("OSC 51: Unknown command '{}'", command);
}
}
}
}
}
_ => {
log::debug!("Unhandled OSC {}", osc_num);
}