Skip to content

Commit

Permalink
added support for 2 windows
Browse files Browse the repository at this point in the history
  • Loading branch information
chobeat committed Jan 12, 2020
1 parent 6af6ed1 commit a3a108a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
25 changes: 22 additions & 3 deletions src/display/components/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ impl<'a> Layout<'a> {
layout
})
}
fn build_layout(&self, rect: Rect) -> Vec<Rect> {
if self.children.len() == 1 {

fn build_two_children_layout(&self, rect: Rect) -> Vec<Rect> {
if rect.height < FIRST_HEIGHT_BREAKPOINT && rect.width < FIRST_WIDTH_BREAKPOINT {
self.progressive_split(rect, vec![])
} else if rect.height < FIRST_HEIGHT_BREAKPOINT && rect.width < FIRST_WIDTH_BREAKPOINT {
} else if rect.width < FIRST_WIDTH_BREAKPOINT {
self.progressive_split(rect, vec![Direction::Vertical])
} else {
self.progressive_split(rect, vec![Direction::Horizontal])
}
}

fn build_three_children_layout(&self, rect: Rect) -> Vec<Rect> {
if rect.height < FIRST_HEIGHT_BREAKPOINT && rect.width < FIRST_WIDTH_BREAKPOINT {
self.progressive_split(rect, vec![])
} else if rect.height < FIRST_HEIGHT_BREAKPOINT {
self.progressive_split(rect, vec![Direction::Horizontal])
Expand All @@ -53,6 +62,16 @@ impl<'a> Layout<'a> {
self.progressive_split(rect, vec![Direction::Horizontal, Direction::Vertical])
}
}

fn build_layout(&self, rect: Rect) -> Vec<Rect> {
if self.children.len() == 1 {
self.progressive_split(rect, vec![])
} else if self.children.len() == 2 {
self.build_two_children_layout(rect)
} else {
self.build_three_children_layout(rect)
}
}
pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) {
let app = leave_gap_on_top_of_rect(rect);
let layout_slots = self.build_layout(app);
Expand Down
22 changes: 14 additions & 8 deletions src/display/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,25 @@ where

fn get_tables_to_display(&self) -> Vec<Table<'static>> {
let opts = &self.opts;
let mut children: Vec<Table> = Vec::new();
if opts.processes {
vec![self.build_processes_table()]
} else if opts.addresses {
vec![self.build_addresses_table()]
} else if opts.connections {
vec![self.build_connections_table()]
} else {
vec![
children.push(self.build_processes_table());
}
if opts.addresses {
children.push(self.build_addresses_table());
}

if opts.connections {
children.push(self.build_connections_table());
}
if !(opts.processes || opts.addresses || opts.connections) {
children = vec![
self.build_processes_table(),
self.build_connections_table(),
self.build_addresses_table(),
]
];
}
children
}
pub fn update_state(
&mut self,
Expand Down
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ use ::std::io;
use ::std::time::Instant;
use ::termion::raw::IntoRawMode;
use ::tui::backend::TermionBackend;
use structopt::{clap::ArgGroup, StructOpt};
use structopt::StructOpt;

const DISPLAY_DELTA: time::Duration = time::Duration::from_millis(1000);

#[derive(StructOpt, Debug)]
#[structopt(name = "bandwhich")]
#[structopt(group = ArgGroup::with_name("windows").required(false))]
pub struct Opt {
#[structopt(short, long)]
/// The network interface to listen on, eg. eth0
Expand All @@ -45,11 +44,11 @@ pub struct Opt {
#[structopt(short, long)]
/// Do not attempt to resolve IPs to their hostnames
no_resolve: bool,
#[structopt(short, long, group("windows"))]
#[structopt(short, long)]
processes: bool,
#[structopt(short, long, group("windows"))]
#[structopt(short, long)]
connections: bool,
#[structopt(short, long, group("windows"))]
#[structopt(short, long)]
addresses: bool,
}

Expand Down

0 comments on commit a3a108a

Please sign in to comment.