terminal_rb 0.9.7 → 0.10.0

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: 151c319bb4dc4f395db83f3966bd37dd2436736b33f89c124baa3eb19ff7412a
4
- data.tar.gz: 3a5a1fa68a55cf7de4a63688c76587dc4f6f5f03ad6a4531a7586abcc6c6601b
3
+ metadata.gz: 6b6f4c3e8cfa6ca602f831ef011a146ff0f70d77d9a0da4a7a37a9768e52da39
4
+ data.tar.gz: 73f1ce0355077b7803c7c03924aaa764e8dac2f05e2534a653f37ba4b7d32b27
5
5
  SHA512:
6
- metadata.gz: 978e14d08f3335a08ba06a70a4c92f4ed8a188eed03a255a7892fbf155ab11a66380a1eafb203fd81e398b49cfc4c46e81e05f4ff0dc7c8a134fed22f9bcfdb6
7
- data.tar.gz: fc42bc22a4a92feea2eab08684ebe7fd0b9ccfc8d1ff08ee4e6ca2020e3a374c4ca2c048bd7d8ac8271e4b7c210d1a30697b42d9c7d9bc430d6b51b9375a7bd3
6
+ metadata.gz: 2e65c5d198050d41671d57fb5a60c67efd0d4f22c4da71cb4253e8260481fa5c0bc32713be85bf4d1c14a3e5eb7ad886f088ff78418059197b89bf685615a152
7
+ data.tar.gz: 9376328d7d488c039ce14411061ee41f4f46efa9ee244c33481f03a855bd6861e871248f3e5faee2b07826b09646e3789a09fd3e2398784c801d527d784114bf
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Terminal.rb ![version](https://img.shields.io/gem/v/terminal_rb?label=)
2
2
 
3
- Terminal access with support for ANSI control codes and [BBCode-like](https://en.wikipedia.org/wiki/BBCode) embedded text attribute syntax.
3
+ Terminal access with super fast ANSI control codes support and [BBCode-like](https://en.wikipedia.org/wiki/BBCode) embedded text attribute syntax.
4
4
 
5
5
  - Gem: [rubygems.org](https://rubygems.org/gems/terminal_rb)
6
6
  - Source: [codeberg.org](https://codeberg.org/mblumtritt/Terminal.rb)
data/lib/terminal/ansi.rb CHANGED
@@ -226,7 +226,7 @@ module Terminal
226
226
  str = str.to_s
227
227
  return str.dup unless str.index('[')
228
228
  str.gsub(BBCODE) do |match_str|
229
- next match_str if (match = Regexp.last_match[1]).empty?
229
+ match = Regexp.last_match(1) or next match_str
230
230
  next "[#{match[1..]}]" if match[0] == '\\'
231
231
  try_convert(match) || match_str
232
232
  end
@@ -246,7 +246,7 @@ module Terminal
246
246
  str = str.to_s
247
247
  return str.dup unless str.index('[')
248
248
  str.gsub(BBCODE) do |match_str|
249
- next match_str if (match = Regexp.last_match[1]).empty?
249
+ match = Regexp.last_match(1) or next match_str
250
250
  next "[#{match[1..]}]" if match[0] == '\\'
251
251
  next match_str if (match = match.split).empty?
252
252
  next if match.all? { ATTRIBUTES[_1] || COLORS[_1] || _color(_1) }
@@ -274,7 +274,7 @@ module Terminal
274
274
  end
275
275
  str =
276
276
  str.gsub(BBCODE) do |match_str|
277
- next match_str if (match = Regexp.last_match[1]).empty?
277
+ match = Regexp.last_match(1) or next match_str
278
278
  next "[#{match[1..]}]" if match[0] == '\\'
279
279
  next match_str if (match = match.split).empty?
280
280
  next if match.all? { ATTRIBUTES[_1] || COLORS[_1] || _color(_1) }
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Terminal
4
4
  # The version number of the gem.
5
- VERSION = '0.9.7'
5
+ VERSION = '0.10.0'
6
6
  end
data/lib/terminal.rb CHANGED
@@ -182,7 +182,7 @@ module Terminal
182
182
  # @param [#to_s] object object to write
183
183
  # @return [Terminal] itself
184
184
  def <<(object)
185
- @out&.write(@bbcode[object]) unless object.nil?
185
+ @out.write(Ansi.bbcode(object)) if @out && object != nil
186
186
  self
187
187
  rescue IOError
188
188
  @out = nil
@@ -197,17 +197,15 @@ module Terminal
197
197
  # @return [nil]
198
198
  def print(*objects, bbcode: true)
199
199
  return unless @out
200
- objects.flatten!
201
- return if (line = objects.join).empty?
202
- return if (line = (bbcode ? @bbcode : @nobbcode)[line]).empty?
203
- @out.write(line)
200
+ return @out.print(*objects) unless bbcode
201
+ objects.each { @out.write(Ansi.bbcode(_1)) }
204
202
  nil
205
203
  rescue IOError
206
204
  @out = nil
207
205
  end
208
206
 
209
207
  # Writes the given objects to the terminal.
210
- # Writes a newline after each objects that does not already end with a
208
+ # Writes a newline after each object that does not already end with a
211
209
  # newline sequence in it's String represenation.
212
210
  # If called without any arguments, writes a newline only.
213
211
  #
@@ -217,18 +215,10 @@ module Terminal
217
215
  # @return (see print)
218
216
  def puts(*objects, bbcode: true)
219
217
  return unless @out
218
+ return @out.puts if objects.empty?
219
+ return @out.puts(objects) unless bbcode
220
220
  objects.flatten!
221
- if objects.empty?
222
- @out.write("\n")
223
- return
224
- end
225
- bbcode = bbcode ? @bbcode : @nobbcode
226
- objects.each do |s|
227
- next @out.write("\n") if s.nil?
228
- @out.write(s = bbcode[s])
229
- @out.write("\n") if s[-1] != "\n"
230
- end
231
- nil
221
+ objects.empty? ? @out.puts : @out.puts(objects.map! { Ansi.bbcode(_1) })
232
222
  rescue IOError
233
223
  @out = nil
234
224
  end
@@ -261,20 +251,48 @@ module Terminal
261
251
  @cc = 0
262
252
  tty, @ansi = _determine_modes
263
253
 
264
- (@out = STDOUT).sync = true unless tty.nil?
265
-
266
- if tty
267
- @inf = STDOUT
268
- @con = IO.console
269
- Signal.trap('WINCH') { @size = nil } if Signal.list.key?('WINCH')
254
+ unless tty.nil?
255
+ @out = STDOUT
256
+ @out.sync = true
257
+ if tty
258
+ @inf = STDOUT
259
+ @con = IO.console
260
+ Signal.trap('WINCH') { @size = nil } if Signal.list.key?('WINCH')
261
+ end
270
262
  end
271
263
 
272
- if @ansi
273
- @bbcode = ->(s) { Ansi.bbcode(s) }
274
- @nobbcode = lambda(&:to_s)
275
- else
276
- @bbcode = ->(s) { Ansi.plain(s) }
277
- @nobbcode = ->(s) { Ansi.undecorate(s) }
264
+ unless @ansi
265
+ @plain = ->(s) { Ansi.plain(s) }
266
+ @undecorate = ->(s) { Ansi.undecorate(s) }
267
+
268
+ class << self
269
+ alias << <<
270
+ def <<(object)
271
+ @out.write(Ansi.plain(object)) if @out && object != nil
272
+ self
273
+ rescue IOError
274
+ @out = nil
275
+ self
276
+ end
277
+
278
+ alias print print
279
+ def print(*objects, bbcode: true)
280
+ return if @out.nil? || objects.empty?
281
+ @out.print(*objects.map!(&(bbcode ? @plain : @undecorate)))
282
+ rescue IOError
283
+ @out = nil
284
+ end
285
+
286
+ alias puts puts
287
+ def puts(*objects, bbcode: true)
288
+ return unless @out
289
+ objects.flatten!
290
+ return @out.puts if objects.empty?
291
+ @out.puts(objects.map!(&(bbcode ? @plain : @undecorate)))
292
+ rescue IOError
293
+ @out = nil
294
+ end
295
+ end
278
296
  end
279
297
 
280
298
  dir = "#{__dir__}/terminal"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -10,7 +10,7 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |
13
- Terminal access with support for ANSI control codes and
13
+ Terminal access with super fast ANSI control codes support and
14
14
  BBCode-like embedded text attribute syntax.
15
15
  executables:
16
16
  - bbcode
@@ -49,7 +49,7 @@ metadata:
49
49
  rubygems_mfa_required: 'true'
50
50
  source_code_uri: https://codeberg.org/mblumtritt/Terminal.rb
51
51
  bug_tracker_uri: https://codeberg.org/mblumtritt/Terminal.rb/issues
52
- documentation_uri: https://rubydoc.info/gems/terminal_rb/0.9.7/Terminal
52
+ documentation_uri: https://rubydoc.info/gems/terminal_rb/0.10.0/Terminal
53
53
  rdoc_options: []
54
54
  require_paths:
55
55
  - lib
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubygems_version: 3.6.9
67
+ rubygems_version: 3.7.0
68
68
  specification_version: 4
69
- summary: Easy terminal access with ANSI and BBCode support.
69
+ summary: Fast terminal access with ANSI and BBCode support.
70
70
  test_files: []