Skip to content

Commit

Permalink
Fix unicode support
Browse files Browse the repository at this point in the history
  • Loading branch information
reflectronic committed Apr 9, 2024
1 parent 1f2acea commit ba564fc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void QmlTerminalScreenController::paste() {
QVariantList QmlTerminalScreenController::calculateRuns(int start, int cols, std::function<TerminalScreen::CharacterSpace(int)> getCharacter) {
QVariantList runs;
QVariantMap currentMap = initFormat({});
QByteArray currentText;
QString currentText;
TerminalScreen::CharacterSpace::CharacterFormat previousFormat;
for (auto i = start; i < cols; i++) {
auto character = getCharacter(i);
Expand All @@ -229,7 +229,7 @@ QVariantList QmlTerminalScreenController::calculateRuns(int start, int cols, std
currentMap = initFormat(character.format);
}

currentText.append(character.character.unicode());
currentText.append(character.character);

previousFormat = character.format;
}
Expand Down
15 changes: 10 additions & 5 deletions libtheterminal/common/Emulation/vt100emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

struct VT100EmulationPrivate {
QIODevice* device;
QTextStream reader;
TerminalScreen* screen;

bool echo = false;
Expand Down Expand Up @@ -44,10 +45,14 @@ VT100Emulation::VT100Emulation(QIODevice* device, TerminalScreen* screen, QObjec
setupStateMachine();
setupCsiStateMachine();

d->reader.setAutoDetectUnicode(false);
d->reader.setDevice(device);

connect(device, &QIODevice::readyRead, this, [this] {
auto buf = d->device->readAll();
for (auto character : buf) {
processCharacter(character);
while (!d->reader.atEnd()) {
QChar ch;
d->reader >> ch;
processCharacter(ch);
}
});
}
Expand Down Expand Up @@ -77,7 +82,7 @@ void VT100Emulation::pressKey(Qt::KeyboardModifiers modifiers, Qt::Key key, QStr
this->write("\x1B[B");
return;
} else if (key == Qt::Key_Up) {
this->write("\x1B[A");
this->write("\x1B[A");
return;
}

Expand Down Expand Up @@ -589,7 +594,7 @@ void VT100Emulation::invokeCsi(QString csi) {

switch (lastResult) {
case TerminalStateMachine::Result::Accepted:
return;
return;
case TerminalStateMachine::Result::Pending:
break;
case TerminalStateMachine::Result::Rejected:
Expand Down
9 changes: 6 additions & 3 deletions libtheterminal/common/PtyImpl/winpty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ struct ReadFileWorker : public QThread
ReadFileWorker(HANDLE hnd, QObject* parent) : QThread(parent), hnd(hnd) {}

void run() override {
std::byte buf[1024];
char buf[1024];
while (true) {
DWORD readBytes;
if (!ReadFile(hnd, buf, sizeof(buf), &readBytes, nullptr)) {
auto err = GetLastError();
return;
}

emit dataRead(QByteArrayView(buf, readBytes));
emit dataRead(QByteArray(buf, readBytes));
}
}
Expand Down Expand Up @@ -173,7 +172,7 @@ bool WinPty::setWindowSize(qint16 cols, qint16 rows) {
if (d->hPC != nullptr) {
auto hr = ResizePseudoConsole(d->hPC, { cols, rows });
return SUCCEEDED(hr);
}
}
return false;
}

Expand All @@ -189,6 +188,10 @@ qint64 WinPty::writeData(const char* data, qint64 len) {
return len;
}

qint64 WinPty::bytesAvailable() const {
return d->readBuffer.length();
}

QStringList WinPty::runningProcesses() {
return {};
}
Expand Down
1 change: 1 addition & 0 deletions libtheterminal/common/PtyImpl/winpty.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WinPty : public AbstractPty {
protected:
qint64 readData(char *data, qint64 maxlen) override;
qint64 writeData(const char *data, qint64 len) override;
qint64 bytesAvailable() const override;
};

#endif // WINPTY_H

0 comments on commit ba564fc

Please sign in to comment.