Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
termion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
termion
Commits
f2cec304
Commit
f2cec304
authored
8 years ago
by
ticki
Browse files
Options
Downloads
Patches
Plain Diff
Default to the TTY device in async_stdin.
parent
0d1025c5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Cargo.toml
+1
-1
1 addition, 1 deletion
Cargo.toml
src/async.rs
+10
-5
10 additions, 5 deletions
src/async.rs
with
11 additions
and
6 deletions
Cargo.toml
+
1
−
1
View file @
f2cec304
[package]
name
=
"termion"
version
=
"1.1.
0
"
version
=
"1.1.
1
"
authors
=
[
"ticki <Ticki@users.noreply.github.com>"
]
description
=
"A bindless library for manipulating terminals."
repository
=
"https://github.com/ticki/termion"
...
...
This diff is collapsed.
Click to expand it.
src/async.rs
+
10
−
5
View file @
f2cec304
...
...
@@ -2,20 +2,23 @@ use std::io::{self, Read};
use
std
::
sync
::
mpsc
;
use
std
::
thread
;
/// Construct an asynchronous handle to the standard input.
use
tty
;
/// Construct an asynchronous handle to the TTY standard input.
///
/// This allows you to read from standard input _without blocking_ the current thread.
/// Specifically, it works by firing up another thread to handle the event stream, which will then
/// be buffered in a mpsc queue, which will eventually be read by the current thread.
///
/// Note that this will acquire the Mutex lock on the standard input, making all future stdin
/// construction hang the program until the reader is dropped.
/// This will not read the piped standard input, but rather read from the TTY device, since reading
/// asyncronized from piped input would rarely make sense. In other words, if you pipe standard
/// output from another process, it won't be reflected in the stream returned by this function, as
/// this represents the TTY device, and not the piped standard input.
pub
fn
async_stdin
()
->
AsyncReader
{
let
(
send
,
recv
)
=
mpsc
::
channel
();
thread
::
spawn
(
move
||
{
let
stdin
=
io
::
stdin
();
for
i
in
stdin
.lock
()
.bytes
()
{
for
i
in
tty
::
get_tty
()
.unwrap
()
.bytes
()
{
if
send
.send
(
i
)
.is_err
()
{
return
;
}
...
...
@@ -36,6 +39,8 @@ pub struct AsyncReader {
recv
:
mpsc
::
Receiver
<
io
::
Result
<
u8
>>
,
}
// FIXME: Allow constructing an async reader from an arbitrary stream.
impl
Read
for
AsyncReader
{
/// Read from the byte stream.
///
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment