Class: Charming::Internal::Terminal::MemoryBackend

Inherits:
Object
  • Object
show all
Includes:
Adapter
Defined in:
lib/charming/internal/terminal/memory_backend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events: [], width: 80, height: 24) ⇒ MemoryBackend

Returns a new instance of MemoryBackend.



11
12
13
14
15
16
17
18
# File 'lib/charming/internal/terminal/memory_backend.rb', line 11

def initialize(events: [], width: 80, height: 24)
  @events = events.dup
  @width = width
  @height = height
  @frames = []
  @operations = []
  @mouse_enabled = false
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames.



9
10
11
# File 'lib/charming/internal/terminal/memory_backend.rb', line 9

def frames
  @frames
end

#operationsObject (readonly)

Returns the value of attribute operations.



9
10
11
# File 'lib/charming/internal/terminal/memory_backend.rb', line 9

def operations
  @operations
end

Instance Method Details

#clearObject



53
54
55
# File 'lib/charming/internal/terminal/memory_backend.rb', line 53

def clear
  @operations << :clear
end

#disable_mouse_trackingObject



70
71
72
73
# File 'lib/charming/internal/terminal/memory_backend.rb', line 70

def disable_mouse_tracking
  @mouse_enabled = false
  @operations << :disable_mouse_tracking
end

#enable_mouse_trackingObject



65
66
67
68
# File 'lib/charming/internal/terminal/memory_backend.rb', line 65

def enable_mouse_tracking
  @mouse_enabled = true
  @operations << :enable_mouse_tracking
end

#enter_alt_screenObject



37
38
39
# File 'lib/charming/internal/terminal/memory_backend.rb', line 37

def enter_alt_screen
  @operations << :enter_alt_screen
end

#hide_cursorObject



49
50
51
# File 'lib/charming/internal/terminal/memory_backend.rb', line 49

def hide_cursor
  @operations << :hide_cursor
end

#leave_alt_screenObject



41
42
43
# File 'lib/charming/internal/terminal/memory_backend.rb', line 41

def leave_alt_screen
  @operations << :leave_alt_screen
end

#mouse_enabled?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/charming/internal/terminal/memory_backend.rb', line 75

def mouse_enabled?
  @mouse_enabled
end

#move_cursor(row, column) ⇒ Object



57
58
59
# File 'lib/charming/internal/terminal/memory_backend.rb', line 57

def move_cursor(row, column)
  @operations << [:move_cursor, row, column]
end

#read_event(timeout: nil) ⇒ Object



20
21
22
23
# File 'lib/charming/internal/terminal/memory_backend.rb', line 20

def read_event(timeout: nil)
  @operations << [:read_event, timeout]
  @events.shift
end

#show_cursorObject



45
46
47
# File 'lib/charming/internal/terminal/memory_backend.rb', line 45

def show_cursor
  @operations << :show_cursor
end

#sizeObject



61
62
63
# File 'lib/charming/internal/terminal/memory_backend.rb', line 61

def size
  [@width, @height]
end

#write_frame(frame) ⇒ Object



25
26
27
28
29
# File 'lib/charming/internal/terminal/memory_backend.rb', line 25

def write_frame(frame)
  @current_frame = frame
  @frames << frame
  @operations << [:write_frame, frame]
end

#write_lines(line_changes, frame: nil) ⇒ Object



31
32
33
34
35
# File 'lib/charming/internal/terminal/memory_backend.rb', line 31

def write_lines(line_changes, frame: nil)
  @current_frame = frame || apply_line_changes(line_changes)
  @frames << @current_frame
  @operations << [:write_lines, line_changes]
end