Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-rust-mirrors-rustyline
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-rust-mirrors-rustyline
Commits
e487552b
Commit
e487552b
authored
9 years ago
by
Main
Browse files
Options
Downloads
Patches
Plain Diff
Removed the KEYPRESS enum because Rust doesn't support the FromPrimitive trait anymore
parent
a2eac621
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/lib.rs
+27
-24
27 additions, 24 deletions
src/lib.rs
with
27 additions
and
24 deletions
src/lib.rs
+
27
−
24
View file @
e487552b
...
...
@@ -11,27 +11,25 @@ use nix::sys::termios::{BRKINT, ICRNL, INPCK, ISTRIP, IXON, OPOST, CS8, ECHO, IC
static
MAX_LINE
:
i32
=
4096
;
static
UNSUPPORTED_TERM
:
[
&
'static
str
;
3
]
=
[
"dumb"
,
"cons25"
,
"emacs"
];
enum
KEYPRESS
{
NULL
=
0
,
// NULL
CTRLA
=
1
,
// C-a
CTRLB
=
2
,
// C-b
CTRLC
=
3
,
// C-c
CTRLD
=
4
,
// C-d
CTRLE
=
5
,
// C-e
CTRLF
=
6
,
// C-f
CTRLH
=
8
,
// C-h
TAB
=
9
,
// Tab
CTRLK
=
11
,
// C-k
CTRLL
=
12
,
// C-l
ENTER
=
13
,
// Enter
CTRLN
=
14
,
// C-n
CTRLP
=
16
,
// C-p
CTRLT
=
20
,
// C-t
CTRLU
=
21
,
// C-u
CTRLW
=
23
,
// C-w
ESC
=
27
,
// Esc
BACKSPACE
=
127
// Backspace
}
const
NULL
:
u8
=
0
;
// NULL
const
CTRLA
:
u8
=
1
;
// C-a
const
CTRLB
:
u8
=
2
;
// C-b
const
CTRLC
:
u8
=
3
;
// C-c
const
CTRLD
:
u8
=
4
;
// C-d
const
CTRLE
:
u8
=
5
;
// C-e
const
CTRLF
:
u8
=
6
;
// C-f
const
CTRLH
:
u8
=
8
;
// C-h
const
TAB
:
u8
=
9
;
// Tab
const
CTRLK
:
u8
=
11
;
// C-k
const
CTRLL
:
u8
=
12
;
// C-l
const
ENTER
:
u8
=
13
;
// Enter
const
CTRLN
:
u8
=
14
;
// C-n
const
CTRLP
:
u8
=
16
;
// C-p
const
CTRLT
:
u8
=
20
;
// C-t
const
CTRLU
:
u8
=
21
;
// C-u
const
CTRLW
:
u8
=
23
;
// C-w
const
ESC
:
u8
=
27
;
// Esc
const
BACKSPACE
:
u8
=
127
;
// Backspace
fn
is_a_tty
()
->
bool
{
let
isatty
=
unsafe
{
libc
::
isatty
(
libc
::
STDIN_FILENO
as
i32
)
}
!=
0
;
...
...
@@ -72,9 +70,14 @@ fn disable_raw_mode(original_termios: termios::Termios) -> Result<(), nix::Error
fn
readline_edit
()
->
Result
<
String
,
io
::
Error
>
{
let
mut
buffer
=
Vec
::
new
();
let
mut
input
:
[
u8
;
1
]
=
[
0
];
let
numread
=
io
::
stdin
()
.read
(
&
mut
input
)
.unwrap
();
buffer
.push
(
input
[
0
]);
println!
(
"{}"
,
input
[
0
]);
loop
{
let
numread
=
io
::
stdin
()
.read
(
&
mut
input
)
.unwrap
();
match
input
[
0
]
{
ENTER
=>
break
,
_
=>
{
print!
(
"{}"
,
input
[
0
]);
io
::
stdout
()
.flush
();
}
}
buffer
.push
(
input
[
0
]);
}
Ok
(
String
::
from_utf8
(
buffer
)
.unwrap
())
}
...
...
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