Skip to content

Commit

Permalink
fix: check if stdin is terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
ccbrown committed Jan 8, 2025
1 parent e98418d commit 14af000
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/iocraft/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use futures::{
};
use std::{
collections::VecDeque,
io::{self, stdout, Write},
io::{self, stdin, stdout, IsTerminal, Write},
mem,
pin::Pin,
sync::{Arc, Mutex, Weak},
Expand Down Expand Up @@ -120,6 +120,7 @@ trait TerminalImpl: Write + Send {
}

struct StdTerminal {
input_is_terminal: bool,
dest: io::Stdout,
fullscreen: bool,
raw_mode_enabled: bool,
Expand Down Expand Up @@ -169,6 +170,10 @@ impl TerminalImpl for StdTerminal {
}

fn event_stream(&mut self) -> io::Result<BoxStream<'static, TerminalEvent>> {
if !self.input_is_terminal {
return Ok(stream::pending().boxed());
}

self.set_raw_mode_enabled(true)?;

Ok(EventStream::new()
Expand Down Expand Up @@ -207,6 +212,7 @@ impl StdTerminal {
}
Ok(Self {
dest,
input_is_terminal: stdin().is_terminal(),
fullscreen,
raw_mode_enabled: false,
enabled_keyboard_enhancement: false,
Expand Down

0 comments on commit 14af000

Please sign in to comment.