Commit 2be00da5 authored by Carlos Alves's avatar Carlos Alves Committed by Tomaz Canabrava
Browse files

Changed from 'NewLine' char to _lineProperties

_lineProperties is something that existed before. And in some Terminal
emulators it was used to wrap lines, I'm using it now to wrap lines
while resizing.
And improved the _history flux control when resizing.
parent 284ed7ae
......@@ -373,82 +373,68 @@ void Screen::resizeImage(int new_lines, int new_columns)
return;
}
if (new_columns != _columns) {
// Random not printable char to mark nextline
const auto NextLine = Character(130,
CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR),
CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR),
DEFAULT_RENDITION,
false);
// First join everything.
int currentPos = 0;
int count_needed_lines = 0;
while (currentPos != _screenLines.count()) {
// if the line have the 'NextLine' char, concat with the next line and remove it.
if (_screenLines[currentPos].count() && _screenLines[currentPos].at(_screenLines[currentPos].count() - 1) == NextLine) {
_screenLines[currentPos].pop_back(); // remove 'NextLine'
_screenLines[currentPos].append(_screenLines[currentPos + 1]);
_screenLines.remove(currentPos + 1);
_cuY--;
continue;
}
count_needed_lines += _screenLines[currentPos].count() / (new_columns + 1);
currentPos++;
// First join everything.
int currentPos = 0;
int count_needed_lines = 0;
while (currentPos != _screenLines.count()) {
// if the line have the 'NextLine' char, concat with the next line and remove it.
if ((_lineProperties[currentPos] & LINE_WRAPPED) != 0) {
_screenLines[currentPos].append(_screenLines[currentPos + 1]);
_screenLines.remove(currentPos + 1);
_lineProperties.remove(currentPos);
_cuY--;
continue;
}
count_needed_lines += _screenLines[currentPos].count() / (new_columns + 1);
currentPos++;
}
// If it will need more lines than new_lines have, send lines to _history
count_needed_lines += _cuY;
if (count_needed_lines > new_lines - 1) {
_screenLines.resize(_lines + 1);
// attempt to preserve focus and _lines
_bottomMargin = _lines - 1; //FIXME: margin lost
for (int i = 0; i < count_needed_lines - (new_lines - 1); i++) {
addHistLine();
scrollUp(0, 1);
}
// If it will need more lines than new_lines have, send lines to _history
count_needed_lines += _cuY;
if (count_needed_lines > new_lines - 1) {
_lineProperties.resize(_lines + 1);
for (int i = _screenLines.count(); (i > 0) && (i < new_lines + 1); i++) {
_lineProperties[i] = LINE_DEFAULT;
}
_screenLines.resize(_lines + 1);
// attempt to preserve focus and _lines
_bottomMargin = _lines - 1; //FIXME: margin lost
for (int i = 0; i < count_needed_lines - (new_lines - 1); i++) {
addHistLine();
scrollUp(0, 1);
_cuY--;
}
}
// Then move the data to lines below.
currentPos = 0;
while (currentPos != _screenLines.count()) {
const bool shouldCopy = _screenLines[currentPos].size() > new_columns;
// Copy from the current line, to the next one.
if (shouldCopy) {
// If we are in the last line, append a new one.
if (currentPos == _screenLines.count() - 1) {
_screenLines.append(ImageLine{});
}
_cuY++;
// Then move the data to lines below.
currentPos = 0;
while (currentPos != _screenLines.count()) {
const bool shouldCopy = _screenLines[currentPos].size() > new_columns;
auto values = _screenLines[currentPos].mid(new_columns);
_screenLines[currentPos].remove(new_columns, values.size());
_screenLines[currentPos].append(NextLine);
_screenLines.insert(currentPos + 1, values);
}
currentPos += 1;
}
_screenLines.resize(new_lines + 1);
} else {
if (_cuY > new_lines - 1) {
// attempt to preserve focus and _lines
_bottomMargin = _lines - 1; //FIXME: margin lost
for (int i = 0; i < _cuY - (new_lines - 1); i++) {
addHistLine();
scrollUp(0, 1);
// Copy from the current line, to the next one.
if (shouldCopy) {
// If we are in the last line, append a new one.
if (currentPos == _screenLines.count() - 1) {
_screenLines.append(ImageLine{});
}
_cuY++;
auto values = _screenLines[currentPos].mid(new_columns);
_screenLines[currentPos].remove(new_columns, values.size());
_lineProperties[currentPos] = _lineProperties[currentPos] | LINE_WRAPPED;
_screenLines.insert(currentPos + 1, values);
_lineProperties.insert(currentPos + 1, LINE_DEFAULT);
}
_screenLines.resize(new_lines + 1);
currentPos += 1;
}
clearSelection();
_screenLinesSize = new_lines;
_lineProperties.resize(new_lines + 1);
for (int i = _lines; (i > 0) && (i < new_lines + 1); i++) {
for (int i = _screenLines.count(); (i > 0) && (i < new_lines + 1); i++) {
_lineProperties[i] = LINE_DEFAULT;
}
_screenLines.resize(new_lines + 1);
clearSelection();
_screenLinesSize = new_lines;
_lines = new_lines;
_columns = new_columns;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment