Skip to content

Commit

Permalink
Optimize document refresh;
Browse files Browse the repository at this point in the history
Rather than redraw the whole screen on a document character change
we update the buffer and redraw only the document area.

Fixes #302.
  • Loading branch information
gavinlaking committed Nov 13, 2015
1 parent 9b70a4a commit 00690ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/vedeu/editor/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def refresh

Vedeu.trigger(:_clear_view_content_, name)

Vedeu.render_output(output)
Vedeu.buffer_update(output)

Vedeu.direct_write(output.map(&:to_s).join)

self
end
Expand Down
27 changes: 25 additions & 2 deletions lib/vedeu/output/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ module Output
#
class Output

# @param output [Array<Array<Vedeu::Views::Char>>|
# NilClass|Vedeu::Models::Escape]
# @return [Array]
def self.buffer_update(output)
return nil if output.nil?

new(output).buffer_update
end

# @param output [Array<Array<Vedeu::Views::Char>>|
# NilClass|Vedeu::Models::Escape]
# @return [Array]
Expand Down Expand Up @@ -47,6 +56,11 @@ def initialize(output)
@output = output
end

# @return [Array]
def buffer_update
buffer_update!
end

# @return [Array]
def buffer_write
buffer_write!
Expand Down Expand Up @@ -84,6 +98,11 @@ def render_output

private

# @return [Array]
def buffer_update!
Vedeu::Terminal::Buffer.update(output)
end

# @return [Array]
def buffer_write!
Vedeu::Terminal::Buffer.write(output)
Expand All @@ -106,13 +125,17 @@ def escape_sequence?
# Write the given output to the configured or default renderers.
#
# @example
# Vedeu.buffer_update(output)
# Vedeu.buffer_write(output)
# Vedeu.direct_write(output)
# Vedeu.render_output(output)
#
# @!method render_output
# @return [Array|NilClass]
def_delegators Vedeu::Output::Output,
:render_output,
:buffer_update,
:buffer_write,
:direct_write
:direct_write,
:render_output

end # Vedeu

0 comments on commit 00690ae

Please sign in to comment.