Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
termion
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Bradshaw
termion
Commits
994b0af7
Commit
994b0af7
authored
Jul 24, 2017
by
ticki
Committed by
GitHub
Jul 24, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #115 from redox-os/redox_termios
Implement size and is_tty with termios on Redox
parents
dbf6546b
5fdabb43
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
Cargo.toml
Cargo.toml
+5
-0
src/lib.rs
src/lib.rs
+6
-0
src/size.rs
src/size.rs
+13
-8
src/tty.rs
src/tty.rs
+9
-2
No files found.
Cargo.toml
View file @
994b0af7
...
...
@@ -11,3 +11,8 @@ exclude = ["target", "CHANGELOG.md", "image.png", "Cargo.lock"]
[target.'cfg(not(target_os
=
"redox"
))
'.dependencies]
libc
=
"0.2.8"
[target.'cfg(target_os
=
"redox"
)
'.dependencies]
redox_syscall
=
"0.1"
redox_termios
=
"0.1"
src/lib.rs
View file @
994b0af7
...
...
@@ -17,6 +17,12 @@ extern crate libc;
#[cfg(not(target_os
=
"redox"
))]
mod
termios
;
#[cfg(target_os
=
"redox"
)]
extern
crate
redox_termios
;
#[cfg(target_os
=
"redox"
)]
extern
crate
syscall
;
mod
async
;
pub
use
async
::{
AsyncReader
,
async_stdin
};
...
...
src/size.rs
View file @
994b0af7
...
...
@@ -57,16 +57,21 @@ pub fn terminal_size() -> io::Result<(u16, u16)> {
/// Get the size of the terminal.
#[cfg(target_os
=
"redox"
)]
pub
fn
terminal_size
()
->
io
::
Result
<
(
u16
,
u16
)
>
{
use
std
::
env
;
use
redox_termios
;
use
syscall
;
let
width
=
try!
(
env
::
var
(
"COLUMNS"
)
.map_err
(|
x
|
io
::
Error
::
new
(
io
::
ErrorKind
::
NotFound
,
x
)))
.parse
()
.unwrap_or
(
0
);
let
height
=
try!
(
env
::
var
(
"LINES"
)
.map_err
(|
x
|
io
::
Error
::
new
(
io
::
ErrorKind
::
NotFound
,
x
)))
.parse
()
.unwrap_or
(
0
);
if
let
Ok
(
fd
)
=
syscall
::
dup
(
1
,
b
"winsize"
)
{
let
mut
winsize
=
redox_termios
::
Winsize
::
default
();
let
res
=
syscall
::
read
(
fd
,
&
mut
winsize
);
let
_
=
syscall
::
close
(
fd
);
if
let
Ok
(
count
)
=
res
{
if
count
==
winsize
.len
()
{
return
Ok
((
winsize
.ws_col
,
winsize
.ws_row
));
}
}
}
Ok
((
width
,
height
))
Err
(
io
::
Error
::
new
(
io
::
ErrorKind
::
Other
,
"Unable to get the terminal size."
))
}
#[cfg(test)]
...
...
src/tty.rs
View file @
994b0af7
...
...
@@ -11,8 +11,15 @@ pub fn is_tty<T: AsRawFd>(stream: &T) -> bool {
/// This will panic.
#[cfg(target_os
=
"redox"
)]
pub
fn
is_tty
<
T
:
AsRawFd
>
(
_
stream
:
&
T
)
->
bool
{
unimplemented!
();
pub
fn
is_tty
<
T
:
AsRawFd
>
(
stream
:
&
T
)
->
bool
{
use
syscall
;
if
let
Ok
(
fd
)
=
syscall
::
dup
(
stream
.as_raw_fd
(),
b
"termios"
)
{
let
_
=
syscall
::
close
(
fd
);
true
}
else
{
false
}
}
/// Get the TTY device.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment