1use anyhow::Result;
12
13#[cfg(target_os = "linux")]
14mod linux;
15#[cfg(target_os = "macos")]
16mod macos;
17#[cfg(target_os = "windows")]
18mod windows;
19
20pub fn initialize_platform() -> Result<()> {
24 #[cfg(target_os = "windows")]
25 {
26 windows::configure_utf8_codepage()?;
27 }
28
29 #[cfg(target_os = "linux")]
30 {
31 linux::detectar_sandbox();
32 }
33
34 #[cfg(target_os = "macos")]
35 {
36 macos::initialize();
37 }
38
39 Ok(())
40}
41
42#[must_use]
46pub fn normalize_stdin_line(line: &str) -> &str {
47 line.trim_end_matches(['\r', '\n'])
49}
50
51#[must_use]
53pub fn e_tty() -> bool {
54 std::io::IsTerminal::is_terminal(&std::io::stdout())
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn normalize_strips_trailing_cr() {
63 assert_eq!(normalize_stdin_line("teste\r"), "teste");
64 assert_eq!(normalize_stdin_line("teste\r\n"), "teste");
65 assert_eq!(normalize_stdin_line("teste\n"), "teste");
66 assert_eq!(normalize_stdin_line("teste"), "teste");
67 }
68
69 #[test]
70 fn normalize_empty_string() {
71 assert_eq!(normalize_stdin_line(""), "");
72 }
73
74 #[test]
75 fn normalize_newlines_only() {
76 assert_eq!(normalize_stdin_line("\n\n\n"), "");
77 }
78
79 #[test]
80 fn normalize_mixed_crlf_lf() {
81 assert_eq!(
82 normalize_stdin_line("linha1\r\nlinha2\r\nlinha3"),
83 "linha1\r\nlinha2\r\nlinha3"
84 );
85 }
86
87 #[test]
88 fn normalize_with_spaces() {
89 assert_eq!(
90 normalize_stdin_line("texto com espacos \r\n"),
91 "texto com espacos "
92 );
93 }
94
95 #[test]
96 fn is_tty_returns_bool() {
97 let _ = e_tty();
98 }
99}