Skip to main content

psn/
lib.rs

1/*
2   Copyright (C) 2026 l5yth
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17//! Core library for `psn`.
18
19pub mod app;
20pub mod cli;
21pub mod model;
22pub mod process;
23pub mod runtime;
24pub mod signal;
25pub mod tree;
26pub mod ui;
27
28#[cfg(all(feature = "debug_tui", debug_assertions))]
29mod debug_tui;
30
31use crate::runtime::run_interactive;
32use anyhow::Result;
33
34/// Run the interactive TUI application.
35pub fn run(filter: Option<String>, regex_mode: bool, user_only: bool) -> Result<()> {
36    let compiled_filter = process::compile_filter(filter.clone(), regex_mode)?;
37    run_interactive(filter, compiled_filter, user_only)
38}
39
40/// Run the hidden synthetic-data TUI used for local development.
41#[cfg(all(feature = "debug_tui", debug_assertions))]
42#[doc(hidden)]
43pub fn run_debug_tui() -> Result<()> {
44    debug_tui::run()
45}
46
47#[cfg(test)]
48mod tests {
49    use super::run;
50
51    #[test]
52    fn run_returns_error_for_invalid_regex_before_terminal_setup() {
53        let result = run(Some("(".to_string()), true, false);
54        assert!(result.is_err());
55    }
56
57    #[cfg(all(feature = "debug_tui", debug_assertions))]
58    #[test]
59    fn run_debug_tui_symbol_is_available_when_feature_is_enabled() {
60        let debug_runner: fn() -> anyhow::Result<()> = super::run_debug_tui;
61        let _ = debug_runner;
62    }
63}