File indexing completed on 2024-05-12 05:53:27
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 // Own 0008 #include "CompactHistoryType.h" 0009 0010 #include "CompactHistoryScroll.h" 0011 0012 using namespace Konsole; 0013 0014 // Reasonable line size 0015 static const int LINE_SIZE = 1024; 0016 0017 CompactHistoryType::CompactHistoryType(unsigned int nbLines) 0018 : _maxLines(nbLines) 0019 { 0020 } 0021 0022 bool CompactHistoryType::isEnabled() const 0023 { 0024 return true; 0025 } 0026 0027 int CompactHistoryType::maximumLineCount() const 0028 { 0029 return _maxLines; 0030 } 0031 0032 void CompactHistoryType::scroll(std::unique_ptr<HistoryScroll> &old) const 0033 { 0034 if (auto *newBuffer = dynamic_cast<CompactHistoryScroll *>(old.get())) { 0035 newBuffer->setMaxNbLines(_maxLines); 0036 return; 0037 } 0038 auto newScroll = std::make_unique<CompactHistoryScroll>(_maxLines); 0039 0040 Character line[LINE_SIZE]; 0041 int lines = (old != nullptr) ? old->getLines() : 0; 0042 int i = qMax((lines - (int)_maxLines), 0); 0043 std::vector<Character> tmp_line; 0044 for (; i < lines; i++) { 0045 int size = old->getLineLen(i); 0046 if (size > LINE_SIZE) { 0047 tmp_line.resize(size); 0048 old->getCells(i, 0, size, tmp_line.data()); 0049 newScroll->addCellsMove(tmp_line.data(), size); 0050 newScroll->addLine(old->getLineProperty(i)); 0051 } else { 0052 old->getCells(i, 0, size, line); 0053 newScroll->addCells(line, size); 0054 newScroll->addLine(old->getLineProperty(i)); 0055 } 0056 } 0057 old = std::move(newScroll); 0058 }