use crossterm::event::Event;
use seer_core::RecordType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Focus {
#[default]
Nav,
Pane,
}
impl Focus {
pub fn toggled(self) -> Self {
match self {
Focus::Nav => Focus::Pane,
Focus::Pane => Focus::Nav,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EditTarget {
Target,
DiffB,
FollowInterval,
FollowCount,
BulkPath,
BulkDomains,
WatchAdd,
TldFilter,
LensFilter,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum InputMode {
#[default]
Normal,
Command(crate::tui::line_editor::LineEditor),
Field {
target: EditTarget,
buf: crate::tui::line_editor::LineEditor,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FetchReq {
Overview(String),
Whois(String),
RdapDomain(String),
RdapIp(String),
RdapAsn(u32),
Dns {
domain: String,
record_type: RecordType,
nameserver: Option<String>,
},
Dnssec(String),
Compare {
domain: String,
record_type: RecordType,
a: String,
b: String,
},
Ssl(String),
Status(String),
Prop(String),
Reverse(String),
Avail(String),
Tld(String),
Diff {
a: String,
b: String,
},
Watch,
History,
Subdomains(String),
}
impl FetchReq {
pub fn lens_key(&self) -> &'static str {
match self {
FetchReq::Overview(_) => "overview",
FetchReq::Whois(_) => "whois",
FetchReq::RdapDomain(_) | FetchReq::RdapIp(_) | FetchReq::RdapAsn(_) => "rdap",
FetchReq::Dns { .. } => "dns",
FetchReq::Dnssec(_) | FetchReq::Compare { .. } => "dns",
FetchReq::Ssl(_) => "ssl",
FetchReq::Status(_) => "status",
FetchReq::Prop(_) => "propagation",
FetchReq::Reverse(_) => "reverse",
FetchReq::Avail(_) => "avail",
FetchReq::Tld(_) => "tld",
FetchReq::Diff { .. } => "diff",
FetchReq::Watch => "watch",
FetchReq::History => "history",
FetchReq::Subdomains(_) => "subdomains",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FollowParams {
pub domain: String,
pub iterations: usize,
pub interval_secs: u64,
pub gen: u64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BulkParams {
pub op: String, pub domains: Vec<String>,
pub gen: u64,
}
#[derive(Debug, Clone)]
pub enum Action {
Quit,
Fetch {
req: FetchReq,
gen: u64,
},
Copy {
text: String,
label: String,
},
StartFollow(FollowParams),
StopFollow,
StartBulk(BulkParams),
StopBulk,
StartBulkFromFile {
op: String,
path: String,
gen: u64,
},
WriteCsv {
path: String,
contents: String,
},
WatchMutate {
add: Option<String>,
remove: Option<String>,
gen: u64,
},
HistoryClear {
gen: u64,
},
}
pub use crate::payload::Payload as LensData;
#[derive(Debug, Clone, Default)]
pub enum LensState {
#[default]
Idle,
Loading,
Loaded(LensData),
Error(String),
}
#[derive(Debug)]
pub enum Msg {
Input(Event),
Tick,
Data {
lens: String,
gen: u64,
result: Result<LensData, String>,
},
CopyResult {
ok: bool,
label: String,
},
FollowStep {
gen: u64,
it: Box<seer_core::dns::FollowIteration>,
},
FollowDone {
gen: u64,
},
BulkStep {
gen: u64,
result: Box<seer_core::bulk::BulkResult>,
},
BulkDone {
gen: u64,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn fetch_req_lens_keys() {
assert_eq!(FetchReq::RdapIp("1.2.3.4".into()).lens_key(), "rdap");
assert_eq!(FetchReq::Dnssec("x".into()).lens_key(), "dns");
assert_eq!(
FetchReq::Compare {
domain: "x".into(),
record_type: RecordType::A,
a: "8.8.8.8".into(),
b: "1.1.1.1".into()
}
.lens_key(),
"dns"
);
assert_eq!(FetchReq::Tld(".com".into()).lens_key(), "tld");
}
#[test]
fn input_mode_default_and_focus() {
assert_eq!(InputMode::Normal, InputMode::default());
assert_eq!(Focus::Nav.toggled(), Focus::Pane);
}
}