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
redox-os
termion
Commits
59d4ae42
Commit
59d4ae42
authored
8 years ago
by
ticki
Browse files
Options
Downloads
Patches
Plain Diff
Fix mouse input
parent
30afb4c3
No related branches found
Branches containing commit
No related tags found
1 merge request
!31
Termion fmt overhaul
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/click.rs
+31
-0
31 additions, 0 deletions
examples/click.rs
src/event.rs
+8
-4
8 additions, 4 deletions
src/event.rs
with
39 additions
and
4 deletions
examples/click.rs
0 → 100644
+
31
−
0
View file @
59d4ae42
extern
crate
termion
;
use
termion
::
event
::{
Key
,
Event
,
MouseEvent
};
use
termion
::
input
::
TermRead
;
use
termion
::
raw
::
IntoRawMode
;
use
std
::
io
::{
Write
,
stdout
,
stdin
};
fn
main
()
{
let
stdin
=
stdin
();
let
mut
stdout
=
stdout
()
.into_raw_mode
()
.unwrap
()
.with_mouse
()
.unwrap
();
write!
(
stdout
,
"{}{}q to exit. Click, click, click!"
,
termion
::
clear
::
All
,
termion
::
cursor
::
Goto
(
1
,
1
))
.unwrap
();
stdout
.flush
()
.unwrap
();
for
c
in
stdin
.events
()
{
let
evt
=
c
.unwrap
();
match
evt
{
Event
::
Key
(
Key
::
Char
(
'q'
))
=>
break
,
Event
::
Mouse
(
me
)
=>
{
match
me
{
MouseEvent
::
Press
(
_
,
x
,
y
)
=>
{
write!
(
stdout
,
"{}x"
,
termion
::
cursor
::
Goto
(
x
,
y
))
.unwrap
();
},
_
=>
(),
}
}
_
=>
{}
}
stdout
.flush
()
.unwrap
();
}
}
This diff is collapsed.
Click to expand it.
src/event.rs
+
8
−
4
View file @
59d4ae42
...
...
@@ -19,8 +19,12 @@ pub enum Event {
#[derive(Debug,
Copy,
Clone,
PartialEq,
Eq,
Hash)]
pub
enum
MouseEvent
{
/// A mouse button was pressed.
///
/// The coordinates are one-based.
Press
(
MouseButton
,
u16
,
u16
),
/// A mouse button was released.
///
/// The coordinates are one-based.
Release
(
u16
,
u16
),
}
...
...
@@ -114,8 +118,8 @@ where I: Iterator<Item = Result<u8, Error>>
// X10 emulation mouse encoding: ESC [ CB Cx Cy (6 characters only).
let
cb
=
iter
.next
()
.unwrap
()
.unwrap
()
as
i8
-
32
;
// (1, 1) are the coords for upper left.
let
c
x
=
(
iter
.next
()
.unwrap
()
.unwrap
()
as
u8
-
1
)
.saturating_sub
(
32
)
as
u16
;
let
c
y
=
(
iter
.next
()
.unwrap
()
.unwrap
()
as
u8
-
1
)
.saturating_sub
(
32
)
as
u16
;
let
c
y
=
(
iter
.next
()
.unwrap
()
.unwrap
()
as
u8
)
.saturating_sub
(
32
)
as
u16
;
let
c
x
=
(
iter
.next
()
.unwrap
()
.unwrap
()
as
u8
)
.saturating_sub
(
32
)
as
u16
;
Event
::
Mouse
(
match
cb
&
0b11
{
0
=>
{
if
cb
&
0x40
!=
0
{
...
...
@@ -152,8 +156,8 @@ where I: Iterator<Item = Result<u8, Error>>
let
ref
mut
nums
=
str_buf
.split
(
';'
);
let
cb
=
nums
.next
()
.unwrap
()
.parse
::
<
u16
>
()
.unwrap
();
let
c
x
=
nums
.next
()
.unwrap
()
.parse
::
<
u16
>
()
.unwrap
()
-
1
;
let
c
y
=
nums
.next
()
.unwrap
()
.parse
::
<
u16
>
()
.unwrap
()
-
1
;
let
c
y
=
nums
.next
()
.unwrap
()
.parse
::
<
u16
>
()
.unwrap
();
let
c
x
=
nums
.next
()
.unwrap
()
.parse
::
<
u16
>
()
.unwrap
();
let
button
=
match
cb
{
0
=>
MouseButton
::
Left
,
...
...
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