90 lines
2.5 KiB
Rust
90 lines
2.5 KiB
Rust
mod domain;
|
|
use crate::domain::Domain;
|
|
|
|
mod config;
|
|
use crate::config::Config;
|
|
|
|
mod whois;
|
|
use crate::whois::WhoisData;
|
|
|
|
mod app;
|
|
use crate::app::*;
|
|
|
|
mod ui;
|
|
use crate::ui::*;
|
|
|
|
use crossterm::event::{
|
|
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind,
|
|
};
|
|
use crossterm::execute;
|
|
use crossterm::terminal::{
|
|
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
|
|
};
|
|
use ratatui::backend::{Backend, CrosstermBackend};
|
|
use ratatui::Terminal;
|
|
use std::error::Error;
|
|
use std::io::{self, stderr};
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
enable_raw_mode()?;
|
|
let mut stderr = stderr();
|
|
execute!(stderr, EnterAlternateScreen, EnableMouseCapture)?;
|
|
|
|
let backend = CrosstermBackend::new(stderr);
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
// Initialise the App and config
|
|
let mut app = App::new();
|
|
let config = Config::from_file("test.ini".to_string());
|
|
|
|
// Run the app
|
|
let _res = run_app(&mut terminal, &mut app, &config);
|
|
|
|
disable_raw_mode()?;
|
|
execute!(
|
|
terminal.backend_mut(),
|
|
LeaveAlternateScreen,
|
|
DisableMouseCapture
|
|
)?;
|
|
terminal.show_cursor()?;
|
|
Ok(())
|
|
}
|
|
|
|
fn run_app<B: Backend>(
|
|
terminal: &mut Terminal<B>,
|
|
app: &mut App,
|
|
config: &Config,
|
|
) -> io::Result<bool> {
|
|
loop {
|
|
terminal.draw(|f| ui(f, app))?;
|
|
|
|
if let Event::Key(key) = event::read()? {
|
|
if key.kind == event::KeyEventKind::Release {
|
|
continue;
|
|
}
|
|
match app.current_state {
|
|
CurrentState::Lookup => match key.code {
|
|
KeyCode::Esc => return Ok(false),
|
|
KeyCode::Backspace => {
|
|
app.domain_input.pop();
|
|
}
|
|
KeyCode::Char(char) => {
|
|
app.domain_input.push(char);
|
|
}
|
|
KeyCode::Enter => {
|
|
// This will do the lookup and populate the UI with the info
|
|
let mut domain = Domain::new(app.domain_input.clone());
|
|
domain.apply_config(&config);
|
|
domain.lookup_all_records();
|
|
app.dns_info = domain.to_vec();
|
|
let whois = WhoisData::new(app.domain_input.clone());
|
|
app.whois_info = whois.to_vec();
|
|
}
|
|
_ => {}
|
|
},
|
|
CurrentState::Menu => {}
|
|
}
|
|
}
|
|
}
|
|
}
|