rcurses 5.1.4 → 5.1.6
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 +4 -4
- data/lib/rcurses.rb +75 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd5e0ec070d80452ce6733eed313a97b78b33db8ec992f329d2153ae3fcb6901
|
4
|
+
data.tar.gz: b9b7a0c97d31385dc2698e18b2e29baa0c95c9d584eaf7b7f0acde11b1c8910b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0e343b3cad38bd4f96b1ba47ca414ba84456c836a9fb1c64c624665101d7e0c214895a34ecaae8dfb87fc3de14c0e2dceb44db36f0c86e72303cb82a20b182f
|
7
|
+
data.tar.gz: 226e33514574213c955582af9eddbe3d45d18c5ecc3b84fd4f78250e2d2fb376261ea28120f4944fbe2c166edd3597006a0f5b13a752767cc93e9a761ce5010a
|
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: 5.1.
|
8
|
+
# Version: 5.1.6: Ruby 3.4+ compatibility - handle potential raw!/cooked! blocking
|
9
9
|
|
10
10
|
require 'io/console' # Basic gem for rcurses
|
11
11
|
require 'io/wait' # stdin handling
|
@@ -26,8 +26,33 @@ module Rcurses
|
|
26
26
|
return unless $stdin.tty?
|
27
27
|
|
28
28
|
# enter raw mode, disable echo
|
29
|
-
|
30
|
-
|
29
|
+
# Ruby 3.4+ compatibility: Handle potential blocking in raw!
|
30
|
+
begin
|
31
|
+
if RUBY_VERSION >= "3.4.0"
|
32
|
+
# Flush outputs before changing terminal mode (Ruby 3.4+ requirement)
|
33
|
+
$stdout.flush if $stdout.respond_to?(:flush)
|
34
|
+
$stderr.flush if $stderr.respond_to?(:flush)
|
35
|
+
|
36
|
+
# Use timeout to detect hanging raw! call
|
37
|
+
begin
|
38
|
+
Timeout::timeout(0.5) do
|
39
|
+
$stdin.raw!
|
40
|
+
$stdin.echo = false
|
41
|
+
end
|
42
|
+
rescue Timeout::Error
|
43
|
+
# Fallback to stty for Ruby 3.4+ if raw! hangs
|
44
|
+
system("stty raw -echo 2>/dev/null")
|
45
|
+
@using_stty = true
|
46
|
+
end
|
47
|
+
else
|
48
|
+
# Original code for Ruby < 3.4
|
49
|
+
$stdin.raw!
|
50
|
+
$stdin.echo = false
|
51
|
+
end
|
52
|
+
rescue Errno::ENOTTY, Errno::ENODEV
|
53
|
+
# Not a real terminal
|
54
|
+
return
|
55
|
+
end
|
31
56
|
|
32
57
|
# ensure cleanup on normal exit
|
33
58
|
at_exit do
|
@@ -51,9 +76,42 @@ module Rcurses
|
|
51
76
|
def cleanup!
|
52
77
|
return if @cleaned_up
|
53
78
|
|
54
|
-
|
55
|
-
|
56
|
-
|
79
|
+
# Restore terminal to normal mode
|
80
|
+
begin
|
81
|
+
if @using_stty
|
82
|
+
# If we used stty for init, use it for cleanup
|
83
|
+
system("stty sane 2>/dev/null")
|
84
|
+
elsif RUBY_VERSION >= "3.4.0"
|
85
|
+
# Ruby 3.4+ with timeout protection
|
86
|
+
begin
|
87
|
+
Timeout::timeout(0.5) do
|
88
|
+
$stdin.cooked!
|
89
|
+
$stdin.echo = true
|
90
|
+
end
|
91
|
+
rescue Timeout::Error
|
92
|
+
# Fallback if cooked! hangs
|
93
|
+
system("stty sane 2>/dev/null")
|
94
|
+
end
|
95
|
+
else
|
96
|
+
# Original code for Ruby < 3.4
|
97
|
+
$stdin.cooked!
|
98
|
+
$stdin.echo = true
|
99
|
+
end
|
100
|
+
rescue => e
|
101
|
+
# Last resort fallback
|
102
|
+
system("stty sane 2>/dev/null")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Only clear screen if there's no error to display
|
106
|
+
# This preserves the error context on screen
|
107
|
+
if @error_to_display.nil?
|
108
|
+
Rcurses.clear_screen
|
109
|
+
else
|
110
|
+
# Just move cursor to bottom of screen without clearing
|
111
|
+
print "\e[999;1H" # Move to bottom-left
|
112
|
+
print "\e[K" # Clear current line
|
113
|
+
end
|
114
|
+
|
57
115
|
Cursor.show
|
58
116
|
|
59
117
|
@cleaned_up = true
|
@@ -69,20 +127,25 @@ module Rcurses
|
|
69
127
|
# Only display if we're in a TTY and not in a test environment
|
70
128
|
return unless $stdout.tty?
|
71
129
|
|
72
|
-
|
73
|
-
puts "\e[
|
130
|
+
# Add some spacing and make the error very visible
|
131
|
+
puts "\n\n\e[41;37m APPLICATION CRASHED \e[0m"
|
132
|
+
puts "\e[31m═══════════════════════════════════════════════════════════\e[0m"
|
133
|
+
puts "\e[33mError Type:\e[0m #{error.class}"
|
134
|
+
puts "\e[33mMessage:\e[0m #{error.message}"
|
74
135
|
|
75
136
|
# Show backtrace if debug mode is enabled
|
76
137
|
if ENV['DEBUG'] || ENV['RCURSES_DEBUG']
|
77
|
-
puts "\n\e[
|
78
|
-
error.backtrace.first(
|
138
|
+
puts "\n\e[33mBacktrace:\e[0m"
|
139
|
+
error.backtrace.first(15).each do |line|
|
79
140
|
puts " \e[90m#{line}\e[0m"
|
80
141
|
end
|
81
142
|
else
|
82
|
-
puts "\e[
|
143
|
+
puts "\n\e[90mTip: Set DEBUG=1 or RCURSES_DEBUG=1 to see the full backtrace\e[0m"
|
83
144
|
end
|
84
145
|
|
85
|
-
puts "\e[31m
|
146
|
+
puts "\e[31m═══════════════════════════════════════════════════════════\e[0m"
|
147
|
+
puts "\e[33mNote:\e[0m The application state above shows where the error occurred."
|
148
|
+
puts ""
|
86
149
|
end
|
87
150
|
|
88
151
|
# Public: Run a block with proper error handling and terminal cleanup
|