### Complete QTermWidget Initialization Example Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md A comprehensive example demonstrating the complete configuration of QTermWidget, including shell settings, environment, appearance, keyboard bindings, behavior, and text handling. This example also shows how to connect signals and start the shell. ```cpp #include "qtermwidget.h" #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow window; // Create terminal (don't start yet) QTermWidget *terminal = new QTermWidget(0); // Configure shell terminal->setShellProgram("/bin/zsh"); terminal->setArgs(QStringList() << "-i" << "-l"); terminal->setWorkingDirectory(QDir::homePath()); // Configure environment QStringList env = QProcess::systemEnvironment(); env << "TERM=xterm-256color"; terminal->setEnvironment(env); // Configure appearance QFont font("DejaVu Sans Mono", 11); terminal->setTerminalFont(font); terminal->setColorScheme("Solarized"); terminal->setScrollBarPosition(QTermWidget::ScrollBarRight); // Configure keyboard terminal->setKeyBindings("linux"); // Configure behavior terminal->setHistorySize(-1); // Unlimited history terminal->setFlowControlEnabled(true); terminal->setAutoClose(true); terminal->setMonitorActivity(true); // Configure text behavior terminal->setConfirmMultilinePaste(true); terminal->setMotionAfterPasting(2); // MoveEnd // Apply to window window.setCentralWidget(terminal); window.resize(800, 600); window.show(); // Connect signals connect(terminal, &QTermWidget::finished, &app, &QApplication::quit); connect(terminal, &QTermWidget::activity, [terminal]() { qDebug() << "Activity in terminal"; }); // Start the shell terminal->startShellProgram(); return app.exec(); } ``` -------------------------------- ### Build Example Application Source: https://github.com/lxqt/qtermwidget/blob/master/CMakeLists.txt Conditionally builds an example C++ application if BUILD_EXAMPLE is set. Links the application against the QTermWidget library. ```cmake if(BUILD_EXAMPLE) set(EXAMPLE_SRC examples/cpp/main.cpp) add_executable(example ${EXAMPLE_SRC}) target_link_libraries(example ${QTERMWIDGET_LIBRARY_NAME}) endif() ``` -------------------------------- ### Define Installation Directories Source: https://github.com/lxqt/qtermwidget/blob/master/CMakeLists.txt Sets installation directories for keyboard layouts, color schemes, and translations. These paths are used to inform users where these resources will be installed. ```cmake set(KB_LAYOUT_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/kb-layouts") message(STATUS "Keyboard layouts will be installed in: ${KB_LAYOUT_DIR}") set(COLORSCHEMES_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/color-schemes") message(STATUS "Color schemes will be installed in: ${COLORSCHEMES_DIR}" ) set(TRANSLATIONS_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/translations") message(STATUS "Translations will be installed in: ${TRANSLATIONS_DIR}") set(QTERMWIDGET_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${QTERMWIDGET_LIBRARY_NAME}") ``` -------------------------------- ### Filter::HotSpot Usage Example Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/types.md Example of how to retrieve a hotspot at a given position and activate it if it's a link. ```cpp if (auto *hotspot = terminal->getHotSpotAt(position)) { if (hotspot->type() == Filter::HotSpot::Link) { hotspot->activate(); // Open the link } } ``` -------------------------------- ### Complete URL Detection Example Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/filter-system.md Provides a complete example of a QTermWidget application that enables default URL detection and connects to the urlActivated signal to open detected URLs using QDesktopServices. ```cpp #include "qtermwidget.h" #include "Filter.h" #include #include #include using namespace Konsole; class TerminalWithLinks : public QMainWindow { Q_OBJECT public: TerminalWithLinks() { QTermWidget *terminal = new QTermWidget(1); // Enable URL detection by default (via internal FilterChain) setCentralWidget(terminal); // Connect to URL activation connect(terminal, QOverload::of(&QTermWidget::urlActivated), this, [](const QUrl &url) { QDesktopServices::openUrl(url); }); resize(800, 600); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); TerminalWithLinks window; window.show(); return app.exec(); } ``` -------------------------------- ### Install Header Files Source: https://github.com/lxqt/qtermwidget/blob/master/CMakeLists.txt Installs the distribution header files, the generated export header, and the version header for the QTermWidget library. These are placed in the public include directory. ```cmake install(FILES ${HDRS_DISTRIB} "${CMAKE_CURRENT_BINARY_DIR}/lib/qtermwidget_export.h" "${CMAKE_CURRENT_BINARY_DIR}/lib/qtermwidget_version.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${QTERMWIDGET_LIBRARY_NAME}" COMPONENT Devel ) ``` -------------------------------- ### QTermWidget Constructor Options Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Control when the shell program starts. Use `1` for auto-start (recommended) or `0` for manual start with explicit `startShellProgram()` call. ```cpp // Option 1: Auto-start (recommended for most use cases) QTermWidget *terminal = new QTermWidget(1); // or just QTermWidget() ``` ```cpp // Option 2: Manual start QTermWidget *terminal = new QTermWidget(0); terminal->setShellProgram("/bin/zsh"); terminal->setArgs(QStringList() << "-l"); terminal->startShellProgram(); // Explicitly start later ``` -------------------------------- ### Handle Session Start Event Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Connects to the 'started' signal to execute code when the shell process begins. Useful for performing actions once the session is ready for input. ```cpp connect(session, &Session::started, this, [this]() { qDebug() << "Session started, PID:" << session->processId(); }); ``` -------------------------------- ### startShellProgram Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Starts the shell program if it was not started in the constructor. Use this when the widget was constructed with `startnow=0` and you are ready to begin the terminal session. ```APIDOC ## void startShellProgram() ### Description Starts the shell program if it was not started in the constructor. ### Use when Constructed with `startnow=0` and you're ready to begin the terminal session. ### Example ```cpp QTermWidget *terminal = new QTermWidget(0); // Don't start yet terminal->setShellProgram("/bin/bash"); terminal->setArgs(QStringList() << "--login"); terminal->startShellProgram(); // Now start ``` ``` -------------------------------- ### Set Shell Program and Start Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Specify the shell executable to run and then explicitly start it. Supports various shells like bash, zsh, sh, fish, and tcsh. ```cpp terminal->setShellProgram("/bin/zsh"); terminal->startShellProgram(); ``` -------------------------------- ### Initialize QTermWidget Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/INDEX.md Basic setup for creating and displaying a QTermWidget instance. Sets the font and color scheme. ```cpp #include "qtermwidget.h" #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QTermWidget *terminal = new QTermWidget(); terminal->setTerminalFont(QFont("Monospace", 11)); terminal->setColorScheme("Solarized"); QMainWindow window; window.setCentralWidget(terminal); window.resize(800, 600); window.show(); return app.exec(); } ``` -------------------------------- ### Start Shell Program Explicitly Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Use this when the QTermWidget was constructed with `startnow=0` and you are ready to initiate the terminal session. This method explicitly starts the shell program. ```cpp QTermWidget *terminal = new QTermWidget(0); // Don't start yet terminal->setShellProgram("/bin/bash"); terminal->setArgs(QStringList() << "--login"); terminal->startShellProgram(); // Now start ``` -------------------------------- ### Get Available Color Schemes Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Use `availableColorSchemes()` to retrieve a list of all installed color schemes. Iterate through the list to display or process each scheme name. ```cpp QStringList schemes = QTermWidget::availableColorSchemes(); for (const QString &scheme : schemes) { qDebug() << scheme; } ``` -------------------------------- ### QTermWidget Constructor Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Initializes a new instance of the QTermWidget. Optionally starts the pseudo-terminal immediately. ```APIDOC ## QTermWidget(int _startnow_ = 1, QWidget *_parent_ = 0) ### Description Constructs a QTermWidget. ### Parameters - **_startnow_** (int) - Optional. If 1 (default), starts the pseudo-terminal immediately. - **_parent_** (QWidget *) - Optional. Parent widget. ``` -------------------------------- ### Install Package Version File Source: https://github.com/lxqt/qtermwidget/blob/master/CMakeLists.txt Installs the generated package version file to the CMake configuration directory. This makes the package discoverable by find_package. ```cmake install(FILES "${CMAKE_BINARY_DIR}/${QTERMWIDGET_LIBRARY_NAME}-config-version.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QTERMWIDGET_LIBRARY_NAME}" COMPONENT Devel ) ``` -------------------------------- ### List Available Key Bindings Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Retrieves a list of all installed keyboard binding configurations. Use this to see available options before setting them. ```cpp QStringList bindings = QTermWidget::availableKeyBindings(); ``` -------------------------------- ### Custom EmailFilter Example Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/filter-system.md Example of creating a custom filter, EmailFilter, by subclassing RegExpFilter and configuring it to detect email patterns. ```cpp class EmailFilter : public Konsole::RegExpFilter { public: EmailFilter() : RegExpFilter() { // Configure regex pattern for emails } void process() override { // Process terminal text line by line // Create hotspots for matched patterns RegExpFilter::process(); } }; ``` -------------------------------- ### startShellProgram Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Starts the configured shell program in the terminal. ```APIDOC ## startShellProgram() ### Description Starts the shell program that was previously configured using setShellProgram(). ``` -------------------------------- ### availableKeyBindings Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Gets a list of all available keyboard binding schemes that can be used. ```APIDOC ## availableKeyBindings ### Description Returns all available keyboard binding schemes. ### Method static QStringList ### Returns QStringList - List of keybinding names ### Request Example ```cpp QStringList bindings = QTermWidget::availableKeyBindings(); qDebug() << "Available bindings:" << bindings; ``` ``` -------------------------------- ### Create and Run a Terminal Session Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Demonstrates the basic setup for creating a terminal session, configuring its program and arguments, attaching a display widget, connecting signals for session events, and running the session within a main window. ```cpp #include "Session.h" #include "TerminalDisplay.h" #include #include using namespace Konsole; int main(int argc, char *argv[]) { QApplication app(argc, argv); // Create session Session *session = new Session(); session->setProgram("/bin/bash"); session->setArguments(QStringList() << "-i" << "-l"); session->setInitialWorkingDirectory(QDir::home().absolutePath()); // Create display widget TerminalDisplay *display = new TerminalDisplay(); session->addView(display); // Connect signals QObject::connect(session, &Session::started, [session]() { qDebug() << "Session started with PID:" << session->processId(); }); QObject::connect(session, &Session::finished, &app, &QApplication::quit); QMainWindow window; window.setCentralWidget(display); window.resize(800, 600); window.show(); // Start session session->run(); return app.exec(); } ``` -------------------------------- ### Set Selection Start Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Sets the starting point of text selection using row and column indices. ```cpp void setSelectionStart(int row, int column) ``` -------------------------------- ### Get Selection Start Position Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Retrieves the current selection start position via output parameters for row and column. ```cpp void getSelectionStart(int &row, int &column) ``` -------------------------------- ### started Signal Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Emitted when the shell process has been started and is running. Use this signal to know when the session is ready for input. ```APIDOC ## void started() ### Description Emitted when the shell process has been started and is running. ### Use when Knowing when session is ready for input. ### Request Example ```cpp connect(session, &Session::started, this, [this]() { qDebug() << "Session started, PID:" << session->processId(); }); ``` ``` -------------------------------- ### Basic QTermWidget Application Example Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Demonstrates how to create and configure a QTermWidget within a Qt application. This snippet shows setting the font, scroll bar position, and connecting the finished signal. ```cpp #include "qtermwidget.h" #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow mainWindow; QTermWidget *terminal = new QTermWidget(1, &mainWindow); terminal->setTerminalFont(QFont("Monospace", 12)); terminal->setScrollBarPosition(QTermWidget::ScrollBarRight); mainWindow.setCentralWidget(terminal); mainWindow.resize(800, 600); mainWindow.show(); QObject::connect(terminal, &QTermWidget::finished, &mainWindow, &QMainWindow::close); return app.exec(); } ``` -------------------------------- ### createWidget Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Creates a new QTermWidget instance, optionally starting the associated process immediately. ```APIDOC ## createWidget ### Description Creates a new QTermWidget instance (for plugin interface). ### Parameters #### Path Parameters - **startnow** (int) - Required - 1 to auto-start, 0 to require manual start ### Returns QTermWidgetInterface* — Pointer to new widget instance ``` -------------------------------- ### Session::run() Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/INDEX.md Starts the terminal session and the associated shell program. ```APIDOC ## Session::run() ### Description Starts the terminal session and executes the configured shell program. ### Method `run()` ### Returns `bool` - `true` if the session started successfully, `false` otherwise. ``` -------------------------------- ### Set ScrollBar Position Example Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/types.md Example demonstrating how to set the scrollbar's position on a QTermWidget. Choose from left, right, or no scrollbar. ```cpp terminal->setScrollBarPosition(QTermWidget::ScrollBarRight); ``` -------------------------------- ### Add Filter to FilterChain Example Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/types.md Demonstrates how to obtain a FilterChain instance and add a new filter, such as UrlFilter, to it. ```cpp auto chain = display->filterChain(); auto *urlFilter = new UrlFilter(); chain->addFilter(urlFilter); ``` -------------------------------- ### Install Export Targets Source: https://github.com/lxqt/qtermwidget/blob/master/CMakeLists.txt Installs the CMake export targets file for the QTermWidget library. This allows other CMake projects to link against this library using 'target_link_libraries'. ```cmake install(EXPORT "${QTERMWIDGET_LIBRARY_NAME}-targets" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${QTERMWIDGET_LIBRARY_NAME}" COMPONENT Devel ) ``` -------------------------------- ### Set Initial Working Directory for QTermWidget Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Specify the starting directory for the shell process using `setInitialWorkingDirectory()`. This must be set before calling `run()`. ```cpp session->setInitialWorkingDirectory(QDir::home().absolutePath()); session->run(); ``` -------------------------------- ### getSelectionStart Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Retrieves the start coordinates of the current text selection. ```APIDOC ## getSelectionStart(int &_row_, int &_column_) ### Description Retrieves the start coordinates (row and column) of the current text selection. ### Parameters - **_row_** (int &) - Output parameter for the row of the selection start. - **_column_** (int &) - Output parameter for the column of the selection start. ``` -------------------------------- ### QTermWidget Configuration Reference Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/README.md A comprehensive guide to all configuration options and parameters for customizing QTermWidget's behavior and appearance. ```APIDOC ## QTermWidget Configuration Reference ### Description This document provides a detailed breakdown of all configuration options available for QTermWidget. It covers settings related to shell execution, display properties, color schemes, keyboard bindings, text behavior, and more. ### Configuration Categories - **Constructor Options**: Settings applied during widget initialization. - **Shell Program Configuration**: Executable path, arguments, environment variables, and working directory for the shell. - **Display Configuration**: Font selection, scrollbar visibility and position, widget size, margins, and background settings. - **Color Schemes**: Options for using built-in schemes, defining custom colors, and color format specifications. - **Keyboard Bindings**: Configuration for default and custom keyboard shortcuts. - **Text Behavior**: Settings for flow control, paste handling, word selection logic, and character encoding. - **Cursor Settings**: Customization of cursor shape and blinking behavior. - **History Configuration**: Strategies for managing the size and behavior of command history. - **Text Rendering**: Options for line drawing characters, bold text rendering, and bidirectional text support. - **Activity Monitoring**: Configuration for detecting terminal activity, silence, and timeouts. - **Auto-close and Mouse Behavior**: Settings for automatic closing and mouse interaction. - **Configuration Priority Rules**: Explanation of how different configuration sources are prioritized. ### Configuration Tables This document includes complete tables listing every configuration setting, its type, default value, and a description of its effect. ``` -------------------------------- ### QTermWidget(int startnow, QWidget *parent = nullptr) Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Constructs a new terminal widget with optional auto-start behavior. If startnow is 1, the shell program starts immediately. Otherwise, an explicit startShellProgram() call is required. ```APIDOC ## QTermWidget(int startnow, QWidget *parent = nullptr) ### Description Constructs a new terminal widget with optional auto-start behavior. ### Parameters #### Path Parameters - **startnow** (int) - Required - If 1, starts the shell program immediately; if 0, requires explicit `startShellProgram()` call - **parent** (QWidget*) - Optional - Parent widget for Qt object hierarchy ### Request Example ```cpp #include "qtermwidget.h" #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow mainWindow; QTermWidget *terminal = new QTermWidget(1, &mainWindow); terminal->setTerminalFont(QFont("Monospace", 12)); terminal->setScrollBarPosition(QTermWidget::ScrollBarRight); mainWindow.setCentralWidget(terminal); mainWindow.resize(800, 600); mainWindow.show(); QObject::connect(terminal, &QTermWidget::finished, &mainWindow, &QMainWindow::close); return app.exec(); } ``` ``` -------------------------------- ### startTerminalTeletype Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Initializes and starts the terminal's pseudo-teletype (TTY) interface. ```APIDOC ## startTerminalTeletype() ### Description Initializes and starts the terminal's pseudo-teletype (TTY) interface, preparing it for interaction. ``` -------------------------------- ### Run QTermWidget Session Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Initiates the shell process within the PTY. Ensure the program, arguments, and emulation are configured before calling `run()`. The `started()` signal is emitted upon successful execution, and `isRunning()` will return true. ```cpp session->setProgram("/bin/zsh"); session->setArgs(QStringList() << "--login"); session->run(); QObject::connect(session, &Session::finished, [this]() { qDebug() << "Session ended"; }); ``` -------------------------------- ### Implementing Custom Filter Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/filter-system.md Example of how to implement a custom filter by subclassing Filter and overriding the process() method to add detected hotspots. ```cpp class MyFilter : public Filter { public: void process() override { // ... scan terminal text ... if (foundPattern) { addHotSpot(new HotSpot(line1, col1, line2, col2)); } } }; ``` -------------------------------- ### setSelectionStart Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Sets the start coordinates of the text selection. ```APIDOC ## setSelectionStart(int _row_, int _column_) ### Description Sets the start coordinates (row and column) for the text selection. ### Parameters - **_row_** (int) - The row to set as the selection start. - **_column_** (int) - The column to set as the selection start. ``` -------------------------------- ### Property: keyBindings Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Gets the current key bindings configuration for the terminal. ```APIDOC ## GET keyBindings ### Description Returns current key bindings. ### Endpoint Not applicable (property getter) ### Returns - **QString**: A string representing the current key bindings. ``` -------------------------------- ### Define Package Configuration Requirements Source: https://github.com/lxqt/qtermwidget/blob/master/CMakeLists.txt Sets the string for package configuration requirements, typically used for pkg-config. This example specifies Qt6Widgets. ```cmake set(PKG_CONFIG_REQ "Qt6Widgets") ``` -------------------------------- ### Available Key Bindings Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Retrieves a list of all installed keyboard bindings available for QTermWidget. Common built-in bindings include linux, vt100, xterm, and vt420pc. ```APIDOC ## Available Key Bindings List installed keyboard bindings: ```cpp QStringList bindings = QTermWidget::availableKeyBindings(); ``` **Common built-in bindings:** | Binding | |---------| | linux | | vt100 | | xterm | | vt420pc | ``` -------------------------------- ### Set Terminal Background Image Mode Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Configure how the background image is displayed. This example sets the mode to 'Fit'. ```cpp // Assumes BackgroundMode enum values: // None = 0, Stretch = 1, Zoom = 2, Fit = 3, Center = 4 terminal->setTerminalBackgroundImage("/path/to/image.png"); terminal->setTerminalBackgroundMode(3); // Fit ``` -------------------------------- ### Get Keyboard Bindings Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Retrieves the name of the current keyboard bindings scheme. ```APIDOC ## keyBindings() ### Description Returns the current keyboard bindings scheme. ### Returns - QString — Keybindings name ``` -------------------------------- ### Configure Shell Program for QTermWidget Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Set the shell executable path using `setProgram()`. If not specified, the SHELL environment variable is used by default. Call `run()` after configuration to start the session. ```cpp session->setProgram("/bin/bash"); session->run(); ``` -------------------------------- ### Get Available Color Schemes Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Retrieves a list of available color scheme names on the system. This is a static method. ```cpp QStringList schemes = QTermWidget::availableColorSchemes(); for (const QString& scheme : schemes) { qDebug() << "Available scheme:" << scheme; } ``` -------------------------------- ### Detecting Shell Startup Failure Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/errors.md Check if the shell program has started successfully by verifying its PID. This helps identify issues like invalid paths or permission errors. ```cpp terminal->setShellProgram("/nonexistent/shell"); terminal->startShellProgram(); // Check if actually running if (terminal->getShellPID() > 0) { qDebug() << "Shell started with PID" << terminal->getShellPID(); } else { qWarning() << "Failed to start shell"; // Could be due to: invalid program, permission denied, no PTY available } ``` -------------------------------- ### Get and Set Emulation Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Retrieve the terminal emulation engine and set its key bindings. The emulation instance is typically Vt102Emulation for VT100 compatibility. ```cpp Emulation *emul = session->emulation(); emul->setKeyBindings("linux"); ``` -------------------------------- ### Get HotSpot Position Details Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/filter-system.md Retrieves the start and end line and column coordinates of a hotspot. This is useful for determining the exact location and extent of a detected pattern on the screen. ```cpp if (auto *spot = display->getHotSpotAt(pos)) { int startRow = spot->startLine(); int startCol = spot->startColumn(); int endRow = spot->endLine(); int endCol = spot->endColumn(); qDebug() << "Hotspot at" << startRow << "," << startCol << "to" << endRow << "," << endCol; } ``` -------------------------------- ### Set Working Directory Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Configure the initial directory from which the shell process will run. Use QDir::homePath() for the user's home directory. ```cpp terminal->setWorkingDirectory(QDir::homePath()); terminal->startShellProgram(); ``` -------------------------------- ### Create and Run a Terminal Session Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Demonstrates how to instantiate a Session object, configure its program and arguments, and then run the session. Ensure the shell program and arguments are set before calling run. ```cpp #include "Session.h" using namespace Konsole; Session *session = new Session(); session->setProgram("/bin/bash"); session->setArguments(QStringList() << "-i"); session->run(); ``` -------------------------------- ### Configure and Use Emulation Class Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/emulation.md This snippet shows how to retrieve an Emulation object from a Session, configure its key bindings and image size, create a window, connect a signal for sending data to the PTY, and send text to the terminal. It's useful for advanced use cases where direct interaction with the emulation is required. ```cpp #include "Emulation.h" #include "Session.h" // Get emulation from session Session *session = new Session(); Konsole::Emulation *emul = session->emulation(); // Configure emulation emul->setKeyBindings("linux"); emul->setImageSize(24, 80); // 24 lines, 80 columns // Create a view Konsole::ScreenWindow *window = emul->createWindow(); // Connect signals connect(emul, QOverload::of(&Emulation::sendData), this, [this](const char *data, int len) { // Send to PTY }); // Send text to terminal emul->sendText("echo 'Hello'\n"); ``` -------------------------------- ### Custom Color Scheme File Format Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Example of a `.colorscheme` file format. This INI-like structure defines general metadata and a 256-color palette, along with background, foreground, and underline colors. ```ini [General] ; Color scheme metadata Name=MyCustomScheme Description=My custom terminal colors Author=Your Name [Colors] ; 256-color palette (0-255) 0=30,30,30 ; Black 1=205,49,49 ; Red 2=19,161,14 ; Green 3=229,229,16 ; Yellow 4=36,114,200 ; Blue 5=188,63,60 ; Magenta 6=17,168,205 ; Cyan 7=204,204,204 ; White ; Bright colors (8-15) 8=102,102,102 ; Bright Black 9=255,85,85 ; Bright Red 10=85,255,85 ; Bright Green 11=255,255,85 ; Bright Yellow 12=85,85,255 ; Bright Blue 13=255,85,255 ; Bright Magenta 14=85,255,255 ; Bright Cyan 15=255,255,255 ; Bright White ; Background and text Background=30,30,30 Foreground=204,204,204 Underline=169,169,169 ``` -------------------------------- ### General Compile Definitions Source: https://github.com/lxqt/qtermwidget/blob/master/CMakeLists.txt Sets several general compile definitions for the QTermWidget library, including installation paths for resources and flags for POSIX openpt and sys/time.h. ```cmake target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME} PRIVATE "KB_LAYOUT_DIR=\"${KB_LAYOUT_DIR}\"" "COLORSCHEMES_DIR=\"${COLORSCHEMES_DIR}\"" "TRANSLATIONS_DIR=\"${TRANSLATIONS_DIR}\"" "HAVE_POSIX_OPENPT" "HAVE_SYS_TIME_H" ) ``` -------------------------------- ### Create New Screen Window Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/emulation.md Creates a new view onto the emulation's screen output. Use this when you need a separate display for the same terminal session, such as in a split-screen setup. ```cpp Emulation *emul = session->emulation(); ScreenWindow *window1 = emul->createWindow(); ScreenWindow *window2 = emul->createWindow(); // Both windows show the same emulation output ``` -------------------------------- ### Set Shell Arguments Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Define command-line arguments passed to the shell. Useful for starting shells in specific modes like login or interactive. ```cpp terminal->setShellProgram("/bin/bash"); terminal->setArgs(QStringList() << "--login" << "-i"); terminal->startShellProgram(); ``` -------------------------------- ### Create and Configure TerminalDisplay Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/terminal-display.md Demonstrates how to create a TerminalDisplay instance, set its font, opacity, margin, scroll bar position, and add URL detection filters. This is useful for building custom terminal applications. ```cpp #include "TerminalDisplay.h" #include "Emulation.h" #include #include using namespace Konsole; int main(int argc, char *argv[]) { QApplication app(argc, argv); // Create display auto *display = new TerminalDisplay(); // Configure appearance QFont font("DejaVu Sans Mono", 12); display->setFont(font); display->setOpacity(0.95); display->setMargin(5); display->setScrollBarPosition(QTermWidget::ScrollBarRight); // Get filter chain for URL detection auto *chain = display->filterChain(); chain->addFilter(new UrlFilter()); // Configure colors // (Usually set via ColorScheme system) // Use in window QMainWindow window; window.setCentralWidget(display); window.resize(800, 600); window.show(); // Connect to emulation (in real code) // emulation->connectView(display); return app.exec(); } ``` -------------------------------- ### Set Color Scheme by Name or File Path Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Configure the terminal's color scheme using `setColorScheme()`. You can provide either the name of a built-in or installed scheme, or a direct file path to a custom `.colorscheme` file. ```cpp // By name terminal->setColorScheme("Solarized"); ``` ```cpp // By file path terminal->setColorScheme("/usr/share/color-schemes/custom.colorscheme"); ``` ```cpp // Get list and apply auto schemes = QTermWidget::availableColorSchemes(); if (schemes.contains("Monokai")) { terminal->setColorScheme("Monokai"); } ``` -------------------------------- ### availableKeyBindings (static) Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Returns a list of available key binding configurations. ```APIDOC ## static QStringList availableKeyBindings() ### Description Returns a list of strings, where each string represents an available key binding configuration that can be loaded or applied. ### Returns QStringList - A list of available key binding configuration names. ``` -------------------------------- ### Start Terminal Teletype Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Use this to start the terminal teletype without launching a shell program, redirecting data for external control and display. This is useful when you want to control a remote terminal or handle I/O externally via the `sendData()` signal. ```cpp QTermWidget *terminal = new QTermWidget(0); terminal->startTerminalTeletype(); connect(terminal, QOverload::of(&QTermWidget::sendData), this, &MyClass::handleTerminalOutput); ``` -------------------------------- ### Create a Basic Terminal Widget Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/README.md Demonstrates the minimal code required to create and display a QTermWidget within a QMainWindow. ```cpp #include "qtermwidget.h" #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow window; QTermWidget *terminal = new QTermWidget(); window.setCentralWidget(terminal); window.resize(800, 600); window.show(); return app.exec(); } ``` -------------------------------- ### Profile-Based Session Configuration Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Illustrates how to set a profile key for a session, which can later be used to load and apply specific profile settings like fonts and colors. ```cpp Session *session = new Session(); session->setProfileKey("my-profile"); // Can later retrieve and apply profile settings QString profileKey = session->profileKey(); // Load profile settings (font, colors, etc.) and apply ``` -------------------------------- ### Set Shell Arguments Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Configure shell startup arguments such as interactive mode (`-i`), login shell (`-l`), single command mode (`-s`), or executing a specific command (`-c "command"`). ```cpp terminal->setArgs(QStringList() << "-i" << "-l"); ``` -------------------------------- ### QTermWidget(QWidget *parent = nullptr) Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Qt Designer compatible constructor. This constructor is provided for compatibility with Qt Designer, and the `startnow` parameter defaults to 1. ```APIDOC ## QTermWidget(QWidget *parent = nullptr) ### Description Qt Designer compatible constructor. Provided for compatibility with Qt Designer; `startnow` defaults to 1. ### Parameters #### Path Parameters - **parent** (QWidget*) - Optional - Parent widget for Qt object hierarchy ### Note This constructor is for Qt Designer use. In code, prefer the explicit `startnow` parameter for clarity. ``` -------------------------------- ### Session ID Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Gets the unique identifier for the current terminal session. ```APIDOC ## sessionId() ### Description Returns the unique ID for this session. ### Returns - int — Unique session identifier ``` -------------------------------- ### Property: wordCharacters Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Gets the characters considered as word characters for text selection. ```APIDOC ## GET wordCharacters ### Description When selecting text by word, consider these characters to be word characters in addition to alphanumeric characters, default is `:@-./_~`. ### Endpoint Not applicable (property getter) ### Returns - **QString**: A string containing characters considered as word characters. ``` -------------------------------- ### Terminal Dimensions Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Methods for getting and setting the terminal's dimensions (rows and columns). ```APIDOC ## QSize size() ### Description Returns the terminal size (rows and columns). ### Returns QSize — Size with width=columns, height=lines ``` ```APIDOC ## void setSize(QSize newSize) ### Description Sets the terminal size. ### Parameters #### Path Parameters - **newSize** (QSize) - Required - New dimensions ### Request Example ```cpp session->setSize(QSize(80, 24)); // 80 columns x 24 rows ``` ``` -------------------------------- ### List Available Key Bindings Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Retrieves and prints a list of all available keyboard binding schemes. This is useful for discovering supported keymap configurations. ```cpp QStringList bindings = QTermWidget::availableKeyBindings(); qDebug() << "Available bindings:" << bindings; ``` -------------------------------- ### Configure Shell and Environment Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/INDEX.md Sets the shell program, arguments, working directory, and environment variables for the terminal session. Ensure `startShellProgram()` is called to launch the configured shell. ```cpp terminal->setShellProgram("/bin/zsh"); terminal->setArgs(QStringList() << "-i" << "-l"); terminal->setWorkingDirectory(QDir::homePath()); QStringList env = QProcess::systemEnvironment(); env << "TERM=xterm-256color"; terminal->setEnvironment(env); terminal->startShellProgram(); ``` -------------------------------- ### User-Provided Title Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Gets the title explicitly set by the user, distinct from titles set by the shell. ```APIDOC ## userTitle() ### Description Returns the title set explicitly by the user (not by the shell). ### Returns - QString — User-provided title, or empty string ``` -------------------------------- ### Get Random Seed Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/terminal-display.md Returns the current seed value used for random color generation. ```cpp uint randomSeed() const; ``` -------------------------------- ### createWindow() Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/emulation.md Creates a new window/view onto the emulation's screen output. Use when you need a separate view into the same terminal session (e.g., split view). ```APIDOC ## createWindow() ### Description Creates a new window/view onto the emulation's screen output. **Use when:** You need a separate view into the same terminal session (e.g., split view). ### Returns ScreenWindow* — A new screen window for viewing terminal output ### Example ```cpp Emulation *emul = session->emulation(); ScreenWindow *window1 = emul->createWindow(); ScreenWindow *window2 = emul->createWindow(); // Both windows show the same emulation output ``` ``` -------------------------------- ### Property: getForegroundProcessId Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Gets the Process ID (PID) of the foreground process running within the terminal. ```APIDOC ## GET getForegroundProcessId ### Description Returns the PID of the foreground process. This is initially the same as processId() but can change as the user starts other programs inside the terminal. If there is a problem reading the foreground process id, 0 will be returned. ### Endpoint Not applicable (property getter) ### Returns - **int**: The PID of the foreground process, or 0 if an error occurs. ``` -------------------------------- ### Get Current Keyboard Bindings Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/emulation.md Retrieves the name of the currently active keyboard bindings scheme. ```cpp QString activeBindings = emulation->keyBindings(); qDebug() << "Using:" << activeBindings; ``` -------------------------------- ### Get Selected Text Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Returns the currently selected text in the terminal. Optionally preserves line breaks. ```cpp QString selected = terminal->selectedText(); qDebug() << "Selected:" << selected; ``` -------------------------------- ### Enable URL Detection and Handling Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/README.md Configures the QTermWidget to automatically detect URLs and opens them using the system's default handler when activated. ```cpp // URLs are detected automatically and emitted via signal connect(terminal, QOverload::of(&QTermWidget::urlActivated), this, [](const QUrl &url) { QDesktopServices::openUrl(url); }); ``` -------------------------------- ### Get Filter Chain - QTermWidget Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/filter-system.md Retrieve the filter chain object from a TerminalDisplay instance to manage filters. ```cpp TerminalDisplay *display = /* ... */; FilterChain *chain = display->filterChain(); ``` -------------------------------- ### Shell Configuration Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/session.md Configure the shell program, arguments, environment, and working directory for the session. ```APIDOC ## setProgram(const QString &program) ### Description Sets the shell program to execute. ### Parameters #### Path Parameters - **program** (const QString&) - Required - Path to shell executable ### Default Uses SHELL environment variable if not set ### Example ```cpp session->setProgram("/bin/bash"); session->run(); ``` ``` ```APIDOC ## program() const ### Description Returns the currently configured shell program. ### Returns - **QString**: Path to shell executable ``` ```APIDOC ## setArguments(const QStringList &arguments) ### Description Sets command-line arguments for the shell. ### Parameters #### Path Parameters - **arguments** (const QStringList&) - Required - List of arguments ### Common arguments - `-i` : Interactive shell - `-l` : Login shell - `-s` : Single command mode ### Example ```cpp session->setArguments(QStringList() << "-i" << "-l"); ``` ``` ```APIDOC ## arguments() const ### Description Returns the configured shell arguments. ### Returns - **QStringList**: Currently set arguments ``` ```APIDOC ## setEnvironment(const QStringList &environment) ### Description Sets environment variables for the shell process. ### Parameters #### Path Parameters - **environment** (const QStringList&) - Required - List of "VAR=VALUE" strings ### Example ```cpp QStringList env = QProcess::systemEnvironment(); env << "CUSTOM_VAR=myvalue"; env << "TERM=xterm-256color"; session->setEnvironment(env); session->run(); ``` ``` ```APIDOC ## environment() const ### Description Returns the session's environment variables. ### Returns - **QStringList**: Current environment variables ``` ```APIDOC ## setInitialWorkingDirectory(const QString &directory) ### Description Sets the working directory for the shell. ### Parameters #### Path Parameters - **directory** (const QString&) - Required - Absolute path to working directory ### Note Must be set before `run()` ### Example ```cpp session->setInitialWorkingDirectory(QDir::home().absolutePath()); session->run(); ``` ``` -------------------------------- ### Emulation() Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/emulation.md Constructs a new terminal emulation instance. Note: This is an abstract base class. Use Vt102Emulation for concrete implementation or access through Session::emulation(). ```APIDOC ## Emulation() ### Description Constructs a new terminal emulation instance. **Note:** This is an abstract base class. Use `Vt102Emulation` for concrete implementation or access through `Session::emulation()`. ``` -------------------------------- ### startTerminalTeletype Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Starts the terminal teletype (TTY) and redirects data for external recipients, enabling remote terminal control. ```APIDOC ## POST startTerminalTeletype ### Description Starts terminal teletype as is and redirect data for external recipient. It can be used for display and control a remote terminal. ### Endpoint Not applicable (method call) ``` -------------------------------- ### Configure Text Rendering Options Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/configuration.md Enables or disables specific text rendering features. Use `setBidiEnabled(true)` for right-to-left text support (e.g., Arabic/Hebrew) and `setBoldIntense(true)` to make bold text use bright colors instead of increased weight. ```cpp // Arabic/Hebrew support terminal->setBidiEnabled(true); ``` ```cpp // Make bold text bright colored terminal->setBoldIntense(true); ``` -------------------------------- ### Filter::HotSpot Position Methods Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/filter-system.md Provides methods to retrieve the start and end line and column coordinates of a hotspot. ```APIDOC ## Filter::HotSpot Position Methods ### Description Retrieves the positional information of the hotspot. ### Methods #### int startLine() const Returns the starting line of the hotspot. **Returns:** int — Starting row index (0-based) #### int endLine() const Returns the ending line of the hotspot. **Returns:** int — Ending row index #### int startColumn() const Returns the starting column. **Returns:** int — Starting column on startLine (0-based) #### int endColumn() const Returns the ending column. **Returns:** int — Ending column on endLine ### Request Example ```cpp if (auto *spot = display->getHotSpotAt(pos)) { int startRow = spot->startLine(); int startCol = spot->startColumn(); int endRow = spot->endLine(); int endCol = spot->endColumn(); qDebug() << "Hotspot at" << startRow << "," << startCol << "to" << endRow << "," << endCol; } ``` ``` -------------------------------- ### History Management Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/qtermwidget-main.md Methods for managing the terminal's history buffer, including getting and setting its size, and saving it. ```APIDOC ## historyLinesCount ### Description Returns the number of lines currently stored in the terminal's history buffer. ### Returns - int: The total number of lines available in the history. ## setHistorySize ### Description Sets the maximum number of lines to store in the terminal's history buffer. ### Parameters #### Path Parameters - **lines** (int) - Required - Number of lines to store. A value of 0 disables history, and a negative value enables infinite history. ### Example ```cpp terminal->setHistorySize(-1); // Infinite history terminal->setHistorySize(10000); // Keep 10,000 lines ``` ## historySize ### Description Retrieves the currently configured maximum size of the terminal's history buffer. ### Returns - int: The history size in lines. ## saveHistory ### Description Saves the entire terminal history to a specified device. ### Parameters #### Path Parameters - **device** (QIODevice*) - Required - The device (e.g., a file) to which the history will be written. ### Example ```cpp QFile historyFile("terminal_history.txt"); historyFile.open(QIODevice::WriteOnly | QIODevice::Text); terminal->saveHistory(&historyFile); historyFile.close(); ``` ``` -------------------------------- ### Display HotSpot Context Menu Actions Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/filter-system.md Retrieves a list of available QAction objects for a hotspot, which can then be used to populate a context menu. This allows users to perform specific actions on detected patterns. ```cpp if (auto *spot = display->getHotSpotAt(mousePos)) { auto actions = spot->actions(); QMenu contextMenu; for (auto *action : actions) { contextMenu.addAction(action); } contextMenu.exec(cursor().pos()); } ``` -------------------------------- ### QTermWidget Project Files Source: https://github.com/lxqt/qtermwidget/blob/master/README.md Lists the source files and copyright information for the QTermWidget project. This includes files related to terminal decoding, process management, and the widget itself. ```text Files: example/main.cpp lib/TerminalCharacterDecoder.cpp lib/TerminalCharacterDecoder.h lib/kprocess.cpp lib/kprocess.h lib/kpty.cpp lib/kpty.h lib/kpty_p.h lib/kptydevice.cpp lib/kptydevice.h lib/kptyprocess.cpp lib/kptyprocess.h lib/qtermwidget.cpp lib/qtermwidget.h lib/qtermwidget_interface.h Copyright: Author Adriaan de Groot 2010, KDE e.V 2002-2007, Oswald Buddenhagen 2006-2008, Robert Knight 2002, Waldo Bastian 2008, e_k 2022, Francesc Martinez License: LGPL-2+ ``` ```text Files: cmake/FindUtf8Proc.cmake Copyright: 2009-2011, Kitware, Inc 2009-2011, Philip Lowman License: BSD-3-clause ``` -------------------------------- ### QTermWidget Keyboard and Input Bindings Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/INDEX.md Methods for configuring keyboard input and custom key bindings. ```APIDOC ## Keyboard & Input Bindings ### Description Configure keyboard input behavior and set custom key bindings for terminal actions. ### Methods - `setKeyBindings(const KeyBindings &bindings)`: Sets custom key bindings. ``` -------------------------------- ### Monitor Session Status Source: https://github.com/lxqt/qtermwidget/blob/master/_autodocs/INDEX.md Manages and monitors the lifecycle of a terminal session. Connect to `started` and `finished` signals for status updates. ```cpp Session *session = new Session(); session->setProgram("/bin/bash"); session->run(); connect(session, &Session::started, [session]() { qDebug() << "Session started, PID:" << session->processId(); }); connect(session, &Session::finished, []() { qDebug() << "Session ended"; }); ```