From e5b91eaed823988fdd64b24ac0df6a24543e3c14 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sun, 1 Feb 2026 20:20:39 -0500 Subject: [PATCH] Add basic debug logger. --- build.rs | 2 ++ qml/ClideEditor.qml | 25 +++++++++-------- qml/ClideLogger.qml | 58 ++++++++++++++++++++++++++++++++++++++++ qml/ClideProjectView.qml | 9 +++---- qml/ClideTreeView.qml | 5 ++-- qml/Logger/Logger.qml | 30 +++++++++++++++++++++ qml/Logger/qmldir | 1 + qml/main.qml | 1 + src/gui/colors.rs | 16 +++++++++-- 9 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 qml/ClideLogger.qml create mode 100644 qml/Logger/Logger.qml create mode 100644 qml/Logger/qmldir diff --git a/build.rs b/build.rs index 29ac905..664dd6e 100644 --- a/build.rs +++ b/build.rs @@ -8,6 +8,8 @@ fn main() { "qml/ClideProjectView.qml", "qml/ClideEditor.qml", "qml/ClideMenuBar.qml", + "qml/ClideLogger.qml", + "qml/Logger/Logger.qml", ])) // Link Qt's Network library // - Qt Core is always linked diff --git a/qml/ClideEditor.qml b/qml/ClideEditor.qml index 464637c..8e3558e 100644 --- a/qml/ClideEditor.qml +++ b/qml/ClideEditor.qml @@ -7,6 +7,7 @@ import QtQuick.Controls import QtQuick.Layouts import clide.module 1.0 +import Logger 1.0 SplitView { id: root @@ -78,6 +79,9 @@ SplitView { text: parent.index + 1 verticalAlignment: Text.AlignVCenter width: parent.width - indicator.width + background: Rectangle { + color: RustColors.terminal_background + } } // Draw edge along the right side of the line number. Rectangle { @@ -149,20 +153,8 @@ SplitView { } } } - TextArea { + ClideLogger { id: areaConsole - - height: 100 - width: parent.width - placeholderText: qsTr("shaun@pc:~/Code/clide$ ") - placeholderTextColor: "white" - readOnly: true - wrapMode: TextArea.Wrap - background: Rectangle { - color: RustColors.terminal_background - implicitHeight: 100 - // border.color: control.enabled ? RustColors.active : RustColors.inactive - } } // We use an inline component to customize the horizontal and vertical @@ -208,4 +200,11 @@ SplitView { } } } + + + Component.onCompleted: { + // Show logging is working. + Logger.debug("Debug console ready") + Logger.warn("Warnings show up too") + } } diff --git a/qml/ClideLogger.qml b/qml/ClideLogger.qml new file mode 100644 index 0000000..c7b185b --- /dev/null +++ b/qml/ClideLogger.qml @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2026, Shaun Reed +// +// SPDX-License-Identifier: GNU General Public License v3.0 or later + +import QtQuick +import QtQuick.Controls + +import clide.module 1.0 +import Logger 1.0 + +Item { + ListModel { id: model } + + Rectangle { + anchors.fill: parent + color: "#111" + } + + ListView { + id: listView + anchors.fill: parent + model: model + clip: true + + function getLogColor(level) { + switch (level) { + case "INFO": + return RustColors.info_log + break; + case "DEBUG": + return RustColors.debug_log + break; + case "WARN": + return RustColors.warn_log + break; + case "ERROR": + return RustColors.error_log + break; + default: + return RustColors.info_log + break; + } + } + + delegate: Text { + text: `[${level}] ${message}` + font.family: "monospace" + color: listView.getLogColor(level) + } + } + + Connections { + target: Logger + function onLogged(level, message) { + model.append({ level, message }) + } + } +} diff --git a/qml/ClideProjectView.qml b/qml/ClideProjectView.qml index 34b3ff1..7ef39f6 100644 --- a/qml/ClideProjectView.qml +++ b/qml/ClideProjectView.qml @@ -7,6 +7,7 @@ import QtQuick.Controls import QtQuick.Layouts import clide.module 1.0 +import Logger 1.0 SplitView { id: root @@ -62,9 +63,7 @@ SplitView { TapHandler { acceptedButtons: Qt.RightButton - onSingleTapped: (eventPoint, button) => { - contextMenu.popup() - } + onSingleTapped: (eventPoint, button) => contextMenu.popup() } Menu { @@ -72,7 +71,7 @@ SplitView { Action { text: qsTr("Reset root index") onTriggered: { - console.log("Resetting root directory: " + clideTreeView.originalRootDirectory) + Logger.log("Resetting root directory: " + clideTreeView.originalRootDirectory) clideTreeView.rootDirectory = clideTreeView.originalRootDirectory } } @@ -89,7 +88,7 @@ SplitView { originalRootDirectory: root.projectDir rootDirectory: root.projectDir onRootDirectoryChanged: { - console.log(clideTreeView.rootDirectory) + Logger.log(clideTreeView.rootDirectory) breadCrumb.text = clideTreeView.rootDirectory } } diff --git a/qml/ClideTreeView.qml b/qml/ClideTreeView.qml index cf68a74..1ba5db5 100644 --- a/qml/ClideTreeView.qml +++ b/qml/ClideTreeView.qml @@ -7,6 +7,7 @@ import QtQuick.Effects import QtQuick.Controls import clide.module 1.0 +import Logger 1.0 TreeView { id: fileSystemTreeView @@ -133,14 +134,14 @@ TreeView { text: qsTr("Set as root index") enabled: treeDelegate.hasChildren onTriggered: { - console.log("Setting new root directory: " + treeDelegate.filePath) + Logger.debug("Setting new root directory: " + treeDelegate.filePath) fileSystemTreeView.rootDirectory = treeDelegate.filePath } } Action { text: qsTr("Reset root index") onTriggered: { - console.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory) + Logger.log("Resetting root directory: " + fileSystemTreeView.originalRootDirectory) fileSystemTreeView.rootDirectory = fileSystemTreeView.originalRootDirectory } } diff --git a/qml/Logger/Logger.qml b/qml/Logger/Logger.qml new file mode 100644 index 0000000..5f80b54 --- /dev/null +++ b/qml/Logger/Logger.qml @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2026, Shaun Reed +// +// SPDX-License-Identifier: GNU General Public License v3.0 or later + +pragma Singleton +import QtQuick + +QtObject { + signal logged(string level, string message) + + function log(msg) { + console.log(msg) + logged("INFO", msg) + } + + function debug(msg) { + console.log(msg) + logged("DEBUG", msg) + } + + function warn(msg) { + console.warn(msg) + logged("WARN", msg) + } + + function error(msg) { + console.error(msg) + logged("ERROR", msg) + } +} diff --git a/qml/Logger/qmldir b/qml/Logger/qmldir new file mode 100644 index 0000000..019474e --- /dev/null +++ b/qml/Logger/qmldir @@ -0,0 +1 @@ +singleton Logger 1.0 Logger.qml diff --git a/qml/main.qml b/qml/main.qml index 85200b3..6f71d32 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -27,6 +27,7 @@ ApplicationWindow { title: qsTr("Error") } ClideProjectView { + id: clideProjectView projectDir: appWindow.appContextPath } } diff --git a/src/gui/colors.rs b/src/gui/colors.rs index a413442..c7c1fbd 100644 --- a/src/gui/colors.rs +++ b/src/gui/colors.rs @@ -37,6 +37,10 @@ pub mod qobject { #[qproperty(QColor, explorer_folder)] #[qproperty(QColor, explorer_folder_open)] #[qproperty(QColor, terminal_background)] + #[qproperty(QColor, info_log)] + #[qproperty(QColor, debug_log)] + #[qproperty(QColor, warn_log)] + #[qproperty(QColor, error_log)] type RustColors = super::RustColorsImpl; } } @@ -67,6 +71,10 @@ pub struct RustColorsImpl { explorer_folder: QColor, explorer_folder_open: QColor, terminal_background: QColor, + info_log: QColor, + debug_log: QColor, + warn_log: QColor, + error_log: QColor, } impl Default for RustColorsImpl { @@ -83,7 +91,7 @@ impl Default for RustColorsImpl { linenumber: QColor::try_from("#94989b").unwrap(), active: QColor::try_from("#a9acb0").unwrap(), inactive: QColor::try_from("#FFF").unwrap(), - editor_background: QColor::try_from("#2b2b2b").unwrap(), + editor_background: QColor::try_from("#111111").unwrap(), editor_text: QColor::try_from("#acaea3").unwrap(), editor_highlighted_text: QColor::try_from("#ccced3").unwrap(), editor_highlight: QColor::try_from("#ccced3").unwrap(), @@ -94,7 +102,11 @@ impl Default for RustColorsImpl { explorer_background: QColor::try_from("#1E1F22").unwrap(), explorer_folder: QColor::try_from("#54585b").unwrap(), explorer_folder_open: QColor::try_from("#2b2b2b").unwrap(), - terminal_background: QColor::try_from("#2C2E32").unwrap(), + terminal_background: QColor::try_from("#111111").unwrap(), + info_log: QColor::try_from("#C4FFFF").unwrap(), + debug_log: QColor::try_from("#55ff99").unwrap(), + warn_log: QColor::try_from("#ffaa00").unwrap(), + error_log: QColor::try_from("#ff5555").unwrap(), } } }