rcurses 3.8.1 → 4.0

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: ce853c344b8eb5bf0f3cf398344fd038a54052687036dacd3ffe9030eb9d0ed2
4
- data.tar.gz: bd6899c2572a9d663bb02436061733f369cb8857d19bce499d737dae2f683785
3
+ metadata.gz: 64fede93e0d646b947c3cf6c3217a1aa7bf62f923b724a4dd55b02e3981b8593
4
+ data.tar.gz: 3dca4a698dbbc31356e50e322d3e52ba2c0d6a574b7b824e6d6fe7d5d5b49dd2
5
5
  SHA512:
6
- metadata.gz: d9d6db33bd763b7f2f6db4098babede2d6500b3a3d10d467849457791e2ed8a5975eacbfd7c5376fda1b1592401024ddb2f952631a82c45dc5b101a0b89bb583
7
- data.tar.gz: 0e4ce716e6398e86c213105932345215e684ec4b7e02b9a3332e513c73a5cf4f5664fd1cc11b706e550ce398745be49191a2faeb3cbfe394d819cc442dd631f1
6
+ metadata.gz: e866db8fa1db394653b90a88c73632d024b7b565db7f984360004b6d4bb4b83c56650e2784669bf827f32585dbbbb9918f98016d5a6612ee39ff352e194b7f84
7
+ data.tar.gz: 67ceadf4ccb04fb5708e0faa33253099156cddedd9fe906d5d24a11d9ccfeac836a945ff7990f19df380f64061a986836a6432206e5f7a8cd09cb6f9e112e81b
data/README.md CHANGED
@@ -6,6 +6,10 @@
6
6
 
7
7
  Create curses applications for the terminal easier than ever.
8
8
 
9
+ Here's a somewhat simple example of a TUI program using rcurses: The [T-REX](https://github.com/isene/T-REX) calculator.
10
+
11
+ And here's a much more involved example: The [RTFM](https://github.com/isene/RTFM) terminal file manager.
12
+
9
13
  # Why?
10
14
  Having struggled with the venerable curses library and the ruby interface to it for many years, I finally got around to write an alternative - in pure Ruby.
11
15
 
@@ -239,6 +243,17 @@ mypane.edit
239
243
 
240
244
  And - try running the example file `rcurses_example.rb`.
241
245
 
246
+ # Clean exit for your application
247
+ To restore the terminal fully after you exit your application, add this:
248
+ ```
249
+ at_exit do # Always restore terminal state on quit (or fatal)
250
+ $stdin.cooked!
251
+ $stdin.echo = true
252
+ Rcurses.clear_screen
253
+ Cursor.show
254
+ end
255
+ ```
256
+
242
257
  # Not yet implemented
243
258
  Let me know what other features you like to see.
244
259
 
@@ -35,3 +35,9 @@ pane_mid.refresh
35
35
  pane_bottom.prompt = "Now hit ENTER again "
36
36
  pane_bottom.text = ""
37
37
  pane_bottom.editline
38
+
39
+ # Reset terminal
40
+ $stdin.cooked!
41
+ $stdin.echo = true
42
+ Rcurses::clear_screen
43
+ Rcurses::Cursor.show
@@ -7,11 +7,11 @@ include Rcurses::Cursor
7
7
  @max_h, @max_w = IO.console.winsize
8
8
  @pane = []
9
9
  @focused = 3 # Start with pane 3 so that the first keypress focuses back to Pane 0
10
- hide_cursor
10
+ Rcurses::Cursor.hide
11
11
 
12
12
  # Start by creating the panes; Format:
13
13
  # pane = Rcurses::Pane.new( startx, starty, width, height, fg, bg)
14
- pane_back = Rcurses::Pane.new( 1, 1, @max_w, @max_h, 255, 236)
14
+ pane_back = Rcurses::Pane.new( 1, 1, @max_w, @max_h, nil, 236)
15
15
  @pane[0] = Rcurses::Pane.new( 4, 4, 20, 10, 236, 254)
16
16
  @pane[1] = Rcurses::Pane.new( 30, 10, 16, 12, 232, 132)
17
17
  @pane[2] = Rcurses::Pane.new( 8, 20, 30, 20, 136, 54)
@@ -19,21 +19,24 @@ pane_back = Rcurses::Pane.new( 1, 1, @max_w, @max_h, 255, 236)
19
19
 
20
20
  pane_back.text = "PRESS ANY KEY TO SHIFT FOCUS. PRESS 'ESC' TO QUIT."
21
21
  @pane.each_index { |i| @pane[i].text = "This is pane " + i.to_s }
22
- pane_back.refresh
22
+ pane_back.full_refresh
23
23
  @pane.each_index { |i| @pane[i].refresh }
24
24
 
25
25
  input = ''
26
26
  while input != 'ESC'
27
27
  input = getchr
28
- @pane[@focused].border = false
28
+ pane_back.full_refresh
29
29
  @focused += 1
30
30
  @focused = 0 if @focused == @pane.size
31
+ @pane.each_index {|i| @pane[i].border = false}
32
+ @pane.each_index {|i| @pane[i].full_refresh}
31
33
  @pane[@focused].border = true
32
- pane_back.refresh
33
- @pane.each_index { |i| @pane[i].refresh }
34
- @pane[@focused].refresh
34
+ @pane[@focused].full_refresh
35
35
  end
36
- col(1)
37
- row(1)
38
- clear_screen_down
39
- show_cursor
36
+
37
+ # Always end an application with these lines:
38
+ $stdin.cooked!
39
+ $stdin.echo = true
40
+ Rcurses.clear_screen
41
+ Rcurses::Cursor.show
42
+
data/lib/rcurses/pane.rb CHANGED
@@ -128,6 +128,35 @@ module Rcurses
128
128
  refresh(cont)
129
129
  end
130
130
 
131
+ # Refresh only the border
132
+ def border_refresh
133
+ left_col = @x - 1
134
+ right_col = @x + @w
135
+ top_row = @y - 1
136
+ bottom_row = @y + @h
137
+
138
+ if @border
139
+ fmt = [@fg.to_s, @bg.to_s].join(',')
140
+ top = ("┌" + "─" * @w + "┐").c(fmt)
141
+ STDOUT.print "\e[#{top_row};#{left_col}H" + top
142
+ (0...@h).each do |i|
143
+ row = @y + i
144
+ STDOUT.print "\e[#{row};#{left_col}H" + "│".c(fmt)
145
+ STDOUT.print "\e[#{row};#{right_col}H" + "│".c(fmt)
146
+ end
147
+ bottom = ("└" + "─" * @w + "┘").c(fmt)
148
+ STDOUT.print "\e[#{bottom_row};#{left_col}H" + bottom
149
+ else
150
+ STDOUT.print "\e[#{top_row};#{left_col}H" + " " * (@w + 2)
151
+ (0...@h).each do |i|
152
+ row = @y + i
153
+ STDOUT.print "\e[#{row};#{left_col}H" + " "
154
+ STDOUT.print "\e[#{row};#{right_col}H" + " "
155
+ end
156
+ STDOUT.print "\e[#{bottom_row};#{left_col}H" + " " * (@w + 2)
157
+ end
158
+ end
159
+
131
160
  # Diff-based refresh that minimizes flicker.
132
161
  # In this updated version we lazily process only the raw lines required to fill the pane.
133
162
  def refresh(cont = @text)
@@ -150,7 +179,7 @@ module Rcurses
150
179
  # Hide cursor and disable auto-wrap (minimal fix)
151
180
  STDOUT.print "\e[?25l\e[?7l"
152
181
 
153
- fmt = [@fg, @bg].compact.join(',')
182
+ fmt = [@fg.to_s, @bg.to_s].join(',')
154
183
 
155
184
  # Lazy evaluation: If the content or pane width has changed, reinitialize the lazy cache.
156
185
  if !defined?(@cached_text) || @cached_text != cont || @cached_w != @w
@@ -444,7 +473,7 @@ module Rcurses
444
473
  @scroll = false
445
474
  @ix = 0
446
475
  row(@y)
447
- fmt = [@fg, @bg].compact.join(',')
476
+ fmt = [@fg.to_s, @bg.to_s].join(',')
448
477
  col(@x)
449
478
  print @prompt.c(fmt)
450
479
  prompt_len = @prompt.pure.length
data/lib/rcurses.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Web_site: http://isene.com/
6
6
  # Github: https://github.com/isene/rcurses
7
7
  # License: Public domain
8
- # Version: 3.8.1: Code clean-up
8
+ # Version: 4.0: Added border_refresh to refresh only the border of a pane
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcurses
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.1
4
+ version: '4.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-27 00:00:00.000000000 Z
11
+ date: 2025-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -30,7 +30,8 @@ description: 'Create curses applications for the terminal easier than ever. Crea
30
30
  color, blink and in any 256 terminal colors for foreground and background. Use a
31
31
  simple editor to let users edit text in panes. Left, right or center align text
32
32
  in panes. Cursor movement around the terminal. New in 3.8: Fixed border fragments
33
- upon utf-8 characters. 3.8.1: Code clean-up'
33
+ upon utf-8 characters. 4.0: Added border_refresh to refresh only the border of a
34
+ pane.'
34
35
  email: g@isene.com
35
36
  executables: []
36
37
  extensions: []