rcurses 3.8 → 3.9

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: 423857a2047f4ee924c2d339d4d6971158a97e0de5998e81d9c27cc2c6ad0cc8
4
- data.tar.gz: eaf71c2c3c559fbdff2c946875b0ec3ee1a5d2296fe7a501368a46790edbb496
3
+ metadata.gz: b86d406d96a0e08b0cf5b1d5e6ddc0a0e3a8908293405e59dcedf230276bde95
4
+ data.tar.gz: 91a3ac14bc426f1d864baee262b3b070aa1b5c7fdd94397f82b10ddd405b91b2
5
5
  SHA512:
6
- metadata.gz: 297b2ceaa57f8abe2b727efb58d03efcefa2226a62af8b2436f97bbf5b3d0ccda72335ca312d356d905876b0d88396a8bd11e5aa45778dbbc85cc91e5836f0af
7
- data.tar.gz: fc23a173b5e555c533e92f34821da8808a0712b709242dbc5374ceebf15f179aaee5273a3d61767210c246b45d90c76bd37560d39f935f4746c61f8c667e3ad0
6
+ metadata.gz: cfef56d215b5906f531c23b81756cba928ee25249893ad3464c9c64c42b121c8e5a1de3cf5110511dbb4b1b538ef09e1e1cdcf629724109c9c081c9371109135
7
+ data.tar.gz: 6c422acb468b451f959399161c8483d9812d99dc88c0afd1aa76335635a31ab2d81e247c98fca69f0242b7fd92e0e35e3f39338a09d2a1dd52e55374d8f51537
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
 
@@ -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
@@ -150,7 +150,7 @@ module Rcurses
150
150
  # Hide cursor and disable auto-wrap (minimal fix)
151
151
  STDOUT.print "\e[?25l\e[?7l"
152
152
 
153
- fmt = [@fg, @bg].compact.join(',')
153
+ fmt = [@fg.to_s, @bg.to_s].join(',')
154
154
 
155
155
  # Lazy evaluation: If the content or pane width has changed, reinitialize the lazy cache.
156
156
  if !defined?(@cached_text) || @cached_text != cont || @cached_w != @w
@@ -208,8 +208,7 @@ module Rcurses
208
208
  new_frame.each_with_index do |line, i|
209
209
  row_num = @y + i
210
210
  col_num = @x
211
- if @prev_frame.nil? || @prev_frame[i] != line ||
212
- (@border && (i == 0 || i == new_frame.size - 1))
211
+ if @prev_frame.nil? || @prev_frame[i] != line
213
212
  diff_buf << "\e[#{row_num};#{col_num}H" << line
214
213
  end
215
214
  end
@@ -221,7 +220,7 @@ module Rcurses
221
220
 
222
221
  # Draw scroll markers after printing the frame.
223
222
  if @scroll
224
- marker_col = @border ? (@x + @w - 1) : (@x + @w - 1)
223
+ marker_col = @x + @w - 1
225
224
  if @ix > 0
226
225
  print "\e[#{@y};#{marker_col}H" + "∆".c(fmt)
227
226
  end
@@ -445,7 +444,7 @@ module Rcurses
445
444
  @scroll = false
446
445
  @ix = 0
447
446
  row(@y)
448
- fmt = [@fg, @bg].compact.join(',')
447
+ fmt = [@fg.to_s, @bg.to_s].join(',')
449
448
  col(@x)
450
449
  print @prompt.c(fmt)
451
450
  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: Fixed border fragments upon utf-8 characters
8
+ # Version: 3.9: Fixed bug on pane parameters passed as nil. Better examples.
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'
4
+ version: '3.9'
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-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -30,7 +30,7 @@ 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.'
33
+ upon utf-8 characters. 3.9: Fixed bug on pane parameters passed as nil. Better examples.'
34
34
  email: g@isene.com
35
35
  executables: []
36
36
  extensions: []