Commit 5b1aaa65 authored by Carlos Alves's avatar Carlos Alves
Browse files

Reflow lines with unlimited scroll

It is not reflowing unlimited history lines (there is no limit and it
can be very long), it just reflow screenlines and join the lines when it
get to history.
parent 4f1864ab
......@@ -469,7 +469,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
_screenLines.resize(new_lines + 1);
// Check if _history need to change
if (new_columns != _columns && _history->getLines()) {
if (new_columns != _columns && _history->getLines() && _history->getMaxLines()) {
// Join next line from _screenLine to _history
while (_history->isWrappedLine(_history->getLines() - 1)) {
fastAddHistLine();
......@@ -477,7 +477,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
}
currentPos = 0;
// Join everything in _history
while (currentPos < _history->getLines() - 1) {
while (currentPos < _history->getLines() - 1 && currentPos < _history->getMaxLines()) {
// if it's true, join the line with next line
if (_history->isWrappedLine(currentPos)) {
int curr_linelen = _history->getLineLen(currentPos);
......@@ -499,7 +499,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
}
// Now move data to next line if needed
currentPos = 0;
while (currentPos < _history->getLines()) {
while (currentPos < _history->getLines() && currentPos < _history->getMaxLines()) {
int curr_linelen = _history->getLineLen(currentPos);
// if the current line > new_columns it will need a new line
......@@ -1644,7 +1644,7 @@ void Screen::addHistLine()
hist_linelen += _screenLines[0].count();
// After join, check if it needs new line in history to show it on scroll
if (hist_linelen > _columns) {
if (_history->getMaxLines() && hist_linelen > _columns) {
_history->setCellsAt(oldHistLines - 1, hist_line, _columns);
_history->setLineAt(oldHistLines - 1, true);
_history->addCells(hist_line + _columns, hist_linelen - _columns);
......
......@@ -192,6 +192,15 @@ void HistoryFile::get(char *buffer, qint64 size, qint64 loc)
}
}
void HistoryFile::removeLast(qint64 loc)
{
if (loc < 0 || loc > _length) {
fprintf(stderr, "removeLast(%lld): invalid args.\n", loc);
return;
}
_length = loc;
}
qint64 HistoryFile::len() const
{
return _length;
......
......@@ -26,6 +26,7 @@ public:
virtual void add(const char *buffer, qint64 count);
virtual void get(char *buffer, qint64 size, qint64 loc);
virtual void removeLast(qint64 loc);
virtual qint64 len() const;
//mmaps the file in read-only mode
......
......@@ -35,7 +35,7 @@ int HistoryScrollFile::getLines()
int HistoryScrollFile::getMaxLines()
{
return _index.len() / sizeof(qint64);
return 0;
}
int HistoryScrollFile::getLineLen(int lineno)
......@@ -85,26 +85,53 @@ void HistoryScrollFile::addLine(bool previousWrapped)
_lineflags.add(reinterpret_cast<char *>(&flags), sizeof(char));
}
void HistoryScrollFile::insertCells(int , const Character [], int)
void HistoryScrollFile::insertCells(int, const Character[], int)
{
}
void HistoryScrollFile::removeCells(int )
void HistoryScrollFile::removeCells(int)
{
qint64 res = (getLines() - 2) * sizeof(qint64);
if (getLines() < 2) {
_cells.removeLast(0);
} else {
_index.get(reinterpret_cast<char *>(&res), sizeof(qint64), res);
_cells.removeLast(res);
}
res = qMax(0, getLines() - 1);
_index.removeLast(res * sizeof(qint64));
_lineflags.removeLast(res * sizeof(unsigned char));
}
void HistoryScrollFile::insertCellsVector(int , const QVector<Character> &)
void HistoryScrollFile::insertCellsVector(int, const QVector<Character> &)
{
}
void HistoryScrollFile::setCellsAt(int , const Character [], int)
void HistoryScrollFile::setCellsAt(int, const Character text[], int count)
{
qint64 res = (getLines() - 2) * sizeof(qint64);
if (getLines() < 2) {
_cells.removeLast(0);
} else {
_index.get(reinterpret_cast<char *>(&res), sizeof(qint64), res);
_cells.removeLast(res);
}
_cells.add(reinterpret_cast<const char *>(text), count * sizeof(Character));
}
void HistoryScrollFile::setCellsVectorAt(int , const QVector<Character> &)
void HistoryScrollFile::setCellsVectorAt(int, const QVector<Character> &)
{
}
void HistoryScrollFile::setLineAt(int , bool)
void HistoryScrollFile::setLineAt(int, bool previousWrapped)
{
qint64 locn = qMax(0, getLines() - 1);
_index.removeLast(locn * sizeof(qint64));
_lineflags.removeLast(locn * sizeof(unsigned char));
locn = _cells.len();
_index.add(reinterpret_cast<char *>(&locn), sizeof(qint64));
unsigned char flags = previousWrapped ? 0x01 : 0x00;
_lineflags.add(reinterpret_cast<char *>(&flags), sizeof(char));
}
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