-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from bash/windows
- Loading branch information
Showing
23 changed files
with
139 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod time_out; | ||
use time_out::*; | ||
mod poll; | ||
pub(crate) use poll::*; | ||
mod read_until; | ||
pub(crate) use read_until::*; | ||
mod term_reader; | ||
pub(crate) use term_reader::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use cfg_if::cfg_if; | ||
|
||
cfg_if! { | ||
if #[cfg(target_os = "macos")] { | ||
mod macos; | ||
pub(crate) use macos::*; | ||
} else if #[cfg(unix)] { | ||
mod unix; | ||
pub(crate) use unix::*; | ||
} else if #[cfg(windows)] { | ||
mod windows; | ||
pub(crate) use windows::*; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use super::super::read_timed_out; | ||
use std::io; | ||
use std::os::windows::io::AsRawHandle as _; | ||
use std::time::Duration; | ||
use terminal_trx::Transceive; | ||
use windows_sys::Win32::Foundation::{WAIT_ABANDONED, WAIT_OBJECT_0, WAIT_TIMEOUT}; | ||
use windows_sys::Win32::System::Threading::WaitForSingleObject; | ||
|
||
pub(crate) fn poll_read(terminal: &dyn Transceive, timeout: Duration) -> io::Result<()> { | ||
let handle = terminal.input_buffer_handle(); | ||
match unsafe { WaitForSingleObject(handle.as_raw_handle(), timeout.as_millis() as u32) } { | ||
// The state of the specified object is signaled. | ||
WAIT_OBJECT_0 => Ok(()), | ||
WAIT_ABANDONED | WAIT_TIMEOUT => Err(read_timed_out()), | ||
_ => Err(io::Error::last_os_error()), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use super::poll_read; | ||
use std::io; | ||
use std::time::{Duration, Instant}; | ||
use terminal_trx::Transceive; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct TermReader<R> { | ||
inner: R, | ||
timeout: Duration, | ||
first_read: Option<Instant>, | ||
} | ||
|
||
impl<R> io::Read for TermReader<R> | ||
where | ||
R: Transceive, | ||
{ | ||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
let timeout = self.remaining_timeout(); | ||
poll_read(&self.inner, timeout)?; | ||
self.inner.read(buf) | ||
} | ||
} | ||
|
||
impl<R> TermReader<R> { | ||
pub(crate) fn new(inner: R, timeout: Duration) -> Self { | ||
Self { | ||
inner, | ||
timeout, | ||
first_read: None, | ||
} | ||
} | ||
|
||
fn remaining_timeout(&mut self) -> Duration { | ||
let first_read = self.first_read.get_or_insert_with(Instant::now); | ||
self.timeout.saturating_sub(first_read.elapsed()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.