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
c26d2f0a
Commit
c26d2f0a
authored
7 years ago
by
Matthias Devlamynck
Browse files
Options
Downloads
Patches
Plain Diff
Implement hide cursor wrapper type
parent
e07cae2a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cursor.rs
+46
-0
46 additions, 0 deletions
src/cursor.rs
with
46 additions
and
0 deletions
src/cursor.rs
+
46
−
0
View file @
c26d2f0a
//! Cursor movement.
use
std
::
fmt
;
use
std
::
ops
;
use
std
::
io
::{
self
,
Write
,
Error
,
ErrorKind
,
Read
};
use
async
::
async_stdin
;
use
std
::
time
::{
SystemTime
,
Duration
};
...
...
@@ -135,3 +136,48 @@ impl<W: Write> DetectCursorPos for W {
Ok
((
cx
,
cy
))
}
}
/// Hide the cursor for the lifetime of this struct.
/// It will hide the cursor on creation with from() and show it back on drop().
pub
struct
HideCursor
<
W
:
Write
>
{
/// The output target.
output
:
W
,
}
impl
<
W
:
Write
>
HideCursor
<
W
>
{
/// Create a hide cursor wrapper struct for the provided output and hides the cursor.
pub
fn
from
(
mut
output
:
W
)
->
Self
{
write!
(
output
,
"{}"
,
Hide
)
.expect
(
"hide the cursor"
);
HideCursor
{
output
:
output
}
}
}
impl
<
W
:
Write
>
Drop
for
HideCursor
<
W
>
{
fn
drop
(
&
mut
self
)
{
write!
(
self
,
"{}"
,
Show
)
.expect
(
"show the cursor"
);
}
}
impl
<
W
:
Write
>
ops
::
Deref
for
HideCursor
<
W
>
{
type
Target
=
W
;
fn
deref
(
&
self
)
->
&
W
{
&
self
.output
}
}
impl
<
W
:
Write
>
ops
::
DerefMut
for
HideCursor
<
W
>
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
W
{
&
mut
self
.output
}
}
impl
<
W
:
Write
>
Write
for
HideCursor
<
W
>
{
fn
write
(
&
mut
self
,
buf
:
&
[
u8
])
->
io
::
Result
<
usize
>
{
self
.output
.write
(
buf
)
}
fn
flush
(
&
mut
self
)
->
io
::
Result
<
()
>
{
self
.output
.flush
()
}
}
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