ruby_rich 0.3.0 → 0.3.1
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/ruby_rich/console.rb +3 -1
- data/lib/ruby_rich/panel.rb +7 -2
- data/lib/ruby_rich/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e70688e9f049e91cc514d529ece0fe5dfad219b45117a8da518d5252f93e0f9
|
4
|
+
data.tar.gz: 17d1c30049d5f295a51815e6b6c1e2e1900e6e6567dbb561ba433a7ccf57e4ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ebc794ba61ee56bd49e18b424cc2c9a821dd0b1581f26a4a1fa96147362ca8696446359d06d6cffc9f99f7e2dcc21fcc6ceef692235e799c827b3c8252ed805
|
7
|
+
data.tar.gz: 752acc4ba0e823af2e40ad2e338f341fa46a7f46d8769798d1112fca4b175e7f564d9e7813e67876b43ce1724a62a208043b59ba1932b1475dffbda44208dedc
|
data/lib/ruby_rich/console.rb
CHANGED
@@ -78,7 +78,9 @@ module RubyRich
|
|
78
78
|
char = io.getch
|
79
79
|
# 优先处理回车键(ASCII 13 = \r,ASCII 10 = \n)
|
80
80
|
if char == "\r" || char == "\n"
|
81
|
-
|
81
|
+
# 检查是否有后续输入(粘贴内容会有多个字符)
|
82
|
+
has_more = IO.select([io], nil, nil, 0)
|
83
|
+
return has_more ? {:name => :string, :value => char} : {:name=>:enter}
|
82
84
|
end
|
83
85
|
# 单独处理 Tab 键(ASCII 9)
|
84
86
|
if char == "\t"
|
data/lib/ruby_rich/panel.rb
CHANGED
@@ -134,10 +134,15 @@ module RubyRich
|
|
134
134
|
# Split text into tokens of ANSI codes and regular text
|
135
135
|
tokens = text.scan(/(\e\[[0-9;]*m)|(.)/)
|
136
136
|
.map { |m| m.compact.first }
|
137
|
-
|
137
|
+
start_color = nil
|
138
138
|
tokens.each do |token|
|
139
139
|
# Calculate width for regular text, ANSI codes have 0 width
|
140
140
|
if token.start_with?("\e[")
|
141
|
+
if token == "\e[0m"
|
142
|
+
start_color = nil
|
143
|
+
else
|
144
|
+
start_color = token
|
145
|
+
end
|
141
146
|
token_width = 0
|
142
147
|
else
|
143
148
|
token_width = token.chars.sum { |c| Unicode::DisplayWidth.of(c) }
|
@@ -148,7 +153,7 @@ module RubyRich
|
|
148
153
|
current_width += token_width
|
149
154
|
else
|
150
155
|
result << current_line
|
151
|
-
current_line = token
|
156
|
+
current_line = start_color.to_s+token
|
152
157
|
current_width = token_width
|
153
158
|
end
|
154
159
|
end
|
data/lib/ruby_rich/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_rich
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhuang biaowei
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-14 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rake
|