Class: ScripTTY::Term::DG410

Inherits:
Object
  • Object
show all
Defined in:
lib/scriptty/term/dg410/parser.rb,
lib/scriptty/term/dg410.rb

Overview

reopen

Defined Under Namespace

Classes: Parser

Constant Summary collapse

DEFAULT_FLAGS =
{
  :insert_mode => false,
  :wraparound_mode => false,
  :roll_mode => true,   # scroll up when the cursor moves beyond the bottom
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height = 24, width = 80) ⇒ DG410

Returns a new instance of DG410.



45
46
47
48
49
50
51
52
53
54
# File 'lib/scriptty/term/dg410.rb', line 45

def initialize(height=24, width=80)
  @parser = self.class.parser_class.new(:callback => self, :callback_method => :send)

  @height = height
  @width = width

  @proprietary_escape_callback = nil

  reset_to_initial_state!
end

Instance Attribute Details

#heightObject (readonly)

width and height of the display buffer



38
39
40
# File 'lib/scriptty/term/dg410.rb', line 38

def height
  @height
end

#widthObject (readonly)

width and height of the display buffer



38
39
40
# File 'lib/scriptty/term/dg410.rb', line 38

def width
  @width
end

Class Method Details

.parser_classObject

Return ScripTTY::Term::DG410::Parser



41
42
43
# File 'lib/scriptty/term/dg410.rb', line 41

def self.parser_class
  Parser
end

Instance Method Details

#cursor_posObject

Return the cursor position, as an array of [row, column].

0,0

represents the topmost, leftmost position.



108
109
110
# File 'lib/scriptty/term/dg410.rb', line 108

def cursor_pos
  [@cursor.row, @cursor.column]
end

#cursor_pos=(v) ⇒ Object

Set the cursor position to [row, column].

0,0

represents the topmost, leftmost position.



115
116
117
# File 'lib/scriptty/term/dg410.rb', line 115

def cursor_pos=(v)
  @cursor.pos = v
end

#debug_infoObject

Return an array of lines of text representing the state of the terminal. Used for debugging.



81
82
83
84
85
86
87
# File 'lib/scriptty/term/dg410.rb', line 81

def debug_info
  output = []
  output << "state:#{@parser.fsm.state.inspect} seq:#{@parser.fsm.input_sequence && @parser.fsm.input_sequence.join.inspect}"
  output << "scrolling_region: #{@scrolling_region.inspect}"
  output << "flags: roll:#{@flags[:roll_mode]} wraparound:#{@flags[:wraparound_mode]} insert:#{@flags[:insert_mode]}"
  output
end

#feed_byte(byte) ⇒ Object



75
76
77
# File 'lib/scriptty/term/dg410.rb', line 75

def feed_byte(byte)
  @parser.feed_byte(byte)
end

#feed_bytes(bytes) ⇒ Object



71
72
73
# File 'lib/scriptty/term/dg410.rb', line 71

def feed_bytes(bytes)
  @parser.feed_bytes(bytes)
end

#inspectObject

:nodoc:



89
90
91
92
# File 'lib/scriptty/term/dg410.rb', line 89

def inspect # :nodoc:
  # The default inspect method shows way too much information.  Simplify it.
  "#<#{self.class.name}:#{sprintf('0x%0x', object_id)} h=#{@height.inspect} w=#{@width.inspect} cursor=#{cursor_pos.inspect}>"
end

#on_proprietary_escape(mode = nil, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/scriptty/term/dg410.rb', line 60

def on_proprietary_escape(mode=nil, &block)
  if mode == :ignore and !block
    @proprietary_escape_callback = nil
  elsif !mode and block
    @proprietary_escape_callback = block
  else
    raise ArgumentError.new("mode and block are mutually exclusive")
  end
  nil
end

#on_unknown_sequence(mode = nil, &block) ⇒ Object



56
57
58
# File 'lib/scriptty/term/dg410.rb', line 56

def on_unknown_sequence(mode=nil, &block)
  @parser.on_unknown_sequence(mode, &block)
end

#text(copy = true) ⇒ Object

Return an array of strings representing the lines of text on the screen

NOTE: If passing copy=false, do not modify the return value or the strings inside it.



97
98
99
100
101
102
103
# File 'lib/scriptty/term/dg410.rb', line 97

def text(copy=true)
  if copy
    @glyphs.content.map{|line| line.dup}
  else
    @glyphs.content
  end
end

#text=(a) ⇒ Object

Replace the text on the screen with the specified text.

NOTE: This is API is very likely to change in the future.



122
123
124
125
126
# File 'lib/scriptty/term/dg410.rb', line 122

def text=(a)
  @glyphs.clear!
  @glyphs.replace_at(0, 0, a)
  a
end