mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
147e7118e0
This PR adds a new `tui.notifications_method` config option that accepts values of "auto", "osc9" and "bel". It defaults to "auto", which attempts to auto-detect whether the terminal supports OSC 9 escape sequences and falls back to BEL if not. The PR also removes the inconsistent handling of notifications on Windows when WSL was used.
38 lines
825 B
Rust
38 lines
825 B
Rust
use std::fmt;
|
|
use std::io;
|
|
use std::io::stdout;
|
|
|
|
use crossterm::Command;
|
|
use ratatui::crossterm::execute;
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct BelBackend;
|
|
|
|
impl BelBackend {
|
|
pub fn notify(&mut self, _message: &str) -> io::Result<()> {
|
|
execute!(stdout(), PostNotification)
|
|
}
|
|
}
|
|
|
|
/// Command that emits a BEL desktop notification.
|
|
#[derive(Debug, Clone)]
|
|
pub struct PostNotification;
|
|
|
|
impl Command for PostNotification {
|
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
|
write!(f, "\x07")
|
|
}
|
|
|
|
#[cfg(windows)]
|
|
fn execute_winapi(&self) -> io::Result<()> {
|
|
Err(std::io::Error::other(
|
|
"tried to execute PostNotification using WinAPI; use ANSI instead",
|
|
))
|
|
}
|
|
|
|
#[cfg(windows)]
|
|
fn is_ansi_code_supported(&self) -> bool {
|
|
true
|
|
}
|
|
}
|