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
akitsu-sanae
termion
Commits
54ce18f1
Commit
54ce18f1
authored
9 years ago
by
Ticki
Browse files
Options
Downloads
Patches
Plain Diff
Better documentation, fix TIOCGWINSZ
parent
34f1d6a4
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
examples/size.rs
+7
-0
7 additions, 0 deletions
examples/size.rs
src/extra.rs
+3
-0
3 additions, 0 deletions
src/extra.rs
src/lib.rs
+4
-1
4 additions, 1 deletion
src/lib.rs
src/size.rs
+3
-3
3 additions, 3 deletions
src/size.rs
src/termios.rs
+6
-2
6 additions, 2 deletions
src/termios.rs
with
23 additions
and
6 deletions
examples/size.rs
0 → 100644
+
7
−
0
View file @
54ce18f1
extern
crate
libterm
;
use
libterm
::
terminal_size
;
fn
main
()
{
println!
(
"Size is {:?}"
,
terminal_size
()
.unwrap
())
}
This diff is collapsed.
Click to expand it.
src/extra.rs
+
3
−
0
View file @
54ce18f1
...
...
@@ -4,6 +4,9 @@ use {IntoRawMode, TerminalError};
/// Extension to `Read` trait.
pub
trait
ReadExt
{
/// Read a password.
///
/// EOT and ETX will abort the prompt, returning `None`. Newline or carriage return will
/// complete the password input.
fn
read_passwd
<
W
:
Write
>
(
&
mut
self
,
writer
:
&
mut
W
)
->
Result
<
Option
<
String
>
,
TerminalError
>
;
}
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
4
−
1
View file @
54ce18f1
...
...
@@ -18,8 +18,11 @@ pub use error::TerminalError;
mod
raw
;
pub
use
raw
::{
IntoRawMode
,
TerminalRestorer
};
// TODO Redox terminal size
#[cfg(not(target_os
=
"redox"
))]
mod
size
;
pub
use
size
::
termsize
;
#[cfg(not(target_os
=
"redox"
))]
pub
use
size
::
terminal_size
;
mod
color
;
pub
use
color
::
Color
;
...
...
This diff is collapsed.
Click to expand it.
src/size.rs
+
3
−
3
View file @
54ce18f1
...
...
@@ -3,7 +3,7 @@ use libc::{c_ushort, STDOUT_FILENO};
use
std
::
mem
;
use
termios
::
tiocgwinsz
;
use
termios
::
TIOCGWINSZ
;
use
TerminalError
;
#[repr(C)]
...
...
@@ -16,11 +16,11 @@ struct TermSize {
/// Get the size of the terminal. If the program isn't running in a terminal, it will return
/// `None`.
pub
fn
termsize
()
->
Result
<
(
usize
,
usize
),
TerminalError
>
{
pub
fn
term
inal_
size
()
->
Result
<
(
usize
,
usize
),
TerminalError
>
{
unsafe
{
let
mut
size
:
TermSize
=
mem
::
zeroed
();
if
ioctl
(
STDOUT_FILENO
,
tiocgwinsz
as
u64
,
&
mut
size
as
*
mut
_
)
==
0
{
if
ioctl
(
STDOUT_FILENO
,
TIOCGWINSZ
,
&
mut
size
as
*
mut
_
)
==
0
{
Ok
((
size
.col
as
usize
,
size
.row
as
usize
))
}
else
{
Err
(
TerminalError
::
TermSizeError
)
...
...
This diff is collapsed.
Click to expand it.
src/termios.rs
+
6
−
2
View file @
54ce18f1
use
libc
::{
c_int
,
c_uint
,
c_uchar
};
extern
{
pub
static
tiocgwinsz
:
c_int
;
#[cfg(not(target_os
=
"macos"
))]
pub
const
TIOCGWINSZ
:
u64
=
0x00005413
;
#[cfg(target_os
=
"macos"
)]
pub
const
TIOCGWINSZ
:
u64
=
0x40087468
;
extern
{
pub
fn
tcgetattr
(
filedes
:
c_int
,
termptr
:
*
mut
Termios
)
->
c_int
;
pub
fn
tcsetattr
(
filedes
:
c_int
,
opt
:
c_int
,
termptr
:
*
mut
Termios
)
->
c_int
;
pub
fn
cfmakeraw
(
termptr
:
*
mut
Termios
);
...
...
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