Skip to content

Commit

Permalink
replace throbber widget for own simple solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Chleba committed May 3, 2024
1 parent b1085d2 commit 5127ebd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 50 deletions.
39 changes: 3 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ lazy_static = "1.4.0"
libc = "0.2.148"
log = "0.4.20"
mac_oui = { version = "0.4.8", features = ["with-db"] }
ping = "0.5.1"
pnet = "0.34.0"
pretty_assertions = "1.4.0"
rand = "0.8.5"
Expand All @@ -42,7 +41,6 @@ signal-hook = "0.3.17"
strip-ansi-escapes = "0.2.0"
strum = "0.26.1"
surge-ping = "0.8.0"
throbber-widgets-tui = "0.4.1"
tokio = { version = "1.32.0", features = ["full"] }
tokio-util = "0.7.9"
tokio-wifiscanner = "0.2.1"
Expand Down
27 changes: 15 additions & 12 deletions src/components/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use pnet::packet::{
};
use pnet::util::MacAddr;

use core::str;
use ratatui::{prelude::*, widgets::*};
use std::net::{IpAddr, Ipv4Addr};
use std::string;
use std::time::{Duration, Instant};
use surge_ping::{Client, Config, IcmpPacket, PingIdentifier, PingSequence, ICMP};
use throbber_widgets_tui::{Throbber, ThrobberState};
use tokio::{
sync::mpsc::{self, UnboundedSender},
task::{self, JoinHandle},
Expand All @@ -40,6 +40,7 @@ use tui_input::Input;
static POOL_SIZE: usize = 32;
static INPUT_SIZE: usize = 30;
static DEFAULT_IP: &str = "192.168.1.0/24";
const SPINNER_SYMBOLS: [&str; 6] = ["⠷", "⠯", "⠟", "⠻", "⠽", "⠾"];

#[derive(Clone)]
pub struct ScannedIp {
Expand All @@ -64,7 +65,7 @@ pub struct Discovery {
table_state: TableState,
scrollbar_state: ScrollbarState,
show_packets: bool,
throbber_state: ThrobberState,
spinner_index: usize,
}

impl Default for Discovery {
Expand All @@ -90,7 +91,7 @@ impl Discovery {
table_state: TableState::default().with_selected(0),
scrollbar_state: ScrollbarState::new(0),
show_packets: false,
throbber_state: ThrobberState::default(),
spinner_index: 0,
}
}

Expand Down Expand Up @@ -481,11 +482,12 @@ impl Discovery {
error
}

fn make_throbber() -> Throbber<'static> {
Throbber::default()
.label("scanning..")
.style(Style::default().fg(Color::Green))
.throbber_set(throbber_widgets_tui::BRAILLE_SIX)
fn make_spinner(&self) -> Span {
let spinner = SPINNER_SYMBOLS[self.spinner_index];
Span::styled(
format!("{spinner}scanning.."),
Style::default().fg(Color::Yellow),
)
}
}

Expand Down Expand Up @@ -529,7 +531,9 @@ impl Component for Discovery {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
if self.is_scanning {
if let Action::Tick = action {
self.throbber_state.calc_next();
let mut s_index = self.spinner_index + 1;
s_index %= SPINNER_SYMBOLS.len() - 1;
self.spinner_index = s_index;
}
}

Expand Down Expand Up @@ -674,10 +678,9 @@ impl Component for Discovery {

// -- THROBBER
if self.is_scanning {
let throbber = Self::make_throbber();
let throbber = self.make_spinner();
let throbber_rect = Rect::new(input_rect.x + 1, input_rect.y, 12, 1);
// let throbber_rect = Rect::new(table_rect.x + table_rect.width - 30, table_rect.y, 12, 1);
f.render_stateful_widget(throbber, throbber_rect, &mut self.throbber_state);
f.render_widget(throbber, throbber_rect);
}
}

Expand Down

0 comments on commit 5127ebd

Please sign in to comment.