Class: DebugShell

Inherits:
Moon::RenderContainer show all
Defined in:
lib/moon/packages/debug/debug_shell.rb

Defined Under Namespace

Classes: Caret, DebugContext

Instance Attribute Summary

Attributes inherited from Moon::RenderContext

#id

Attributes included from Moon::RenderPrimitive::DataAttributes

#data_attrs

Attributes included from Moon::RenderPrimitive::Rectangular

#h, #position, #w

Attributes included from Moon::RenderPrimitive::Containable

#parent

Instance Method Summary collapse

Methods inherited from Moon::RenderContainer

#add, #clear_elements, #each, #h, #h=, #on_resize, #ppd_rc, #remove, #w, #w=

Methods inherited from Moon::RenderContext

#apply_position_modifier, #post_initialize, #pre_initialize, #render?, #render_abs, #render_content, #screen_bounds, #screen_position, #update

Methods included from Moon::RenderPrimitive::DataAttributes

#initialize_data_attrs

Methods included from Moon::RenderPrimitive::Rectangular

#align!, #bounds, #contains?, #cx, #cx=, #cy, #cy=, #move, #on_resize, #resize, #to_rect, #x, #x2, #x2=, #x=, #y, #y2, #y2=, #y=, #z, #z=

Methods included from Moon::RenderPrimitive::Containable

#containerize, #disown

Methods included from Moon::RenderPrimitive::Visibility

#hide, #invisible?, #show, #visible?

Methods included from Moon::RenderPrimitive::Renderable

#render, #render?

Methods included from Moon::RenderPrimitive::ScreenElement

#contains_pos?, #relative_contains_pos?, #relative_to_screen, #screen_to_relative

Methods included from Moon::Eventable

#allow_event?, #clear_events, #each_listener, #each_typed_listener, filter_from_options, #has_events?, #initialize_eventable, #off, #on, #ppd_ev, #trigger, #typing

Methods included from Moon::Transitionable

#key_transition, #remove_transitions, #transition

Methods included from Moon::TransitionHost

#add_transition, #finish_transitions, #remove_transition, #remove_transitions, #update_transitions

Constructor Details

#initialize(font) ⇒ DebugShell

Returns a new instance of DebugShell.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/moon/packages/debug/debug_shell.rb', line 40

def initialize(font)
  super()
  self.w = Moon::Screen.w
  self.h = 16 * 6

  @input_background = Moon::SkinSlice9.new
  @input_background.windowskin = Moon::Spritesheet.new("resources/ui/console_windowskin_dark_16x16.png", 16, 16)

  @seperator = Moon::SkinSlice3.new
  @seperator.windowskin = Moon::Spritesheet.new("resources/ui/line_96x1_ff777777.png", 32, 1)

  @caret = Caret.new

  @history = []
  @history_index = 0
  @contents = []
  @input_text = Moon::Text.new("", font)
  @log_text = Moon::Text.new("", font)
  @log_text.line_h = 1
  @context = DebugContext.new

  @input_text.color = Moon::Vector4.new(1, 1, 1, 1)
  @log_text.color = Moon::Vector4.new(1, 1, 1, 1)

  @input_background.w = w
  @input_background.h = h
  @seperator.w = w
  @seperator.h = 1

  @log_text.position.set(4, 4-8, 0)
  @input_text.position.set(4,5*h/6+4-8, 0)
  @seperator.position.set(0, @input_text.y, 0)
  @caret.position.set(@input_text.x, @input_text.position.y+2, 0)

  add(@input_background)
  add(@seperator)
  add(@input_text)
  add(@log_text)
  add(@caret)
end

Instance Method Details

#add_history(str) ⇒ Object


85
86
87
88
# File 'lib/moon/packages/debug/debug_shell.rb', line 85

def add_history(str)
  @history << str
  @history_index = @history.size
end

#add_log(str) ⇒ Object


81
82
83
# File 'lib/moon/packages/debug/debug_shell.rb', line 81

def add_log(str)
  @contents << str
end

#cursor_nextObject


104
105
106
# File 'lib/moon/packages/debug/debug_shell.rb', line 104

def cursor_next
  #
end

#cursor_prevObject


100
101
102
# File 'lib/moon/packages/debug/debug_shell.rb', line 100

def cursor_prev
  #
end

#eraseObject


108
109
110
# File 'lib/moon/packages/debug/debug_shell.rb', line 108

def erase
  self.string = string.chop
end

#execObject


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/moon/packages/debug/debug_shell.rb', line 126

def exec
  return if string.blank?
  add_history string
  begin
    @contents << ">> #{string}"
    result = @context.eval(string).to_s
    add_log result
  rescue Exception => ex
    @contents << ex.message
    @input_text.color.set(1, 0, 0, 1)
  end
  @contents = @contents.last(5)
  @log_text.string = @contents.join("\n")
  self.string = ""
end

#history_nextObject


95
96
97
98
# File 'lib/moon/packages/debug/debug_shell.rb', line 95

def history_next
  @history_index = (@history_index + 1).min(@history.size)
  self.string = @history[@history_index]
end

#history_prevObject


90
91
92
93
# File 'lib/moon/packages/debug/debug_shell.rb', line 90

def history_prev
  @history_index = (@history_index - 1).max(0)
  self.string = @history[@history_index]
end

#insert(str) ⇒ Object


112
113
114
# File 'lib/moon/packages/debug/debug_shell.rb', line 112

def insert(str)
  self.string += str
end

#stringObject


116
117
118
# File 'lib/moon/packages/debug/debug_shell.rb', line 116

def string
  @input_text.string
end

#string=(string) ⇒ Object


120
121
122
123
124
# File 'lib/moon/packages/debug/debug_shell.rb', line 120

def string=(string)
  @input_text.string = string
  @input_text.color.set(1, 1, 1, 1)
  @caret.position.x = @input_text.x + @input_text.w + 2
end