pub trait ShellConfig {
const MAX_INPUT: usize;
const MAX_PATH_DEPTH: usize;
const MAX_ARGS: usize;
const MAX_PROMPT: usize;
const MAX_RESPONSE: usize;
const HISTORY_SIZE: usize;
const MSG_WELCOME: &'static str;
const MSG_LOGIN_PROMPT: &'static str;
const MSG_LOGIN_SUCCESS: &'static str;
const MSG_LOGIN_FAILED: &'static str;
const MSG_LOGOUT: &'static str;
const MSG_INVALID_LOGIN_FORMAT: &'static str;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct DefaultConfig;
impl ShellConfig for DefaultConfig {
const MAX_INPUT: usize = 128;
const MAX_PATH_DEPTH: usize = 8;
const MAX_ARGS: usize = 16;
const MAX_PROMPT: usize = 64;
const MAX_RESPONSE: usize = 256;
#[cfg(feature = "history")]
const HISTORY_SIZE: usize = 10;
#[cfg(not(feature = "history"))]
const HISTORY_SIZE: usize = 0;
#[cfg(feature = "authentication")]
const MSG_WELCOME: &'static str = "Welcome to nut-shell! Please login.";
#[cfg(not(feature = "authentication"))]
const MSG_WELCOME: &'static str = "Welcome to nut-shell! Type '?' for help.";
const MSG_LOGIN_PROMPT: &'static str = "Login> ";
const MSG_INVALID_LOGIN_FORMAT: &'static str = "Invalid login format. Use: <name>:<password>";
const MSG_LOGIN_FAILED: &'static str = "Login failed. Try again.";
const MSG_LOGIN_SUCCESS: &'static str = "Logged in. Type '?' for help.";
const MSG_LOGOUT: &'static str = "Logged out.";
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct MinimalConfig;
impl ShellConfig for MinimalConfig {
const MAX_INPUT: usize = 64;
const MAX_PATH_DEPTH: usize = 4;
const MAX_ARGS: usize = 8;
const MAX_PROMPT: usize = 32;
const MAX_RESPONSE: usize = 128;
#[cfg(feature = "history")]
const HISTORY_SIZE: usize = 4;
#[cfg(not(feature = "history"))]
const HISTORY_SIZE: usize = 0;
const MSG_WELCOME: &'static str = "Welcome";
const MSG_LOGIN_PROMPT: &'static str = "Login> ";
const MSG_INVALID_LOGIN_FORMAT: &'static str = "Invalid format. Use name:pass";
const MSG_LOGIN_FAILED: &'static str = "Login failed";
const MSG_LOGIN_SUCCESS: &'static str = "Logged in";
const MSG_LOGOUT: &'static str = "Logged out";
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_messages_are_const() {
const _WELCOME: &str = DefaultConfig::MSG_WELCOME;
const _LOGIN: &str = DefaultConfig::MSG_LOGIN_PROMPT;
const _SUCCESS: &str = DefaultConfig::MSG_LOGIN_SUCCESS;
const _FAILED: &str = DefaultConfig::MSG_LOGIN_FAILED;
const _LOGOUT: &str = DefaultConfig::MSG_LOGOUT;
const _FORMAT: &str = DefaultConfig::MSG_INVALID_LOGIN_FORMAT;
}
}