diff --git a/crates/libtiny_client/src/stream.rs b/crates/libtiny_client/src/stream.rs index 844a1bf1..d65118d8 100644 --- a/crates/libtiny_client/src/stream.rs +++ b/crates/libtiny_client/src/stream.rs @@ -66,7 +66,7 @@ fn tls_connector(sasl: Option<&Vec>) -> tokio_rustls::TlsConnector { .expect("Cert PEM must have at least one private key"); builder - .with_single_cert(vec![Certificate(cert)], PrivateKey(key)) + .with_client_auth_cert(vec![Certificate(cert)], PrivateKey(key)) .expect("Client auth cert") } else { builder.with_no_client_auth() diff --git a/crates/libtiny_logger/src/lib.rs b/crates/libtiny_logger/src/lib.rs index 71025402..b7ea2495 100644 --- a/crates/libtiny_logger/src/lib.rs +++ b/crates/libtiny_logger/src/lib.rs @@ -193,7 +193,7 @@ impl LoggerInner { } let mut path = self.log_dir.clone(); - path.push(&format!("{}.txt", serv)); + path.push(format!("{}.txt", serv)); if let Some(mut fd) = try_open_log_file(&path, &*self.report_err) { report_io_err!(self.report_err, print_header(&mut fd)); self.servers.insert( @@ -233,7 +233,7 @@ impl LoggerInner { } let mut path = self.log_dir.clone(); - path.push(&format!( + path.push(format!( "{}_{}.txt", serv, replace_forward_slash(&chan_name_normalized) @@ -384,7 +384,7 @@ impl LoggerInner { // can't reuse it because of borrowchk issues. let mut path = self.log_dir.clone(); let chan_name_normalized = chan.normalized(); - path.push(&format!( + path.push(format!( "{}_{}.txt", serv, replace_forward_slash(&chan_name_normalized) @@ -414,7 +414,7 @@ impl LoggerInner { // We don't have a `new_user_tab` trait method so user log files // are created here let mut path = self.log_dir.clone(); - path.push(&format!("{}_{}.txt", serv, replace_forward_slash(nick))); + path.push(format!("{}_{}.txt", serv, replace_forward_slash(nick))); if let Some(mut fd) = try_open_log_file(&path, &*self.report_err) { report_io_err!(self.report_err, print_header(&mut fd)); f(&mut fd, &*self.report_err); diff --git a/crates/libtiny_tui/src/input_area/input_line.rs b/crates/libtiny_tui/src/input_area/input_line.rs index 7dbd5bc5..ed7c374c 100644 --- a/crates/libtiny_tui/src/input_area/input_line.rs +++ b/crates/libtiny_tui/src/input_area/input_line.rs @@ -34,9 +34,9 @@ impl InputLine { &self.buffer } - /** - ** Functions to interface with InputLine::buffer - **/ + /* + * Functions to interface with InputLine::buffer + */ /// Interface for Vec::get() pub(crate) fn get(&self, idx: usize) -> char { @@ -77,9 +77,9 @@ impl InputLine { } } - /** - ** End of InputLine::buffer interface - **/ + /* + * End of InputLine::buffer interface + */ /// Calculate hedight of the widget, taking nickname length into account. Only needed when /// buffer is wider than width and scrolling is off. diff --git a/crates/libtiny_tui/src/messaging.rs b/crates/libtiny_tui/src/messaging.rs index 159c6e45..9d124eaf 100644 --- a/crates/libtiny_tui/src/messaging.rs +++ b/crates/libtiny_tui/src/messaging.rs @@ -198,7 +198,7 @@ impl MessagingUI { self.msg_area.resize(width, msg_area_height); // We don't show the nick in exit dialogue, so it has the full width - for exit_dialogue in &mut self.exit_dialogue { + if let Some(exit_dialogue) = &mut self.exit_dialogue { exit_dialogue.resize(width); } } diff --git a/crates/libtiny_tui/src/msg_area/line.rs b/crates/libtiny_tui/src/msg_area/line.rs index abc0c971..bedde36b 100644 --- a/crates/libtiny_tui/src/msg_area/line.rs +++ b/crates/libtiny_tui/src/msg_area/line.rs @@ -124,7 +124,11 @@ impl Line { } } - fn add_text_inner(&mut self, str: &str) { + /// Add the text to the line. The text can contain IRC formatting characters. The text should + /// not contain other control characters like '\n' or '\r'. + pub(crate) fn add_text(&mut self, str: &str, style: SegStyle) { + self.set_message_style(style); + for format_event in parse_irc_formatting(str) { match format_event { IrcFormatEvent::Bold => self.add_attr(termbox_simple::TB_BOLD), @@ -161,20 +165,16 @@ impl Line { } } } - } - pub(crate) fn add_text(&mut self, str: &str, style: SegStyle) { - self.set_message_style(style); - self.add_text_inner(str) + self.line_data.set_dirty(); } + /// Add a single character to the line. The character should not be an IRC formatting character + /// or other control characters like '\n' and '\r'. pub(crate) fn add_char(&mut self, char: char, style: SegStyle) { self.set_message_style(style); self.current_seg.string.push(char); - } - - pub(crate) fn force_recalculation(&mut self) { - self.line_data.set_dirty() + self.line_data.set_dirty(); } /// Calculates the number of lines that this line will be. @@ -367,7 +367,7 @@ fn align_test() { 67 8 */ - line.add_text_inner("12345678"); + line.add_text("12345678", SegStyle::UserMsg); assert_eq!(line.rendered_height(3), 4); } diff --git a/crates/libtiny_tui/src/msg_area/mod.rs b/crates/libtiny_tui/src/msg_area/mod.rs index 094126a4..bafe76ea 100644 --- a/crates/libtiny_tui/src/msg_area/mod.rs +++ b/crates/libtiny_tui/src/msg_area/mod.rs @@ -229,8 +229,6 @@ impl MsgArea { F: Fn(&mut Line), { f(&mut self.lines[idx]); - // Line was modified so we need to invalidate its height - self.lines[idx].force_recalculation(); } pub(crate) fn clear(&mut self) { diff --git a/crates/termbox/src/lib.rs b/crates/termbox/src/lib.rs index 36817da1..683b0702 100644 --- a/crates/termbox/src/lib.rs +++ b/crates/termbox/src/lib.rs @@ -16,10 +16,13 @@ use unicode_width::UnicodeWidthChar; // FIXME: Use enter_ca_mode(smcup)/exit_ca_mode(rmcup) from terminfo pub const TB_DEFAULT: u16 = 0x0000; -pub const TB_BOLD: u16 = 0x0100; -pub const TB_UNDERLINE: u16 = 0x0200; -pub const TB_ITALIC: u16 = 0x0400; -pub const TB_STRIKETHROUGH: u16 = 0x0800; + +// Each attribute is a distinct bit after the low byte, so attributes can be manipulated with +// bitwise operations. +pub const TB_BOLD: u16 = 1 << 8; +pub const TB_UNDERLINE: u16 = 1 << 9; +pub const TB_ITALIC: u16 = 1 << 10; +pub const TB_STRIKETHROUGH: u16 = 1 << 11; pub struct Termbox { // Not available in test instances