History.h 4.86 KB
Newer Older
1
2
/*
    This file is part of Konsole, an X terminal.
3
    Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/
20

21
22
#ifndef HISTORY_H
#define HISTORY_H
23

Jekyll Wu's avatar
Jekyll Wu committed
24
25
26
// System
#include <sys/mman.h>

27
// Qt
28
29
30
#include <QList>
#include <QVector>
#include <QTemporaryFile>
31

Laurent Montel's avatar
Laurent Montel committed
32
#include "konsoleprivate_export.h"
33

34
35
// History
#include "HistoryFile.h"
36
#include "HistoryScroll.h"
37
38
#include "HistoryScrollFile.h"
#include "HistoryScrollNone.h"
39
#include "CharacterFormat.h"
40
#include "CompactHistoryBlock.h"
41
#include "CompactHistoryBlockList.h"
42

43
// Konsole
44
#include "Character.h"
45

Kurt Hindenburg's avatar
Kurt Hindenburg committed
46
namespace Konsole {
47

48
49
50
51
52
typedef QVector<Character> TextLine;

class CompactHistoryLine
{
public:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
53
    CompactHistoryLine(const TextLine &, CompactHistoryBlockList &blockList);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
54
55
56
    virtual ~CompactHistoryLine();

    // custom new operator to allocate memory from custom pool instead of heap
Kurt Hindenburg's avatar
Kurt Hindenburg committed
57
58
59
    static void *operator new(size_t size, CompactHistoryBlockList &blockList);
    static void operator delete(void *)
    {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
60
        /* do nothing, deallocation from pool is done in destructor*/
Kurt Hindenburg's avatar
Kurt Hindenburg committed
61
    }
Kurt Hindenburg's avatar
Kurt Hindenburg committed
62

63
    virtual void getCharacters(Character *array, int size, int startColumn);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
64
65
66
    virtual void getCharacter(int index, Character &r);
    virtual bool isWrapped() const
    {
67
        return _wrapped;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
68
    }
Kurt Hindenburg's avatar
Kurt Hindenburg committed
69
70
71

    virtual void setWrapped(bool value)
    {
72
        _wrapped = value;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
73
    }
Kurt Hindenburg's avatar
Kurt Hindenburg committed
74
75
76

    virtual unsigned int getLength() const
    {
77
        return _length;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
78
    }
79
80

protected:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
81
82
    CompactHistoryBlockList &_blockListRef;
    CharacterFormat *_formatArray;
83
    quint16 _length;
84
    uint    *_text;
85
86
    quint16 _formatLength;
    bool _wrapped;
87
88
};

89
class KONSOLEPRIVATE_EXPORT CompactHistoryScroll : public HistoryScroll
90
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
91
    typedef QList<CompactHistoryLine *> HistoryArray;
92
93

public:
94
    explicit CompactHistoryScroll(unsigned int maxLineCount = 1000);
95
    ~CompactHistoryScroll() override;
96

97
98
99
100
    int  getLines() override;
    int  getLineLen(int lineNumber) override;
    void getCells(int lineNumber, int startColumn, int count, Character buffer[]) override;
    bool isWrappedLine(int lineNumber) override;
101

102
103
104
    void addCells(const Character a[], int count) override;
    void addCellsVector(const TextLine &cells) override;
    void addLine(bool previousWrapped = false) override;
105

106
    void setMaxNbLines(unsigned int lineCount);
107
108

private:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
109
    bool hasDifferentColors(const TextLine &line) const;
110
111
    HistoryArray _lines;
    CompactHistoryBlockList _blockList;
112

Kurt Hindenburg's avatar
Kurt Hindenburg committed
113
    unsigned int _maxLineCount;
114
115
};

116
117
118
119
//////////////////////////////////////////////////////////////////////
// History type
//////////////////////////////////////////////////////////////////////

120
class KONSOLEPRIVATE_EXPORT HistoryType
121
122
{
public:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    HistoryType();
    virtual ~HistoryType();

    /**
     * Returns true if the history is enabled ( can store lines of output )
     * or false otherwise.
     */
    virtual bool isEnabled() const = 0;
    /**
     * Returns the maximum number of lines which this history type
     * can store or -1 if the history can store an unlimited number of lines.
     */
    virtual int maximumLineCount() const = 0;
    /**
Kurt Hindenburg's avatar
Kurt Hindenburg committed
137
138
     * Converts from one type of HistoryScroll to another or if given the
     * same type, returns it.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
139
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
140
    virtual HistoryScroll *scroll(HistoryScroll *) const = 0;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
141
142
143
    /**
     * Returns true if the history size is unlimited.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
144
145
    bool isUnlimited() const
    {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
146
147
        return maximumLineCount() == -1;
    }
148
149
};

150
class KONSOLEPRIVATE_EXPORT HistoryTypeNone : public HistoryType
151
152
{
public:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
153
    HistoryTypeNone();
154

155
156
    bool isEnabled() const override;
    int maximumLineCount() const override;
157

158
    HistoryScroll *scroll(HistoryScroll *) const override;
159
160
};

161
class KONSOLEPRIVATE_EXPORT HistoryTypeFile : public HistoryType
162
163
{
public:
164
    explicit HistoryTypeFile();
165

166
167
    bool isEnabled() const override;
    int maximumLineCount() const override;
168

169
    HistoryScroll *scroll(HistoryScroll *) const override;
170
171
};

172
class KONSOLEPRIVATE_EXPORT CompactHistoryType : public HistoryType
173
174
{
public:
175
    explicit CompactHistoryType(unsigned int nbLines);
176

177
178
    bool isEnabled() const override;
    int maximumLineCount() const override;
179

180
    HistoryScroll *scroll(HistoryScroll *) const override;
181
182

protected:
183
    unsigned int _maxLines;
184
};
Stephan Binner's avatar
Stephan Binner committed
185
}
186

187
#endif // HISTORY_H