mini_readline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +207 -0
  6. data/Rakefile +40 -0
  7. data/lib/mini_readline.rb +28 -0
  8. data/lib/mini_readline/options.rb +19 -0
  9. data/lib/mini_readline/raw_term.rb +14 -0
  10. data/lib/mini_readline/raw_term/other.rb +67 -0
  11. data/lib/mini_readline/raw_term/other/map.rb +75 -0
  12. data/lib/mini_readline/raw_term/other/set_posn.rb +22 -0
  13. data/lib/mini_readline/raw_term/windows.rb +88 -0
  14. data/lib/mini_readline/raw_term/windows/map.rb +71 -0
  15. data/lib/mini_readline/raw_term/windows/set_posn.rb +40 -0
  16. data/lib/mini_readline/raw_term/windows/win_32_api.rb +47 -0
  17. data/lib/mini_readline/read_line.rb +65 -0
  18. data/lib/mini_readline/read_line/edit.rb +87 -0
  19. data/lib/mini_readline/read_line/edit/cancel.rb +15 -0
  20. data/lib/mini_readline/read_line/edit/delete_left.rb +21 -0
  21. data/lib/mini_readline/read_line/edit/delete_right.rb +19 -0
  22. data/lib/mini_readline/read_line/edit/enter.rb +14 -0
  23. data/lib/mini_readline/read_line/edit/go_end.rb +14 -0
  24. data/lib/mini_readline/read_line/edit/go_home.rb +14 -0
  25. data/lib/mini_readline/read_line/edit/go_left.rb +18 -0
  26. data/lib/mini_readline/read_line/edit/go_right.rb +18 -0
  27. data/lib/mini_readline/read_line/edit/insert_text.rb +18 -0
  28. data/lib/mini_readline/read_line/edit/next_history.rb +19 -0
  29. data/lib/mini_readline/read_line/edit/previous_history.rb +19 -0
  30. data/lib/mini_readline/read_line/edit/unmapped.rb +18 -0
  31. data/lib/mini_readline/read_line/edit_window.rb +72 -0
  32. data/lib/mini_readline/read_line/edit_window/sync_cursor.rb +15 -0
  33. data/lib/mini_readline/read_line/edit_window/sync_window.rb +46 -0
  34. data/lib/mini_readline/read_line/history.rb +61 -0
  35. data/lib/mini_readline/version.rb +4 -0
  36. data/mini_readline.gemspec +26 -0
  37. data/reek.txt +1 -0
  38. data/sire.rb +102 -0
  39. data/tests/mini_readline_tests.rb +55 -0
  40. metadata +110 -0
data/reek.txt ADDED
@@ -0,0 +1 @@
1
+ 0 total warnings
data/sire.rb ADDED
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+ # A Simple Interactive Ruby Environment
3
+
4
+ require 'pp'
5
+
6
+ if ARGV[0] == 'old'
7
+ require 'readline'
8
+ puts "\nOption(old). Loaded the standard readline gem."
9
+ elsif ARGV[0] == 'local'
10
+ require './lib/mini_readline'
11
+ puts "\nOption(local). Loaded mini_readline from the local code folder."
12
+ elsif defined?(MiniReadline)
13
+ puts "The mini_readline gem is already loaded."
14
+ else
15
+ begin
16
+ require 'mini_readline'
17
+ puts "\nLoaded mini_readline from the system gem."
18
+ rescue LoadError
19
+ begin
20
+ require './lib/mini_readline'
21
+ puts "\nLoaded mini_readline from the local code folder."
22
+ rescue LoadError
23
+ require 'readline'
24
+ puts "\nLoaded the standard readline gem."
25
+ end
26
+ end
27
+ end
28
+
29
+ class Object
30
+ #Generate the class lineage of the object.
31
+ def classes
32
+ begin
33
+ result = ""
34
+ klass = self.instance_of?(Class) ? self : self.class
35
+
36
+ begin
37
+ result << klass.to_s
38
+ klass = klass.superclass
39
+ result << " < " if klass
40
+ end while klass
41
+
42
+ result
43
+ end
44
+ end
45
+ end
46
+
47
+ class SIRE
48
+ #Set up the interactive session.
49
+ def initialize
50
+ @_done = false
51
+ end
52
+
53
+ #Quit the interactive session.
54
+ def q
55
+ @_done = true
56
+ puts
57
+ "Bye bye for now!"
58
+ end
59
+
60
+ #Test spawning a process. This breaks the regular readline gem.
61
+ def run(command)
62
+ IO.popen(command, "r+") do |io|
63
+ io.close_write
64
+ return io.read
65
+ end
66
+ end
67
+
68
+ #Execute a single line.
69
+ def exec_line(line)
70
+ result = eval line
71
+ pp result unless line.length == 0
72
+
73
+ rescue Interrupt => e
74
+ puts "\nExecution Interrupted!"
75
+ puts "\n#{e.class} detected: #{e}\n"
76
+ puts e.backtrace
77
+ puts "\n"
78
+
79
+ rescue Exception => e
80
+ puts "\n#{e.class} detected: #{e}\n"
81
+ puts e.backtrace
82
+ puts
83
+ end
84
+
85
+ #Run the interactive session.
86
+ def run_sire
87
+ puts
88
+ puts "Welcome to a Simple Interactive Ruby Environment\n"
89
+ puts "Use the command 'q' to quit.\n\n"
90
+
91
+ until @_done
92
+ exec_line(Readline.readline('SIRE>', true))
93
+ end
94
+
95
+ puts "\n\n"
96
+ end
97
+
98
+ end
99
+
100
+ if __FILE__ == $0
101
+ SIRE.new.run_sire
102
+ end
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/mini_readline'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest_visible'
7
+
8
+ #Test the monkey patches applied to the Object class.
9
+ class MiniReadlineTester < Minitest::Test
10
+
11
+ #Track mini-test progress.
12
+ MinitestVisible.track self, __FILE__
13
+
14
+ def test_that_module_entities_exists
15
+ assert_equal(Module, MiniReadline.class)
16
+ assert_equal(String, MiniReadline::VERSION.class)
17
+ assert_equal(Class, MiniReadline::Readline.class)
18
+ assert_equal(Class, MiniReadline::Edit.class)
19
+ assert_equal(Class, MiniReadline::EditWindow.class)
20
+ end
21
+
22
+ def test_platform_detection
23
+ if (RUBY_PLATFORM =~ /\bcygwin\b/i) || (RUBY_PLATFORM !~ /mswin|mingw/)
24
+ assert_equal(:other, MiniReadline::PLATFORM)
25
+ else
26
+ assert_equal(:windows, MiniReadline::PLATFORM)
27
+ end
28
+ end
29
+
30
+ def test_reading_a_line
31
+ puts
32
+ puts "To finish this test, enter the word: quit"
33
+
34
+ edit = MiniReadline::Readline.new()
35
+
36
+ result = ''
37
+
38
+ loop do
39
+ result = edit.readline(">")
40
+ puts result.inspect
41
+ break unless result != 'quit'
42
+ end
43
+
44
+ assert_equal("quit", result)
45
+ end
46
+
47
+ def test_prompt_verification
48
+ opts = {:window_width => 39}
49
+ edit = MiniReadline::Readline.new()
50
+ assert_raises(RuntimeError) {edit.readline(">"*20, opts)}
51
+ end
52
+
53
+
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini_readline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Camilleri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A gem for console command entry with line edit and history.
42
+ email:
43
+ - peter.c.camilleri@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/mini_readline.rb
54
+ - lib/mini_readline/options.rb
55
+ - lib/mini_readline/raw_term.rb
56
+ - lib/mini_readline/raw_term/other.rb
57
+ - lib/mini_readline/raw_term/other/map.rb
58
+ - lib/mini_readline/raw_term/other/set_posn.rb
59
+ - lib/mini_readline/raw_term/windows.rb
60
+ - lib/mini_readline/raw_term/windows/map.rb
61
+ - lib/mini_readline/raw_term/windows/set_posn.rb
62
+ - lib/mini_readline/raw_term/windows/win_32_api.rb
63
+ - lib/mini_readline/read_line.rb
64
+ - lib/mini_readline/read_line/edit.rb
65
+ - lib/mini_readline/read_line/edit/cancel.rb
66
+ - lib/mini_readline/read_line/edit/delete_left.rb
67
+ - lib/mini_readline/read_line/edit/delete_right.rb
68
+ - lib/mini_readline/read_line/edit/enter.rb
69
+ - lib/mini_readline/read_line/edit/go_end.rb
70
+ - lib/mini_readline/read_line/edit/go_home.rb
71
+ - lib/mini_readline/read_line/edit/go_left.rb
72
+ - lib/mini_readline/read_line/edit/go_right.rb
73
+ - lib/mini_readline/read_line/edit/insert_text.rb
74
+ - lib/mini_readline/read_line/edit/next_history.rb
75
+ - lib/mini_readline/read_line/edit/previous_history.rb
76
+ - lib/mini_readline/read_line/edit/unmapped.rb
77
+ - lib/mini_readline/read_line/edit_window.rb
78
+ - lib/mini_readline/read_line/edit_window/sync_cursor.rb
79
+ - lib/mini_readline/read_line/edit_window/sync_window.rb
80
+ - lib/mini_readline/read_line/history.rb
81
+ - lib/mini_readline/version.rb
82
+ - mini_readline.gemspec
83
+ - reek.txt
84
+ - sire.rb
85
+ - tests/mini_readline_tests.rb
86
+ homepage: http://teuthida-technologies.com/
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.9.3
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A simplified replacement for readline.
110
+ test_files: []