Skip to main content

scxtui/backend/
mod.rs

1// SPDX-License-Identifier: GPL-2.0
2
3//! The backend is `scxcli`, the one program that changes what
4//! `scx.service` runs. scxtui spawns it for everything, reads its
5//! `--json` output for state, and runs the privileged commands through
6//! `pkexec` when it is not root. The trait exists so the application
7//! logic is exercised against an in-memory stub in tests, not to
8//! support another backend.
9
10pub mod scxcli;
11
12use crate::model::Listing;
13use anyhow::Result;
14
15/// What a write command printed, for the message bar.
16pub type Report = String;
17
18pub trait Backend {
19    /// Short description for the header line.
20    fn label(&self) -> String;
21
22    /// `scxcli list --json`.
23    fn list(&self) -> Result<Listing>;
24
25    /// `scxcli start ID`: `default`, or a scheduler by name with its
26    /// defaults. Returns scxcli's one-line report; the state comes
27    /// back through [`Self::list`].
28    fn start(&self, id: &str) -> Result<Report>;
29
30    /// `scxcli run SCHED ARGS...`.
31    fn run(&self, sched: &str, args: &[String]) -> Result<Report>;
32
33    /// `scxcli stop`: the unit stops, the selection stays.
34    fn stop(&self) -> Result<Report>;
35
36    /// Whether the privileged commands go through `pkexec`, which may
37    /// prompt on the terminal and so needs it handed over.
38    fn escalates(&self) -> bool;
39}