Skip to content

Commit

Permalink
Update modalkit for newer ratatui and crossterm
Browse files Browse the repository at this point in the history
  • Loading branch information
benjajaja authored and ulyssa committed Oct 8, 2023
1 parent 9197864 commit 95af00b
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 183 deletions.
86 changes: 58 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ features = ["build", "git", "gitcl",]

[dependencies]
arboard = "3.2.0"
bitflags = "1.3.2"
bitflags = "^2.3"
chrono = "0.4"
clap = {version = "~4.3", features = ["derive"]}
comrak = {version = "0.18.0", features = ["shortcodes"]}
Expand Down Expand Up @@ -54,7 +54,9 @@ url = {version = "^2.2.2", features = ["serde"]}
edit = "0.1.4"

[dependencies.modalkit]
version = "0.0.16"
# version = "0.0.16"
git = "https://github.com/ulyssa/modalkit"
rev = "f9f0517ed6a6152c1eab36d2e71b11f38831d5e6"

[dependencies.matrix-sdk]
version = "^0.6.2"
Expand Down
30 changes: 16 additions & 14 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use modalkit::{
tui::{
buffer::Buffer,
layout::{Alignment, Rect},
text::{Span, Spans},
text::{Line, Span},
widgets::{Paragraph, Widget},
},
};
Expand Down Expand Up @@ -174,6 +174,7 @@ pub enum CreateRoomType {

bitflags::bitflags! {
/// Available options for newly created rooms.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CreateRoomFlags: u32 {
/// No flags specified.
const NONE = 0b00000000;
Expand All @@ -188,6 +189,7 @@ bitflags::bitflags! {

bitflags::bitflags! {
/// Available options when downloading files.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DownloadFlags: u32 {
/// No flags specified.
const NONE = 0b00000000;
Expand Down Expand Up @@ -701,30 +703,30 @@ impl RoomInfo {
}
}

fn get_typing_spans<'a>(&'a self, settings: &'a ApplicationSettings) -> Spans<'a> {
fn get_typing_spans<'a>(&'a self, settings: &'a ApplicationSettings) -> Line<'a> {
let typers = self.get_typers();
let n = typers.len();

match n {
0 => Spans(vec![]),
0 => Line::from(vec![]),
1 => {
let user = settings.get_user_span(typers[0].as_ref(), self);

Spans(vec![user, Span::from(" is typing...")])
Line::from(vec![user, Span::from(" is typing...")])
},
2 => {
let user1 = settings.get_user_span(typers[0].as_ref(), self);
let user2 = settings.get_user_span(typers[1].as_ref(), self);

Spans(vec![
Line::from(vec![
user1,
Span::raw(" and "),
user2,
Span::from(" are typing..."),
])
},
n if n < 5 => Spans::from("Several people are typing..."),
_ => Spans::from("Many people are typing..."),
n if n < 5 => Line::from("Several people are typing..."),
_ => Line::from("Many people are typing..."),
}
}

Expand Down Expand Up @@ -1364,19 +1366,19 @@ pub mod tests {

// Nothing set.
assert_eq!(info.users_typing, None);
assert_eq!(info.get_typing_spans(&settings), Spans(vec![]));
assert_eq!(info.get_typing_spans(&settings), Line::from(vec![]));

// Empty typing list.
info.set_typing(users0);
assert!(info.users_typing.is_some());
assert_eq!(info.get_typing_spans(&settings), Spans(vec![]));
assert_eq!(info.get_typing_spans(&settings), Line::from(vec![]));

// Single user typing.
info.set_typing(users1);
assert!(info.users_typing.is_some());
assert_eq!(
info.get_typing_spans(&settings),
Spans(vec![
Line::from(vec![
Span::styled("@user1:example.com", user_style("@user1:example.com")),
Span::from(" is typing...")
])
Expand All @@ -1387,7 +1389,7 @@ pub mod tests {
assert!(info.users_typing.is_some());
assert_eq!(
info.get_typing_spans(&settings),
Spans(vec![
Line::from(vec![
Span::styled("@user1:example.com", user_style("@user1:example.com")),
Span::raw(" and "),
Span::styled("@user2:example.com", user_style("@user2:example.com")),
Expand All @@ -1398,19 +1400,19 @@ pub mod tests {
// Four users typing.
info.set_typing(users4);
assert!(info.users_typing.is_some());
assert_eq!(info.get_typing_spans(&settings), Spans::from("Several people are typing..."));
assert_eq!(info.get_typing_spans(&settings), Line::from("Several people are typing..."));

// Five users typing.
info.set_typing(users5);
assert!(info.users_typing.is_some());
assert_eq!(info.get_typing_spans(&settings), Spans::from("Many people are typing..."));
assert_eq!(info.get_typing_spans(&settings), Line::from("Many people are typing..."));

// Test that USER5 gets rendered using the configured color and name.
info.set_typing(vec![TEST_USER5.clone()]);
assert!(info.users_typing.is_some());
assert_eq!(
info.get_typing_spans(&settings),
Spans(vec![
Line::from(vec![
Span::styled("USER 5", user_style_from_color(Color::Black)),
Span::from(" is typing...")
])
Expand Down
Loading

0 comments on commit 95af00b

Please sign in to comment.