Module: Vedeu::VirtualBuffer

Extended by:
VirtualBuffer
Included in:
VirtualBuffer
Defined in:
lib/vedeu/output/virtual_buffer.rb

Overview

Store and retrieve VirtualTerminal objects.

Each VirtualTerminal object is a copy of the current terminal including content but not as String objects but Char objects. Using Char objects means that we can store the data used to make up the displayed character, complete with its colour, position and style.

Once a Char has been converted to a String, it is tricky to separate the escape sequences and string data. By deferring this conversion we can display the Char in multiple ways (e.g. HTML) or in multiple formats (e.g. JSON), and render/use that in an appropriate way.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearArray Also known as: reset

Destroy all virtual buffers currently stored.

Returns:

  • (Array)


43
44
45
# File 'lib/vedeu/output/virtual_buffer.rb', line 43

def clear
  @storage = in_memory
end

.in_memoryArray (private)

Returns an empty collection ready for the storing of virtual buffers.

Returns:

  • (Array)


60
61
62
# File 'lib/vedeu/output/virtual_buffer.rb', line 60

def in_memory
  []
end

.retrieveArray<Array<Vedeu::Char>>|NilClass

Fetch the oldest stored virtual buffer first.

Returns:



22
23
24
# File 'lib/vedeu/output/virtual_buffer.rb', line 22

def retrieve
  storage.pop
end

.sizeFixnum

Return the number of virtual buffers currently stored.

Returns:

  • (Fixnum)


36
37
38
# File 'lib/vedeu/output/virtual_buffer.rb', line 36

def size
  storage.size
end

.storageArray (private)

Access to the storage for this repository.

Returns:

  • (Array)


53
54
55
# File 'lib/vedeu/output/virtual_buffer.rb', line 53

def storage
  @storage ||= in_memory
end

.store(data) ⇒ Array<Array<Vedeu::Char>>

Store a new virtual buffer.

Returns:



29
30
31
# File 'lib/vedeu/output/virtual_buffer.rb', line 29

def store(data)
  storage.unshift(data)
end

Instance Method Details

#clearArray Also known as: reset

Destroy all virtual buffers currently stored.

Returns:

  • (Array)


43
44
45
# File 'lib/vedeu/output/virtual_buffer.rb', line 43

def clear
  @storage = in_memory
end

#in_memoryArray (private)

Returns an empty collection ready for the storing of virtual buffers.

Returns:

  • (Array)


60
61
62
# File 'lib/vedeu/output/virtual_buffer.rb', line 60

def in_memory
  []
end

#retrieveArray<Array<Vedeu::Char>>|NilClass

Fetch the oldest stored virtual buffer first.

Returns:



22
23
24
# File 'lib/vedeu/output/virtual_buffer.rb', line 22

def retrieve
  storage.pop
end

#sizeFixnum

Return the number of virtual buffers currently stored.

Returns:

  • (Fixnum)


36
37
38
# File 'lib/vedeu/output/virtual_buffer.rb', line 36

def size
  storage.size
end

#storageArray (private)

Access to the storage for this repository.

Returns:

  • (Array)


53
54
55
# File 'lib/vedeu/output/virtual_buffer.rb', line 53

def storage
  @storage ||= in_memory
end

#store(data) ⇒ Array<Array<Vedeu::Char>>

Store a new virtual buffer.

Returns:



29
30
31
# File 'lib/vedeu/output/virtual_buffer.rb', line 29

def store(data)
  storage.unshift(data)
end