ORE Studio 0.0.4
Loading...
Searching...
No Matches
ShellMdiWindow.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_SHELL_MDI_WINDOW_HPP
21#define ORES_QT_SHELL_MDI_WINDOW_HPP
22
23#include <deque>
24#include <mutex>
25#include <thread>
26#include <string>
27#include <vector>
28#include <memory>
29#include <streambuf>
30#include <condition_variable>
31#include <QColor>
32#include <QWidget>
33#include <QToolBar>
34#include <QLineEdit>
35#include <QPlainTextEdit>
36#include <QVBoxLayout>
37#include <QCloseEvent>
38#include "ores.qt/ClientManager.hpp"
39#include "ores.nats/service/nats_client.hpp"
40#include "ores.shell/app/repl.hpp"
41#include "ores.logging/make_logger.hpp"
42
43namespace ores::qt {
44
51class qt_output_streambuf : public QObject, public std::streambuf {
52 Q_OBJECT
53
54public:
55 explicit qt_output_streambuf(QObject* parent = nullptr);
56
57signals:
58 void text_ready(const QString& text);
59
60protected:
61 int_type overflow(int_type ch) override;
62 int sync() override;
63
64private:
65 void flush_buffer();
66
67 std::mutex mutex_;
68 std::string buffer_;
69};
70
77class qt_input_streambuf : public std::streambuf {
78public:
79 qt_input_streambuf() = default;
80
84 void feed_line(const std::string& line);
85
89 void close();
90
91protected:
92 int_type underflow() override;
93
94private:
95 std::mutex mutex_;
96 std::condition_variable cv_;
97 std::deque<std::string> pending_;
98 std::string current_;
99 bool closed_{false};
100};
101
109class ShellMdiWindow : public QWidget {
110 Q_OBJECT
111
112private:
113 inline static std::string_view logger_name =
114 "ores.qt.shell_mdi_window";
115
116 [[nodiscard]] static auto& lg() {
117 using namespace ores::logging;
118 static auto instance = make_logger(logger_name);
119 return instance;
120 }
121
122public:
123 explicit ShellMdiWindow(ClientManager* clientManager,
124 QWidget* parent = nullptr);
125 ~ShellMdiWindow() override;
126
127signals:
128 void statusChanged(const QString& message);
129
130protected:
131 void closeEvent(QCloseEvent* event) override;
132
133private slots:
134 void on_command_entered();
135 void on_output_ready(const QString& text);
136 void on_load_script();
137 void on_save_script();
138
139private:
140 void setup_ui();
141 void start_shell();
142 void stop_shell();
143 void on_repl_finished();
144
145 ClientManager* client_manager_;
146 QToolBar* toolbar_;
147 QPlainTextEdit* output_area_;
148 QLineEdit* input_line_;
149
150 std::unique_ptr<qt_output_streambuf> output_buf_;
151 std::unique_ptr<qt_input_streambuf> input_buf_;
152 std::unique_ptr<std::ostream> out_stream_;
153 std::unique_ptr<std::istream> in_stream_;
154
156 std::unique_ptr<shell::app::repl> shell_repl_;
157 std::unique_ptr<std::thread> worker_thread_;
158
159 // Soft violet for prompt, teal-blue for user input
160 QColor prompt_color_{0xB4, 0x8E, 0xAD};
161 QColor input_color_{0x88, 0xC0, 0xD0};
162
163 // History of commands entered by the user for Save
164 std::vector<std::string> command_history_;
165};
166
167}
168
169#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Authenticated NATS client for both interactive and service-to-service use.
Definition nats_client.hpp:71
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Stream buffer that emits Qt signals when text is written.
Definition ShellMdiWindow.hpp:51
Stream buffer that blocks on read until data is fed from the UI.
Definition ShellMdiWindow.hpp:77
void close()
Signal EOF to unblock the reader.
Definition ShellMdiWindow.cpp:82
void feed_line(const std::string &line)
Feed a line of input (called from UI thread).
Definition ShellMdiWindow.cpp:76
MDI window embedding the ores.shell REPL.
Definition ShellMdiWindow.hpp:109