Skip to content

Commit

Permalink
Resync qtermwidget with version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 10, 2023
1 parent bf97c4a commit d3770d3
Show file tree
Hide file tree
Showing 129 changed files with 13,290 additions and 4,027 deletions.
29 changes: 14 additions & 15 deletions src/plugins/grass/qtermwidget/BlockArray.cpp
Expand Up @@ -27,11 +27,10 @@
#include "BlockArray.h"

// System
#include <assert.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <unistd.h>
#include <stdio.h>
#include <cstdio>


using namespace Konsole;
Expand All @@ -42,9 +41,9 @@ BlockArray::BlockArray()
: size(0),
current(size_t(-1)),
index(size_t(-1)),
lastmap(0),
lastmap(nullptr),
lastmap_index(size_t(-1)),
lastblock(0), ion(-1),
lastblock(nullptr), ion(-1),
length(0)
{
// lastmap_index = index = current = size_t(-1);
Expand All @@ -57,7 +56,7 @@ BlockArray::BlockArray()
BlockArray::~BlockArray()
{
setHistorySize(0);
assert(!lastblock);
Q_ASSERT(!lastblock);
}

size_t BlockArray::append(Block * block)
Expand Down Expand Up @@ -139,7 +138,7 @@ const Block * BlockArray::at(size_t i)

if (i > index) {
qDebug() << "BlockArray::at() i > index\n";
return 0;
return nullptr;
}

// if (index - i >= length) {
Expand All @@ -149,14 +148,14 @@ const Block * BlockArray::at(size_t i)

size_t j = i; // (current - (index - i) + (index/size+1)*size) % size ;

assert(j < size);
Q_ASSERT(j < size);
unmap();

Block * block = (Block *)mmap(0, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
Block * block = (Block *)mmap(nullptr, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);

if (block == (Block *)-1) {
perror("mmap");
return 0;
return nullptr;
}

lastmap = block;
Expand All @@ -173,7 +172,7 @@ void BlockArray::unmap()
perror("munmap");
}
}
lastmap = 0;
lastmap = nullptr;
lastmap_index = size_t(-1);
}

Expand All @@ -194,7 +193,7 @@ bool BlockArray::setHistorySize(size_t newsize)

if (!newsize) {
delete lastblock;
lastblock = 0;
lastblock = nullptr;
if (ion >= 0) {
close(ion);
}
Expand All @@ -218,7 +217,7 @@ bool BlockArray::setHistorySize(size_t newsize)
return false;
}

assert(!lastblock);
Q_ASSERT(!lastblock);

lastblock = new Block();
size = newsize;
Expand All @@ -231,7 +230,7 @@ bool BlockArray::setHistorySize(size_t newsize)
return false;
} else {
decreaseBuffer(newsize);
(void) ftruncate(ion, length*blocksize);
ftruncate(ion, length*blocksize);
size = newsize;

return true;
Expand Down Expand Up @@ -272,7 +271,7 @@ void BlockArray::decreaseBuffer(size_t newsize)
return;
}

// The Block constructor could do somthing in future...
// The Block constructor could do something in future...
char * buffer1 = new char[blocksize];

FILE * fion = fdopen(dup(ion), "w+b");
Expand Down Expand Up @@ -320,7 +319,7 @@ void BlockArray::increaseBuffer()
return;
}

// The Block constructor could do somthing in future...
// The Block constructor could do something in future...
char * buffer1 = new char[blocksize];
char * buffer2 = new char[blocksize];

Expand Down
16 changes: 10 additions & 6 deletions src/plugins/grass/qtermwidget/BlockArray.h
Expand Up @@ -27,16 +27,20 @@

//#error Do not use in KDE 2.1

#define BlockSize (1 << 12)
#define ENTRIES ((BlockSize - sizeof(size_t) ))
#define QTERMWIDGET_BLOCKSIZE (1 << 12)
#define ENTRIES ((QTERMWIDGET_BLOCKSIZE - sizeof(size_t) ) / sizeof(unsigned char))

namespace Konsole {

struct Block {
unsigned char data[ENTRIES] = {};
size_t size = 0;
Block() {
size = 0;
}
unsigned char data[ENTRIES];
size_t size;
};

// ///////////////////////////////////////////////////////

class BlockArray {
public:
Expand All @@ -55,7 +59,7 @@ class BlockArray {
* adds the Block at the end of history.
* This may drop other blocks.
*
* The ownership on the block is transfered.
* The ownership on the block is transferred.
* An unique index number is returned for accessing
* it later (if not yet dropped then)
*
Expand All @@ -69,7 +73,7 @@ class BlockArray {
* 0 if the block isn't available any more.
*
* The returned block is strictly readonly as only
* maped in memory - and will be invalid on the next
* mapped in memory - and will be invalid on the next
* operation on this class.
*/
const Block * at(size_t index);
Expand Down
29 changes: 17 additions & 12 deletions src/plugins/grass/qtermwidget/Character.h
Expand Up @@ -45,8 +45,13 @@ static const int LINE_DOUBLEHEIGHT = (1 << 2);
#define RE_UNDERLINE (1 << 2)
#define RE_REVERSE (1 << 3) // Screen only
#define RE_INTENSIVE (1 << 3) // Widget only
#define RE_CURSOR (1 << 4)
#define RE_EXTENDED_CHAR (1 << 5)
#define RE_ITALIC (1 << 4)
#define RE_CURSOR (1 << 5)
#define RE_EXTENDED_CHAR (1 << 6)
#define RE_FAINT (1 << 7)
#define RE_STRIKEOUT (1 << 8)
#define RE_CONCEAL (1 << 9)
#define RE_OVERLINE (1 << 10)

/**
* A single character in the terminal which consists of a unicode character
Expand All @@ -59,10 +64,10 @@ class Character
/**
* Constructs a new character.
*
* \param _c The unicode character value of this character.
* \param _f The foreground color used to draw the character.
* \param _b The color used to draw the character's background.
* \param _r A set of rendition flags which specify how this character is to be drawn.
* @param _c The unicode character value of this character.
* @param _f The foreground color used to draw the character.
* @param _b The color used to draw the character's background.
* @param _r A set of rendition flags which specify how this character is to be drawn.
*/
inline Character(quint16 _c = ' ',
CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_FORE_COLOR),
Expand All @@ -73,7 +78,7 @@ class Character
union
{
/** The unicode character value for this character. */
quint16 character;
wchar_t character;
/**
* Experimental addition which allows a single Character instance to contain more than
* one unicode character.
Expand Down Expand Up @@ -187,19 +192,19 @@ class ExtendedCharTable
* If the same sequence already exists in the table, the hash
* of the existing sequence will be returned.
*
* \param unicodePoints An array of unicode character points
* \param length Length of @p unicodePoints
* @param unicodePoints An array of unicode character points
* @param length Length of @p unicodePoints
*/
ushort createExtendedChar(ushort* unicodePoints , ushort length);
/**
* Looks up and returns a pointer to a sequence of unicode characters
* which was added to the table using createExtendedChar().
*
* \param hash The hash key returned by createExtendedChar()
* \param length This variable is set to the length of the
* @param hash The hash key returned by createExtendedChar()
* @param length This variable is set to the length of the
* character sequence.
*
* \returns A unicode character sequence of size @p length.
* @return A unicode character sequence of size @p length.
*/
ushort* lookupExtendedChar(ushort hash , ushort& length) const;

Expand Down
32 changes: 14 additions & 18 deletions src/plugins/grass/qtermwidget/CharacterColor.h
Expand Up @@ -65,9 +65,9 @@ class ColorEntry
/**
* Constructs a new color palette entry.
*
* \param c The color value for this entry.
* \param tr Specifies that the color should be transparent when used as a background color.
* \param weight Specifies the font weight to use when drawing text with this color.
* @param c The color value for this entry.
* @param tr Specifies that the color should be transparent when used as a background color.
* @param weight Specifies the font weight to use when drawing text with this color.
*/
ColorEntry(QColor c, bool tr, FontWeight weight = UseCurrentFormat)
: color(c), transparent(tr), fontWeight(weight) {}
Expand Down Expand Up @@ -140,7 +140,7 @@ class CharacterColor
friend class Character;

public:
/** Constructs a new CharacterColor whoose color and color space are undefined. */
/** Constructs a new CharacterColor whose color and color space are undefined. */
CharacterColor()
: _colorSpace(COLOR_SPACE_UNDEFINED),
_u(0),
Expand Down Expand Up @@ -195,13 +195,13 @@ class CharacterColor
}

/**
* Toggles the value of this color between a normal system color and the corresponding intensive
* system color.
* Set the value of this color from a normal system color to the corresponding intensive
* system color if it's not already an intensive system color.
*
* This is only applicable if the color is using the COLOR_SPACE_DEFAULT or COLOR_SPACE_SYSTEM
* color spaces.
*/
void toggleIntensive();
void setIntensive();

/**
* Returns the color within the specified color @p palette
Expand Down Expand Up @@ -246,23 +246,19 @@ inline bool operator != (const CharacterColor& a, const CharacterColor& b)
inline const QColor color256(quint8 u, const ColorEntry* base)
{
// 0.. 16: system colors
if (u < 8)
return base[u+2].color;
if (u < 8) return base[u+2 ].color;
u -= 8;
if (u < 8)
return base[u+2+BASE_COLORS].color;
if (u < 8) return base[u+2+BASE_COLORS].color;
u -= 8;

// 16..231: 6x6x6 rgb color cube
if (u < 216)
return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0,
if (u < 216) return QColor(((u/36)%6) ? (40*((u/36)%6)+55) : 0,
((u/ 6)%6) ? (40*((u/ 6)%6)+55) : 0,
((u/ 1)%6) ? (40*((u/ 1)%6)+55) : 0);
u -= 216;

// 232..255: gray, leaving out black and white
int gray = u*10+8;
return QColor(gray,gray,gray);
int gray = u*10+8; return QColor(gray,gray,gray);
}

inline QColor CharacterColor::color(const ColorEntry* base) const
Expand All @@ -272,7 +268,7 @@ inline QColor CharacterColor::color(const ColorEntry* base) const
case COLOR_SPACE_DEFAULT: return base[_u+0+(_v?BASE_COLORS:0)].color;
case COLOR_SPACE_SYSTEM: return base[_u+2+(_v?BASE_COLORS:0)].color;
case COLOR_SPACE_256: return color256(_u,base);
case COLOR_SPACE_RGB: return QColor(_u,_v,_w);
case COLOR_SPACE_RGB: return {_u,_v,_w};
case COLOR_SPACE_UNDEFINED: return QColor();
}

Expand All @@ -281,11 +277,11 @@ inline QColor CharacterColor::color(const ColorEntry* base) const
return QColor();
}

inline void CharacterColor::toggleIntensive()
inline void CharacterColor::setIntensive()
{
if (_colorSpace == COLOR_SPACE_SYSTEM || _colorSpace == COLOR_SPACE_DEFAULT)
{
_v = !_v;
_v = 1;
}
}

Expand Down

0 comments on commit d3770d3

Please sign in to comment.