65 lines
2.1 KiB
C++
Executable File
65 lines
2.1 KiB
C++
Executable File
#include <QApplication>
|
|
#include <QWidget>
|
|
#include <QTextEdit>
|
|
#include <QProcess>
|
|
#include <QVBoxLayout>
|
|
#include <QString>
|
|
#include <QFont>
|
|
#include <QScreen>
|
|
#include <QScrollBar>
|
|
#include <QGuiApplication>
|
|
|
|
#include <qpa/qplatformnativeinterface.h>
|
|
#include <wayland-client-protocol.h>
|
|
#include <QPlatformSurfaceEvent>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
QApplication app(argc, argv);
|
|
|
|
if (argc < 2) {
|
|
printf("Usage: %s '<command>'\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
QWidget window;
|
|
window.setWindowTitle("Shell Command Output Viewer");
|
|
window.setStyleSheet("background-color: black;");
|
|
|
|
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
|
|
wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", window.windowHandle()));
|
|
wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270);
|
|
wl_surface_commit(s);
|
|
void *egl = native->nativeResourceForWindow("egldisplay", window.windowHandle());
|
|
assert(egl != nullptr);
|
|
|
|
window.showFullScreen();
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(&window);
|
|
QTextEdit *outputDisplay = new QTextEdit;
|
|
outputDisplay->setFont(QFont("Consolas", 32));
|
|
outputDisplay->setReadOnly(true);
|
|
outputDisplay->setStyleSheet("color: white; background-color: black;");
|
|
layout->addWidget(outputDisplay);
|
|
|
|
QProcess process;
|
|
QObject::connect(&process, &QProcess::readyReadStandardOutput, [&]() {
|
|
static QStringList lines;
|
|
QString output = process.readAllStandardOutput();
|
|
lines += output.split("\n", QString::SkipEmptyParts);
|
|
while (lines.size() > 100) {
|
|
lines.removeFirst();
|
|
}
|
|
outputDisplay->setPlainText(lines.join("\n"));
|
|
outputDisplay->verticalScrollBar()->setValue(outputDisplay->verticalScrollBar()->maximum());
|
|
});
|
|
|
|
QObject::connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [&]() {
|
|
app.quit();
|
|
});
|
|
|
|
QString command = argv[1];
|
|
process.start(QString("bash -c \"%1\"").arg(command));
|
|
|
|
return app.exec();
|
|
}
|