Update modalkit for newer ratatui and crossterm

This commit is contained in:
Benjamin Große 2023-07-01 08:58:48 +01:00 committed by Ulyssa
parent 9197864c5c
commit 95af00ba93
No known key found for this signature in database
GPG key ID: F2873CA2997B83C5
12 changed files with 221 additions and 183 deletions

View file

@ -26,7 +26,7 @@ use modalkit::tui::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Modifier as StyleModifier, Style},
text::{Span, Spans, Text},
text::{Line, Span, Text},
widgets::StatefulWidget,
};
@ -102,7 +102,7 @@ fn bold_span(s: &str) -> Span {
}
#[inline]
fn bold_spans(s: &str) -> Spans {
fn bold_spans(s: &str) -> Line {
bold_span(s).into()
}
@ -537,7 +537,7 @@ impl Window<IambInfo> for IambWindow {
}
}
fn get_tab_title(&self, store: &mut ProgramStore) -> Spans {
fn get_tab_title(&self, store: &mut ProgramStore) -> Line {
match self {
IambWindow::DirectList(_) => bold_spans("Direct Messages"),
IambWindow::RoomList(_) => bold_spans("Rooms"),
@ -548,7 +548,7 @@ impl Window<IambInfo> for IambWindow {
IambWindow::Room(w) => {
let title = store.application.get_room_title(w.id());
Spans::from(title)
Line::from(title)
},
IambWindow::MemberList(state, room_id, _) => {
let title = store.application.get_room_title(room_id.as_ref());
@ -558,12 +558,12 @@ impl Window<IambInfo> for IambWindow {
Span::styled(format!("({n}): "), bold_style()),
title.into(),
];
Spans(v)
Line::from(v)
},
}
}
fn get_win_title(&self, store: &mut ProgramStore) -> Spans {
fn get_win_title(&self, store: &mut ProgramStore) -> Line {
match self {
IambWindow::DirectList(_) => bold_spans("Direct Messages"),
IambWindow::RoomList(_) => bold_spans("Rooms"),
@ -580,7 +580,7 @@ impl Window<IambInfo> for IambWindow {
Span::styled(format!("({n}): "), bold_style()),
title.into(),
];
Spans(v)
Line::from(v)
},
}
}
@ -730,7 +730,7 @@ impl ListItem<IambInfo> for RoomItem {
append_tags(tags, &mut spans, style);
Text::from(Spans(spans))
Text::from(Line::from(spans))
} else {
selected_text(self.name.as_str(), selected)
}
@ -796,7 +796,7 @@ impl ListItem<IambInfo> for DirectItem {
append_tags(tags, &mut spans, style);
Text::from(Spans(spans))
Text::from(Line::from(spans))
} else {
selected_text(self.name.as_str(), selected)
}
@ -1023,47 +1023,47 @@ impl ListItem<IambInfo> for VerifyItem {
let bold = Style::default().add_modifier(StyleModifier::BOLD);
let item = Span::styled(self.show_item(), selected_style(selected));
lines.push(Spans::from(item));
lines.push(Line::from(item));
if self.sasv1.is_done() {
// Print nothing.
} else if self.sasv1.is_cancelled() {
if let Some(info) = self.sasv1.cancel_info() {
lines.push(Spans::from(format!(" Cancelled: {}", info.reason())));
lines.push(Spans::from(""));
lines.push(Line::from(format!(" Cancelled: {}", info.reason())));
lines.push(Line::from(""));
}
lines.push(Spans::from(" You can start a new verification request with:"));
lines.push(Line::from(" You can start a new verification request with:"));
} else if let Some(emoji) = self.sasv1.emoji() {
lines.push(Spans::from(
lines.push(Line::from(
" Both devices should see the following Emoji sequence:".to_string(),
));
lines.push(Spans::from(""));
lines.push(Line::from(""));
for line in format_emojis(emoji).lines() {
lines.push(Spans::from(format!(" {line}")));
lines.push(Line::from(format!(" {line}")));
}
lines.push(Spans::from(""));
lines.push(Spans::from(" If they don't match, run:"));
lines.push(Spans::from(""));
lines.push(Spans::from(Span::styled(
lines.push(Line::from(""));
lines.push(Line::from(" If they don't match, run:"));
lines.push(Line::from(""));
lines.push(Line::from(Span::styled(
format!(":verify mismatch {}", self.user_dev),
bold,
)));
lines.push(Spans::from(""));
lines.push(Spans::from(" If everything looks right, you can confirm with:"));
lines.push(Line::from(""));
lines.push(Line::from(" If everything looks right, you can confirm with:"));
} else {
lines.push(Spans::from(" To accept this request, run:"));
lines.push(Line::from(" To accept this request, run:"));
}
let cmd = self.to_string();
if !cmd.is_empty() {
lines.push(Spans::from(""));
lines.push(Spans(vec![Span::from(" "), Span::styled(cmd, bold)]));
lines.push(Spans::from(""));
lines.push(Spans(vec![
lines.push(Line::from(""));
lines.push(Line::from(vec![Span::from(" "), Span::styled(cmd, bold)]));
lines.push(Line::from(""));
lines.push(Line::from(vec![
Span::from("You can copy the above command with "),
Span::styled("yy", bold),
Span::from(" and then execute it with "),
@ -1167,7 +1167,7 @@ impl ListItem<IambInfo> for MemberItem {
spans.extend(state);
return Spans(spans).into();
return Line::from(spans).into();
}
fn get_word(&self) -> Option<String> {

View file

@ -35,7 +35,7 @@ use modalkit::{
tui::{
buffer::Buffer,
layout::Rect,
text::{Span, Spans},
text::{Line, Span},
widgets::{Paragraph, StatefulWidget, Widget},
},
widgets::textbox::{TextBox, TextBoxState},
@ -812,7 +812,7 @@ impl<'a> StatefulWidget for Chat<'a> {
// Determine whether we have a description to show for the message bar.
let desc_spans = match (&state.editing, &state.reply_to) {
(None, None) => None,
(Some(_), None) => Some(Spans::from("Editing message")),
(Some(_), None) => Some(Line::from("Editing message")),
(editing, Some(_)) => {
state.reply_to.as_ref().and_then(|k| {
let room = self.store.application.rooms.get(state.id())?;
@ -824,7 +824,7 @@ impl<'a> StatefulWidget for Chat<'a> {
} else {
Span::from("Replying to ")
};
let spans = Spans(vec![prefix, user]);
let spans = Line::from(vec![prefix, user]);
spans.into()
})

View file

@ -15,7 +15,7 @@ use modalkit::tui::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Modifier as StyleModifier, Style},
text::{Span, Spans, Text},
text::{Line, Span, Text},
widgets::{Paragraph, StatefulWidget, Widget},
};
@ -150,8 +150,8 @@ impl RoomState {
invited.push(store.application.settings.get_user_span(inviter.user_id(), info));
}
let l1 = Spans(invited);
let l2 = Spans::from(
let l1 = Line::from(invited);
let l2 = Line::from(
"You can run `:invite accept` or `:invite reject` to accept or reject this invitation.",
);
let text = Text { lines: vec![l1, l2] };
@ -305,7 +305,7 @@ impl RoomState {
}
}
pub fn get_title(&self, store: &mut ProgramStore) -> Spans {
pub fn get_title(&self, store: &mut ProgramStore) -> Line {
let title = store.application.get_room_title(self.id());
let style = Style::default().add_modifier(StyleModifier::BOLD);
let mut spans = vec![Span::styled(title, style)];
@ -319,7 +319,7 @@ impl RoomState {
_ => {},
}
Spans(spans)
Line::from(spans)
}
pub fn focus_toggle(&mut self) {

View file

@ -9,7 +9,7 @@ use modalkit::tui::{
buffer::Buffer,
layout::{Alignment, Rect},
style::{Modifier as StyleModifier, Style},
text::{Span, Spans},
text::{Line, Span},
widgets::{Paragraph, StatefulWidget, Widget},
};
use modalkit::widgets::{ScrollActions, TerminalCursor, WindowOps};
@ -1226,7 +1226,7 @@ fn render_jump_to_recent(area: Rect, buf: &mut Buffer, focused: bool) -> Rect {
Span::raw(" to jump to latest message"),
];
Paragraph::new(Spans::from(msg))
Paragraph::new(Line::from(msg))
.alignment(Alignment::Center)
.render(bar, buf);
@ -1342,7 +1342,7 @@ impl<'a> StatefulWidget for Scrollback<'a> {
let x = area.left();
for (_, _, txt) in lines.into_iter() {
let _ = buf.set_spans(x, y, &txt, area.width);
let _ = buf.set_line(x, y, &txt, area.width);
y += 1;
}

View file

@ -11,7 +11,7 @@ use modalkit::tui::{
buffer::Buffer,
layout::Rect,
style::{Color, Style},
text::{Span, Spans, Text},
text::{Line, Span, Text},
widgets::StatefulWidget,
};
@ -140,7 +140,7 @@ impl<'a> StatefulWidget for Space<'a> {
},
Err(e) => {
let lines = vec![
Spans::from("Unable to fetch space room hierarchy:"),
Line::from("Unable to fetch space room hierarchy:"),
Span::styled(e.to_string(), Style::default().fg(Color::Red)).into(),
];