Add support for copying HTML formatted text from terminal

Currently, only text is supported - this add HTML

Thanks to Anonymous Koavohv koavohv gmail com

REVIEW: 119914
This commit is contained in:
Kurt Hindenburg
2014-10-04 11:57:54 -04:00
parent b6304bcc59
commit abb83e8ef0
5 changed files with 41 additions and 17 deletions

View File

@@ -1107,23 +1107,35 @@ bool Screen::isSelected(const int x, const int y) const
return pos >= _selTopLeft && pos <= _selBottomRight && columnInSelection;
}
QString Screen::selectedText(bool preserveLineBreaks, bool trimTrailingSpaces) const
QString Screen::selectedText(bool preserveLineBreaks, bool trimTrailingSpaces, bool html) const
{
if (!isSelectionValid())
return QString();
return text(_selTopLeft, _selBottomRight, preserveLineBreaks, trimTrailingSpaces);
return text(_selTopLeft, _selBottomRight, preserveLineBreaks, trimTrailingSpaces, html);
}
QString Screen::text(int startIndex, int endIndex, bool preserveLineBreaks, bool trimTrailingSpaces) const
QString Screen::text(int startIndex, int endIndex, bool preserveLineBreaks, bool trimTrailingSpaces, bool html) const
{
QString result;
QTextStream stream(&result, QIODevice::ReadWrite);
PlainTextDecoder decoder;
decoder.begin(&stream);
writeToStream(&decoder, startIndex, endIndex, preserveLineBreaks, trimTrailingSpaces);
decoder.end();
HTMLDecoder htmlDecoder;
PlainTextDecoder plainTextDecoder;
TerminalCharacterDecoder *decoder;
if(html)
{
decoder = &htmlDecoder;
}
else
{
decoder = &plainTextDecoder;
}
decoder->begin(&stream);
writeToStream(decoder, startIndex, endIndex, preserveLineBreaks, trimTrailingSpaces);
decoder->end();
return result;
}