mouse_input 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +60 -0
- data/bin/mouse_input +8 -0
- data/lib/mouse_input/input.rb +32 -0
- data/lib/mouse_input/terminal.rb +33 -0
- data/lib/mouse_input/version.rb +7 -0
- data/lib/mouse_input.rb +24 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '09050a87c6483508fe73feb165c208906fcd2b9d64e70d5df6bf09a5d40add89'
|
4
|
+
data.tar.gz: f422fcecb9f71b6511d8aa8b75666b83d5360698281458f0f20715716a949f45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd5cb3deab22b4a6771fe8d5318f28d3b9c29820388705a48eb0b5fd273d3758681c21e553049c129b92066492eddf277aee1970610ff85f49c3db7141602940
|
7
|
+
data.tar.gz: '09376e2b8262a01a9bbb3da8ea9037e1a6b5f0869207e2fe6f111e9caba052daae7427fb264da7535d864f96a74f38503736cd67c7bc80a75abdfd84e191589e'
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# MouseInput
|
2
|
+
|
3
|
+
[](https://github.com/XAJX179/mouse_input/actions/workflows/documentation.yml)
|
4
|
+
[](https://github.com/XAJX179/mouse_input/actions/workflows/rubocop.yml)
|
5
|
+
[](https://github.com/XAJX179/mouse_input/actions/workflows/tests.yml)
|
6
|
+
|
7
|
+
get mouse click input inside terminal.
|
8
|
+
|
9
|
+
> [!NOTE]
|
10
|
+
> supported in most - Xfce Terminal, GNOME Terminal, Konsole, Alacritty,
|
11
|
+
> Kitty, ITerm2, etc
|
12
|
+
>
|
13
|
+
> requirement is support for SGR mode(CSI?1006h)
|
14
|
+
|
15
|
+
> [!IMPORTANT]
|
16
|
+
> tmux users must `:set mouse on` to enable mouse mode
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Install the gem and add to the application's Gemfile by executing:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
bundle add mouse_input
|
24
|
+
```
|
25
|
+
|
26
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
gem install mouse_input
|
30
|
+
```
|
31
|
+
|
32
|
+
## Test it
|
33
|
+
|
34
|
+
after installing the gem -
|
35
|
+
run `mouse_input` in your terminal and click anywhere in terminal
|
36
|
+
```bash
|
37
|
+
mouse_input
|
38
|
+
```
|
39
|
+
if you see X and Y coordinates printed correctly it works
|
40
|
+
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
```rb
|
45
|
+
require 'mouse_input'
|
46
|
+
coords = MouseInput.Read # listens for mouse click and returns X and Y coords.
|
47
|
+
pp coords # will print X and Y coords
|
48
|
+
```
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/XAJX179/mouse_input. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/XAJX179/mouse_input/blob/main/CODE_OF_CONDUCT.md).
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
57
|
+
|
58
|
+
## Code of Conduct
|
59
|
+
|
60
|
+
Everyone interacting in the MouseInput project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/XAJX179/mouse_input/blob/main/CODE_OF_CONDUCT.md).
|
data/bin/mouse_input
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Mouse Input for terminal
|
4
|
+
module MouseInput
|
5
|
+
# Mouse reader and parser
|
6
|
+
module Mouse
|
7
|
+
# listen input from mouse
|
8
|
+
# returns the coords X and Y
|
9
|
+
# @return [Array(x,y)]
|
10
|
+
def self.read_input
|
11
|
+
while (char = $stdin.getc)
|
12
|
+
break if char == "\e"
|
13
|
+
end
|
14
|
+
parse_input(char)
|
15
|
+
end
|
16
|
+
|
17
|
+
# reads whole input sequence and returns the coords X and Y
|
18
|
+
# @param char [Char]
|
19
|
+
# @return [Array(x,y)]
|
20
|
+
def self.parse_input(char)
|
21
|
+
sequence = char + $stdin.read(17)
|
22
|
+
# storing anything left out here
|
23
|
+
sequence += $stdin.getc while $stdin.ready?
|
24
|
+
input = sequence.split(";")
|
25
|
+
x = input[1].to_i
|
26
|
+
# for y the to_i will only take the first number from e.g "34M[0;12;0"
|
27
|
+
# ignoring everything after the first non Integer
|
28
|
+
y = input[2].to_i
|
29
|
+
[x, y]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Mouse Input for terminal
|
4
|
+
module MouseInput
|
5
|
+
# Terminal settings
|
6
|
+
module Terminal
|
7
|
+
# setup terminal for reading input
|
8
|
+
def self.setup
|
9
|
+
system("stty -icanon -echo") # Disable canonical mode and echo in terminal
|
10
|
+
enable_mouse_tracking
|
11
|
+
end
|
12
|
+
|
13
|
+
# enable the mouse tracking using control sequences -
|
14
|
+
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
|
15
|
+
def self.enable_mouse_tracking
|
16
|
+
print "\e[?1000h" # Enable normal mouse tracking
|
17
|
+
print "\e[?1006h" # Enable SGR mouse tracking
|
18
|
+
end
|
19
|
+
|
20
|
+
# undo the setup for reading input
|
21
|
+
def self.restore
|
22
|
+
disable_mouse_tracking
|
23
|
+
system("stty icanon echo") # Restore terminal to sane mode
|
24
|
+
end
|
25
|
+
|
26
|
+
# disable the mouse tracking using control sequences -
|
27
|
+
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
|
28
|
+
def self.disable_mouse_tracking
|
29
|
+
print "\e[?1006l" # Disable SGR mouse tracking
|
30
|
+
print "\e[?1000l" # Disable normal mouse tracking
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/mouse_input.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# for using $stdin.ready? you must require io/wait
|
4
|
+
# docs: https://docs.ruby-lang.org/en/3.4/IO.html#method-i-ready-3F
|
5
|
+
require "io/wait"
|
6
|
+
require_relative "mouse_input/terminal"
|
7
|
+
require_relative "mouse_input/input"
|
8
|
+
require_relative "mouse_input/version"
|
9
|
+
|
10
|
+
# Mouse Input for terminal
|
11
|
+
module MouseInput
|
12
|
+
# read mouse input and
|
13
|
+
# returns the coords X and Y
|
14
|
+
# @return [Array(x,y)]
|
15
|
+
def self.read
|
16
|
+
begin
|
17
|
+
Terminal.setup
|
18
|
+
coords = Mouse.read_input
|
19
|
+
ensure
|
20
|
+
Terminal.restore
|
21
|
+
end
|
22
|
+
coords
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mouse_input
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- X_AJ_X
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: io-wait
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.3.2
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.3.2
|
26
|
+
description: |-
|
27
|
+
Mouse click input listener ,
|
28
|
+
requirement: any modern terminal.(supported in most -
|
29
|
+
Xfce Terminal, GNOME Terminal, Konsole, Alacritty, Kitty, ITerm2, etc)
|
30
|
+
email:
|
31
|
+
- xajx179@gmail.com
|
32
|
+
executables:
|
33
|
+
- mouse_input
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files:
|
36
|
+
- README.md
|
37
|
+
files:
|
38
|
+
- README.md
|
39
|
+
- bin/mouse_input
|
40
|
+
- lib/mouse_input.rb
|
41
|
+
- lib/mouse_input/input.rb
|
42
|
+
- lib/mouse_input/terminal.rb
|
43
|
+
- lib/mouse_input/version.rb
|
44
|
+
homepage: https://xajx179.github.io/mouse_input
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
homepage_uri: https://xajx179.github.io/mouse_input
|
49
|
+
source_code_uri: https://github.com/XAJX179/mouse_input
|
50
|
+
rubygems_mfa_required: 'true'
|
51
|
+
post_install_message: Thanks for installing! by X_AJ_X
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.2.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.7.1
|
67
|
+
specification_version: 4
|
68
|
+
summary: read mouse clicks for terminal!
|
69
|
+
test_files: []
|