Skip to content

Commit

Permalink
Output (#20)
Browse files Browse the repository at this point in the history
* Print colors! White is base, green means something completed, red means an error occurred

* found a bug in the connection verification while working on colorizing text, so fixing that

* i think that's it for output for now
  • Loading branch information
kmanc committed Aug 12, 2022
1 parent 68b05ca commit d795b20
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 32 deletions.
202 changes: 202 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "imd"
version = "1.2.0"
version = "1.2.1"
authors = ["Kevin Conley <koins@duck.com>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
crossterm = ">=0.25.0"
nix = ">=0.24.2"

[profile.release]
Expand Down
4 changes: 2 additions & 2 deletions src/drives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::{Arc, mpsc};

pub fn network_drives(tx: mpsc::Sender<String>, user: Arc<imd::IMDUser>, ip_address: &str) -> Result<(), Box<dyn Error>> {
// Report that we are scanning network drives
let log = imd::format_log(ip_address, "Scanning for network drives using 'showmount -e'");
let log = imd::format_log(ip_address, "Scanning for network drives using 'showmount -e'", None);
tx.send(log)?;

// Run the showmount command and capture the output
Expand All @@ -20,7 +20,7 @@ pub fn network_drives(tx: mpsc::Sender<String>, user: Arc<imd::IMDUser>, ip_addr
writeln!(f, "{command}")?;

// Report that we completed the network drive scan
let log = imd::format_log(ip_address, "Network drive scan complete");
let log = imd::format_log(ip_address, "Network drive scan complete", Some(imd::Color::Green));
tx.send(log)?;

Ok(())
Expand Down
17 changes: 14 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crossterm::style::Stylize;
use nix::unistd::{chown, Gid, Uid};
use std::error::Error;
use std::fs::File;
Expand All @@ -6,6 +7,12 @@ use std::process::Command;
use std::sync::Arc;


pub enum Color {
Green,
Red,
}


pub struct TargetMachine {
hostname: Option<String>,
ip_address: IpAddr,
Expand All @@ -23,8 +30,8 @@ impl TargetMachine {

pub fn new(hostname: Option<String>, ip_address: IpAddr) -> TargetMachine {
TargetMachine {
ip_address,
hostname,
ip_address,
}
}
}
Expand Down Expand Up @@ -78,8 +85,12 @@ pub fn create_file(user: Arc<IMDUser>, filename: &str) -> Result<File, Box<dyn E
}


pub fn format_log(machine: &str, log: &str) -> String {
format!("{machine: <16}- {log}")
pub fn format_log(machine: &str, log: &str, color: Option<Color>) -> String {
match color {
Some(Color::Green) => format!("{machine: <16}- {log}").green().to_string(),
None => format!("{machine: <16}- {log}"),
Some(Color::Red) => format!("{machine: <16}- {log}").red().to_string(),
}
}


Expand Down

0 comments on commit d795b20

Please sign in to comment.