From 155bb69a7f2112b1f58a83b157f67dbb7c9d1f25 Mon Sep 17 00:00:00 2001
From: sammyette <torchedsammy@gmail.com>
Date: Wed, 2 Apr 2025 14:47:21 -0400
Subject: [PATCH] feat: add processors api

---
 nature/processors.lua | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 nature/processors.lua

diff --git a/nature/processors.lua b/nature/processors.lua
new file mode 100644
index 0000000..7ad0da0
--- /dev/null
+++ b/nature/processors.lua
@@ -0,0 +1,32 @@
+-- @module hilbish.processors
+
+hilbish.processors = {
+	list = {}
+	sorted = {}
+}
+
+function hilbish.processors.add(processor)
+	if not processor.func then
+		error 'processor is missing function'
+	end
+
+	table.insert(hilbish.processors.list, processor)
+	table.sort(hilbish.processors.list, function(a, b) return a.priority < b.priority end)
+end
+
+--- Run all command processors, in order by priority.
+--- It returns the processed command (which may be the same as the passed command)
+--- and a boolean which states whether to proceed with command execution.
+function hilbish.processors.execute(command)
+	local continue = true
+	for _, processor in ipairs(hilbish.processors.list) do
+		local processed = hilbish.processors.func(command)
+		if processed.command then command = processed.command end
+		if not processed.continue then
+			continue = false
+			break
+		end
+	end
+
+	return command, continue
+end