+ s_outputBuffer.str(std::string());
+ }
+ }
+}
+
+Console::Console(ConsoleBuffer& buffer) :
+ m_buffer(buffer),
+ m_inputBuffer(),
+ m_inputBufferPosition(0),
+ m_history(),
+ m_history_position(m_history.end()),
+ m_background(Surface::create("images/engine/console.png")),
+ m_background2(Surface::create("images/engine/console2.png")),
+ m_vm(NULL),
+ m_vm_object(),
+ m_backgroundOffset(0),
+ m_height(0),
+ m_alpha(1.0),
+ m_offset(0),
+ m_focused(false),
+ m_font(new Font(Font::FIXED, "fonts/andale12.stf", 1)),
+ m_stayOpen(0)
+{
+}
+
+Console::~Console()
+{
+ if (m_vm != NULL)
+ {
+ sq_release(scripting::global_vm, &m_vm_object);
+ }
+}
+
+void
+Console::on_buffer_change(int line_count)
+{
+ if (!m_font)
+ {
+ // FIXME: This is an ugly workaround for a crash at startup.
+ // Console::current() becomes valid before the Console constructor
+ // is finished and loading Surfaces and Fonts wants to write text
+ // to the Console, with Fonts that aren't yet loaded, thus
+ // crashing
+ return;
+ }
+
+ // increase console height if necessary
+ if (m_stayOpen > 0 && m_height < 64)
+ {
+ if(m_height < 4)
+ {
+ m_height = 4;