1use rustix::io::Errno;
2use thiserror::Error as ThisError;
3
4#[derive(Debug, ThisError)]
6#[non_exhaustive]
7pub enum Error {
8 #[error("no terminal found")]
10 NoTerminal,
11 #[error("the process is not in the terminal's foreground process group")]
13 NotForegroundProcess,
14 #[error("failed to read the terminal's foreground process group: {0}")]
16 GetForegroundProcess(#[source] Errno),
17 #[error("failed to resume terminal output: {0}")]
19 ResumeOutput(#[source] Errno),
20 #[error("failed to read terminal state: {0}")]
22 GetTerminalState(#[source] Errno),
23 #[error("failed to set terminal state: {0}")]
25 SetTerminalState(#[source] Errno),
26 #[error("TERM is not set")]
28 TermNotSet,
29 #[error("TERM is not a valid terminal name")]
31 InvalidTermName,
32 #[error("no terminfo entry was found for TERM")]
34 TerminfoNotFound,
35 #[error("the terminfo entry for TERM could not be read")]
37 TerminfoUnreadable,
38 #[error("the terminfo entry for TERM is invalid")]
40 InvalidTerminfo,
41 #[error("failed to write terminal reset data: {0}")]
43 TerminalWrite(#[source] Errno),
44 #[error("a terminal write made no progress")]
46 TerminalWriteMadeNoProgress,
47}
48
49impl Error {
50 #[must_use]
52 pub const fn requires_silent_exit(&self) -> bool {
53 matches!(
54 self,
55 Self::NotForegroundProcess | Self::GetForegroundProcess(_)
56 )
57 }
58}