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
cfacc186
Commit
cfacc186
authored
8 years ago
by
gwenn
Browse files
Options
Downloads
Patches
Plain Diff
InputBuffer.read on windows (in progress)
parent
0c64a1ff
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/lib.rs
+41
-4
41 additions, 4 deletions
src/lib.rs
with
41 additions
and
4 deletions
src/lib.rs
+
41
−
4
View file @
cfacc186
...
@@ -895,10 +895,18 @@ fn stdout_handle() -> Result<Handle> {
...
@@ -895,10 +895,18 @@ fn stdout_handle() -> Result<Handle> {
#[cfg(windows)]
#[cfg(windows)]
struct
InputBuffer
(
winapi
::
HANDLE
);
struct
InputBuffer
(
winapi
::
HANDLE
);
#[cfg(windows)]
#[cfg(windows)]
impl
InputBuffer
{
fn
single_byte
(
c
:
u8
,
buf
:
&
mut
[
u8
])
->
io
::
Result
<
usize
>
{
buf
[
0
]
=
c
;
Ok
(
1
)
}
}
#[cfg(windows)]
impl
Read
for
InputBuffer
{
impl
Read
for
InputBuffer
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
io
::
Result
<
usize
>
{
fn
read
(
&
mut
self
,
buf
:
&
mut
[
u8
])
->
io
::
Result
<
usize
>
{
let
mut
rec
:
winapi
::
INPUT_RECORD
=
unsafe
{
mem
::
zeroed
()
};
let
mut
rec
:
winapi
::
INPUT_RECORD
=
unsafe
{
mem
::
zeroed
()
};
let
mut
count
=
0
;
let
mut
count
=
0
;
let
mut
esc_seen
=
false
;
loop
{
loop
{
check!
(
kernel32
::
ReadConsoleInputW
(
self
.0
,
&
mut
rec
,
1
as
winapi
::
DWORD
,
&
mut
count
));
check!
(
kernel32
::
ReadConsoleInputW
(
self
.0
,
&
mut
rec
,
1
as
winapi
::
DWORD
,
&
mut
count
));
...
@@ -910,14 +918,43 @@ impl Read for InputBuffer {
...
@@ -910,14 +918,43 @@ impl Read for InputBuffer {
continue
;
continue
;
}
}
let
key_event
=
unsafe
{
rec
.KeyEvent
()
};
let
key_event
=
unsafe
{
rec
.KeyEvent
()
};
if
key_event
.bKeyDown
==
0
&&
key_event
.wVirtualKeyCode
!=
winapi
::
VK_MENU
as
winapi
::
WORD
{
if
key_event
.bKeyDown
==
0
&&
key_event
.wVirtualKeyCode
!=
winapi
::
VK_MENU
as
winapi
::
WORD
{
continue
;
continue
;
}
}
if
key_event
.UnicodeChar
!=
0
{
let
ctrl
=
key_event
.dwControlKeyState
&
(
winapi
::
LEFT_CTRL_PRESSED
|
winapi
::
RIGHT_CTRL_PRESSED
)
==
(
winapi
::
LEFT_CTRL_PRESSED
|
winapi
::
RIGHT_CTRL_PRESSED
);
let
meta
=
(
key_event
.dwControlKeyState
&
(
winapi
::
LEFT_ALT_PRESSED
|
winapi
::
RIGHT_ALT_PRESSED
)
==
(
winapi
::
LEFT_ALT_PRESSED
|
winapi
::
RIGHT_ALT_PRESSED
))
||
esc_seen
;
let
utf16
=
key_event
.UnicodeChar
;
if
utf16
==
0
{
match
key_event
.wVirtualKeyCode
as
i32
{
winapi
::
VK_LEFT
=>
return
InputBuffer
::
single_byte
(
b'\x02'
,
buf
),
winapi
::
VK_RIGHT
=>
return
InputBuffer
::
single_byte
(
b'\x06'
,
buf
),
winapi
::
VK_UP
=>
return
InputBuffer
::
single_byte
(
b'\x10'
,
buf
),
winapi
::
VK_DOWN
=>
return
InputBuffer
::
single_byte
(
b'\x0e'
,
buf
),
// winapi::VK_DELETE => b"\x1b[3~",
winapi
::
VK_HOME
=>
return
InputBuffer
::
single_byte
(
b'\x01'
,
buf
),
winapi
::
VK_END
=>
return
InputBuffer
::
single_byte
(
b'\x05'
,
buf
),
_
=>
continue
,
};
}
else
if
utf16
==
27
{
esc_seen
=
true
;
continue
;
}
else
{
if
ctrl
{
}
else
if
meta
{
}
else
{
// return utf8.read(buf);
}
}
}
// TODO dwControlKeyState
// TODO wVirtualKeyCode WORD & winapi::VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_DELETE, VK_HOME, VK_END, VK_PRIOR, VK_NEXT c_int
unimplemented!
()
unimplemented!
()
}
}
}
}
...
...
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