rb-readline 0.5.3 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4d13c41012b1013ec975862515264f6fd631054
4
- data.tar.gz: 346bac63e5dbb35e44c9874f7709145dfc293072
3
+ metadata.gz: c3159d70047f7143ac3691670bf88e0d49962c03
4
+ data.tar.gz: bc91ac5ba0ac0c0a09da8f6e60d42be1044df171
5
5
  SHA512:
6
- metadata.gz: b95940171a294f7380b325363a01dbb2489c5c701b5909cac3de86dc038fbb2263c3b1620209cf3ff86a01cf7821097d86833a1d72ed1c94153658bd62e44a48
7
- data.tar.gz: f8717f77149f38446ba5947edf8578facad9e53685880237fdd9e02fa1899dc8b5441ac29ceb0494d37c1a290cfa25bfd91662ab671954005c029c21071e7cc6
6
+ metadata.gz: f81bd2d07418af204da27451fa28ad7ea58ea91f3c5e222fa8dff96afa6957233d72aa8512b1754e5aeefc5c8ca6020968e7b315f85bbefdc080335d42cd6828
7
+ data.tar.gz: c1a2292dd3db790d667a60b5b5af9d4ffb39bc8b8b86d9f839c572097cee256d3112c55c74fe9629d01f0ed6d40ef276230b4e6af31aaf58c4c5defe09614b9f
@@ -1,28 +1,38 @@
1
- = Description
1
+ # Description
2
2
 
3
3
  The readline library provides a pure Ruby implementation of the GNU
4
4
  readline C library, as well as the Readline extension that ships as part
5
5
  of the standard library.
6
6
 
7
- = Synopsis
7
+ ## Installation
8
8
 
9
- require 'readline'
9
+ gem install rb-readline
10
+
11
+ Or in a `Gemfile`:
12
+
13
+ gem 'rb-readline'
10
14
 
11
- loop do
12
- line = Readline::readline('> ')
13
- break if line.nil? || line == 'quit'
14
- Readline::HISTORY.push(line)
15
- puts "You typed: #{line}"
16
- end
15
+ ## Synopsis
17
16
 
18
- = Compatibility
17
+ ```ruby
18
+ require 'readline'
19
+
20
+ loop do
21
+ line = Readline::readline('> ')
22
+ break if line.nil? || line == 'quit'
23
+ Readline::HISTORY.push(line)
24
+ puts "You typed: #{line}"
25
+ end
26
+ ```
27
+
28
+ ## Compatibility
19
29
 
20
30
  rb-readline should work on all Unix-like systems and Windows. It is regularly
21
31
  used with MRI 1.8/1.9 and Rubinius. JRuby is not supported and there are no
22
32
  plans to support it in the future - it comes bundled with a Java implementation
23
33
  of Readline.
24
34
 
25
- = Motivation
35
+ ## Motivation
26
36
 
27
37
  First, building the GNU readline library on MS Windows with Visual C++ is
28
38
  almost impossible. However, certain libraries depend on readline. By providing
@@ -47,7 +57,7 @@ weak, and only provides a very limited subset of the actual GNU readline
47
57
  library. By providing a pure Ruby implementation we allow 3rd party library
48
58
  authors to write their own interface as they see fit.
49
59
 
50
- = Tutorial
60
+ ## Tutorial
51
61
 
52
62
  For an excellent tutorial on how to use Readline in practice, please see
53
63
  Joseph Pecoraro's examples at http://bogojoker.com/readline/.
@@ -55,14 +65,14 @@ Joseph Pecoraro's examples at http://bogojoker.com/readline/.
55
65
  You can also take a look at Ruby 1.9 stdlib Readline documentation located
56
66
  at http://rubydoc.info/stdlib/readline/1.9.2/frames
57
67
 
58
- = Alternatives
68
+ ## Alternatives
59
69
 
60
70
  See Rawline for a library that began life in pure Ruby and provides an
61
71
  interface that's probably more comfortable to Ruby programmer. It has certain
62
72
  features that Readline does not. In addition, it provides a Readline
63
73
  compatibility mode.
64
74
 
65
- = Authors
75
+ ## Authors
66
76
 
67
77
  * Park Heesob (C translation, code donated as part of bounty)
68
78
  * Daniel Berger (Documentation and testing)
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems/package_task'
2
2
  require 'rake/testtask'
3
+ require 'bundler/gem_tasks'
3
4
 
4
5
  spec = Gem::Specification.load "rb-readline.gemspec"
5
6
 
@@ -1,3 +1,3 @@
1
1
  module RbReadline
2
- RB_READLINE_VERSION = "0.5.3"
2
+ RB_READLINE_VERSION = "0.5.5"
3
3
  end
data/lib/rbreadline.rb CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  require "rbreadline/version"
12
12
 
13
- class Fixnum
13
+ class Integer
14
14
  def ord; self; end
15
15
  end
16
16
 
@@ -1555,7 +1555,7 @@ module RbReadline
1555
1555
  end
1556
1556
 
1557
1557
  if @hConsoleHandle
1558
- csbi = 0.chr * 24
1558
+ csbi = Fiddle::Pointer.malloc(24)
1559
1559
  @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi)
1560
1560
  x,y = csbi[4,4].unpack('SS')
1561
1561
  x = dpos
@@ -1812,7 +1812,7 @@ module RbReadline
1812
1812
 
1813
1813
  def get_term_capabilities(buffer)
1814
1814
  hash = {}
1815
- `infocmp -C`.split(':').select{|x| x =~ /(.*)=(.*)/ and hash[$1]=$2.gsub('\\E',"\e").gsub(/\^(.)/){($1[0].ord ^ ((?a..?z).include?($1[0]) ? 0x60 : 0x40)).chr}}
1815
+ `infocmp -C`.split(':').select{|x| x =~ /(.*)=(.*)/ and hash[$1]=$2.gsub("\\r", "\r").gsub('\\E',"\e").gsub(/\^(.)/){($1[0].ord ^ ((?a..?z).include?($1[0]) ? 0x60 : 0x40)).chr}}
1816
1816
  @_rl_term_at7 = hash["@7"]
1817
1817
  @_rl_term_DC = hash["DC"]
1818
1818
  @_rl_term_IC = hash["IC"]
@@ -1859,7 +1859,7 @@ module RbReadline
1859
1859
  def _rl_get_screen_size(tty, ignore_env)
1860
1860
 
1861
1861
  if @hConsoleHandle
1862
- csbi = 0.chr * 24
1862
+ csbi = Fiddle::Pointer.malloc(24)
1863
1863
  @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi)
1864
1864
  wc,wr = csbi[0,4].unpack('SS')
1865
1865
  # wr,wc, = `mode con`.scan(/\d+\n/).map{|x| x.to_i}
@@ -2392,9 +2392,54 @@ module RbReadline
2392
2392
  nil
2393
2393
  end
2394
2394
 
2395
+ def rl_translate_keyseq(seq)
2396
+ require 'strscan'
2397
+
2398
+ ss = StringScanner.new(seq)
2399
+ new_seq = ''
2400
+
2401
+ until ss.eos?
2402
+ char = ss.getch
2403
+ next new_seq << char unless char == '\\'
2404
+
2405
+ char = ss.getch
2406
+ new_seq << case char
2407
+ when 'a'
2408
+ "\007"
2409
+ when 'b'
2410
+ "\b"
2411
+ when 'd'
2412
+ RUBOUT
2413
+ when 'e'
2414
+ ESC
2415
+ when 'f'
2416
+ "\f"
2417
+ when 'n'
2418
+ NEWLINE
2419
+ when 'r'
2420
+ RETURN
2421
+ when 't'
2422
+ TAB
2423
+ when 'v'
2424
+ 0x0B
2425
+ when '\\'
2426
+ '\\'
2427
+ when 'x'
2428
+ ss.scan(/\d\d/).to_i(16).chr
2429
+ when '0'..'7'
2430
+ ss.pos -= 1
2431
+ ss.scan(/\d\d\d/).to_i(8).chr
2432
+ else
2433
+ char
2434
+ end
2435
+ end
2436
+
2437
+ new_seq
2438
+ end
2439
+
2395
2440
  # Bind KEY to FUNCTION. Returns non-zero if KEY is out of range.
2396
2441
  def rl_bind_key(key, function)
2397
- @_rl_keymap[key] = function
2442
+ @_rl_keymap[rl_translate_keyseq(key)] = function
2398
2443
  @rl_binding_keymap = @_rl_keymap
2399
2444
  0
2400
2445
  end
@@ -2648,7 +2693,7 @@ module RbReadline
2648
2693
  end
2649
2694
 
2650
2695
  def vis_pos(line)
2651
- @vis_lbreaks[line]
2696
+ @vis_lbreaks[line] || 0
2652
2697
  end
2653
2698
 
2654
2699
  def vis_line(line)
@@ -4022,7 +4067,7 @@ module RbReadline
4022
4067
  def _rl_isearch_dispatch(cxt, c)
4023
4068
  f = nil
4024
4069
 
4025
- if c.class == Fixnum && c < 0
4070
+ if c.is_a?(Integer) && c < 0
4026
4071
  cxt.sflags |= SF_FAILED
4027
4072
  cxt.history_pos = cxt.last_found_line
4028
4073
  return -1
@@ -4391,7 +4436,7 @@ module RbReadline
4391
4436
 
4392
4437
  def call(*args)
4393
4438
  args.each_with_index do |x, i|
4394
- args[i], = [x == 0 ? nil : x].pack("p").unpack("l!*") if @proto[i] == "S"
4439
+ args[i], = [x == 0 ? nil : x].pack("p").unpack("l!*") if @proto[i] == "S" && !x.is_a?(Fiddle::Pointer)
4395
4440
  args[i], = [x].pack("I").unpack("i") if @proto[i] == "I"
4396
4441
  end
4397
4442
  @func.call(*args).to_i || 0
@@ -4613,10 +4658,10 @@ module RbReadline
4613
4658
  # number of character spaces to clear,
4614
4659
  def space_to_eol(count)
4615
4660
  if @hConsoleHandle
4616
- csbi = 0.chr * 24
4661
+ csbi = Fiddle::Pointer.malloc(24)
4617
4662
  @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi)
4618
4663
  cursor_pos = csbi[4,4].unpack('L').first
4619
- written = 0.chr * 4
4664
+ written = Fiddle::Pointer.malloc(4)
4620
4665
  @FillConsoleOutputCharacter.Call(@hConsoleHandle,0x20,count,cursor_pos,written)
4621
4666
  else
4622
4667
  @rl_outstream.write(' ' * count)
@@ -5615,7 +5660,7 @@ module RbReadline
5615
5660
  c = rl_read_key()
5616
5661
  rl_unsetstate(RL_STATE_MOREINPUT)
5617
5662
 
5618
- if c.class == Fixnum && c < 0
5663
+ if c.is_a?(Integer) && c < 0
5619
5664
  return -1
5620
5665
  end
5621
5666
 
@@ -6087,7 +6132,7 @@ module RbReadline
6087
6132
 
6088
6133
  def alloc_history_entry(string, ts)
6089
6134
  temp = Struct.new(:line,:data,:timestamp).new
6090
- temp.line = string ? string.delete(0.chr) : string
6135
+ temp.line = string ? string.encode('UTF-8', invalid: :replace, undef: :replace, replace: '').delete(0.chr) : string
6091
6136
  temp.data = nil
6092
6137
  temp.timestamp = ts
6093
6138
 
@@ -6494,7 +6539,7 @@ module RbReadline
6494
6539
  end
6495
6540
 
6496
6541
  def _rl_internal_pager(lines)
6497
- @rl_outstream.puts "--More--"
6542
+ @rl_outstream.write("--More--")
6498
6543
  @rl_outstream.flush
6499
6544
  i = get_y_or_n(1)
6500
6545
  _rl_erase_entire_line()
@@ -6610,7 +6655,7 @@ module RbReadline
6610
6655
  if (c == 'n' || c == 'N' || c == RUBOUT)
6611
6656
  return (0)
6612
6657
  end
6613
- if (c == ABORT_CHAR || (c.class == Fixnum && c < 0))
6658
+ if (c == ABORT_CHAR || (c.is_a?(Integer) && c < 0))
6614
6659
  _rl_abort_internal()
6615
6660
  end
6616
6661
  if (for_pager && (c == NEWLINE || c == RETURN))
@@ -6971,7 +7016,7 @@ module RbReadline
6971
7016
 
6972
7017
  setting << " -ixoff"
6973
7018
 
6974
- rl_bind_key(@_rl_tty_chars.t_start, :rl_restart_output)
7019
+ rl_bind_key(@_rl_tty_chars.t_start, :rl_restart_output) unless @_rl_tty_chars.t_start.nil?
6975
7020
  @_rl_eof_char = @_rl_tty_chars.t_eof
6976
7021
 
6977
7022
  #setting << " -isig"
@@ -7592,7 +7637,7 @@ module RbReadline
7592
7637
  mbchar = ''
7593
7638
  mb_len = _rl_read_mbchar(mbchar, MB_LEN_MAX)
7594
7639
 
7595
- if (mbchar.class == Fixnum && c < 0) || mbchar == 0.chr
7640
+ if (mbchar.is_a?(Integer) && c < 0) || mbchar == 0.chr
7596
7641
  return -1
7597
7642
  end
7598
7643
 
@@ -7777,7 +7822,7 @@ module RbReadline
7777
7822
  rl_restore_prompt()
7778
7823
  rl_clear_message()
7779
7824
  rl_unsetstate(RL_STATE_NUMERICARG)
7780
- if key.class == Fixnum && key < 0
7825
+ if key.is_a?(Integer) && key < 0
7781
7826
  return -1
7782
7827
  end
7783
7828
  return (_rl_dispatch(key, @_rl_keymap))
@@ -8735,7 +8780,7 @@ module RbReadline
8735
8780
  c = rl_read_key()
8736
8781
  rl_unsetstate(RL_STATE_MOREINPUT)
8737
8782
 
8738
- break if c.class == Fixnum && c < 0
8783
+ break if c.is_a?(Integer) && c < 0
8739
8784
 
8740
8785
  mbchar << c
8741
8786
  mb_len += 1
@@ -8765,7 +8810,7 @@ module RbReadline
8765
8810
  # Read more for multibyte character
8766
8811
  rl_setstate(RL_STATE_MOREINPUT)
8767
8812
  c = rl_read_key()
8768
- break if c.class == Fixnum && c < 0
8813
+ break if c.is_a?(Integer) && c < 0
8769
8814
  rl_unsetstate(RL_STATE_MOREINPUT)
8770
8815
  else
8771
8816
  break
data/lib/readline.rb CHANGED
@@ -316,6 +316,16 @@ module Readline
316
316
  RbReadline.rl_point
317
317
  end
318
318
 
319
+ # Temporarily disable warnings and call a block
320
+ #
321
+ def self.silence_warnings(&block)
322
+ warn_level = $VERBOSE
323
+ $VERBOSE = nil
324
+ result = block.call
325
+ $VERBOSE = warn_level
326
+ result
327
+ end
328
+
319
329
  # The History class encapsulates a history of all commands entered by
320
330
  # users at the prompt, providing an interface for inspection and retrieval
321
331
  # of all commands.
@@ -455,7 +465,7 @@ module Readline
455
465
 
456
466
  end
457
467
 
458
- HISTORY = History
468
+ silence_warnings { HISTORY = History }
459
469
 
460
470
  # The Fcomp class provided to encapsulate typical filename completion
461
471
  # procedure. You will not typically use this directly, but will instead
@@ -483,7 +493,7 @@ module Readline
483
493
  end
484
494
  end
485
495
 
486
- FILENAME_COMPLETION_PROC = Fcomp
496
+ silence_warnings { FILENAME_COMPLETION_PROC = Fcomp }
487
497
 
488
498
  # The Ucomp class provided to encapsulate typical filename completion
489
499
  # procedure. You will not typically use this directly, but will instead
@@ -514,13 +524,13 @@ module Readline
514
524
  end
515
525
  end
516
526
 
517
- USERNAME_COMPLETION_PROC = Ucomp
527
+ silence_warnings { USERNAME_COMPLETION_PROC = Ucomp }
518
528
 
519
529
  RbReadline.rl_readline_name = "Ruby"
520
530
 
521
531
  RbReadline.using_history()
522
532
 
523
- VERSION = RbReadline.rl_library_version
533
+ silence_warnings { VERSION = RbReadline.rl_library_version }
524
534
 
525
535
  module_function :readline
526
536
 
data/rb-readline.gemspec CHANGED
@@ -34,7 +34,7 @@ spec = Gem::Specification.new do |s|
34
34
  # components, files and paths
35
35
  s.files = Dir[
36
36
  "{bench,examples,lib,test}/**/*.rb",
37
- "README.rdoc",
37
+ "README.md",
38
38
  "LICENSE",
39
39
  "CHANGES",
40
40
  "Rakefile",
@@ -45,7 +45,7 @@ spec = Gem::Specification.new do |s|
45
45
  s.require_path = 'lib'
46
46
 
47
47
  # documentation
48
- s.rdoc_options << '--main' << 'README.rdoc' << '--title' << 'Rb-Readline - Documentation'
48
+ s.rdoc_options << '--main' << 'README.md' << '--title' << 'Rb-Readline - Documentation'
49
49
 
50
- s.extra_rdoc_files = %w(README.rdoc LICENSE CHANGES)
50
+ s.extra_rdoc_files = %w(README.md LICENSE CHANGES)
51
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-readline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Park Heesob
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-06-03 00:00:00.000000000 Z
14
+ date: 2017-07-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -52,13 +52,13 @@ email:
52
52
  executables: []
53
53
  extensions: []
54
54
  extra_rdoc_files:
55
- - README.rdoc
55
+ - README.md
56
56
  - LICENSE
57
57
  - CHANGES
58
58
  files:
59
59
  - CHANGES
60
60
  - LICENSE
61
- - README.rdoc
61
+ - README.md
62
62
  - Rakefile
63
63
  - bench/_rl_adjust_point.rb
64
64
  - examples/example_readline.rb
@@ -83,7 +83,7 @@ metadata: {}
83
83
  post_install_message:
84
84
  rdoc_options:
85
85
  - "--main"
86
- - README.rdoc
86
+ - README.md
87
87
  - "--title"
88
88
  - Rb-Readline - Documentation
89
89
  require_paths:
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: 1.3.5
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.5.1
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Pure-Ruby Readline Implementation