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
b3e0bbdf
Unverified
Commit
b3e0bbdf
authored
7 years ago
by
ticki
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #127 from nivkner/term_size
use `TIOCGWINSZ` directly from `libc`
parents
52a22ea8
00f87e5e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sys/unix/size.rs
+2
-30
2 additions, 30 deletions
src/sys/unix/size.rs
with
2 additions
and
30 deletions
src/sys/unix/size.rs
+
2
−
30
View file @
b3e0bbdf
use
std
::{
io
,
mem
};
use
std
::{
io
,
mem
};
use
super
::
cvt
;
use
super
::
cvt
;
use
super
::
libc
::{
c_ushort
,
ioctl
,
STDOUT_FILENO
};
use
super
::
libc
::{
c_ushort
,
ioctl
,
STDOUT_FILENO
,
TIOCGWINSZ
};
#[repr(C)]
#[repr(C)]
struct
TermSize
{
struct
TermSize
{
...
@@ -10,39 +10,11 @@ struct TermSize {
...
@@ -10,39 +10,11 @@ struct TermSize {
_x
:
c_ushort
,
_x
:
c_ushort
,
_y
:
c_ushort
,
_y
:
c_ushort
,
}
}
#[cfg(target_os
=
"linux"
)]
pub
const
TIOCGWINSZ
:
usize
=
0x00005413
;
#[cfg(not(target_os
=
"linux"
))]
pub
const
TIOCGWINSZ
:
usize
=
0x40087468
;
// Since attributes on non-item statements is not stable yet, we use a function.
#[cfg(not(target_os
=
"android"
))]
#[cfg(not(target_os
=
"redox"
))]
#[cfg(target_pointer_width
=
"64"
)]
#[cfg(not(target_env
=
"musl"
))]
fn
tiocgwinsz
()
->
u64
{
TIOCGWINSZ
as
u64
}
#[cfg(not(target_os
=
"android"
))]
#[cfg(not(target_os
=
"redox"
))]
#[cfg(target_pointer_width
=
"32"
)]
#[cfg(not(target_env
=
"musl"
))]
fn
tiocgwinsz
()
->
u32
{
TIOCGWINSZ
as
u32
}
#[cfg(any(target_env
=
"musl"
,
target_os
=
"android"
))]
fn
tiocgwinsz
()
->
i32
{
TIOCGWINSZ
as
i32
}
/// Get the size of the terminal.
/// Get the size of the terminal.
pub
fn
terminal_size
()
->
io
::
Result
<
(
u16
,
u16
)
>
{
pub
fn
terminal_size
()
->
io
::
Result
<
(
u16
,
u16
)
>
{
unsafe
{
unsafe
{
let
mut
size
:
TermSize
=
mem
::
zeroed
();
let
mut
size
:
TermSize
=
mem
::
zeroed
();
cvt
(
ioctl
(
STDOUT_FILENO
,
tiocgwinsz
()
,
&
mut
size
as
*
mut
_
))
?
;
cvt
(
ioctl
(
STDOUT_FILENO
,
TIOCGWINSZ
,
&
mut
size
as
*
mut
_
))
?
;
Ok
((
size
.col
as
u16
,
size
.row
as
u16
))
Ok
((
size
.col
as
u16
,
size
.row
as
u16
))
}
}
}
}
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