Update toss

This commit is contained in:
Joscha 2022-08-01 19:13:06 +02:00
parent 32bb9898dc
commit 2d1c953250
7 changed files with 34 additions and 33 deletions

View file

@ -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 {

View file

@ -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<Option<Status>>) -> 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 {

View file

@ -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<String>, rooms: Vec<String>) {
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);
}
};

View file

@ -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<u16>, _max_height: Option<u16>) -> 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<Self>, 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);

View file

@ -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();