rawline 0.2.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.
- data/CHANGELOG +13 -0
- data/LICENSE +11 -0
- data/README +43 -0
- data/examples/key_tester.rb +19 -0
- data/examples/rawline_shell.rb +26 -0
- data/lib/rawline/editor.rb +647 -0
- data/lib/rawline/history_buffer.rb +130 -0
- data/lib/rawline/line.rb +158 -0
- data/lib/rawline/terminal/vt220_terminal.rb +66 -0
- data/lib/rawline/terminal/windows_terminal.rb +66 -0
- data/lib/rawline/terminal.rb +87 -0
- data/lib/rawline.rb +32 -0
- data/test/test_all.rb +9 -0
- data/test/test_editor.rb +169 -0
- data/test/test_history_buffer.rb +113 -0
- data/test/test_line.rb +60 -0
- metadata +76 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
module RawLine
|
4
|
+
TEST_HOME = File.dirname(File.expand_path(__FILE__))+'/..' unless const_defined?(:TEST_HOME)
|
5
|
+
end
|
6
|
+
|
7
|
+
require "#{RawLine::TEST_HOME}/lib/RawLine/history_buffer"
|
8
|
+
|
9
|
+
describe RawLine::HistoryBuffer do
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
@history = RawLine::HistoryBuffer.new(5)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "instantiates an empty array when created" do
|
16
|
+
@history.length.should == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
it "allows items to be added to the history" do
|
20
|
+
@history.duplicates = false
|
21
|
+
@history << "line #1"
|
22
|
+
@history << "line #2"
|
23
|
+
@history << "line #3"
|
24
|
+
@history << "line #2"
|
25
|
+
@history.should == ["line #1", "line #3", "line #2"]
|
26
|
+
@history.duplicates = true
|
27
|
+
@history << "line #3"
|
28
|
+
@history.should == ["line #1", "line #3", "line #2", "line #3"]
|
29
|
+
@history.exclude = lambda { |i| i.match(/line #[456]/) }
|
30
|
+
@history << "line #4"
|
31
|
+
@history << "line #5"
|
32
|
+
@history << "line #6"
|
33
|
+
@history.should == ["line #1", "line #3", "line #2", "line #3"]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not overflow" do
|
37
|
+
@history << "line #1"
|
38
|
+
@history << "line #2"
|
39
|
+
@history << "line #3"
|
40
|
+
@history << "line #4"
|
41
|
+
@history << "line #5"
|
42
|
+
@history << "line #6"
|
43
|
+
@history.length.should == 5
|
44
|
+
end
|
45
|
+
|
46
|
+
it "allows navigation back and forward" do
|
47
|
+
@history.back
|
48
|
+
@history.forward
|
49
|
+
@history.position.should == nil
|
50
|
+
@history << "line #1"
|
51
|
+
@history << "line #2"
|
52
|
+
@history << "line #3"
|
53
|
+
@history << "line #4"
|
54
|
+
@history << "line #5"
|
55
|
+
@history.back
|
56
|
+
@history.back
|
57
|
+
@history.back
|
58
|
+
@history.back
|
59
|
+
@history.back
|
60
|
+
@history.position.should == 0
|
61
|
+
@history.back
|
62
|
+
@history.position.should == 0
|
63
|
+
@history.forward
|
64
|
+
@history.position.should == 1
|
65
|
+
@history.forward
|
66
|
+
@history.forward
|
67
|
+
@history.forward
|
68
|
+
@history.forward
|
69
|
+
@history.position.should == 4
|
70
|
+
@history.forward
|
71
|
+
@history.position.should == 4
|
72
|
+
@history.cycle = true
|
73
|
+
@history.forward
|
74
|
+
@history.forward
|
75
|
+
@history.position.should == 1
|
76
|
+
end
|
77
|
+
|
78
|
+
it "can retrieve the last element or the element at @position via 'get'" do
|
79
|
+
@history.get.should == nil
|
80
|
+
@history << "line #1"
|
81
|
+
@history << "line #2"
|
82
|
+
@history << "line #3"
|
83
|
+
@history << "line #4"
|
84
|
+
@history << "line #5"
|
85
|
+
@history.get.should == "line #5"
|
86
|
+
@history.back
|
87
|
+
@history.get.should == "line #4"
|
88
|
+
@history.forward
|
89
|
+
@history.get.should == "line #5"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "can be cleared and resized" do
|
93
|
+
@history << "line #1"
|
94
|
+
@history << "line #2"
|
95
|
+
@history << "line #3"
|
96
|
+
@history << "line #4"
|
97
|
+
@history << "line #5"
|
98
|
+
@history.back
|
99
|
+
@history.back
|
100
|
+
@history.get.should == "line #4"
|
101
|
+
@history.resize(6)
|
102
|
+
@history.position.should == nil
|
103
|
+
@history << "line #6"
|
104
|
+
@history.get.should == "line #6"
|
105
|
+
@history.empty
|
106
|
+
@history.should == []
|
107
|
+
@history.size.should == 6
|
108
|
+
@history.position.should == nil
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
data/test/test_line.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
module RawLine
|
4
|
+
TEST_HOME = File.dirname(File.expand_path(__FILE__))+'/..' unless const_defined?(:TEST_HOME)
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'highline'
|
8
|
+
|
9
|
+
require "#{RawLine::TEST_HOME}/lib/RawLine/history_buffer"
|
10
|
+
require "#{RawLine::TEST_HOME}/lib/RawLine/line"
|
11
|
+
|
12
|
+
describe RawLine::Line do
|
13
|
+
|
14
|
+
before :each do
|
15
|
+
@line = RawLine::Line.new(5) {|l| l.prompt = "=>" }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "allows characters to be added to @text via the '<<' operator" do
|
19
|
+
@line.text = "test #1"
|
20
|
+
@line << 'a'[0]
|
21
|
+
@line.text.should == "test #1a"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "allows characters to be retrieved and substituted via '[]' and '[]=' operators" do
|
25
|
+
@line.text = 'test #2'
|
26
|
+
@line[0] = 't'
|
27
|
+
@line[0..3].should == 'test'
|
28
|
+
@line[4..6] = ''
|
29
|
+
@line[0] = "This is a t"
|
30
|
+
@line.text.should == "This is a test"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "updates @position via 'left' and 'right'" do
|
34
|
+
@line.text = "test #3"
|
35
|
+
@line.right 2
|
36
|
+
@line.position.should == 2
|
37
|
+
@line.left
|
38
|
+
@line.position.should == 1
|
39
|
+
@line.left 4
|
40
|
+
@line.position.should == 0
|
41
|
+
@line.right HighLine::SystemExtensions.terminal_size()[0]+10
|
42
|
+
@line.position.should == HighLine::SystemExtensions.terminal_size()[0]-2
|
43
|
+
@line.eol.should == 6
|
44
|
+
end
|
45
|
+
|
46
|
+
it "is aware of the word in which the cursor is" do
|
47
|
+
@line.text = "This is another test"
|
48
|
+
@line.word.should == {:start => 0, :end => 3, :text => "This"}
|
49
|
+
@line.right 2
|
50
|
+
@line[2].should == 'i'[0]
|
51
|
+
@line.word.should == {:start => 0, :end => 3, :text => "This"}
|
52
|
+
@line.right
|
53
|
+
@line.word.should == {:start => 0, :end => 3, :text => "This"}
|
54
|
+
@line.right
|
55
|
+
@line.word.should == {:start => 0, :end => 3, :text => "This"}
|
56
|
+
@line.right
|
57
|
+
@line.word.should == {:start => 5, :end => 6, :text => "is"}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: rawline
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2008-04-01 00:00:00 +02:00
|
8
|
+
summary: A library for definign custom key bindings and perform line editing operations
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: h3rald@h3rald.com
|
12
|
+
homepage: http://rubyforge.org/projects/rawline
|
13
|
+
rubyforge_project: inline
|
14
|
+
description: RawLine can be used to define custom key bindings, perform common line editing operations, manage command history and define custom command completion rules.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Fabio Cevasco
|
31
|
+
files:
|
32
|
+
- lib/rawline
|
33
|
+
- lib/rawline/editor.rb
|
34
|
+
- lib/rawline/history_buffer.rb
|
35
|
+
- lib/rawline/line.rb
|
36
|
+
- lib/rawline/terminal
|
37
|
+
- lib/rawline/terminal/vt220_terminal.rb
|
38
|
+
- lib/rawline/terminal/windows_terminal.rb
|
39
|
+
- lib/rawline/terminal.rb
|
40
|
+
- lib/rawline.rb
|
41
|
+
- examples/key_tester.rb
|
42
|
+
- examples/rawline_shell.rb
|
43
|
+
- test/test_all.rb
|
44
|
+
- test/test_editor.rb
|
45
|
+
- test/test_history_buffer.rb
|
46
|
+
- test/test_line.rb
|
47
|
+
- README
|
48
|
+
- LICENSE
|
49
|
+
- CHANGELOG
|
50
|
+
test_files:
|
51
|
+
- test/test_all.rb
|
52
|
+
rdoc_options:
|
53
|
+
- --main
|
54
|
+
- README
|
55
|
+
- --exclude
|
56
|
+
- test
|
57
|
+
extra_rdoc_files:
|
58
|
+
- README
|
59
|
+
- LICENSE
|
60
|
+
- CHANGELOG
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions: []
|
64
|
+
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
dependencies:
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: highline
|
70
|
+
version_requirement:
|
71
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.0
|
76
|
+
version:
|