rcurses 5.1.3 → 5.1.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rcurses.rb +65 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4d7bebb69ba43f7cc3d5bcb19898b554d06ca7d238c826f2222822ab699e5a0
4
- data.tar.gz: 2e96402c39a1005574b32014a42e20088d900ca79734938b45586bc45826b299
3
+ metadata.gz: 3912ae6525494a8bc621fc3a088525b660246778420f311d61778891499d88cf
4
+ data.tar.gz: a87bbfb6c23a9eaa8561d7f9606bf0f29b4abac34f674024dc8c7f7ddbc60969
5
5
  SHA512:
6
- metadata.gz: de02f1b55081905e4a34ac88ee15e39f3ca7c0d08e57e01f7513cd5100647c38f8db25ddfcb56797bf31311d5e0e51c26bede41a0c74a1d72811b678c7492396
7
- data.tar.gz: 66f9f70ac65f4e481dafa257cb7bea926e22f7fbc4a107abacfd0c21cf9fc2bed8d63bac413ac395be68855a00deb1bf5dc39f2a4658ca3f501a08d46b8c2e8c
6
+ metadata.gz: 2c87e2dc82b3efdd78a71a805f6d1e52d15c5c32f03d4882cf3095dbd7efefd3492ffb9ce7609d3477212597b582796c009de7af3ea90c8b8b300b9e8a910f60
7
+ data.tar.gz: f6758d24f234f979d3c311ff226afad6d46adcd7e5714fc89389a9a691f386bd6beac30feef438d332a8e1e909045cc75debfa4c7418526f4d530e42518711ca
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.5: Improved error handling - preserves screen content on crash
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|
@@ -45,12 +51,68 @@ module Rcurses
45
51
  def cleanup!
46
52
  return if @cleaned_up
47
53
 
54
+ # Restore terminal to normal mode
48
55
  $stdin.cooked!
49
56
  $stdin.echo = true
50
- Rcurses.clear_screen
57
+
58
+ # Only clear screen if there's no error to display
59
+ # This preserves the error context on screen
60
+ if @error_to_display.nil?
61
+ Rcurses.clear_screen
62
+ else
63
+ # Just move cursor to bottom of screen without clearing
64
+ print "\e[999;1H" # Move to bottom-left
65
+ print "\e[K" # Clear current line
66
+ end
67
+
51
68
  Cursor.show
52
69
 
53
70
  @cleaned_up = true
71
+
72
+ # Display any captured error after terminal is restored
73
+ if @error_to_display
74
+ display_error(@error_to_display)
75
+ end
76
+ end
77
+
78
+ # Private: Display error information after terminal cleanup
79
+ def display_error(error)
80
+ # Only display if we're in a TTY and not in a test environment
81
+ return unless $stdout.tty?
82
+
83
+ # Add some spacing and make the error very visible
84
+ puts "\n\n\e[41;37m APPLICATION CRASHED \e[0m"
85
+ puts "\e[31m═══════════════════════════════════════════════════════════\e[0m"
86
+ puts "\e[33mError Type:\e[0m #{error.class}"
87
+ puts "\e[33mMessage:\e[0m #{error.message}"
88
+
89
+ # Show backtrace if debug mode is enabled
90
+ if ENV['DEBUG'] || ENV['RCURSES_DEBUG']
91
+ puts "\n\e[33mBacktrace:\e[0m"
92
+ error.backtrace.first(15).each do |line|
93
+ puts " \e[90m#{line}\e[0m"
94
+ end
95
+ else
96
+ puts "\n\e[90mTip: Set DEBUG=1 or RCURSES_DEBUG=1 to see the full backtrace\e[0m"
97
+ end
98
+
99
+ puts "\e[31m═══════════════════════════════════════════════════════════\e[0m"
100
+ puts "\e[33mNote:\e[0m The application state above shows where the error occurred."
101
+ puts ""
102
+ end
103
+
104
+ # Public: Run a block with proper error handling and terminal cleanup
105
+ # This ensures errors are displayed after terminal is restored
106
+ def run(&block)
107
+ init!
108
+ begin
109
+ yield
110
+ rescue StandardError => e
111
+ @error_to_display = e
112
+ raise
113
+ ensure
114
+ # cleanup! will be called by at_exit handler
115
+ end
54
116
  end
55
117
  end
56
118
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcurses
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.3
4
+ version: 5.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene