aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-10 22:04:24 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-10 22:13:15 +0530
commit971854bfefad4c644ac3d5f5d6003f24d551bf1d (patch)
tree0f5ee90fd5968d345b157d38964094837315edf0 /include
parentd400369084107104f51fe217d5781c8d7bd07ff9 (diff)
downloadnull-browser-971854bfefad4c644ac3d5f5d6003f24d551bf1d.tar.gz
null-browser-971854bfefad4c644ac3d5f5d6003f24d551bf1d.zip
Add completer + simplify command parsing + class generator
Diffstat (limited to '')
-rw-r--r--include/CommandParser.hpp9
-rw-r--r--include/LuaRuntime.hpp2
-rw-r--r--include/completion/CommandsModel.hpp32
-rw-r--r--include/completion/Completer.hpp14
-rw-r--r--include/completion/CompleterDelegate.hpp15
-rw-r--r--include/widgets/CommandInput.hpp3
6 files changed, 67 insertions, 8 deletions
diff --git a/include/CommandParser.hpp b/include/CommandParser.hpp
index 128b5f4..dea04c5 100644
--- a/include/CommandParser.hpp
+++ b/include/CommandParser.hpp
@@ -12,13 +12,10 @@ enum CommandType {
TabPrev,
};
-class Cmd {
-public:
+struct Cmd {
CommandType command;
- QStringList args;
-
- Cmd(CommandType command = Noop, QStringList args = QStringList())
- : command(command), args(args) {}
+ QString argsString;
+ QString rawInput;
};
class CommandParser {
diff --git a/include/LuaRuntime.hpp b/include/LuaRuntime.hpp
index 85bb1ae..96c0004 100644
--- a/include/LuaRuntime.hpp
+++ b/include/LuaRuntime.hpp
@@ -13,7 +13,7 @@ public:
return &inst;
}
- void evaluate(const char *code);
+ void evaluate(QString code);
protected:
LuaRuntime();
diff --git a/include/completion/CommandsModel.hpp b/include/completion/CommandsModel.hpp
new file mode 100644
index 0000000..6cb25f9
--- /dev/null
+++ b/include/completion/CommandsModel.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <QAbstractListModel>
+#include <QWidget>
+#include <QtCore>
+
+struct Command {
+ QString name;
+ QString description;
+};
+
+const QList<Command> commands = {
+ {.name = "open", .description = "Open a url in the current tab"},
+ {.name = "tabopen", .description = "Open a url in a new tab"},
+ {.name = "bnext", .description = "Go to next tab"},
+ {.name = "bprev", .description = "Go to previous tab"},
+};
+
+class CommandsModel : public QAbstractListModel {
+ Q_OBJECT
+
+public:
+ CommandsModel(QObject *parent = nullptr);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override;
+ QHash<int, QByteArray> roleNames() const override;
+ QVariant data(const QModelIndex &index,
+ int role = Qt::DisplayRole) const override;
+
+private:
+ QList<Command> items;
+};
diff --git a/include/completion/Completer.hpp b/include/completion/Completer.hpp
new file mode 100644
index 0000000..b67de61
--- /dev/null
+++ b/include/completion/Completer.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <QCompleter>
+#include <QWidget>
+#include <QtCore>
+
+class Completer : public QCompleter {
+ Q_OBJECT
+
+public:
+ Completer(QObject *parent = nullptr);
+
+ // bool eventFilter(QObject *watched, QEvent *event) override;
+};
diff --git a/include/completion/CompleterDelegate.hpp b/include/completion/CompleterDelegate.hpp
new file mode 100644
index 0000000..fc7a321
--- /dev/null
+++ b/include/completion/CompleterDelegate.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <QStyledItemDelegate>
+#include <QWidget>
+#include <QtCore>
+
+class CompleterDelegate : public QStyledItemDelegate {
+ Q_OBJECT
+
+public:
+ explicit CompleterDelegate(QObject *parent = nullptr);
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+};
diff --git a/include/widgets/CommandInput.hpp b/include/widgets/CommandInput.hpp
index a6ca0ed..3ce9500 100644
--- a/include/widgets/CommandInput.hpp
+++ b/include/widgets/CommandInput.hpp
@@ -1,8 +1,9 @@
#pragma once
#include <QBoxLayout>
-#include <QKeyEvent>
#include <QLineEdit>
+#include <QWidget>
+#include <QtCore>
class CommandInput : public QWidget {
Q_OBJECT