summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlara Modin <kasm@kasm.eu>2018-05-16 23:33:04 +0200
committerKlara Modin <kasm@kasm.eu>2018-05-16 23:33:04 +0200
commit1c5ca47d8b67ce411d04c232174c8023ff0bba4e (patch)
tree97c317270ee1e704a04cdc79c8e9e757923ac7a0
parent94c275de81d74f76f9e8c45dcfd8bf57a3a500a2 (diff)
print nick in the beginning of input
-rw-r--r--src/server_int.rs2
-rw-r--r--src/ui.rs29
-rw-r--r--src/user_int.rs8
3 files changed, 27 insertions, 12 deletions
diff --git a/src/server_int.rs b/src/server_int.rs
index fd9e64d..bedf85e 100644
--- a/src/server_int.rs
+++ b/src/server_int.rs
@@ -215,7 +215,7 @@ impl Server {
self.conn = Some(connection);
- let mut server = self.try_clone()?;
+ let server = self.try_clone()?;
Ok(thread::spawn(move || server.handle()))
}
diff --git a/src/ui.rs b/src/ui.rs
index bdde45d..81789ea 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -8,9 +8,9 @@ pub struct UI {
input_y: i32,
output_x: i32,
output_y: i32,
- context: String,
+ chan: String,
+ nick: String,
buffer: String,
- buffer_ready: bool,
}
impl UI {
@@ -20,9 +20,9 @@ impl UI {
input_y: 0,
output_x: 0,
output_y: 0,
- context: String::new(),
+ chan: String::new(),
+ nick: String::new(),
buffer: String::new(),
- buffer_ready: false,
}
}
@@ -36,6 +36,18 @@ impl UI {
endwin();
}
+ pub fn nick(&mut self, nick: &str) {
+ self.nick = format!("[{}] ", nick);
+ let mut max_x = 0;
+ let mut max_y = 0;
+ getmaxyx(stdscr(), &mut max_y, &mut max_x);
+ mv(max_y-1, 0);
+ deleteln();
+ printw(&self.nick);
+ printw(" ");
+ getyx(stdscr(), &mut self.input_y, &mut self.input_x);
+ }
+
pub fn put_str(&mut self, text: &str) {
let mut max_x = 0;
let mut max_y = 0;
@@ -57,7 +69,7 @@ impl UI {
let mut max_y = 0;
getmaxyx(stdscr(), &mut max_y, &mut max_x);
mv(max_y-1, 0);
- printw(&self.context.clone());
+ printw(&self.nick);
printw(&self.buffer);
self.getstr_unblocking()
}
@@ -70,12 +82,11 @@ impl UI {
let ch = wch as u8 as char;
match ch {
'\n' => {
- //self.buffer_ready = true;
self.input_x = new_x;
self.input_y = new_y;
deleteln();
mv(new_y, new_x);
- printw(&self.context);
+ printw(&self.nick);
let ret = self.buffer.clone();
self.buffer.clear();
return Some(ret);
@@ -86,7 +97,7 @@ impl UI {
self.input_x -= 1;
deleteln();
mv(new_y, 0);
- printw(&self.context);
+ printw(&self.nick);
printw(&self.buffer);
}
}
@@ -106,7 +117,7 @@ impl UI {
let prefix = message.prefix.clone().unwrap_or(String::new());
let mut iter = prefix.split("!");
let nick = iter.next().unwrap_or("");
- let context = &message.params[0];
+ //let context = &message.params[0];
let content = &message.params[1];
self.put_str(&format!("<{}> {}\n", nick, content));
},
diff --git a/src/user_int.rs b/src/user_int.rs
index a1dd7ae..4752700 100644
--- a/src/user_int.rs
+++ b/src/user_int.rs
@@ -57,7 +57,7 @@ impl Session {
};
self.conn = Some(conn);
self.ui = server.ui.clone();
- let mut session = self.try_clone()?;
+ let session = self.try_clone()?;
Ok(thread::spawn(move || session.handle()))
}
@@ -120,6 +120,10 @@ impl Session {
"NICK" => {
if m.params.len() > 0 {
self.nick = m.params[0].clone();
+ if let Some(ref ui) = self.ui {
+ let mut ui = ui.lock().unwrap();
+ ui.nick(&self.nick);
+ }
Some(m)
} else {
None
@@ -175,7 +179,7 @@ impl Session {
None
} else {
let reply = Message {
- prefix: None,
+ prefix: Some(self.nick.clone()),
command: "PRIVMSG".to_string(),
params: vec![self.chan.clone(), line.clone()],
};