1use crate::app::command::Command;
2use crate::gpg::key::KeyType;
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6pub enum Tab {
7 Help,
9 Keys(KeyType),
11}
12
13impl Tab {
14 pub fn get_command(&self) -> Command {
16 match self {
17 Self::Keys(key_type) => Command::ListKeys(*key_type),
18 Self::Help => Command::ShowHelp,
19 }
20 }
21
22 pub fn next(&self) -> Self {
24 match self {
25 Self::Keys(KeyType::Public) => Self::Keys(KeyType::Secret),
26 _ => Self::Keys(KeyType::Public),
27 }
28 }
29
30 pub fn previous(&self) -> Self {
32 match self {
33 Self::Keys(KeyType::Secret) => Self::Keys(KeyType::Public),
34 _ => Self::Keys(KeyType::Secret),
35 }
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42 use pretty_assertions::{assert_eq, assert_ne};
43 #[test]
44 fn test_app_tab() {
45 let tab = Tab::Keys(KeyType::Public);
46 assert_eq!(Command::ListKeys(KeyType::Public), tab.get_command());
47 let tab = tab.next();
48 assert_eq!(Tab::Keys(KeyType::Secret), tab);
49 assert_ne!(Tab::Keys(KeyType::Public), tab);
50 assert_eq!(Command::ListKeys(KeyType::Secret), tab.get_command());
51 let tab = tab.previous();
52 assert_eq!(Tab::Keys(KeyType::Public), tab);
53 assert_ne!(Tab::Keys(KeyType::Secret), tab);
54 }
55}