From 2d1c95325033739aa0bde59754b3338ce8ef4f2f Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 1 Aug 2022 19:13:06 +0200 Subject: [PATCH] Update toss --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/logger.rs | 4 ++-- src/ui/room.rs | 26 +++++++++++++++----------- src/ui/rooms.rs | 14 ++++++-------- src/ui/widgets/editor.rs | 15 +++++++-------- src/ui/widgets/text.rs | 4 ++-- 7 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1879f49..5b6f2d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1248,7 +1248,7 @@ dependencies = [ [[package]] name = "toss" version = "0.1.0" -source = "git+https://github.com/Garmelon/toss.git?rev=464aefa6d744e671806789dfd6fbd22c7e333273#464aefa6d744e671806789dfd6fbd22c7e333273" +source = "git+https://github.com/Garmelon/toss.git?rev=26a8936cf50ee4b775fd4d1bf96f1b3077421e5c#26a8936cf50ee4b775fd4d1bf96f1b3077421e5c" dependencies = [ "crossterm", "unicode-linebreak", diff --git a/Cargo.toml b/Cargo.toml index 7afafc1..bd0ac8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ features = ["rustls-tls-native-roots"] [dependencies.toss] git = "https://github.com/Garmelon/toss.git" -rev = "464aefa6d744e671806789dfd6fbd22c7e333273" +rev = "26a8936cf50ee4b775fd4d1bf96f1b3077421e5c" # [patch."https://github.com/Garmelon/toss.git"] # toss = { path = "../toss/" } diff --git a/src/logger.rs b/src/logger.rs index 67dd490..0aca9a4 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -43,11 +43,11 @@ impl Msg for LogMsg { Level::Trace => ContentStyle::default().bold().magenta(), }; let text = format!("{}", self.level); - Styled::new((text, style)) + Styled::new(text, style) } fn content(&self) -> Styled { - Styled::new(&self.content) + Styled::new_plain(&self.content) } fn last_possible_id() -> Self::Id { diff --git a/src/ui/room.rs b/src/ui/room.rs index 57dfb10..0a3d519 100644 --- a/src/ui/room.rs +++ b/src/ui/room.rs @@ -100,7 +100,7 @@ impl EuphRoom { Segment::new(Text::new("Choose nick ")), Segment::new( ed.widget() - .highlight(|s| Styled::new((s, euph::nick_style(s)))), + .highlight(|s| Styled::new(s, euph::nick_style(s))), ), ])) .left(1), @@ -146,19 +146,21 @@ impl EuphRoom { fn status_widget(&self, status: &Option>) -> BoxedWidget { let room = self.chat.store().room(); let room_style = ContentStyle::default().bold().blue(); - let mut info = Styled::new((format!("&{room}"), room_style)); + let mut info = Styled::new(format!("&{room}"), room_style); info = match status { - None => info.then(", archive"), - Some(None) => info.then(", connecting..."), - Some(Some(Status::Joining(j))) if j.bounce.is_some() => info.then(", auth required"), - Some(Some(Status::Joining(_))) => info.then(", joining..."), + None => info.then_plain(", archive"), + Some(None) => info.then_plain(", connecting..."), + Some(Some(Status::Joining(j))) if j.bounce.is_some() => { + info.then_plain(", auth required") + } + Some(Some(Status::Joining(_))) => info.then_plain(", joining..."), Some(Some(Status::Joined(j))) => { let nick = &j.session.name; if nick.is_empty() { - info.then(", present without nick") + info.then_plain(", present without nick") } else { let nick_style = euph::nick_style(nick); - info.then(", present as ").then((nick, nick_style)) + info.then_plain(", present as ").then(nick, nick_style) } } }; @@ -202,8 +204,10 @@ impl EuphRoom { "" }; - let normal = Styled::new(owner).then((name, style)).then(perms); - let selected = Styled::new(owner).then((name, style_inv)).then(perms); + let normal = Styled::new_plain(owner).then(name, style).then_plain(perms); + let selected = Styled::new_plain(owner) + .then(name, style_inv) + .then_plain(perms); list.add_sel( id, Text::new(normal), @@ -227,7 +231,7 @@ impl EuphRoom { list.add_unsel(Empty); } - let row = Styled::new((name, heading_style)).then(format!(" ({})", sessions.len())); + let row = Styled::new(name, heading_style).then_plain(format!(" ({})", sessions.len())); list.add_unsel(Text::new(row)); for session in sessions { diff --git a/src/ui/rooms.rs b/src/ui/rooms.rs index 910f87e..537f8ea 100644 --- a/src/ui/rooms.rs +++ b/src/ui/rooms.rs @@ -107,9 +107,7 @@ impl Rooms { Segment::new(Text::new("Connect to ")), Segment::new(HJoin::new(vec![ Segment::new(Text::new(("&", room_style))), - Segment::new( - ed.widget().highlight(|s| Styled::new((s, room_style))), - ), + Segment::new(ed.widget().highlight(|s| Styled::new(s, room_style))), ])), ])) .left(1), @@ -166,7 +164,7 @@ impl Rooms { async fn render_rows(&self, list: &mut List, rooms: Vec) { let heading_style = ContentStyle::default().bold(); - let heading = Styled::new(("Rooms", heading_style)).then(format!(" ({})", rooms.len())); + let heading = Styled::new("Rooms", heading_style).then_plain(format!(" ({})", rooms.len())); list.add_unsel(Text::new(heading)); for room in rooms { @@ -175,13 +173,13 @@ impl Rooms { let room_style = ContentStyle::default().bold().blue(); let room_sel_style = ContentStyle::default().bold().black().on_white(); - let mut normal = Styled::new((format!("&{room}"), room_style)); - let mut selected = Styled::new((format!("&{room}"), room_sel_style)); + let mut normal = Styled::new(format!("&{room}"), room_style); + let mut selected = Styled::new(format!("&{room}"), room_sel_style); if let Some(room) = self.euph_rooms.get(&room) { if let Some(status) = room.status().await { let status = Self::format_status(&status); - normal = normal.then((status.clone(), bg_style)); - selected = selected.then((status, bg_sel_style)); + normal = normal.then(status.clone(), bg_style); + selected = selected.then(status, bg_sel_style); } }; diff --git a/src/ui/widgets/editor.rs b/src/ui/widgets/editor.rs index ac53c61..79646af 100644 --- a/src/ui/widgets/editor.rs +++ b/src/ui/widgets/editor.rs @@ -188,7 +188,7 @@ impl EditorState { pub fn widget(&self) -> Editor { let guard = self.0.lock(); - let text = Styled::new(guard.text.clone()); + let text = Styled::new_plain(guard.text.clone()); let idx = guard.idx; Editor { state: self.0.clone(), @@ -239,9 +239,8 @@ impl Editor { where F: FnOnce(&str) -> Styled, { - let text = self.text.text(); - let new_text = f(&text); - assert_eq!(text, new_text.text()); + let new_text = f(self.text.text()); + assert_eq!(self.text.text(), new_text.text()); self.text = new_text; self } @@ -264,7 +263,7 @@ impl Editor { pub fn cursor_row(&self, frame: &mut Frame) -> usize { let width: usize = frame.size().width.into(); - let indices = frame.wrap(&self.text.text(), width); + let indices = frame.wrap(self.text.text(), width); let (row, _) = Self::wrapped_cursor(self.idx, &indices); row } @@ -275,12 +274,12 @@ impl Widget for Editor { fn size(&self, frame: &mut Frame, max_width: Option, _max_height: Option) -> Size { let max_width = max_width.map(|w| w as usize).unwrap_or(usize::MAX).max(1); let max_text_width = max_width - 1; - let indices = frame.wrap(&self.text.text(), max_text_width); + let indices = frame.wrap(self.text.text(), max_text_width); let lines = self.text.clone().split_at_indices(&indices); let min_width = lines .iter() - .map(|l| frame.width_styled(l)) + .map(|l| frame.width(l.text())) .max() .unwrap_or(0) + 1; @@ -291,7 +290,7 @@ impl Widget for Editor { async fn render(self: Box, frame: &mut Frame) { let width = frame.size().width.max(1); let text_width = (width - 1) as usize; - let indices = frame.wrap(&self.text.text(), text_width); + let indices = frame.wrap(self.text.text(), text_width); let lines = self.text.split_at_indices(&indices); let (cursor_row, cursor_line_idx) = Self::wrapped_cursor(self.idx, &indices); diff --git a/src/ui/widgets/text.rs b/src/ui/widgets/text.rs index 023a16a..43a9770 100644 --- a/src/ui/widgets/text.rs +++ b/src/ui/widgets/text.rs @@ -29,7 +29,7 @@ impl Text { usize::MAX }; - let indices = frame.wrap(&self.styled.text(), max_width); + let indices = frame.wrap(self.styled.text(), max_width); self.styled.clone().split_at_indices(&indices) } } @@ -40,7 +40,7 @@ impl Widget for Text { let lines = self.wrapped(frame, max_width); let min_width = lines .iter() - .map(|l| frame.width_styled(l)) + .map(|l| frame.width(l.text())) .max() .unwrap_or(0); let min_height = lines.len();