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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '009a5bcd619dc3fa975c6ab3b01d1494e002ccc760b6e8ac335026f63860671e'
4
- data.tar.gz: 205f8d0f1cdab77854a564c43761c30113f2989216ba2ed91b7ac66e77f2387f
3
+ metadata.gz: 5e70688e9f049e91cc514d529ece0fe5dfad219b45117a8da518d5252f93e0f9
4
+ data.tar.gz: 17d1c30049d5f295a51815e6b6c1e2e1900e6e6567dbb561ba433a7ccf57e4ee
5
5
  SHA512:
6
- metadata.gz: bedd0da9ee879bcca97fc9faf3c597cf857a05b6b8cca59004e9fbaefdbbee13b885b89902d4909a2b5718d7877201780f44418be7e2f3044f65c9840e40fe58
7
- data.tar.gz: ac828f4bb8e7552b6a1b7310a0ba7be97d256710ce7f4aca3c523e0493b41e458fb722b33afafe01b90ab568338f14f6d56a3d546b29d191131986b07690acab
6
+ metadata.gz: 7ebc794ba61ee56bd49e18b424cc2c9a821dd0b1581f26a4a1fa96147362ca8696446359d06d6cffc9f99f7e2dcc21fcc6ceef692235e799c827b3c8252ed805
7
+ data.tar.gz: 752acc4ba0e823af2e40ad2e338f341fa46a7f46d8769798d1112fca4b175e7f564d9e7813e67876b43ce1724a62a208043b59ba1932b1475dffbda44208dedc
@@ -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
- return {:name=>:enter}
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"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RubyRich
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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 00:00:00.000000000 Z
10
+ date: 2025-03-14 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake