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
a16cc84e
Commit
a16cc84e
authored
9 years ago
by
Ticki
Browse files
Options
Downloads
Patches
Plain Diff
Rename WriteExt to TermWrite
parent
62940e52
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/simple.rs
+1
-1
1 addition, 1 deletion
examples/simple.rs
src/control.rs
+6
-3
6 additions, 3 deletions
src/control.rs
src/input.rs
+2
-2
2 additions, 2 deletions
src/input.rs
src/lib.rs
+4
-4
4 additions, 4 deletions
src/lib.rs
with
13 additions
and
10 deletions
examples/simple.rs
+
1
−
1
View file @
a16cc84e
extern
crate
libterm
;
extern
crate
libterm
;
use
libterm
::{
TermControl
,
IntoRawMode
,
Color
,
Style
};
use
libterm
::{
WriteExt
,
IntoRawMode
,
Color
,
Style
};
use
std
::
io
::{
Read
,
Write
,
stdout
,
stdin
};
use
std
::
io
::{
Read
,
Write
,
stdout
,
stdin
};
fn
main
()
{
fn
main
()
{
...
...
This diff is collapsed.
Click to expand it.
src/control.rs
+
6
−
3
View file @
a16cc84e
use
std
::
io
::{
Write
,
Result
as
IoResult
};
use
std
::
io
::{
Write
,
Result
as
IoResult
};
use
{
Color
,
Style
};
use
{
Color
,
Style
};
/// Controlling terminals.
/// Extension to the `Write` trait.
pub
trait
TermControl
{
///
/// This extension to the `Write` trait is capable of producing the correct ANSI escape sequences
/// for given commands, effectively controlling the terminal.
pub
trait
TermWrite
{
/// Print the CSI (control sequence introducer) followed by a byte string.
/// Print the CSI (control sequence introducer) followed by a byte string.
fn
csi
(
&
mut
self
,
b
:
&
[
u8
])
->
IoResult
<
usize
>
;
fn
csi
(
&
mut
self
,
b
:
&
[
u8
])
->
IoResult
<
usize
>
;
...
@@ -111,7 +114,7 @@ pub trait TermControl {
...
@@ -111,7 +114,7 @@ pub trait TermControl {
}
}
}
}
impl
<
W
:
Write
>
Term
Control
for
W
{
impl
<
W
:
Write
>
Term
Write
for
W
{
fn
csi
(
&
mut
self
,
b
:
&
[
u8
])
->
IoResult
<
usize
>
{
fn
csi
(
&
mut
self
,
b
:
&
[
u8
])
->
IoResult
<
usize
>
{
self
.write
(
b"
\x1B
["
)
.and_then
(|
x
|
{
self
.write
(
b"
\x1B
["
)
.and_then
(|
x
|
{
self
.write
(
b
)
.map
(|
y
|
x
+
y
)
self
.write
(
b
)
.map
(|
y
|
x
+
y
)
...
...
This diff is collapsed.
Click to expand it.
src/
extra
.rs
→
src/
input
.rs
+
2
−
2
View file @
a16cc84e
...
@@ -2,7 +2,7 @@ use std::io::{Read, Write};
...
@@ -2,7 +2,7 @@ use std::io::{Read, Write};
use
{
IntoRawMode
,
TerminalError
};
use
{
IntoRawMode
,
TerminalError
};
/// Extension to `Read` trait.
/// Extension to `Read` trait.
pub
trait
Read
Ext
{
pub
trait
Term
Read
{
/// Read a password.
/// Read a password.
///
///
/// EOT and ETX will abort the prompt, returning `None`. Newline or carriage return will
/// EOT and ETX will abort the prompt, returning `None`. Newline or carriage return will
...
@@ -10,7 +10,7 @@ pub trait ReadExt {
...
@@ -10,7 +10,7 @@ pub trait ReadExt {
fn
read_passwd
<
W
:
Write
>
(
&
mut
self
,
writer
:
&
mut
W
)
->
Result
<
Option
<
String
>
,
TerminalError
>
;
fn
read_passwd
<
W
:
Write
>
(
&
mut
self
,
writer
:
&
mut
W
)
->
Result
<
Option
<
String
>
,
TerminalError
>
;
}
}
impl
<
R
:
Read
>
Read
Ext
for
R
{
impl
<
R
:
Read
>
Term
Read
for
R
{
fn
read_passwd
<
W
:
Write
>
(
&
mut
self
,
writer
:
&
mut
W
)
->
Result
<
Option
<
String
>
,
TerminalError
>
{
fn
read_passwd
<
W
:
Write
>
(
&
mut
self
,
writer
:
&
mut
W
)
->
Result
<
Option
<
String
>
,
TerminalError
>
{
let
_raw
=
try
!
(
writer
.into_raw_mode
());
let
_raw
=
try
!
(
writer
.into_raw_mode
());
let
mut
passbuf
=
Vec
::
with_capacity
(
30
);
let
mut
passbuf
=
Vec
::
with_capacity
(
30
);
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
4
−
4
View file @
a16cc84e
...
@@ -7,7 +7,10 @@ extern crate libc;
...
@@ -7,7 +7,10 @@ extern crate libc;
mod
termios
;
mod
termios
;
mod
control
;
mod
control
;
pub
use
control
::
TermControl
;
pub
use
control
::
WriteExt
;
mod
input
;
pub
use
input
::
ReadExt
;
mod
error
;
mod
error
;
pub
use
error
::
TerminalError
;
pub
use
error
::
TerminalError
;
...
@@ -23,6 +26,3 @@ pub use color::Color;
...
@@ -23,6 +26,3 @@ pub use color::Color;
mod
style
;
mod
style
;
pub
use
style
::
Style
;
pub
use
style
::
Style
;
mod
extra
;
pub
use
extra
::
ReadExt
;
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