From ed5ecf7ea7a482b4649e66ecb35fbc60af680684 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 25 Apr 2016 13:08:12 -0400 Subject: Rearrange the Lumina source tree quite a bit: Now the utilites are arranged by category (core, core-utils, desktop-utils), so all the -utils may be excluded by a package system (or turned into separate packages) as needed. --- src-qt5/desktop-utils/lumina-terminal/TtyProcess.h | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src-qt5/desktop-utils/lumina-terminal/TtyProcess.h (limited to 'src-qt5/desktop-utils/lumina-terminal/TtyProcess.h') diff --git a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h new file mode 100644 index 00000000..9b3873b0 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h @@ -0,0 +1,83 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is basically a replacement for QProcess, where all process/terminal outputs +// are redirected and not just the standard input/output channels. This allows it +// to be used for terminal-like apps (shells) which directly modify the terminal output +// rather than stick to input/output channels for communication. +//=========================================== +// IMPLEMENTATION NOTE +//====================== +// The process requires/uses ANSI control codes (\x1B[) for special operations +// such as moving the cursor, erasing characters, etc.. +// It is recommended that you pair this class with the graphical "TerminalWidget.h" class +// or some other ANSI-compatible display widget. +//=========================================== +#ifndef _LUMINA_DESKTOP_UTILITIES_TERMINAL_TTY_PROCESS_WIDGET_H +#define _LUMINA_DESKTOP_UTILITIES_TERMINAL_TTY_PROCESS_WIDGET_H + +#include +#include +#include + +//Standard C library functions for PTY access/setup +#include +#include +#include +#include +#include +#include +#include +#include + +class TTYProcess : public QObject{ + Q_OBJECT +public: + TTYProcess(QObject *parent = 0); + ~TTYProcess(); + + bool startTTY(QString prog, QStringList args = QStringList(), QString workdir = "~"); + void closeTTY(); + + //Primary read/write functions + void writeTTY(QByteArray output); + QByteArray readTTY(); + + //Setup the terminal size (characters and pixels) + void setTerminalSize(QSize chars, QSize pixels); + + //Status update checks + bool isOpen(); + + //Functions for handling ANSI escape codes (typically not used by hand) + QByteArray CleanANSI(QByteArray, bool &incomplete); + +private: + pid_t childProc; + int ttyfd; + QSocketNotifier *sn; + QByteArray fragBA; //fragment ByteArray + + //==================================== + // C Library function for setting up the PTY + // Inputs: + // int &fd: (output) file descriptor for the master PTY (positive integer if valid) + // char *prog: program to run + // char **args: program arguments + // Returns: + // -1 for errors, child process PID (positive integer) if successful + //==================================== + static pid_t LaunchProcess(int& fd, char *prog, char **child_args); + +private slots: + void checkStatus(int); + +signals: + void readyRead(); + void processClosed(); +}; + +#endif -- cgit