QtPass Developer documentation
QtPass test coverage
Current view: top level - src/processoutputpanel.h Coverage Total Hit
Test: QtPass Lines: 100.0 % 1 1
Test Date: 2026-11-14 13:19:18 Functions: - 0 0

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
       2              : // SPDX-License-Identifier: GPL-3.0-or-later
       3              : /**
       4              :  * @file
       5              :  * @brief ProcessOutputPanel: the dockable console that shows numbered,
       6              :  *        colour-coded git/pass/gpg output.
       7              :  */
       8              : #ifndef SRC_PROCESSOUTPUTPANEL_H_
       9              : #define SRC_PROCESSOUTPUTPANEL_H_
      10              : 
      11              : #include "enums.h"
      12              : #include <QDockWidget>
      13              : #include <QString>
      14              : 
      15              : class QTextEdit;
      16              : class QToolButton;
      17              : 
      18              : /**
      19              :  * @class ProcessOutputPanel
      20              :  * @ingroup ui
      21              :  * @brief The dockable "Process output" console: numbered, colour-coded
      22              :  *        lines of git/pass/gpg output with a line cap and sticky
      23              :  *        auto-scroll.
      24              :  *
      25              :  * A QDockWidget at the bottom dock area is the conventional place for an
      26              :  * IDE-style console and gives users detach/move for free. The panel knows
      27              :  * nothing about settings or the tree; MainWindow decides when to feed it
      28              :  * and when to show it.
      29              :  */
      30              : class ProcessOutputPanel : public QDockWidget {
      31          280 :   Q_OBJECT
      32              : 
      33              : public:
      34              :   /// Oldest lines are dropped once the document holds more than this.
      35              :   static constexpr int MaxLines = 1000;
      36              : 
      37              :   /**
      38              :    * @brief Build the console (Clear button + read-only text edit).
      39              :    * @param parent The main window; it adds the dock to an area itself.
      40              :    */
      41              :   explicit ProcessOutputPanel(QWidget *parent = nullptr);
      42              : 
      43              :   /**
      44              :    * @brief Append output, one numbered line per non-empty input line.
      45              :    *
      46              :    * Lines are right-trimmed (CR and trailing whitespace), empty ones are
      47              :    * skipped, and each gets the running counter and, when given, the
      48              :    * command prefix so multi-line output stays attributed. Errors are red.
      49              :    * Keeps the view at the bottom unless the user scrolled up.
      50              :    * @param output Raw stdout/stderr text.
      51              :    * @param isError true for stderr styling.
      52              :    * @param linePrefix Command label, e.g. "git push"; empty for none.
      53              :    */
      54              :   void append(const QString &output, bool isError,
      55              :               const QString &linePrefix = QString());
      56              : 
      57              :   /**
      58              :    * @brief Number of lines appended since the last clear().
      59              :    * @return The running counter shown as the line number.
      60              :    */
      61              :   [[nodiscard]] auto lineCount() const -> int { return m_counter; }
      62              : 
      63              :   /**
      64              :    * @brief Whether new output scrolls the view to the bottom.
      65              :    * @return false after the user scrolled up, true again at the bottom or
      66              :    *         after clear().
      67              :    */
      68              :   [[nodiscard]] auto autoScroll() const -> bool { return m_autoScroll; }
      69              : 
      70              :   /**
      71              :    * @brief Human-readable command label for a process id.
      72              :    * @param pid Process identifier.
      73              :    * @return e.g. "git push"; empty for processes that are never shown.
      74              :    */
      75              :   static auto processName(Enums::PROCESS pid) -> QString;
      76              : 
      77              :   /**
      78              :    * @brief Whether a process's output may carry secrets and must never
      79              :    *        reach this long-lived panel (pass show, pass insert; pass grep,
      80              :    *        should it ever run again).
      81              :    * @param pid Process identifier.
      82              :    * @return true when the output must be dropped.
      83              :    */
      84              :   static auto isSensitiveProcess(Enums::PROCESS pid) -> bool;
      85              : 
      86              : public slots:
      87              :   /**
      88              :    * @brief Drop all output, reset the counter, re-arm auto-scroll.
      89              :    */
      90              :   void clear();
      91              : 
      92              : private:
      93              :   /**
      94              :    * @brief Drop the oldest text blocks once the document holds more than
      95              :    *        MaxLines; called after every append().
      96              :    */
      97              :   void limitLines();
      98              : 
      99              :   /** @brief Read-only text edit holding the output; child of the dock. */
     100              :   QTextEdit *m_edit = nullptr;
     101              :   /** @brief The "Clear" button wired to clear(). */
     102              :   QToolButton *m_clearButton = nullptr;
     103              :   /**
     104              :    * @brief Running line number shown in front of each line; reset by
     105              :    *        clear(). Keeps counting past MaxLines.
     106              :    */
     107              :   int m_counter = 0;
     108              :   /**
     109              :    * @brief Whether append() scrolls to the bottom: cleared when the user
     110              :    *        scrolls up, set again when the scroll bar reaches its maximum or
     111              :    *        on clear(). Only updated on slider release while dragging.
     112              :    */
     113              :   bool m_autoScroll = true;
     114              : };
     115              : 
     116              : #endif // SRC_PROCESSOUTPUTPANEL_H_
        

Generated by: LCOV version 2.0-1