File indexing completed on 2024-05-05 05:53:47

0001 /*
0002     SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "HistoryTypeFile.h"
0008 #include "HistoryFile.h"
0009 #include "HistoryScrollFile.h"
0010 
0011 using namespace Konsole;
0012 
0013 // Reasonable line size
0014 static const int LINE_SIZE = 1024;
0015 
0016 HistoryTypeFile::HistoryTypeFile() = default;
0017 
0018 bool HistoryTypeFile::isEnabled() const
0019 {
0020     return true;
0021 }
0022 
0023 void HistoryTypeFile::scroll(std::unique_ptr<HistoryScroll> &old) const
0024 {
0025     if (dynamic_cast<HistoryFile *>(old.get()) != nullptr) {
0026         return; // Unchanged.
0027     }
0028     auto newScroll = std::make_unique<HistoryScrollFile>();
0029 
0030     Character line[LINE_SIZE];
0031     int lines = (old != nullptr) ? old->getLines() : 0;
0032     for (int i = 0; i < lines; i++) {
0033         int size = old->getLineLen(i);
0034         if (size > LINE_SIZE) {
0035             auto tmp_line = std::make_unique<Character[]>(size);
0036             old->getCells(i, 0, size, tmp_line.get());
0037             newScroll->addCells(tmp_line.get(), size);
0038             newScroll->addLine(old->getLineProperty(i));
0039         } else {
0040             old->getCells(i, 0, size, line);
0041             newScroll->addCells(line, size);
0042             newScroll->addLine(old->getLineProperty(i));
0043         }
0044     }
0045 
0046     old = std::move(newScroll);
0047 }
0048 
0049 int HistoryTypeFile::maximumLineCount() const
0050 {
0051     return -1;
0052 }