rcurses 5.1.3 → 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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rcurses.rb +48 -2
  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: 42249bd3b99cf1989bef47c062a23c1c576c2ed3a35ff2c28264cf6c6b1712cd
4
+ data.tar.gz: 84ea09a778a340d627dd5c45a06e5b32c4a413a8ecb61e620b9ac7666c87026f
5
5
  SHA512:
6
- metadata.gz: de02f1b55081905e4a34ac88ee15e39f3ca7c0d08e57e01f7513cd5100647c38f8db25ddfcb56797bf31311d5e0e51c26bede41a0c74a1d72811b678c7492396
7
- data.tar.gz: 66f9f70ac65f4e481dafa257cb7bea926e22f7fbc4a107abacfd0c21cf9fc2bed8d63bac413ac395be68855a00deb1bf5dc39f2a4658ca3f501a08d46b8c2e8c
6
+ metadata.gz: 72a020908e7efeb1cbe79f1afd31c7b3eca08b7b54fa72f82ea372ee3fa08903f4c58ccc834b0b7772dfc573be6163423bef751f401f2ecbc3e68684c1919782
7
+ data.tar.gz: 842393733ca9452063f86531fb3ae8b7129f35362ee5d5b03d1ddcf8bf7d92533f2734329614ca20d97b46a35d03d3482c60535b3b233c9dfa151f45333b96b8
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,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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene