diff --git a/src/lib.rs b/src/lib.rs index e646d2b..18f0d55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ -use std::net::TcpStream; -use std::io::{Error, Read, Write}; -use std::time::Duration; use lazy_static::lazy_static; use regex::Regex; +use std::io::{Error, Read, Write}; +use std::net::TcpStream; +use std::time::Duration; lazy_static! { static ref PING_RE: Regex = Regex::new(r"^PING\s*:").unwrap(); @@ -10,20 +10,19 @@ lazy_static! { pub struct Client { stream: TcpStream, - config: Config + config: Config, } pub struct Config { username: String, nickname: String, - mode: String + mode: String, } pub enum Command { - PING(String) + PING(String), } - impl Command { fn from_str(s: &str) -> Option { let new = s.trim(); @@ -50,8 +49,8 @@ impl Client { let mut buffer = [0u8; 512]; match self.stream.read(&mut buffer) { - Ok(_) => {}, - Err(_) => return None + Ok(_) => {} + Err(_) => return None, }; Some(String::from_utf8_lossy(&buffer).into()) @@ -78,7 +77,7 @@ impl Config { Self { username: username.into(), nickname: nickname.unwrap_or(username).into(), - mode: mode.unwrap_or("").into() + mode: mode.unwrap_or("").into(), } } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f13f4f8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,22 @@ +use irsc::{Client, Config}; + +#[allow(unused_macros)] +macro_rules! loop_n { + ($n:expr, $c:expr) => {{ + for _ in 0..$n { + $c + } + }}; +} + +fn main() { + let config = Config::new("test", None, Some("+B")); + let mut client = + Client::new("192.168.1.28", 6667, config).expect("Unable to connect to IRC server"); + + loop { + if let Some(line) = client.read_string() { + print!("{}", line); + } + } +}