1pub trait ShellConfig {
16 const MAX_INPUT: usize;
18
19 const MAX_PATH_DEPTH: usize;
21
22 const MAX_ARGS: usize;
24
25 const MAX_PROMPT: usize;
27
28 const MAX_RESPONSE: usize;
30
31 const HISTORY_SIZE: usize;
33
34 const MSG_WELCOME: &'static str;
39
40 const MSG_LOGIN_PROMPT: &'static str;
42
43 const MSG_LOGIN_SUCCESS: &'static str;
45
46 const MSG_LOGIN_FAILED: &'static str;
48
49 const MSG_LOGOUT: &'static str;
51
52 const MSG_INVALID_LOGIN_FORMAT: &'static str;
54}
55
56#[derive(Debug, Copy, Clone, PartialEq, Eq)]
58pub struct DefaultConfig;
59
60impl ShellConfig for DefaultConfig {
61 const MAX_INPUT: usize = 128;
62 const MAX_PATH_DEPTH: usize = 8;
63 const MAX_ARGS: usize = 16;
64 const MAX_PROMPT: usize = 64;
65 const MAX_RESPONSE: usize = 256;
66
67 #[cfg(feature = "history")]
68 const HISTORY_SIZE: usize = 10;
69
70 #[cfg(not(feature = "history"))]
71 const HISTORY_SIZE: usize = 0;
72
73 #[cfg(feature = "authentication")]
74 const MSG_WELCOME: &'static str = "Welcome to nut-shell! Please login.";
75 #[cfg(not(feature = "authentication"))]
76 const MSG_WELCOME: &'static str = "Welcome to nut-shell! Type '?' for help.";
77
78 const MSG_LOGIN_PROMPT: &'static str = "Login> ";
79 const MSG_INVALID_LOGIN_FORMAT: &'static str = "Invalid login format. Use: <name>:<password>";
80 const MSG_LOGIN_FAILED: &'static str = "Login failed. Try again.";
81 const MSG_LOGIN_SUCCESS: &'static str = "Logged in. Type '?' for help.";
82 const MSG_LOGOUT: &'static str = "Logged out.";
83}
84
85#[derive(Debug, Copy, Clone, PartialEq, Eq)]
87pub struct MinimalConfig;
88
89impl ShellConfig for MinimalConfig {
90 const MAX_INPUT: usize = 64;
91 const MAX_PATH_DEPTH: usize = 4;
92 const MAX_ARGS: usize = 8;
93 const MAX_PROMPT: usize = 32;
94 const MAX_RESPONSE: usize = 128;
95
96 #[cfg(feature = "history")]
97 const HISTORY_SIZE: usize = 4;
98
99 #[cfg(not(feature = "history"))]
100 const HISTORY_SIZE: usize = 0;
101
102 const MSG_WELCOME: &'static str = "Welcome";
103
104 const MSG_LOGIN_PROMPT: &'static str = "Login> ";
105 const MSG_INVALID_LOGIN_FORMAT: &'static str = "Invalid format. Use name:pass";
106 const MSG_LOGIN_FAILED: &'static str = "Login failed";
107 const MSG_LOGIN_SUCCESS: &'static str = "Logged in";
108 const MSG_LOGOUT: &'static str = "Logged out";
109}
110
111#[cfg(test)]
112mod tests {
113 use super::*;
114
115 #[test]
116 fn test_messages_are_const() {
117 const _WELCOME: &str = DefaultConfig::MSG_WELCOME;
119 const _LOGIN: &str = DefaultConfig::MSG_LOGIN_PROMPT;
120 const _SUCCESS: &str = DefaultConfig::MSG_LOGIN_SUCCESS;
121 const _FAILED: &str = DefaultConfig::MSG_LOGIN_FAILED;
122 const _LOGOUT: &str = DefaultConfig::MSG_LOGOUT;
123 const _FORMAT: &str = DefaultConfig::MSG_INVALID_LOGIN_FORMAT;
124 }
125}