Set window title
The title includes the amount of unseen messages in the room or room list. The room list heading also now contains the amount of connected rooms as well as the amount of unseen messages in total (if any).
This commit is contained in:
parent
ed7bd3ddb4
commit
ab81c89854
6 changed files with 86 additions and 26 deletions
|
|
@ -15,6 +15,10 @@ Procedure when bumping the version number:
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Support for setting window title
|
||||||
|
- More information to room list heading
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- Key binding to open present page
|
- Key binding to open present page
|
||||||
|
|
||||||
|
|
|
||||||
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -1477,8 +1477,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toss"
|
name = "toss"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
source = "git+https://github.com/Garmelon/toss.git?tag=v0.2.0#2c7888fa413c9b12bec7d55a73051aa96d59386f"
|
source = "git+https://github.com/Garmelon/toss.git?tag=v0.2.1#b01ee297d5bdbb3b28cafe2b5b130c2767667974"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ thiserror = "1.0.56"
|
||||||
|
|
||||||
[workspace.dependencies.toss]
|
[workspace.dependencies.toss]
|
||||||
git = "https://github.com/Garmelon/toss.git"
|
git = "https://github.com/Garmelon/toss.git"
|
||||||
tag = "v0.2.0"
|
tag = "v0.2.1"
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
|
||||||
|
|
@ -319,7 +319,17 @@ impl EuphRoom {
|
||||||
.then_plain(")");
|
.then_plain(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
Text::new(info).padding().with_horizontal(1).border()
|
let title = if unseen > 0 {
|
||||||
|
format!("&{} ({unseen})", self.name())
|
||||||
|
} else {
|
||||||
|
format!("&{}", self.name())
|
||||||
|
};
|
||||||
|
|
||||||
|
Text::new(info)
|
||||||
|
.padding()
|
||||||
|
.with_horizontal(1)
|
||||||
|
.border()
|
||||||
|
.title(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_chat_input_event(&mut self, event: &mut InputEvent<'_>, keys: &Keys) -> bool {
|
async fn handle_chat_input_event(&mut self, event: &mut InputEvent<'_>, keys: &Keys) -> bool {
|
||||||
|
|
|
||||||
|
|
@ -237,12 +237,16 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
|
|
||||||
match &mut self.state {
|
match &mut self.state {
|
||||||
State::ShowList => {
|
State::ShowList => Self::rooms_widget(
|
||||||
Self::rooms_widget(self.config, &mut self.list, self.order, &self.euph_rooms)
|
&self.vault,
|
||||||
.await
|
self.config,
|
||||||
.desync()
|
&mut self.list,
|
||||||
.boxed_async()
|
self.order,
|
||||||
}
|
&self.euph_rooms,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.desync()
|
||||||
|
.boxed_async(),
|
||||||
|
|
||||||
State::ShowRoom(id) => {
|
State::ShowRoom(id) => {
|
||||||
self.euph_rooms
|
self.euph_rooms
|
||||||
|
|
@ -252,21 +256,29 @@ impl Rooms {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
State::Connect(connect) => {
|
State::Connect(connect) => Self::rooms_widget(
|
||||||
Self::rooms_widget(self.config, &mut self.list, self.order, &self.euph_rooms)
|
&self.vault,
|
||||||
.await
|
self.config,
|
||||||
.below(connect.widget())
|
&mut self.list,
|
||||||
.desync()
|
self.order,
|
||||||
.boxed_async()
|
&self.euph_rooms,
|
||||||
}
|
)
|
||||||
|
.await
|
||||||
|
.below(connect.widget())
|
||||||
|
.desync()
|
||||||
|
.boxed_async(),
|
||||||
|
|
||||||
State::Delete(delete) => {
|
State::Delete(delete) => Self::rooms_widget(
|
||||||
Self::rooms_widget(self.config, &mut self.list, self.order, &self.euph_rooms)
|
&self.vault,
|
||||||
.await
|
self.config,
|
||||||
.below(delete.widget())
|
&mut self.list,
|
||||||
.desync()
|
self.order,
|
||||||
.boxed_async()
|
&self.euph_rooms,
|
||||||
}
|
)
|
||||||
|
.await
|
||||||
|
.below(delete.widget())
|
||||||
|
.desync()
|
||||||
|
.boxed_async(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,6 +412,7 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn rooms_widget<'a>(
|
async fn rooms_widget<'a>(
|
||||||
|
vault: &Vault,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
list: &'a mut ListState<RoomIdentifier>,
|
list: &'a mut ListState<RoomIdentifier>,
|
||||||
order: Order,
|
order: Order,
|
||||||
|
|
@ -419,8 +432,24 @@ impl Rooms {
|
||||||
.with_horizontal(1)
|
.with_horizontal(1)
|
||||||
.border();
|
.border();
|
||||||
|
|
||||||
let heading = Styled::new("Rooms", Style::new().bold())
|
let mut heading = Styled::new("Rooms", Style::new().bold());
|
||||||
.then_plain(format!(" ({})", euph_rooms.len()));
|
let mut title = "Rooms".to_string();
|
||||||
|
|
||||||
|
let total_rooms = euph_rooms.len();
|
||||||
|
let connected_rooms = euph_rooms
|
||||||
|
.iter()
|
||||||
|
.filter(|r| r.1.room_state().is_some())
|
||||||
|
.count();
|
||||||
|
let total_unseen = logging_unwrap!(vault.euph().total_unseen_msgs_count().await);
|
||||||
|
if total_unseen > 0 {
|
||||||
|
heading = heading
|
||||||
|
.then_plain(format!(" ({connected_rooms}/{total_rooms}, "))
|
||||||
|
.then(format!("{total_unseen}"), Style::new().bold().green())
|
||||||
|
.then_plain(")");
|
||||||
|
title.push_str(&format!(" ({total_unseen})"));
|
||||||
|
} else {
|
||||||
|
heading = heading.then_plain(format!(" ({connected_rooms}/{total_rooms})"))
|
||||||
|
}
|
||||||
|
|
||||||
let mut list_builder = ListBuilder::new();
|
let mut list_builder = ListBuilder::new();
|
||||||
Self::render_rows(&mut list_builder, order, euph_rooms).await;
|
Self::render_rows(&mut list_builder, order, euph_rooms).await;
|
||||||
|
|
@ -435,6 +464,7 @@ impl Rooms {
|
||||||
.segment()
|
.segment()
|
||||||
.with_growing(false),
|
.with_growing(false),
|
||||||
)
|
)
|
||||||
|
.title(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_showlist_input_event(
|
async fn handle_showlist_input_event(
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ euph_vault_actions! {
|
||||||
SetCookies : set_cookies(domain: String, cookies: CookieJar) -> ();
|
SetCookies : set_cookies(domain: String, cookies: CookieJar) -> ();
|
||||||
ClearCookies : clear_cookies(domain: Option<String>) -> ();
|
ClearCookies : clear_cookies(domain: Option<String>) -> ();
|
||||||
GetRooms : rooms() -> Vec<RoomIdentifier>;
|
GetRooms : rooms() -> Vec<RoomIdentifier>;
|
||||||
|
GetTotalUnseenMsgsCount : total_unseen_msgs_count() -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for GetCookies {
|
impl Action for GetCookies {
|
||||||
|
|
@ -212,6 +213,21 @@ impl Action for GetRooms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Action for GetTotalUnseenMsgsCount {
|
||||||
|
type Output = usize;
|
||||||
|
type Error = rusqlite::Error;
|
||||||
|
|
||||||
|
fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error> {
|
||||||
|
conn.prepare(
|
||||||
|
"
|
||||||
|
SELECT COALESCE(SUM(amount), 0)
|
||||||
|
FROM euph_unseen_counts
|
||||||
|
",
|
||||||
|
)?
|
||||||
|
.query_row([], |row| row.get(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// EuphRoomVault //
|
// EuphRoomVault //
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue