termcontroller 0.3 → 0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 137ab6e058cbc71d9ac66d57479fcb01a9ab87fb403c795c553c880498c21410
4
- data.tar.gz: b51e7f7353b269fc8e0375d858e9c0ee8605ea0e340b1c4f000ec4557e6ac281
3
+ metadata.gz: 04632d599e81a07a9dcda4090091356de0fe257b01342d31719937fd366ccf8f
4
+ data.tar.gz: 8f411109feb2e00122c80bb7be2978a19e4e1af94f131b66ff6a25476fd1eb99
5
5
  SHA512:
6
- metadata.gz: 4a1d7893783340263e8d92ed7503ef239b77407e4466305f2fbbb1700b73108bb34d23eb34f8fcb3f8680bf5ac40f191cce9eba7ff8d3188d4213c0885c04d16
7
- data.tar.gz: a6270a9cb7c27ee6744540013e6abc599851f846cc5b8b1a76bc08f34a4bc1784cf60ef89e999e588d653afa38f3e407f3d12c9ae4bfddf61e01529e8d5638ce
6
+ metadata.gz: 8b693ada8e7fab935972a7ad40944eac7da728f5292f81b7217c94839dd0ff06896f909ca13ed0dddc630258020d7fa0ed3c9e4eba36efe430b679a962526b68
7
+ data.tar.gz: 5b189f18f46ed86916cef9fedbc7b70766c3fe3d4d229c22c4f704c1b37e05610b2ed8396b324218ed865ba0f8a23ddb34b178a2eba1f80aa61728f06ac7a27f
data/Gemfile CHANGED
@@ -3,6 +3,6 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in termcontroller.gemspec
4
4
  gemspec
5
5
 
6
- gem "keyboard_map" #, path: "../keyboard_map"
6
+ gem "keyboard_map"
7
7
  gem "rake", "~> 12.0"
8
8
  gem "rspec", "~> 3.0"
data/examples/draw.rb ADDED
@@ -0,0 +1,57 @@
1
+
2
+ $: << File.expand_path(File.dirname(__FILE__)+"/../lib/")
3
+
4
+ require 'termcontroller'
5
+
6
+ class Target
7
+
8
+ def initialize
9
+ keymap = { :ctrl_c => :quit }
10
+ @ctrl = Termcontroller::Controller.new(self, keymap)
11
+ @c = " "
12
+ @col = 1
13
+ end
14
+
15
+ # If a method exists in the target class passed to Controller.new
16
+ # that matches the keymap, then it is called directly.
17
+ #
18
+ # In this case `quit` is defined in the map above,
19
+ # while `char` is a default.
20
+ #
21
+ # If nothing is mapped, then `handle_input` will return the
22
+ # symbol instead, as shown for `mouse_down`.
23
+ #
24
+ def quit = (@running = false)
25
+ def char(c) = (@c = c)
26
+
27
+ def call
28
+ @running = true
29
+ col = 1
30
+ while @running
31
+ cmd = @ctrl.handle_input
32
+ case cmd.first
33
+ when :mouse_down
34
+ print "\e[5;1H#{cmd.inspect}"
35
+ print "\e[#{cmd[3]};#{cmd[2]}H"
36
+ if cmd[1] & 3 == 0
37
+ # left
38
+ print "\e[4#{col}m#{@c}\e[49m"
39
+ print "\e[1;1H[DRAWING] "
40
+ elsif cmd[1] & 3 == 2
41
+ # right
42
+ print " "
43
+ print "\e[1;1H[ERASING] "
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+ print "\e[2J" # Clear screen
52
+ print "\e[4;1HHold left button and move mouse to draw; Hold right button and move to clear"
53
+ print "\e[3;1HPress any letter to set a character to fill with on draw."
54
+ print "\e[2;1HCtrl+c to quit"
55
+ Target.new.call
56
+ print "\e[2J" # Clear screen
57
+ print "\e[1;1H" # Move top left
@@ -93,11 +93,11 @@ module Termcontroller
93
93
  IO.console.cooked!
94
94
  cleanup
95
95
  r = yield
96
- setup
97
96
  r
98
97
  rescue Interrupt
99
98
  ensure
100
99
  @mode = old
100
+ setup
101
101
  end
102
102
  end
103
103
  end
@@ -123,6 +123,16 @@ module Termcontroller
123
123
  return Array(c)
124
124
  end
125
125
 
126
+ # USE WITH CAUTION. This will pause processing,
127
+ # yield to the provided block if any, and then send
128
+ # SIGSTOP to the process.
129
+ #
130
+ # This is meant to allow for handling ctrl-z to
131
+ # suspend in processes that need to be able to
132
+ # reset the terminal to a better state before stopping.
133
+ #
134
+ # FIXME: It seems like it does not work as expected.
135
+ #
126
136
  def suspend
127
137
  pause do
128
138
  yield if block_given?
@@ -136,6 +146,14 @@ module Termcontroller
136
146
  @commands << [:resume]
137
147
  end
138
148
 
149
+ def hide_cursor
150
+ STDOUT.print "\e[?25l" # Hide cursor
151
+ end
152
+
153
+ def show_cursor
154
+ STDOUT.print "\e[?25h" # Show cursor
155
+ end
156
+
139
157
  private # # ########################################################
140
158
 
141
159
  def setup
@@ -143,7 +161,7 @@ module Termcontroller
143
161
  STDOUT.print "\e[?1000h" # Enable mouse reporting
144
162
  STDOUT.print "\e[?1002h" # Enable mouse *move when clicked* reporting
145
163
  STDOUT.print "\e[?1006h" # Enable extended reporting
146
- STDOUT.print "\e[?25l" # Hide cursor
164
+ hide_cursor
147
165
  @con.raw!
148
166
  end
149
167
 
@@ -156,7 +174,7 @@ module Termcontroller
156
174
  @con.cooked!
157
175
  STDOUT.print "\e[?2004l" #Disable bracketed paste
158
176
  STDOUT.print "\e[?1000l" #Disable mouse reporting
159
- STDOUT.print "\e[?25h" # Show cursor
177
+ show_cursor
160
178
  end
161
179
 
162
180
  def quit
@@ -1,3 +1,3 @@
1
1
  module Termcontroller
2
- VERSION = "0.3"
2
+ VERSION = "0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termcontroller
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vidar Hokstad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-02 00:00:00.000000000 Z
11
+ date: 2025-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: keyboard_map
@@ -40,6 +40,7 @@ files:
40
40
  - Rakefile
41
41
  - bin/console
42
42
  - bin/setup
43
+ - examples/draw.rb
43
44
  - lib/termcontroller.rb
44
45
  - lib/termcontroller/controller.rb
45
46
  - lib/termcontroller/version.rb
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  - !ruby/object:Gem::Version
65
66
  version: '0'
66
67
  requirements: []
67
- rubygems_version: 3.1.4
68
+ rubygems_version: 3.4.10
68
69
  signing_key:
69
70
  specification_version: 4
70
71
  summary: Controller/input processing for terminal applications