Buffer OSC 0 terminal title writing

This commit is contained in:
Johannes Altmanninger
2025-04-08 19:49:32 +02:00
parent 15379ae409
commit 0ca08ce81d
2 changed files with 19 additions and 5 deletions

View File

@@ -9,6 +9,7 @@
use std::cell::{RefCell, RefMut};
use std::ffi::CStr;
use std::io::{Result, Write};
use std::ops::{Deref, DerefMut};
use std::os::fd::RawFd;
use std::sync::atomic::{AtomicU8, Ordering};
@@ -481,6 +482,20 @@ fn drop(&mut self) {
}
}
impl Deref for BufferedOutputter<'_> {
type Target = Outputter;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for BufferedOutputter<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<'a> Output for BufferedOutputter<'a> {
fn write_bytes(&mut self, buf: &[u8]) {
self.0.write_bytes(buf);

View File

@@ -4535,6 +4535,7 @@ pub fn reader_write_title(
Some(&mut lst),
/*apply_exit_status=*/ false,
);
let mut out = BufferedOutputter::new(Outputter::stdoutput());
if !lst.is_empty() {
let mut title_line = L!("\x1B]0;").to_owned();
for val in &lst {
@@ -4542,15 +4543,13 @@ pub fn reader_write_title(
}
title_line.push_str("\x07"); // BEL
let narrow = wcs2string(&title_line);
let _ = write_loop(&STDOUT_FILENO, &narrow);
out.write_bytes(&narrow);
}
Outputter::stdoutput()
.borrow_mut()
.set_color(RgbColor::RESET, RgbColor::RESET);
out.set_color(RgbColor::RESET, RgbColor::RESET);
if reset_cursor_position && !lst.is_empty() {
// Put the cursor back at the beginning of the line (issue #2453).
let _ = write_loop(&STDOUT_FILENO, b"\r");
out.write_bytes(b"\r");
}
}