lib/vedeu/editor/document.rb in vedeu-0.6.20 vs lib/vedeu/editor/document.rb in vedeu-0.6.21
- old
+ new
@@ -22,27 +22,31 @@
:ox,
:oy,
:x,
:y
+ def_delegators :interface,
+ :colour,
+ :style
+
# @!attribute [r] attributes
# @return [Hash]
attr_reader :attributes
# @!attribute [rw] data
# @return [String]
attr_accessor :data
# @!attribute [rw] name
- # @return [String]
+ # @return [String|Symbol]
attr_accessor :name
# Returns a new instance of Vedeu::Editor::Document.
#
# @param attributes [Hash]
# @option attributes data [String]
- # @option attributes name [String]
+ # @option attributes name [String|Symbol]
# @option attributes repository
# [Vedeu::Repositories::Repository]
# @return [Vedeu::Editor::Document]
def initialize(attributes = {})
defaults.merge!(attributes).each do |key, value|
@@ -52,11 +56,11 @@
# Clear the document content in the terminal.
#
# @return [void]
def clear
- Vedeu::Output::Direct.write(value: clear_output, x: bx, y: by)
+ Vedeu.trigger(:_clear_view_, name)
end
# Deletes the character from the line where the cursor is
# currently positioned.
#
@@ -74,12 +78,10 @@
# @return [Vedeu::Editor::Document]
def delete_line
@lines = lines.delete_line(y)
up
-
- refresh
end
# Move the virtual cursor down.
#
# @return [Vedeu::Editor::Document]
@@ -114,12 +116,10 @@
return self if character.is_a?(Symbol)
@lines = lines.insert_character(character, y, x)
right
-
- refresh
end
# Insert an empty line.
#
# @return [Vedeu::Editor::Document]
@@ -161,11 +161,11 @@
#
# @return [void]
def render
clear
- Vedeu::Output::Direct.write(value: output, x: bx, y: by)
+ Vedeu::Output::Output.render(output)
end
# Reset the document to the empty state.
#
# @return [Vedeu::Editor::Document]
@@ -215,28 +215,18 @@
# @return [Vedeu::Borders::Border]
def border
@border ||= Vedeu.borders.by_name(name)
end
- # Return the data needed to clear the area which the document is
- # using.
- #
- # @return [String]
- def clear_output
- clear_output = ''
-
- (by..byn).each do |row|
- clear_output << "\e[#{row};#{bx}H" + (' ' * width)
- end
-
- # reset cursor to top left of document
- clear_output << "\e[#{by};#{bx}H"
+ # @return [Vedeu::Models::Interface]
+ def interface
+ @interface ||= Vedeu.interfaces.by_name(name)
end
# Returns the default options/attributes for this class.
#
- # @return [Hash]
+ # @return [Hash<Symbol => void|Symbol]
def defaults
{
data: Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new]),
name: nil,
repository: Vedeu.documents,
@@ -245,39 +235,47 @@
# Return the data needed to render the document.
#
# @return [String]
def output
- output = ''
+ out = []
- visible.each_with_index do |line, y_index|
- output << Vedeu::Geometry::Position.new((by + y_index), bx).to_s
- output << line.to_s
+ visible_lines.each_with_index do |line, y_index|
+ line.chars.each_with_index do |char, x_index|
+ position = [(by + y_index), (bx + x_index)]
+
+ out << Vedeu::Views::Char.new(value: char,
+ parent: interface,
+ position: position)
+ end
end
- output << cursor.to_s
+ out << border.render
- output
+ cursor.store
+
+ out.flatten
end
# Return a virtual cursor to track the cursor position within
# the document.
#
# @return [Vedeu::Editor::Cursor]
def cursor
- @cursor ||= Vedeu::Editor::Cursor.new(y: 0,
- x: 0,
- by: by,
- bx: bx,
- byn: byn,
- bxn: bxn)
+ @cursor ||= Vedeu::Editor::Cursor.new(y: 0,
+ x: 0,
+ by: by,
+ bx: bx,
+ byn: byn,
+ bxn: bxn,
+ name: name)
end
# Return only the visible lines for the document based on the
# current virtual cursor position.
#
# @return [Vedeu::Editor::Lines]
- def visible
+ def visible_lines
Vedeu::Editor::Cropper.new(lines: lines,
height: height,
width: width,
ox: ox,
oy: oy).cropped