vedeu 0.5.13 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/bin/vedeu_drb_server +1 -0
- data/config/rubocop_enabled.yml +2 -2
- data/docs/events.md +2 -0
- data/docs/getting_started.md +1 -1
- data/examples/drb_app.rb +1 -0
- data/examples/editor_app.rb +76 -0
- data/lib/vedeu/all.rb +13 -7
- data/lib/vedeu/{bindings.rb → bindings/bindings.rb} +2 -0
- data/lib/vedeu/bindings/focus.rb +66 -0
- data/lib/vedeu/bindings/refresh.rb +77 -0
- data/lib/vedeu/bindings/system.rb +19 -88
- data/lib/vedeu/buffers/buffer.rb +8 -8
- data/lib/vedeu/configuration/api.rb +32 -11
- data/lib/vedeu/configuration/cli.rb +8 -0
- data/lib/vedeu/cursor/move.rb +1 -0
- data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -0
- data/lib/vedeu/{dsl.rb → dsl/dsl.rb} +0 -0
- data/lib/vedeu/exceptions.rb +1 -1
- data/lib/vedeu/geometry/position.rb +28 -0
- data/lib/vedeu/input/capture.rb +76 -0
- data/lib/vedeu/input/editor/all.rb +19 -0
- data/lib/vedeu/input/editor/cropper.rb +74 -0
- data/lib/vedeu/input/editor/document.rb +254 -0
- data/lib/vedeu/input/editor/documents.rb +18 -0
- data/lib/vedeu/input/editor/editor.rb +100 -0
- data/lib/vedeu/input/editor/line.rb +143 -0
- data/lib/vedeu/input/editor/lines.rb +199 -0
- data/lib/vedeu/input/editor/virtual_cursor.rb +167 -0
- data/lib/vedeu/input/input.rb +9 -93
- data/lib/vedeu/input/input_translator.rb +155 -0
- data/lib/vedeu/internal_api.rb +9 -0
- data/lib/vedeu/log/lockless_log_device.rb +1 -1
- data/lib/vedeu/models/escape.rb +7 -8
- data/lib/vedeu/output/direct.rb +59 -0
- data/lib/vedeu/output/renderers/terminal.rb +8 -0
- data/lib/vedeu/output/viewport.rb +2 -3
- data/lib/vedeu/{plugins.rb → plugins/plugins.rb} +0 -0
- data/lib/vedeu/refresh/refresh_cursor.rb +1 -0
- data/lib/vedeu/{repositories.rb → repositories/repositories.rb} +0 -0
- data/lib/vedeu/terminal/content.rb +88 -0
- data/lib/vedeu/terminal/mode.rb +79 -0
- data/lib/vedeu/{terminal.rb → terminal/terminal.rb} +9 -25
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/{bindings_test.rb → bindings/bindings_test.rb} +0 -0
- data/test/lib/vedeu/bindings/focus_test.rb +19 -0
- data/test/lib/vedeu/bindings/refresh_test.rb +19 -0
- data/test/lib/vedeu/bindings/system_test.rb +1 -6
- data/test/lib/vedeu/borders/render_border_test.rb +43 -10
- data/test/lib/vedeu/buffers/buffer_test.rb +18 -0
- data/test/lib/vedeu/buffers/virtual_buffer_test.rb +15 -0
- data/test/lib/vedeu/configuration/api_test.rb +18 -2
- data/test/lib/vedeu/configuration/cli_test.rb +5 -0
- data/test/lib/vedeu/cursor/move_test.rb +1 -1
- data/test/lib/vedeu/dsl/dsl_test.rb +8 -0
- data/test/lib/vedeu/dsl/shared_test.rb +12 -0
- data/test/lib/vedeu/{output → esc}/esc_test.rb +0 -0
- data/test/lib/vedeu/geometry/position_test.rb +56 -0
- data/test/lib/vedeu/input/capture_test.rb +63 -0
- data/test/lib/vedeu/input/editor/cropper_test.rb +82 -0
- data/test/lib/vedeu/input/editor/document_test.rb +190 -0
- data/test/lib/vedeu/input/editor/documents_test.rb +17 -0
- data/test/lib/vedeu/input/editor/editor_test.rb +170 -0
- data/test/lib/vedeu/input/editor/line_test.rb +333 -0
- data/test/lib/vedeu/input/editor/lines_test.rb +561 -0
- data/test/lib/vedeu/input/editor/virtual_cursor_test.rb +184 -0
- data/test/lib/vedeu/input/input_test.rb +20 -4
- data/test/lib/vedeu/input/input_translator_test.rb +32 -0
- data/test/lib/vedeu/internal_api_test.rb +1 -0
- data/test/lib/vedeu/models/escape_test.rb +6 -6
- data/test/lib/vedeu/models/views/view_test.rb +15 -2
- data/test/lib/vedeu/null/null_test.rb +8 -0
- data/test/lib/vedeu/output/direct_test.rb +70 -0
- data/test/lib/vedeu/{plugins_test.rb → plugins/plugins_test.rb} +0 -0
- data/test/lib/vedeu/{repositories_test.rb → repositories/repositories_test.rb} +0 -0
- data/test/lib/vedeu/terminal/content_test.rb +100 -0
- data/test/lib/vedeu/terminal/mode_test.rb +95 -0
- data/test/lib/vedeu/{terminal_test.rb → terminal/terminal_test.rb} +23 -23
- data/test/test_helper.rb +1 -0
- metadata +67 -20
- data/lib/vedeu/terminal_mode.rb +0 -59
- data/test/lib/vedeu/terminal_mode_test.rb +0 -72
@@ -0,0 +1,18 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Editor
|
4
|
+
|
5
|
+
# Allows the storing of documents.
|
6
|
+
#
|
7
|
+
class Documents < Vedeu::Repository
|
8
|
+
|
9
|
+
singleton_class.send(:alias_method, :documents, :repository)
|
10
|
+
|
11
|
+
real Vedeu::Editor::Document
|
12
|
+
null Vedeu::Editor::Document
|
13
|
+
|
14
|
+
end # Documents
|
15
|
+
|
16
|
+
end # Editor
|
17
|
+
|
18
|
+
end # Vedeu
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Editor
|
4
|
+
|
5
|
+
# Handles keypresses for a named document whilst the terminal is in fake
|
6
|
+
# mode.
|
7
|
+
#
|
8
|
+
class Editor
|
9
|
+
|
10
|
+
include Vedeu::Common
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators :document,
|
14
|
+
:clear,
|
15
|
+
:delete_character,
|
16
|
+
:down,
|
17
|
+
:insert_character,
|
18
|
+
:insert_line,
|
19
|
+
:left,
|
20
|
+
:render,
|
21
|
+
:reset!,
|
22
|
+
:retrieve,
|
23
|
+
:right,
|
24
|
+
:up
|
25
|
+
|
26
|
+
# @param name [String]
|
27
|
+
# @param input [String|Symbol]
|
28
|
+
# @return [void]
|
29
|
+
def self.keypress(input:, name:)
|
30
|
+
new(input: input, name: name).keypress
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns a new instance of Vedeu::Editor::Editor.
|
34
|
+
#
|
35
|
+
# @param name [String]
|
36
|
+
# @param input [String|Symbol]
|
37
|
+
# @return [Vedeu::Editor::Editor]
|
38
|
+
def initialize(input:, name:)
|
39
|
+
@input = input
|
40
|
+
@name = name
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String|Symbol]
|
44
|
+
def keypress
|
45
|
+
return input unless document
|
46
|
+
|
47
|
+
case input
|
48
|
+
when :backspace then delete_character
|
49
|
+
when :ctrl_c then Vedeu.trigger(:_exit_)
|
50
|
+
when :down then down
|
51
|
+
when :enter then insert_line
|
52
|
+
when :escape then Vedeu.trigger(:_mode_switch_)
|
53
|
+
when :left then left
|
54
|
+
when :right then right
|
55
|
+
when :tab then command
|
56
|
+
when :up then up
|
57
|
+
# when '' then delete_line
|
58
|
+
else
|
59
|
+
insert_character(input)
|
60
|
+
end
|
61
|
+
|
62
|
+
render unless input == :enter
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
# @!attribute [r] input
|
68
|
+
# @return [Symbol|String]
|
69
|
+
attr_reader :input
|
70
|
+
|
71
|
+
# @!attribute [r] name
|
72
|
+
# @return [String]
|
73
|
+
attr_reader :name
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
#
|
78
|
+
# @return []
|
79
|
+
def command
|
80
|
+
command = retrieve
|
81
|
+
|
82
|
+
reset!
|
83
|
+
|
84
|
+
clear
|
85
|
+
|
86
|
+
Vedeu.trigger(:_command_, command)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Return the document by name from the documents repository.
|
90
|
+
#
|
91
|
+
# @return [Vedeu::Editor::Document]
|
92
|
+
def document
|
93
|
+
@document ||= Vedeu.documents.by_name(name)
|
94
|
+
end
|
95
|
+
|
96
|
+
end # Editor
|
97
|
+
|
98
|
+
end # Editor
|
99
|
+
|
100
|
+
end # Vedeu
|
@@ -0,0 +1,143 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Editor
|
4
|
+
|
5
|
+
# Manipulate a single line of an Vedeu::Editor::Document.
|
6
|
+
#
|
7
|
+
class Line
|
8
|
+
|
9
|
+
# @!attribute [rw] line
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :line
|
12
|
+
alias_method :to_s, :line
|
13
|
+
|
14
|
+
# Coerce a line into a new instance of Vedeu::Editor::Line.
|
15
|
+
#
|
16
|
+
# @param line [String|Vedeu::Editor::Line]
|
17
|
+
# @return [Vedeu::Editor::Line]
|
18
|
+
def self.coerce(line)
|
19
|
+
return line if line.is_a?(self)
|
20
|
+
|
21
|
+
if line.is_a?(String)
|
22
|
+
new(line)
|
23
|
+
|
24
|
+
else
|
25
|
+
new
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a new instance of Vedeu::Editor::Line.
|
31
|
+
#
|
32
|
+
# @param line [String|NilClass]
|
33
|
+
# @return [Vedeu::Editor::Line]
|
34
|
+
def initialize(line = nil)
|
35
|
+
@line = line || ''
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return a character or collection of characters (if index is a Range).
|
39
|
+
#
|
40
|
+
# @param index [Fixnum|Range]
|
41
|
+
# @return [String]
|
42
|
+
def [](index)
|
43
|
+
line[index]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the character from the line positioned at the given index.
|
47
|
+
#
|
48
|
+
# @param index [Fixnum|NilClass]
|
49
|
+
# @return [String|NilClass]
|
50
|
+
def character(index = nil)
|
51
|
+
return '' if line && line.empty?
|
52
|
+
return line[-1] unless index
|
53
|
+
|
54
|
+
if index <= 0
|
55
|
+
line[0]
|
56
|
+
|
57
|
+
elsif index && index <= size
|
58
|
+
line[index]
|
59
|
+
|
60
|
+
else
|
61
|
+
line[-1]
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Delete the character from the line positioned at the given index.
|
67
|
+
#
|
68
|
+
# @param index [Fixnum|NilClass]
|
69
|
+
# @return [String]
|
70
|
+
def delete_character(index = nil)
|
71
|
+
return self if line.empty? || (index && index <= 0)
|
72
|
+
|
73
|
+
new_line = if index && index <= size
|
74
|
+
line.dup.tap { |line| line.slice!(index) }
|
75
|
+
|
76
|
+
else
|
77
|
+
line.chop
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
Vedeu::Editor::Line.coerce(new_line)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Returns a boolean indicating whether there are characters on this line.
|
85
|
+
#
|
86
|
+
# @return [Boolean]
|
87
|
+
def empty?
|
88
|
+
size == 0
|
89
|
+
end
|
90
|
+
|
91
|
+
# An object is equal when its values are the same.
|
92
|
+
#
|
93
|
+
# @param other [Vedeu::Editor::Line]
|
94
|
+
# @return [Boolean]
|
95
|
+
def eql?(other)
|
96
|
+
self.class == other.class && line == other.line
|
97
|
+
end
|
98
|
+
alias_method :==, :eql?
|
99
|
+
|
100
|
+
# Insert the character on the line positioned at the given index.
|
101
|
+
#
|
102
|
+
# @param character [String]
|
103
|
+
# @param index [Fixnum|NilClass]
|
104
|
+
# @return [String]
|
105
|
+
def insert_character(character, index = nil)
|
106
|
+
new_line = if index
|
107
|
+
if index <= 0
|
108
|
+
line.insert(0, character)
|
109
|
+
|
110
|
+
elsif index >= size
|
111
|
+
line << character
|
112
|
+
|
113
|
+
else
|
114
|
+
line.insert(index, character)
|
115
|
+
|
116
|
+
end
|
117
|
+
else
|
118
|
+
line + character
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
Vedeu::Editor::Line.coerce(new_line)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Return the size of the line in characters.
|
126
|
+
#
|
127
|
+
# @return [Fixnum]
|
128
|
+
def size
|
129
|
+
line.size
|
130
|
+
end
|
131
|
+
|
132
|
+
# Return the line as a collection of Vedeu::Views::Char objects.
|
133
|
+
#
|
134
|
+
# @return [Array<Vedeu::Views::Char>]
|
135
|
+
def to_chars
|
136
|
+
line.chars.map { |char| Vedeu::Views::Char.new(value: char) }
|
137
|
+
end
|
138
|
+
|
139
|
+
end # Line
|
140
|
+
|
141
|
+
end # Editor
|
142
|
+
|
143
|
+
end # Vedeu
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Editor
|
4
|
+
|
5
|
+
# Manipulate the lines of an Vedeu::Editor::Document.
|
6
|
+
#
|
7
|
+
class Lines
|
8
|
+
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
# @!attribute [rw] lines
|
12
|
+
# @return [String]
|
13
|
+
attr_accessor :lines
|
14
|
+
|
15
|
+
# Coerce a document into a new instance of Vedeu::Editor::Lines.
|
16
|
+
#
|
17
|
+
# @param document [Array<String>|Vedeu::Editor::Lines]
|
18
|
+
# @return [Vedeu::Editor::Lines]
|
19
|
+
def self.coerce(document)
|
20
|
+
if document.is_a?(self)
|
21
|
+
new(document.lines)
|
22
|
+
|
23
|
+
elsif document.is_a?(Array)
|
24
|
+
lines = document.map do |line|
|
25
|
+
if line.is_a?(Vedeu::Editor::Line)
|
26
|
+
line
|
27
|
+
|
28
|
+
elsif line.is_a?(String)
|
29
|
+
Vedeu::Editor::Line.coerce(line)
|
30
|
+
|
31
|
+
else
|
32
|
+
Vedeu::Editor::Line.new
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
new(lines)
|
38
|
+
|
39
|
+
elsif document.is_a?(String)
|
40
|
+
lines = document.lines.map(&:chomp).map do |line|
|
41
|
+
Vedeu::Editor::Line.coerce(line)
|
42
|
+
end
|
43
|
+
|
44
|
+
new(lines)
|
45
|
+
|
46
|
+
else
|
47
|
+
new
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns a new instance of Vedeu::Editor::Lines.
|
53
|
+
#
|
54
|
+
# @param lines [Array<String>|NilClass]
|
55
|
+
# @return [Vedeu::Editor::Lines]
|
56
|
+
def initialize(lines = nil)
|
57
|
+
@lines = lines || []
|
58
|
+
end
|
59
|
+
|
60
|
+
# Return a line or collection of lines (if index is a Range).
|
61
|
+
#
|
62
|
+
# @param index [Fixnum|Range]
|
63
|
+
# @return [Vedeu::Editor::Line]
|
64
|
+
def [](index)
|
65
|
+
lines[index]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Deletes the character from the line where the cursor is currently
|
69
|
+
# positioned.
|
70
|
+
#
|
71
|
+
# @param y [Fixnum]
|
72
|
+
# @param x [Fixnum]
|
73
|
+
# @return [Vedeu::Editor::Lines]
|
74
|
+
def delete_character(y, x)
|
75
|
+
lines[y] = line(y).delete_character(x)
|
76
|
+
Vedeu::Editor::Lines.coerce(lines)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Delete the line from the lines positioned at the given index.
|
80
|
+
#
|
81
|
+
# @param index [Fixnum|NilClass]
|
82
|
+
# @return [String]
|
83
|
+
def delete_line(index = nil)
|
84
|
+
return self if lines.empty? || (index && index <= 0)
|
85
|
+
|
86
|
+
new_lines = if index && index <= size
|
87
|
+
lines.dup.tap { |lines| lines.slice!(index) }
|
88
|
+
|
89
|
+
else
|
90
|
+
lines.dup.tap(&:pop)
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
Vedeu::Editor::Lines.coerce(new_lines)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Provides iteration over the collection.
|
98
|
+
#
|
99
|
+
# @param block [Proc]
|
100
|
+
# @return [Enumerator]
|
101
|
+
def each(&block)
|
102
|
+
lines.each(&block)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns a boolean indicating whether there are lines.
|
106
|
+
#
|
107
|
+
# @return [Boolean]
|
108
|
+
def empty?
|
109
|
+
size == 0
|
110
|
+
end
|
111
|
+
|
112
|
+
# An object is equal when its values are the same.
|
113
|
+
#
|
114
|
+
# @param other [Vedeu::Editor::Lines]
|
115
|
+
# @return [Boolean]
|
116
|
+
def eql?(other)
|
117
|
+
self.class == other.class && lines == other.lines
|
118
|
+
end
|
119
|
+
alias_method :==, :eql?
|
120
|
+
|
121
|
+
# Insert a character in to a line.
|
122
|
+
#
|
123
|
+
# @param character [String]
|
124
|
+
# @param y [Fixnum]
|
125
|
+
# @param x [Fixnum]
|
126
|
+
# @return [Vedeu::Editor::Lines]
|
127
|
+
def insert_character(character, y, x)
|
128
|
+
lines[y] = line(y).insert_character(character, x)
|
129
|
+
Vedeu::Editor::Lines.coerce(lines)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Insert the line on the line below the given index.
|
133
|
+
#
|
134
|
+
# @param line [String]
|
135
|
+
# @param index [Fixnum|NilClass]
|
136
|
+
# @return [Vedeu::Editor::Lines]
|
137
|
+
def insert_line(line, index = nil)
|
138
|
+
return self unless line
|
139
|
+
|
140
|
+
new_lines = if index
|
141
|
+
if index <= 0
|
142
|
+
lines.insert(0, line)
|
143
|
+
|
144
|
+
elsif index >= size
|
145
|
+
lines << line
|
146
|
+
|
147
|
+
else
|
148
|
+
lines.insert(index, line)
|
149
|
+
|
150
|
+
end
|
151
|
+
else
|
152
|
+
lines << line
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
Vedeu::Editor::Lines.coerce(new_lines)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Returns the line at the given index.
|
160
|
+
#
|
161
|
+
# @param index [Fixnum|NilClass]
|
162
|
+
# @return [Vedeu::Editor::Line]
|
163
|
+
def line(index = nil)
|
164
|
+
return Vedeu::Editor::Line.new unless lines
|
165
|
+
return Vedeu::Editor::Line.coerce(lines.last) unless index
|
166
|
+
|
167
|
+
indexed = if index <= 0
|
168
|
+
lines.first
|
169
|
+
|
170
|
+
elsif index && index <= size
|
171
|
+
lines[index]
|
172
|
+
|
173
|
+
else
|
174
|
+
lines.last
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
Vedeu::Editor::Line.coerce(indexed)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Return the number of lines.
|
182
|
+
#
|
183
|
+
# @return [Fixnum]
|
184
|
+
def size
|
185
|
+
lines.size
|
186
|
+
end
|
187
|
+
|
188
|
+
# Return the lines as a string.
|
189
|
+
#
|
190
|
+
# @return [String]
|
191
|
+
def to_s
|
192
|
+
lines.map(&:to_s).join
|
193
|
+
end
|
194
|
+
|
195
|
+
end # Line
|
196
|
+
|
197
|
+
end # Editor
|
198
|
+
|
199
|
+
end # Vedeu
|