mirror of
https://github.com/helix-editor/termina.git
synced 2025-10-06 00:22:43 +02:00
Add back Drop glue for terminal types
It's somewhat catastrophic to not reset console mode and code pages on Windows - it seems to really mess up the terminal and can cause a crash - so I think it's fine to reset mode automatically on drop. While we're at it we might as well flush the writer buffers.
This commit is contained in:
@@ -70,7 +70,6 @@ fn main() -> io::Result<()> {
|
||||
other => eprintln!("unexpected event: {other:?}\r"),
|
||||
}
|
||||
}
|
||||
terminal.reset_mode()?;
|
||||
println!("Detected features: {features:?}");
|
||||
|
||||
Ok(())
|
||||
|
@@ -124,8 +124,6 @@ fn main() -> io::Result<()> {
|
||||
decreset!(SGRMouse),
|
||||
)?;
|
||||
|
||||
terminal.reset_mode()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use rustix::termios::{self, Termios};
|
||||
use std::{
|
||||
fs,
|
||||
io::{self, BufWriter, IsTerminal as _},
|
||||
io::{self, BufWriter, IsTerminal as _, Write as _},
|
||||
os::unix::prelude::*,
|
||||
};
|
||||
|
||||
@@ -141,12 +141,8 @@ impl Terminal for UnixTerminal {
|
||||
}
|
||||
|
||||
fn reset_mode(&mut self) -> io::Result<()> {
|
||||
termios::tcsetattr(
|
||||
self.write.get_ref(),
|
||||
termios::OptionalActions::Now,
|
||||
&self.original_termios,
|
||||
)?;
|
||||
Ok(())
|
||||
// NOTE: this is the same as entering cooked mode on Unix but involves more on Windows.
|
||||
self.enter_cooked_mode()
|
||||
}
|
||||
|
||||
fn get_dimensions(&self) -> io::Result<(u16, u16)> {
|
||||
@@ -174,6 +170,13 @@ impl Terminal for UnixTerminal {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for UnixTerminal {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.flush();
|
||||
let _ = self.reset_mode();
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Write for UnixTerminal {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.write.write(buf)
|
||||
|
@@ -392,6 +392,13 @@ impl Terminal for WindowsTerminal {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WindowsTerminal {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.flush();
|
||||
let _ = self.reset_mode();
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Write for WindowsTerminal {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.output.write(buf)
|
||||
|
Reference in New Issue
Block a user