Skip to main content

perspt_core/
local_command.rs

1//! Provider-independent commands handled entirely by Perspt frontends.
2
3/// A local command that must never be forwarded to a model provider.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum LocalCommand {
6    /// Display Perspt's dedication.
7    Love,
8}
9
10pub const DEDICATION_TITLE: &str = "Special Dedication";
11pub const DEDICATION_PREAMBLE: &str = "This application is lovingly dedicated to";
12pub const DEDICATION_FAMILY: &str =
13    "my wonderful mothers DaiJun(黛君), VijayLaxmi and grandma Sushila";
14pub const DEDICATION_THANKS: &str = "Thank you for your endless love, wisdom, and support";
15pub const DEDICATION_CLOSING: &str = "With all my love and gratitude";
16
17/// Parse a command that is deliberately handled without an LLM round trip.
18pub fn parse_local_command(input: &str) -> Option<LocalCommand> {
19    input
20        .trim()
21        .eq_ignore_ascii_case("l-o-v-e")
22        .then_some(LocalCommand::Love)
23}
24
25/// Plain-text rendering shared by non-ANSI frontends.
26pub fn dedication_text() -> String {
27    format!(
28        "{DEDICATION_TITLE}\n\n{DEDICATION_PREAMBLE}\n   {DEDICATION_FAMILY}\n\n\
29         {DEDICATION_THANKS}\n\n{DEDICATION_CLOSING}"
30    )
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn love_is_case_insensitive_and_exact() {
39        assert_eq!(parse_local_command("l-o-v-e"), Some(LocalCommand::Love));
40        assert_eq!(parse_local_command("  L-O-V-E  "), Some(LocalCommand::Love));
41        assert_eq!(parse_local_command("love"), None);
42        assert_eq!(parse_local_command("l-o-v-e now"), None);
43    }
44
45    #[test]
46    fn dedication_names_the_family() {
47        let text = dedication_text();
48        assert!(text.contains("DaiJun(黛君), VijayLaxmi and grandma Sushila"));
49    }
50}