rcurses 5.1.2 → 5.1.4

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/rcurses/pane.rb +28 -5
  4. data/lib/rcurses.rb +48 -2
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67b18a3ec884ebcbb7d0a55f6953bad3a55feba14163ea64ed538fbc2b00131f
4
- data.tar.gz: 721fa5b171684ade0adf15d146afcbb7344b3ac26a01cf6e817f0568ed8d193e
3
+ metadata.gz: 42249bd3b99cf1989bef47c062a23c1c576c2ed3a35ff2c28264cf6c6b1712cd
4
+ data.tar.gz: 84ea09a778a340d627dd5c45a06e5b32c4a413a8ecb61e620b9ac7666c87026f
5
5
  SHA512:
6
- metadata.gz: a32d358968c1dae62f7a6448661d00341cb9aa2914d26cb012d0b5a3e12cfbf4f98d86ebba647d177fbdc93ff8a98e66bc857e61575e0d814b395fcdd74c34e2
7
- data.tar.gz: 0257001adf843da5f38afebee39bce279eb2ae873455faf61764b02f883fd6ecd91746d8980943bb51503104ffb1fad7511d6220ecd237bc2197758575682431
6
+ metadata.gz: 72a020908e7efeb1cbe79f1afd31c7b3eca08b7b54fa72f82ea372ee3fa08903f4c58ccc834b0b7772dfc573be6163423bef751f401f2ecbc3e68684c1919782
7
+ data.tar.gz: 842393733ca9452063f86531fb3ae8b7129f35362ee5d5b03d1ddcf8bf7d92533f2734329614ca20d97b46a35d03d3482c60535b3b233c9dfa151f45333b96b8
data/README.md CHANGED
@@ -248,7 +248,7 @@ Try this in `irb`:
248
248
  ```
249
249
  require 'rcurses'
250
250
  @max_h, @max_w = IO.console.winsize
251
- mypane = Pane.new(@max_w/2, 30, 30, 10, 19, 229)
251
+ mypane = Rcurses::Pane.new(@max_w/2, 30, 30, 10, 19, 229)
252
252
  mypane.border = true
253
253
  mypane.text = "Hello".i + " World!".b.i + "\n \n" + "rcurses".r + " " + "is cool".c("16,212")
254
254
  mypane.refresh
data/lib/rcurses/pane.rb CHANGED
@@ -255,9 +255,12 @@ module Rcurses
255
255
  pl = @w - Rcurses.display_width(@txt[l].pure)
256
256
  pl = 0 if pl < 0
257
257
  hl = pl / 2
258
- # Skip color application if pane has no colors set or text has ANY ANSI codes
259
- if @skip_colors || @txt[l].include?("\e[")
260
- # Don't apply pane colors - text already has ANSI sequences
258
+
259
+ # Check if text has ANSI background colors (48 or 4x codes)
260
+ has_bg_color = @txt[l] =~ /\e\[(?:\d+;)*4[0-9](?:;\d+)*m/ || @txt[l] =~ /\e\[(?:\d+;)*48(?:;\d+)*m/
261
+
262
+ if @skip_colors || (@txt[l].include?("\e[") && !@bg)
263
+ # No pane colors to apply, or text has ANSI but pane has no bg
261
264
  case @align
262
265
  when "l"
263
266
  line_str = @txt[l] + " " * pl
@@ -266,8 +269,28 @@ module Rcurses
266
269
  when "c"
267
270
  line_str = " " * hl + @txt[l] + " " * (pl - hl)
268
271
  end
272
+ elsif @txt[l].include?("\e[") && @bg && !has_bg_color
273
+ # Text has ANSI codes but no bg color - apply pane fg and bg to text and padding
274
+ case @align
275
+ when "l"
276
+ line_str = @txt[l].c(fmt) + " ".c(fmt) * pl
277
+ when "r"
278
+ line_str = " ".c(fmt) * pl + @txt[l].c(fmt)
279
+ when "c"
280
+ line_str = " ".c(fmt) * hl + @txt[l].c(fmt) + " ".c(fmt) * (pl - hl)
281
+ end
282
+ elsif @txt[l].include?("\e[") && has_bg_color
283
+ # Text has its own bg color - preserve it, only apply pane bg to padding
284
+ case @align
285
+ when "l"
286
+ line_str = @txt[l] + " ".c(fmt) * pl
287
+ when "r"
288
+ line_str = " ".c(fmt) * pl + @txt[l]
289
+ when "c"
290
+ line_str = " ".c(fmt) * hl + @txt[l] + " ".c(fmt) * (pl - hl)
291
+ end
269
292
  else
270
- # Apply pane colors normally
293
+ # No ANSI codes - apply pane colors normally
271
294
  case @align
272
295
  when "l"
273
296
  line_str = @txt[l].c(fmt) + " ".c(fmt) * pl
@@ -278,7 +301,7 @@ module Rcurses
278
301
  end
279
302
  end
280
303
  else
281
- # Empty line - only apply colors if pane has them
304
+ # Empty line
282
305
  line_str = @skip_colors ? " " * @w : " ".c(fmt) * @w
283
306
  end
284
307
 
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: 4.9.4: Added scrolling best practices documentation
8
+ # Version: 5.1.4: Added error handling with terminal restoration
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
@@ -30,7 +30,13 @@ module Rcurses
30
30
  $stdin.echo = false
31
31
 
32
32
  # ensure cleanup on normal exit
33
- at_exit { cleanup! }
33
+ at_exit do
34
+ # Capture any unhandled exception
35
+ if $! && !$!.is_a?(SystemExit) && !$!.is_a?(Interrupt)
36
+ @error_to_display = $!
37
+ end
38
+ cleanup!
39
+ end
34
40
 
35
41
  # ensure cleanup on signals
36
42
  %w[INT TERM].each do |sig|
@@ -51,6 +57,46 @@ module Rcurses
51
57
  Cursor.show
52
58
 
53
59
  @cleaned_up = true
60
+
61
+ # Display any captured error after terminal is restored
62
+ if @error_to_display
63
+ display_error(@error_to_display)
64
+ end
65
+ end
66
+
67
+ # Private: Display error information after terminal cleanup
68
+ def display_error(error)
69
+ # Only display if we're in a TTY and not in a test environment
70
+ return unless $stdout.tty?
71
+
72
+ puts "\n\e[31m═══ Application Error ═══\e[0m"
73
+ puts "\e[33m#{error.class}:\e[0m #{error.message}"
74
+
75
+ # Show backtrace if debug mode is enabled
76
+ if ENV['DEBUG'] || ENV['RCURSES_DEBUG']
77
+ puts "\n\e[90mBacktrace:\e[0m"
78
+ error.backtrace.first(10).each do |line|
79
+ puts " \e[90m#{line}\e[0m"
80
+ end
81
+ else
82
+ puts "\e[90m(Set DEBUG=1 or RCURSES_DEBUG=1 for backtrace)\e[0m"
83
+ end
84
+
85
+ puts "\e[31m═══════════════════════\e[0m\n"
86
+ end
87
+
88
+ # Public: Run a block with proper error handling and terminal cleanup
89
+ # This ensures errors are displayed after terminal is restored
90
+ def run(&block)
91
+ init!
92
+ begin
93
+ yield
94
+ rescue StandardError => e
95
+ @error_to_display = e
96
+ raise
97
+ ensure
98
+ # cleanup! will be called by at_exit handler
99
+ end
54
100
  end
55
101
  end
56
102
 
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: 5.1.2
4
+ version: 5.1.4
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-08-13 00:00:00.000000000 Z
11
+ date: 2025-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard