/* This file is part of Konsole, an X terminal. Copyright (C) 2006 by Robert Knight Rewritten for QT4 by e_k , Copyright (C)2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ // Own #include "TerminalCharacterDecoder.h" // Qt #include using namespace Konsole; PlainTextDecoder::PlainTextDecoder() : _output(0) , _includeTrailingWhitespace(true) { } void PlainTextDecoder::setTrailingWhitespace(bool enable) { _includeTrailingWhitespace = enable; } bool PlainTextDecoder::trailingWhitespace() const { return _includeTrailingWhitespace; } void PlainTextDecoder::begin(QTextStream* output) { _output = output; } void PlainTextDecoder::end() { _output = 0; } void PlainTextDecoder::decodeLine(const Character* const characters, int count, LineProperty /*properties*/ ) { Q_ASSERT( _output ); //TODO should we ignore or respect the LINE_WRAPPED line property? //note: we build up a QString and send it to the text stream rather writing into the text //stream a character at a time because it is more efficient. //(since QTextStream always deals with QStrings internally anyway) QString plainText; plainText.reserve(count); int outputCount = count; // if inclusion of trailing whitespace is disabled then find the end of the // line if ( !_includeTrailingWhitespace ) { for (int i = count-1 ; i >= 0 ; i--) { if ( characters[i].character != ' ' ) break; else outputCount--; } } for (int i=0;i') text.append(">"); else text.append(ch); } else { text.append(" "); //HTML truncates multiple spaces, so use a space marker instead } } //close any remaining open inner spans if ( _innerSpanOpen ) closeSpan(text); //start new line text.append("
"); *_output << text; } void HTMLDecoder::openSpan(QString& text , const QString& style) { text.append( QString("").arg(style) ); } void HTMLDecoder::closeSpan(QString& text) { text.append(""); } void HTMLDecoder::setColorTable(const ColorEntry* table) { _colorTable = table; }