sgpemv2/src/graphical_terminal_io.cc

89 lines
2.4 KiB
C++
Raw Normal View History

// src/graphicalterminalio.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.h"
#include "gettext.h"
#include "graphical_terminal_io.hh"
#include <gtkmm/button.h>
#include <gtkmm/textview.h>
#include <glibmm/ustring.h>
#include <algorithm>
using namespace sgpem;
GraphicalTerminalIO::GraphicalTerminalIO()
{
using namespace Gtk;
set_title(_("Textual Simulation Log"));
set_default_size(500,300);
Gtk::Box* mainbox = manage(new VBox());
add(*mainbox);
_text_output.set_editable(false);
_text_output.modify_font(Pango::FontDescription("monospace"));
mainbox->pack_start(_text_output);
Gtk::Box* cmdbox = manage(new HBox());
mainbox->pack_end(*cmdbox, false, false);
cmdbox->pack_start(_text_input);
//Gtk::Button* bt_tell = manage(new Button(_("Tell")));
// signals lack return value:
//bt_tell->signal_clicked().connect(sigc::mem_fun(*this, read_buffer));
//cmdbox->pack_start(*bt_tell, false, true);
show_all_children();
}
GraphicalTerminalIO::~GraphicalTerminalIO()
{}
uint
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
{
_text_output.get_buffer()->insert_at_cursor(buffer);
return buffer.size();
}
Glib::ustring
GraphicalTerminalIO::read_command()
{
using Glib::ustring;
static const ustring whitespaces = " \r\b\n\t\a";
// are there any other wspaces?
ustring command = _text_input.get_text();
// trimming:
uint f = command.find_first_not_of(whitespaces);
uint l = command.find_last_not_of(whitespaces);
if(f == ustring::npos)
return 0;
_text_input.set_text(ustring(""));
return command.substr(f,l);
}