Commit d920a41a authored by Matan Ziv-Av's avatar Matan Ziv-Av Committed by Kurt Hindenburg
Browse files

Allow setting line properties of lines in the scroll buffer

This is needed for tracking the error status of the lines, since the
status is known only at the end of command execution, when lines may have
already been scrolled back.

This also fixes a (hidden) bug where only the lower 8 bits of the 16 bits
line property were saved.
parent f5f44048
......@@ -9,6 +9,7 @@
// Konsole
#include "KonsoleSettings.h"
#include "characters/Character.h"
#include "konsoledebug.h"
// System
......@@ -158,7 +159,7 @@ void HistoryFile::add(const char *buffer, qint64 count)
void HistoryFile::get(char *buffer, qint64 size, qint64 loc)
{
if (loc < 0 || size < 0 || loc + size > _length) {
if (loc < 0 || size < 0 || loc + size > (qint64)(_length * sizeof(LineProperty))) {
fprintf(stderr, "getHist(...,%lld,%lld): invalid args.\n", size, loc);
return;
}
......@@ -191,6 +192,41 @@ void HistoryFile::get(char *buffer, qint64 size, qint64 loc)
}
}
void HistoryFile::set(char *buffer, qint64 size, qint64 loc)
{
if (loc < 0 || size < 0 || loc + size > qint64(_length * sizeof(LineProperty))) {
fprintf(stderr, "setHist(...,%lld,%lld): invalid args.\n", size, loc);
return;
}
// count number of get() calls vs. number of add() calls.
// If there are many more get() calls compared with add()
// calls (decided by using MAP_THRESHOLD) then mmap the log
// file to improve performance.
if (_readWriteBalance > INT_MIN) {
_readWriteBalance--;
}
if ((_fileMap == nullptr) && _readWriteBalance < MAP_THRESHOLD) {
map();
}
if (_fileMap != nullptr) {
memcpy(_fileMap + loc, buffer, size);
} else {
qint64 rc = 0;
if (!_tmpFile.seek(loc)) {
perror("HistoryFile::set.seek");
return;
}
rc = _tmpFile.write(buffer, size);
if (rc < 0) {
perror("HistoryFile::set.write");
return;
}
}
}
void HistoryFile::removeLast(qint64 loc)
{
if (loc < 0 || loc > _length) {
......
......@@ -25,6 +25,7 @@ public:
virtual void add(const char *buffer, qint64 count);
virtual void get(char *buffer, qint64 size, qint64 loc);
virtual void set(char *buffer, qint64 size, qint64 loc);
virtual void removeLast(qint64 loc);
virtual qint64 len() const;
......
......@@ -40,6 +40,7 @@ public:
virtual void getCells(const int lineno, const int colno, const int count, Character res[]) const = 0;
virtual bool isWrappedLine(const int lineNumber) const = 0;
virtual LineProperty getLineProperty(const int lineno) const = 0;
virtual void setLineProperty(const int lineno, LineProperty prop) = 0;
// adding lines.
virtual void addCells(const Character a[], const int count) = 0;
......
......@@ -52,12 +52,19 @@ LineProperty HistoryScrollFile::getLineProperty(const int lineno) const
{
if (lineno >= 0 && lineno <= getLines()) {
LineProperty flag = LineProperty();
_lineflags.get(reinterpret_cast<char *>(&flag), sizeof(unsigned char), (lineno) * sizeof(unsigned char));
_lineflags.get(reinterpret_cast<char *>(&flag), sizeof(LineProperty), (lineno) * sizeof(LineProperty));
return flag;
}
return LineProperty();
}
void HistoryScrollFile::setLineProperty(const int lineno, LineProperty prop)
{
if (lineno >= 0 && lineno <= getLines()) {
_lineflags.set(reinterpret_cast<char *>(&prop), sizeof(LineProperty), (lineno) * sizeof(LineProperty));
}
}
qint64 HistoryScrollFile::startOfLine(const int lineno) const
{
Q_ASSERT(lineno >= 0 && lineno <= getLines());
......@@ -87,7 +94,7 @@ void HistoryScrollFile::addLine(LineProperty lineProperty)
{
qint64 locn = _cells.len();
_index.add(reinterpret_cast<char *>(&locn), sizeof(qint64));
_lineflags.add(reinterpret_cast<char *>(&lineProperty), sizeof(char));
_lineflags.add(reinterpret_cast<char *>(&lineProperty), sizeof(LineProperty));
}
void HistoryScrollFile::removeCells()
......@@ -101,7 +108,7 @@ void HistoryScrollFile::removeCells()
}
res = qMax(0, getLines() - 1);
_index.removeLast(res * sizeof(qint64));
_lineflags.removeLast(res * sizeof(unsigned char));
_lineflags.removeLast(res * sizeof(LineProperty));
}
int Konsole::HistoryScrollFile::reflowLines(const int columns, std::map<int, int> *)
......@@ -150,7 +157,7 @@ int Konsole::HistoryScrollFile::reflowLines(const int columns, std::map<int, int
if (getLines() > MAX_REFLOW_LINES) {
currentPos = getLines() - MAX_REFLOW_LINES;
_index.removeLast(currentPos * sizeof(qint64));
_lineflags.removeLast(currentPos * sizeof(char));
_lineflags.removeLast(currentPos * sizeof(LineProperty));
} else {
_index.removeLast(0);
_lineflags.removeLast(0);
......@@ -162,7 +169,7 @@ int Konsole::HistoryScrollFile::reflowLines(const int columns, std::map<int, int
while (currentPos < totalLines) {
reflowFile->get(reinterpret_cast<char *>(&newLine), sizeof(reflowData), currentPos * sizeof(reflowData));
_lineflags.add(reinterpret_cast<char *>(&newLine.lineFlag), sizeof(char));
_lineflags.add(reinterpret_cast<char *>(&newLine.lineFlag), sizeof(LineProperty));
_index.add(reinterpret_cast<char *>(&newLine.index), sizeof(qint64));
currentPos++;
}
......
......@@ -31,6 +31,7 @@ public:
void getCells(const int lineno, const int colno, const int count, Character res[]) const override;
bool isWrappedLine(const int lineno) const override;
LineProperty getLineProperty(const int lineno) const override;
void setLineProperty(const int lineno, LineProperty prop) override;
void addCells(const Character text[], const int count) override;
void addCellsMove(Character text[], const int count) override
......
......@@ -50,6 +50,10 @@ LineProperty HistoryScrollNone::getLineProperty(int /*lineno*/) const
return LineProperty();
}
void HistoryScrollNone::setLineProperty(int /*lineno*/, LineProperty /*prop*/)
{
}
void HistoryScrollNone::getCells(int, int, int, Character[]) const
{
}
......
......@@ -30,6 +30,7 @@ public:
void getCells(const int lineno, const int colno, const int count, Character res[]) const override;
bool isWrappedLine(const int lineno) const override;
LineProperty getLineProperty(const int lineno) const override;
void setLineProperty(const int lineno, LineProperty prop) override;
void addCells(const Character a[], const int count) override;
void addCellsMove(Character a[], const int count) override;
......
......@@ -140,6 +140,12 @@ LineProperty CompactHistoryScroll::getLineProperty(const int lineNumber) const
return _lineDatas.at(lineNumber).flag;
}
void CompactHistoryScroll::setLineProperty(const int lineNumber, LineProperty prop)
{
Q_ASSERT((size_t)lineNumber < _lineDatas.size());
_lineDatas.at(lineNumber).flag = prop;
}
int CompactHistoryScroll::reflowLines(const int columns, std::map<int, int> *deltas)
{
std::vector<LineData> newLineData;
......
......@@ -28,6 +28,7 @@ public:
void getCells(const int lineNumber, const int startColumn, const int count, Character buffer[]) const override;
bool isWrappedLine(const int lineNumber) const override;
LineProperty getLineProperty(const int lineNumber) const override;
void setLineProperty(const int lineno, LineProperty prop) override;
void addCells(const Character a[], const int count) override;
void addCellsMove(Character a[], const int count) override;
......
Supports Markdown
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