File indexing completed on 2024-05-12 04:39:46
0001 /* 0002 SPDX-FileCopyrightText: 2003 John Birch <jbb@kdevelop.org> 0003 SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org> 0004 SPDX-FileCopyrightText: 2016 Aetf <aetf@unlimitedcodeworks.xyz> 0005 0006 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #ifndef DEBUGGERCONSOLEVIEW_H 0010 #define DEBUGGERCONSOLEVIEW_H 0011 0012 #include <QWidget> 0013 #include <QStringList> 0014 #include <QTimer> 0015 0016 #include "dbgglobal.h" 0017 0018 class QTextEdit; 0019 class QToolBar; 0020 class KHistoryComboBox; 0021 0022 namespace KDevelop { 0023 class IDebugSession; 0024 } 0025 0026 namespace KDevMI { 0027 class MIDebuggerPlugin; 0028 0029 /** 0030 * @brief A debugger console gives the user direct access to the debugger command line interface. 0031 */ 0032 class DebuggerConsoleView : public QWidget 0033 { 0034 Q_OBJECT 0035 public: 0036 explicit DebuggerConsoleView(MIDebuggerPlugin *plugin, QWidget *parent = nullptr); 0037 ~DebuggerConsoleView() override; 0038 0039 /** 0040 * Whether show a button allowing user to interrupt debugger execution. 0041 */ 0042 void setShowInterrupt(bool enable); 0043 0044 /** 0045 * If set to a nonempty string, the default "(gdb)" prompt will be replaced. 0046 * This only affects output lines after the call. 0047 */ 0048 void setReplacePrompt(const QString &prompt); 0049 0050 void setShowInternalCommands(bool enable); 0051 0052 Q_SIGNALS: 0053 void requestRaise(); 0054 /** 0055 * Proxy signals for DebugSession 0056 */ 0057 void interruptDebugger(); 0058 void sendCommand(const QString &cmd); 0059 0060 0061 protected: 0062 void setupUi(); 0063 void setupToolBar(); 0064 0065 /** 0066 * Arranges for 'line' to be shown to the user. 0067 * Adds 'line' to m_pendingOutput and makes sure 0068 * m_updateTimer is running. 0069 */ 0070 void appendLine(const QString &line); 0071 void updateColors(); 0072 0073 /** 0074 * escape html meta characters and handle line break 0075 */ 0076 QString toHtmlEscaped(QString text); 0077 0078 QString colorify(QString text, const QColor &color); 0079 0080 /** 0081 * Makes 'l' no longer than 'max_size' by 0082 * removing excessive elements from the top. 0083 */ 0084 void trimList(QStringList& l, int max_size); 0085 0086 void changeEvent(QEvent *e) override; 0087 void focusInEvent(QFocusEvent *e) override; 0088 0089 protected Q_SLOTS: 0090 void showContextMenu(const QPoint &pos); 0091 void toggleRepeat(bool checked); 0092 void toggleShowInternalCommands(bool checked); 0093 void flushPending(); 0094 void clear(); 0095 0096 void handleSessionChanged(KDevelop::IDebugSession *session); 0097 void handleDebuggerStateChange(DBGStateFlags oldStatus, DBGStateFlags newStatus); 0098 void receivedInternalCommandStdout(const QString &line); 0099 void receivedUserCommandStdout(const QString &line); 0100 void receivedStdout(const QString &line, bool internal); 0101 void receivedStderr(const QString &line); 0102 0103 void trySendCommand(QString cmd); 0104 private: 0105 QAction *m_actRepeat; 0106 QAction *m_actInterrupt; 0107 QAction *m_actShowInternal; 0108 QAction *m_actCmdEditor; 0109 0110 QTextEdit *m_textView; 0111 QToolBar *m_toolBar; 0112 KHistoryComboBox *m_cmdEditor; 0113 0114 bool m_repeatLastCommand; 0115 bool m_showInternalCommands; 0116 bool m_cmdEditorHadFocus; 0117 0118 /** 0119 * The output from user commands only and from all 0120 * commands. We keep it here so that if we switch 0121 * "Show internal commands" on, we can show previous 0122 * internal commands. 0123 */ 0124 QStringList m_allOutput; 0125 QStringList m_userOutput; 0126 0127 /** 0128 * For performance reasons, we don't immediately add new text 0129 * to QTExtEdit. Instead we add it to m_pendingOutput and 0130 * flush it on timer. 0131 */ 0132 QString m_pendingOutput; 0133 QTimer m_updateTimer; 0134 0135 QColor m_stdColor; 0136 QColor m_errorColor; 0137 0138 int m_maxLines; 0139 0140 QString m_alterPrompt; 0141 }; 0142 0143 } // end of namespace KDevMI 0144 0145 #endif // DEBUGGERCONSOLEVIEW_H