From 01e2eb433b7101c41f95bbcef5ad3786ccd8b12e Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 3 Apr 2026 19:26:47 +0200 Subject: [PATCH] add MultiTurnProcess --- .../modules/common/utils/MultiTurnProcess.qml | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 dots/.config/quickshell/ii/modules/common/utils/MultiTurnProcess.qml diff --git a/dots/.config/quickshell/ii/modules/common/utils/MultiTurnProcess.qml b/dots/.config/quickshell/ii/modules/common/utils/MultiTurnProcess.qml new file mode 100644 index 000000000..9999b93ad --- /dev/null +++ b/dots/.config/quickshell/ii/modules/common/utils/MultiTurnProcess.qml @@ -0,0 +1,46 @@ +pragma ComponentBehavior: Bound +import QtQuick +import Quickshell.Io + +Process { + id: proc + + signal finished(string output) + + property list sequence: [] + property int index: 0 + + // Runs a sequence of command and functions + function runSequence(seq) { + if (seq.length == 0) + return; + sequence = seq; + running = false; + index = -1; + step(); + } + + function step(output) { + index++; + if (index >= sequence.length) { + finished(output); + return; + } + const nextItem = sequence[index]; + if (typeof nextItem === "function") { + const nextOutput = nextItem(output); + step(nextOutput); + } else { + // If empty command then not set; this allows setting it with previous function + if (nextItem.length > 0) + command = nextItem; + running = true; + } + } + + stdout: StdioCollector { + onStreamFinished: { + proc.step(text); + } + } +}