Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue: WASM, Reading console input does not work #360

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,34 @@ void Console::keyPressEvent(QKeyEvent *e) {
case Qt::Key_Down:
QPlainTextEdit::keyPressEvent(e);
break;

case Qt::Key_Return:
case Qt::Key_Enter:
// Return is interpreted as \n instead of the default \r (\n)
m_buffer += "\n";

// Flush buffer to output
emit sendData(m_buffer.toLocal8Bit());
m_buffer.clear();

if (m_localEchoEnabled)
putData("\r");
break;

case Qt::Key_Backspace:
if (!m_buffer.isEmpty()) {
// Remove the last character from the buffer
m_buffer.chop(1);
if (m_localEchoEnabled)
backspace();
}
break;

default:
if (!e->text().isEmpty()) {
bool backspacedBuffer = false;
const QString text = e->text();
// Buffer managing
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
// Return is interpreted as \n instead of the default \r
m_buffer += "\n";

// Flush buffer to output
emit sendData(m_buffer.toLocal8Bit());
m_buffer.clear();
} else if (e->key() == Qt::Key_Backspace) {
if (!m_buffer.isEmpty()) {
m_buffer.chop(1);
backspacedBuffer = true;
}
} else {
m_buffer += text;
}

// Console echoing
if (m_localEchoEnabled) {
if (e->key() == Qt::Key_Backspace) {
if (backspacedBuffer) {
backspace();
}
} else {
putData(text.toUtf8());
}
}
m_buffer += e->text();
if (m_localEchoEnabled)
putData(e->text().toUtf8());
}
}
}
Expand Down
Loading