1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::{num, char, ffi, convert};
use errno::{errno, Errno};
use thiserror::Error;
use crate::{
COLORS, COLOR_PAIRS, panels::NCurseswPanelsError, mouse::NCurseswMouseError,
menu::NCurseswMenuError, form::NCurseswFormError, shims::ncurses::wint_t
};
#[derive(Error, Debug, PartialEq, Eq)]
pub enum NCurseswError {
#[error("ncurses::{func}(){}{}", rc_error(*rc), os_level_error())]
LibraryError { func: String, rc: Option<i32> },
#[error("interrupted system call (EINTR)")]
InterruptedCall,
#[error("KEY_RESIZE")]
KeyResize,
#[deprecated(since = "0.6.3", note = "this was deprecated as of NCurses API v6.3.20211021")]
#[error("KEY_EVENT")]
KeyEvent,
#[error("'{color}' is not a known color")]
ColorParseError { color: String },
#[error("Terminal only supports a maximum of {} colors", COLORS())]
ColorLimit,
#[error("Terminal only supports a maximum of {} color pairs", COLOR_PAIRS())]
ColorPairLimit,
#[error("Invalid capability")]
InvalidCapability,
#[error("WideChar to char error with a value of {inner}!")]
WideCharTryFromError { inner: wint_t },
#[error("{source}")]
IntError { #[from] source: num::TryFromIntError },
#[error("{source}")]
CharError { #[from] source: char::CharTryFromError },
#[error("{source}")]
NulError { #[from] source: ffi::NulError },
#[error("{source}")]
Infallible { #[from] source: convert::Infallible },
#[error("{source}")]
PanelsError { #[from] source: NCurseswPanelsError },
#[error("{source}")]
MouseError { #[from] source: NCurseswMouseError },
#[error("{source}")]
MenuError { #[from] source: NCurseswMenuError },
#[error("{source}")]
FormError { #[from] source: NCurseswFormError },
#[error("{}() : {} (#{})", func, errno, errno.0)]
OSError { func: String, errno: Errno}
}
pub(in crate) fn rc_error(rc: Option<i32>) -> String {
rc.map_or_else(String::new, |rc| format!(", rc={}", rc))
}
pub(in crate) fn os_level_error() -> String {
if errno().0 == 0 {
String::new()
} else {
format!(", os_level={} ({})", errno().0, errno())
}
}