Added vertical UI
Added reactivity
This commit is contained in:
parent
7c6a4bf70e
commit
80fd57810e
@ -22,7 +22,7 @@ impl App {
|
|||||||
domain_input: String::new(),
|
domain_input: String::new(),
|
||||||
whois_info: vec![],
|
whois_info: vec![],
|
||||||
dns_info: vec![],
|
dns_info: vec![],
|
||||||
render_direction: AppRenderDir::Horizontal,
|
render_direction: AppRenderDir::Vertical,
|
||||||
current_state: CurrentState::Lookup,
|
current_state: CurrentState::Lookup,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,6 +80,9 @@ fn run_app<B: Backend>(
|
|||||||
let whois = WhoisData::new(app.domain_input.clone());
|
let whois = WhoisData::new(app.domain_input.clone());
|
||||||
app.whois_info = whois.to_vec();
|
app.whois_info = whois.to_vec();
|
||||||
}
|
}
|
||||||
|
KeyCode::Delete => {
|
||||||
|
app.domain_input = String::new();
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
CurrentState::Menu => {}
|
CurrentState::Menu => {}
|
||||||
|
|||||||
76
src/ui.rs
76
src/ui.rs
@ -11,7 +11,12 @@ use crate::{
|
|||||||
CurrentState,
|
CurrentState,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn ui(f: &mut Frame, app: &App) {
|
pub fn ui(f: &mut Frame, app: &mut App) {
|
||||||
|
if f.size().width > 100 {
|
||||||
|
app.render_direction = AppRenderDir::Horizontal;
|
||||||
|
} else {
|
||||||
|
app.render_direction = AppRenderDir::Vertical;
|
||||||
|
}
|
||||||
match app.current_state {
|
match app.current_state {
|
||||||
CurrentState::Lookup => {
|
CurrentState::Lookup => {
|
||||||
match app.render_direction {
|
match app.render_direction {
|
||||||
@ -65,6 +70,7 @@ pub fn ui(f: &mut Frame, app: &App) {
|
|||||||
|
|
||||||
// DNS list
|
// DNS list
|
||||||
let mut dns_list_items = Vec::<ListItem>::new();
|
let mut dns_list_items = Vec::<ListItem>::new();
|
||||||
|
|
||||||
for record in &app.dns_info {
|
for record in &app.dns_info {
|
||||||
dns_list_items.push(ListItem::new(Line::from(Span::styled(
|
dns_list_items.push(ListItem::new(Line::from(Span::styled(
|
||||||
record,
|
record,
|
||||||
@ -93,8 +99,9 @@ pub fn ui(f: &mut Frame, app: &App) {
|
|||||||
let key_hint_block = Block::default()
|
let key_hint_block = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.style(Style::default());
|
.style(Style::default());
|
||||||
|
|
||||||
let key_hint = Paragraph::new(Text::styled(
|
let key_hint = Paragraph::new(Text::styled(
|
||||||
"[ESC] Quit / [Enter] Check domain",
|
"[ESC] Quit / [Enter] Check domain / [Del] Clear Input",
|
||||||
Style::default().fg(Color::Red),
|
Style::default().fg(Color::Red),
|
||||||
))
|
))
|
||||||
.block(key_hint_block);
|
.block(key_hint_block);
|
||||||
@ -110,12 +117,73 @@ pub fn ui(f: &mut Frame, app: &App) {
|
|||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Max(30),
|
Constraint::Length(3),
|
||||||
Constraint::Percentage(50),
|
Constraint::Percentage(50),
|
||||||
Constraint::Percentage(50),
|
Constraint::Percentage(50),
|
||||||
Constraint::Max(30),
|
Constraint::Length(3),
|
||||||
])
|
])
|
||||||
.split(f.size());
|
.split(f.size());
|
||||||
|
|
||||||
|
let title_block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.style(Style::default());
|
||||||
|
|
||||||
|
let title = Paragraph::new(Span::styled(
|
||||||
|
"Dns Lookup tool",
|
||||||
|
Style::default().fg(Color::White),
|
||||||
|
))
|
||||||
|
.block(title_block);
|
||||||
|
|
||||||
|
f.render_widget(title, chunks[0]);
|
||||||
|
|
||||||
|
// Whois list
|
||||||
|
let mut whois_list_items = Vec::<ListItem>::new();
|
||||||
|
for record in &app.whois_info {
|
||||||
|
whois_list_items.push(ListItem::new(Line::from(Span::styled(
|
||||||
|
record,
|
||||||
|
Style::default(),
|
||||||
|
))))
|
||||||
|
}
|
||||||
|
let whois_list = List::new(whois_list_items);
|
||||||
|
|
||||||
|
f.render_widget(whois_list, chunks[1]);
|
||||||
|
|
||||||
|
// DNS list
|
||||||
|
let mut dns_list_items = Vec::<ListItem>::new();
|
||||||
|
for record in &app.dns_info {
|
||||||
|
dns_list_items.push(ListItem::new(Line::from(Span::styled(
|
||||||
|
record,
|
||||||
|
Style::default(),
|
||||||
|
))))
|
||||||
|
}
|
||||||
|
let dns_list = List::new(dns_list_items);
|
||||||
|
|
||||||
|
f.render_widget(dns_list, chunks[2]);
|
||||||
|
let footer_chunks = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||||
|
.split(chunks[3]);
|
||||||
|
|
||||||
|
let domain_block = Block::new().borders(Borders::ALL).style(Style::default());
|
||||||
|
let mut domain_string = String::from("Domain: ");
|
||||||
|
domain_string.push_str(&app.domain_input);
|
||||||
|
let domain_text = Paragraph::new(Text::styled(
|
||||||
|
domain_string,
|
||||||
|
Style::default().fg(Color::Blue),
|
||||||
|
))
|
||||||
|
.block(domain_block);
|
||||||
|
f.render_widget(domain_text, footer_chunks[0]);
|
||||||
|
|
||||||
|
let key_hint_block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.style(Style::default());
|
||||||
|
|
||||||
|
let key_hint = Paragraph::new(Text::styled(
|
||||||
|
"[ESC] Quit / [Enter] Check domain",
|
||||||
|
Style::default().fg(Color::Red),
|
||||||
|
))
|
||||||
|
.block(key_hint_block);
|
||||||
|
f.render_widget(key_hint, footer_chunks[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user