mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: force ANSI for keyboard progressive enhancement on Windows (#2474)
This commit is contained in:
parent
a0c6842626
commit
faee35fc44
2 changed files with 15 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{io, ops::{Deref, DerefMut}, sync::atomic::{AtomicBool, AtomicU8, Ordering}};
|
use std::{io, ops::{Deref, DerefMut}, sync::atomic::{AtomicBool, AtomicU8, Ordering}};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crossterm::{event::{DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, execute, queue, style::Print, terminal::{LeaveAlternateScreen, SetTitle, disable_raw_mode, enable_raw_mode}};
|
use crossterm::{Command, event::{DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, execute, queue, style::Print, terminal::{LeaveAlternateScreen, SetTitle, disable_raw_mode, enable_raw_mode}};
|
||||||
use cursor::RestoreCursor;
|
use cursor::RestoreCursor;
|
||||||
use ratatui::{CompletedFrame, Frame, Terminal, backend::CrosstermBackend, buffer::Buffer, layout::Rect};
|
use ratatui::{CompletedFrame, Frame, Terminal, backend::CrosstermBackend, buffer::Buffer, layout::Rect};
|
||||||
use yazi_adapter::{Emulator, Mux};
|
use yazi_adapter::{Emulator, Mux};
|
||||||
|
|
@ -59,13 +59,11 @@ impl Term {
|
||||||
);
|
);
|
||||||
|
|
||||||
if CSI_U.load(Ordering::Relaxed) {
|
if CSI_U.load(Ordering::Relaxed) {
|
||||||
queue!(
|
PushKeyboardEnhancementFlags(
|
||||||
TTY.writer(),
|
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
|
||||||
PushKeyboardEnhancementFlags(
|
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS,
|
||||||
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
|
)
|
||||||
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
|
.write_ansi(&mut TTY.writer())?;
|
||||||
)
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
term.hide_cursor()?;
|
term.hide_cursor()?;
|
||||||
|
|
@ -76,7 +74,7 @@ impl Term {
|
||||||
|
|
||||||
fn stop(&mut self) -> Result<()> {
|
fn stop(&mut self) -> Result<()> {
|
||||||
if CSI_U.swap(false, Ordering::Relaxed) {
|
if CSI_U.swap(false, Ordering::Relaxed) {
|
||||||
execute!(TTY.writer(), PopKeyboardEnhancementFlags)?;
|
PopKeyboardEnhancementFlags.write_ansi(&mut TTY.writer())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
execute!(
|
execute!(
|
||||||
|
|
@ -93,7 +91,7 @@ impl Term {
|
||||||
|
|
||||||
pub(super) fn goodbye(f: impl FnOnce() -> bool) -> ! {
|
pub(super) fn goodbye(f: impl FnOnce() -> bool) -> ! {
|
||||||
if CSI_U.swap(false, Ordering::Relaxed) {
|
if CSI_U.swap(false, Ordering::Relaxed) {
|
||||||
execute!(TTY.writer(), PopKeyboardEnhancementFlags).ok();
|
PopKeyboardEnhancementFlags.write_ansi(&mut TTY.writer()).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !MGR.title_format.is_empty() {
|
if !MGR.title_format.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,14 @@ impl Read for TtyReader<'_> {
|
||||||
// --- Writer
|
// --- Writer
|
||||||
pub struct TtyWriter<'a>(&'a Mutex<BufWriter<Handle>>);
|
pub struct TtyWriter<'a>(&'a Mutex<BufWriter<Handle>>);
|
||||||
|
|
||||||
impl Write for TtyWriter<'_> {
|
impl std::io::Write for TtyWriter<'_> {
|
||||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { self.0.lock().write(buf) }
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { self.0.lock().write(buf) }
|
||||||
|
|
||||||
fn flush(&mut self) -> std::io::Result<()> { self.0.lock().flush() }
|
fn flush(&mut self) -> std::io::Result<()> { self.0.lock().flush() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Write for TtyWriter<'_> {
|
||||||
|
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||||
|
self.0.lock().write_all(s.as_bytes()).map_err(|_| std::fmt::Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue