Commit 8ed037afca
Unregistered key
Layout: unified · split
Cargo.lock +2 −2
| @@ -1600,9 +1600,9 @@ dependencies = [ | ||
| 1600 | 1600 | |
| 1601 | 1601 | [[package]] |
| 1602 | 1602 | name = "modalkit" |
| 1603 | version = "0.0.7" | |
| 1603 | version = "0.0.8" | |
| 1604 | 1604 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1605 | checksum = "dc4385b7136847cd063fbf093f0aa21a098398e26dc9213137fdd4e4f593d6bf" | |
| 1605 | checksum = "7f4e400066e546471efee517b7e5e3ca5af2c04014e76289aecc7af621011bba" | |
| 1606 | 1606 | dependencies = [ |
| 1607 | 1607 | "anymap2", |
| 1608 | 1608 | "bitflags", |
Cargo.toml +1 −1
| @@ -19,7 +19,7 @@ dirs = "4.0.0" | ||
| 19 | 19 | futures = "0.3.21" |
| 20 | 20 | gethostname = "0.4.1" |
| 21 | 21 | matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]} |
| 22 | modalkit = "0.0.7" | |
| 22 | modalkit = "0.0.8" | |
| 23 | 23 | regex = "^1.5" |
| 24 | 24 | rpassword = "^7.2" |
| 25 | 25 | serde = "^1.0" |
README.md +1 −1
| @@ -42,7 +42,7 @@ two other TUI clients and Element Web: | ||
| 42 | 42 | | Room tag showing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: | |
| 43 | 43 | | Room tag editing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: | |
| 44 | 44 | | Search joined rooms | :x: ([#16]) | :heavy_check_mark: | :x: | :heavy_check_mark: | |
| 45 | | Room user list | :x: ([#6]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | |
| 45 | | Room user list | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | |
| 46 | 46 | | Display Room Description | :x: ([#12]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 47 | 47 | | Edit Room Description | :x: ([#12]) | :x: | :heavy_check_mark: | :heavy_check_mark: | |
| 48 | 48 | | Highlights | :x: ([#8]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
src/base.rs +22 −1
| @@ -26,7 +26,7 @@ use modalkit::{ | ||
| 26 | 26 | store::Store, |
| 27 | 27 | }, |
| 28 | 28 | env::vim::{ |
| 29 | command::{VimCommand, VimCommandMachine}, | |
| 29 | command::{CommandContext, VimCommand, VimCommandMachine}, | |
| 30 | 30 | keybindings::VimMachine, |
| 31 | 31 | VimContext, |
| 32 | 32 | }, |
| @@ -59,8 +59,14 @@ pub enum VerifyAction { | ||
| 59 | 59 | Mismatch, |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | #[derive(Clone, Debug, Eq, PartialEq)] | |
| 63 | pub enum RoomAction { | |
| 64 | Members(Box<CommandContext<ProgramContext>>), | |
| 65 | } | |
| 66 | ||
| 62 | 67 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 63 | 68 | pub enum IambAction { |
| 69 | Room(RoomAction), | |
| 64 | 70 | Verify(VerifyAction, String), |
| 65 | 71 | VerifyRequest(String), |
| 66 | 72 | SendMessage(OwnedRoomId, String), |
| @@ -70,6 +76,7 @@ pub enum IambAction { | ||
| 70 | 76 | impl ApplicationAction for IambAction { |
| 71 | 77 | fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus { |
| 72 | 78 | match self { |
| 79 | IambAction::Room(..) => SequenceStatus::Break, | |
| 73 | 80 | IambAction::SendMessage(..) => SequenceStatus::Break, |
| 74 | 81 | IambAction::ToggleScrollbackFocus => SequenceStatus::Break, |
| 75 | 82 | IambAction::Verify(..) => SequenceStatus::Break, |
| @@ -79,6 +86,7 @@ impl ApplicationAction for IambAction { | ||
| 79 | 86 | |
| 80 | 87 | fn is_last_action<C: EditContext>(&self, _: &C) -> SequenceStatus { |
| 81 | 88 | match self { |
| 89 | IambAction::Room(..) => SequenceStatus::Atom, | |
| 82 | 90 | IambAction::SendMessage(..) => SequenceStatus::Atom, |
| 83 | 91 | IambAction::ToggleScrollbackFocus => SequenceStatus::Atom, |
| 84 | 92 | IambAction::Verify(..) => SequenceStatus::Atom, |
| @@ -88,6 +96,7 @@ impl ApplicationAction for IambAction { | ||
| 88 | 96 | |
| 89 | 97 | fn is_last_selection<C: EditContext>(&self, _: &C) -> SequenceStatus { |
| 90 | 98 | match self { |
| 99 | IambAction::Room(..) => SequenceStatus::Ignore, | |
| 91 | 100 | IambAction::SendMessage(..) => SequenceStatus::Ignore, |
| 92 | 101 | IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore, |
| 93 | 102 | IambAction::Verify(..) => SequenceStatus::Ignore, |
| @@ -97,6 +106,7 @@ impl ApplicationAction for IambAction { | ||
| 97 | 106 | |
| 98 | 107 | fn is_switchable<C: EditContext>(&self, _: &C) -> bool { |
| 99 | 108 | match self { |
| 109 | IambAction::Room(..) => false, | |
| 100 | 110 | IambAction::SendMessage(..) => false, |
| 101 | 111 | IambAction::ToggleScrollbackFocus => false, |
| 102 | 112 | IambAction::Verify(..) => false, |
| @@ -275,6 +285,14 @@ impl ChatStore { | ||
| 275 | 285 | } |
| 276 | 286 | } |
| 277 | 287 | |
| 288 | pub fn get_room_title(&self, room_id: &RoomId) -> String { | |
| 289 | self.rooms | |
| 290 | .get(room_id) | |
| 291 | .and_then(|i| i.name.as_ref()) | |
| 292 | .map(String::from) | |
| 293 | .unwrap_or_else(|| "Untitled Matrix Room".to_string()) | |
| 294 | } | |
| 295 | ||
| 278 | 296 | pub fn mark_for_load(&mut self, room_id: OwnedRoomId) { |
| 279 | 297 | self.need_load.insert(room_id); |
| 280 | 298 | } |
| @@ -346,6 +364,7 @@ impl ApplicationStore for ChatStore {} | ||
| 346 | 364 | pub enum IambId { |
| 347 | 365 | Room(OwnedRoomId), |
| 348 | 366 | DirectList, |
| 367 | MemberList(OwnedRoomId), | |
| 349 | 368 | RoomList, |
| 350 | 369 | SpaceList, |
| 351 | 370 | VerifyList, |
| @@ -375,6 +394,7 @@ pub enum IambBufferId { | ||
| 375 | 394 | Command, |
| 376 | 395 | Room(OwnedRoomId, RoomFocus), |
| 377 | 396 | DirectList, |
| 397 | MemberList(OwnedRoomId), | |
| 378 | 398 | RoomList, |
| 379 | 399 | SpaceList, |
| 380 | 400 | VerifyList, |
| @@ -387,6 +407,7 @@ impl IambBufferId { | ||
| 387 | 407 | IambBufferId::Command => None, |
| 388 | 408 | IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())), |
| 389 | 409 | IambBufferId::DirectList => Some(IambId::DirectList), |
| 410 | IambBufferId::MemberList(room) => Some(IambId::MemberList(room.clone())), | |
| 390 | 411 | IambBufferId::RoomList => Some(IambId::RoomList), |
| 391 | 412 | IambBufferId::SpaceList => Some(IambId::SpaceList), |
| 392 | 413 | IambBufferId::VerifyList => Some(IambId::VerifyList), |
src/commands.rs +27 −12
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use modalkit::{ |
| 2 | editing::{action::WindowAction, base::OpenTarget}, | |
| 2 | editing::base::OpenTarget, | |
| 3 | 3 | env::vim::command::{CommandContext, CommandDescription}, |
| 4 | 4 | input::commands::{CommandError, CommandResult, CommandStep}, |
| 5 | 5 | input::InputContext, |
| @@ -11,6 +11,7 @@ use crate::base::{ | ||
| 11 | 11 | ProgramCommand, |
| 12 | 12 | ProgramCommands, |
| 13 | 13 | ProgramContext, |
| 14 | RoomAction, | |
| 14 | 15 | VerifyAction, |
| 15 | 16 | }; |
| 16 | 17 | |
| @@ -22,8 +23,8 @@ fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 22 | 23 | |
| 23 | 24 | match args.len() { |
| 24 | 25 | 0 => { |
| 25 | let open = WindowAction::Switch(OpenTarget::Application(IambId::VerifyList)); | |
| 26 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | |
| 26 | let open = ctx.switch(OpenTarget::Application(IambId::VerifyList)); | |
| 27 | let step = CommandStep::Continue(open, ctx.context.take()); | |
| 27 | 28 | |
| 28 | 29 | return Ok(step); |
| 29 | 30 | }, |
| @@ -61,7 +62,18 @@ fn iamb_dms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 61 | 62 | return Result::Err(CommandError::InvalidArgument); |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | let open = WindowAction::Switch(OpenTarget::Application(IambId::DirectList)); | |
| 65 | let open = ctx.switch(OpenTarget::Application(IambId::DirectList)); | |
| 66 | let step = CommandStep::Continue(open, ctx.context.take()); | |
| 67 | ||
| 68 | return Ok(step); | |
| 69 | } | |
| 70 | ||
| 71 | fn iamb_members(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |
| 72 | if !desc.arg.text.is_empty() { | |
| 73 | return Result::Err(CommandError::InvalidArgument); | |
| 74 | } | |
| 75 | ||
| 76 | let open = IambAction::Room(RoomAction::Members(ctx.clone().into())); | |
| 65 | 77 | let step = CommandStep::Continue(open.into(), ctx.context.take()); |
| 66 | 78 | |
| 67 | 79 | return Ok(step); |
| @@ -72,8 +84,8 @@ fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 72 | 84 | return Result::Err(CommandError::InvalidArgument); |
| 73 | 85 | } |
| 74 | 86 | |
| 75 | let open = WindowAction::Switch(OpenTarget::Application(IambId::RoomList)); | |
| 76 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | |
| 87 | let open = ctx.switch(OpenTarget::Application(IambId::RoomList)); | |
| 88 | let step = CommandStep::Continue(open, ctx.context.take()); | |
| 77 | 89 | |
| 78 | 90 | return Ok(step); |
| 79 | 91 | } |
| @@ -83,8 +95,8 @@ fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 83 | 95 | return Result::Err(CommandError::InvalidArgument); |
| 84 | 96 | } |
| 85 | 97 | |
| 86 | let open = WindowAction::Switch(OpenTarget::Application(IambId::SpaceList)); | |
| 87 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | |
| 98 | let open = ctx.switch(OpenTarget::Application(IambId::SpaceList)); | |
| 99 | let step = CommandStep::Continue(open, ctx.context.take()); | |
| 88 | 100 | |
| 89 | 101 | return Ok(step); |
| 90 | 102 | } |
| @@ -94,8 +106,8 @@ fn iamb_welcome(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 94 | 106 | return Result::Err(CommandError::InvalidArgument); |
| 95 | 107 | } |
| 96 | 108 | |
| 97 | let open = WindowAction::Switch(OpenTarget::Application(IambId::Welcome)); | |
| 98 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | |
| 109 | let open = ctx.switch(OpenTarget::Application(IambId::Welcome)); | |
| 110 | let step = CommandStep::Continue(open, ctx.context.take()); | |
| 99 | 111 | |
| 100 | 112 | return Ok(step); |
| 101 | 113 | } |
| @@ -107,8 +119,8 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 107 | 119 | return Result::Err(CommandError::InvalidArgument); |
| 108 | 120 | } |
| 109 | 121 | |
| 110 | let open = WindowAction::Switch(args.remove(0)); | |
| 111 | let step = CommandStep::Continue(open.into(), ctx.context.take()); | |
| 122 | let open = ctx.switch(args.remove(0)); | |
| 123 | let step = CommandStep::Continue(open, ctx.context.take()); | |
| 112 | 124 | |
| 113 | 125 | return Ok(step); |
| 114 | 126 | } |
| @@ -116,6 +128,7 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 116 | 128 | fn add_iamb_commands(cmds: &mut ProgramCommands) { |
| 117 | 129 | cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); |
| 118 | 130 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); |
| 131 | cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); | |
| 119 | 132 | cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); |
| 120 | 133 | cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces }); |
| 121 | 134 | cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify }); |
| @@ -133,6 +146,8 @@ pub fn setup_commands() -> ProgramCommands { | ||
| 133 | 146 | #[cfg(test)] |
| 134 | 147 | mod tests { |
| 135 | 148 | use super::*; |
| 149 | use modalkit::editing::action::WindowAction; | |
| 150 | ||
| 136 | 151 | #[test] |
| 137 | 152 | fn test_cmd_verify() { |
| 138 | 153 | let mut cmds = setup_commands(); |
src/main.rs +8 −1
| @@ -317,7 +317,7 @@ impl Application { | ||
| 317 | 317 | fn iamb_run( |
| 318 | 318 | &mut self, |
| 319 | 319 | action: IambAction, |
| 320 | _: ProgramContext, | |
| 320 | ctx: ProgramContext, | |
| 321 | 321 | store: &mut ProgramStore, |
| 322 | 322 | ) -> IambResult<EditInfo> { |
| 323 | 323 | let info = match action { |
| @@ -327,6 +327,13 @@ impl Application { | ||
| 327 | 327 | None |
| 328 | 328 | }, |
| 329 | 329 | |
| 330 | IambAction::Room(act) => { | |
| 331 | let acts = self.screen.current_window_mut()?.room_command(act, ctx, store)?; | |
| 332 | self.action_prepend(acts); | |
| 333 | ||
| 334 | None | |
| 335 | }, | |
| 336 | ||
| 330 | 337 | IambAction::SendMessage(room_id, msg) => { |
| 331 | 338 | let (event_id, msg) = self.worker.send_message(room_id.clone(), msg)?; |
| 332 | 339 | let user = store.application.settings.profile.user_id.clone(); |
src/windows/mod.rs +189 −19
| @@ -3,22 +3,23 @@ use std::collections::hash_map::Entry; | ||
| 3 | 3 | |
| 4 | 4 | use matrix_sdk::{ |
| 5 | 5 | encryption::verification::{format_emojis, SasVerification}, |
| 6 | room::Room as MatrixRoom, | |
| 7 | ruma::RoomId, | |
| 6 | room::{Room as MatrixRoom, RoomMember}, | |
| 7 | ruma::{events::room::member::MembershipState, OwnedRoomId, RoomId}, | |
| 8 | 8 | DisplayName, |
| 9 | 9 | }; |
| 10 | 10 | |
| 11 | 11 | use modalkit::tui::{ |
| 12 | 12 | buffer::Buffer, |
| 13 | layout::Rect, | |
| 13 | layout::{Alignment, Rect}, | |
| 14 | 14 | style::{Modifier as StyleModifier, Style}, |
| 15 | 15 | text::{Span, Spans, Text}, |
| 16 | widgets::{Block, Borders, Widget}, | |
| 16 | widgets::{Block, Borders, StatefulWidget, Widget}, | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | use modalkit::{ |
| 20 | 20 | editing::{ |
| 21 | 21 | action::{ |
| 22 | Action, | |
| 22 | 23 | EditError, |
| 23 | 24 | EditInfo, |
| 24 | 25 | EditResult, |
| @@ -42,7 +43,7 @@ use modalkit::{ | ||
| 42 | 43 | }, |
| 43 | 44 | }, |
| 44 | 45 | widgets::{ |
| 45 | list::{ListCursor, ListItem, ListState}, | |
| 46 | list::{List, ListCursor, ListItem, ListState}, | |
| 46 | 47 | TermOffset, |
| 47 | 48 | TerminalCursor, |
| 48 | 49 | Window, |
| @@ -50,15 +51,19 @@ use modalkit::{ | ||
| 50 | 51 | }, |
| 51 | 52 | }; |
| 52 | 53 | |
| 53 | use super::base::{ | |
| 54 | ChatStore, | |
| 55 | IambBufferId, | |
| 56 | IambId, | |
| 57 | IambInfo, | |
| 58 | IambResult, | |
| 59 | ProgramAction, | |
| 60 | ProgramContext, | |
| 61 | ProgramStore, | |
| 54 | use crate::{ | |
| 55 | base::{ | |
| 56 | ChatStore, | |
| 57 | IambBufferId, | |
| 58 | IambId, | |
| 59 | IambInfo, | |
| 60 | IambResult, | |
| 61 | ProgramAction, | |
| 62 | ProgramContext, | |
| 63 | ProgramStore, | |
| 64 | RoomAction, | |
| 65 | }, | |
| 66 | message::user_style, | |
| 62 | 67 | }; |
| 63 | 68 | |
| 64 | 69 | use self::{room::RoomState, welcome::WelcomeState}; |
| @@ -120,6 +125,7 @@ macro_rules! delegate { | ||
| 120 | 125 | match $s { |
| 121 | 126 | IambWindow::Room($id) => $e, |
| 122 | 127 | IambWindow::DirectList($id) => $e, |
| 128 | IambWindow::MemberList($id, _) => $e, | |
| 123 | 129 | IambWindow::RoomList($id) => $e, |
| 124 | 130 | IambWindow::SpaceList($id) => $e, |
| 125 | 131 | IambWindow::VerifyList($id) => $e, |
| @@ -130,6 +136,7 @@ macro_rules! delegate { | ||
| 130 | 136 | |
| 131 | 137 | pub enum IambWindow { |
| 132 | 138 | DirectList(DirectListState), |
| 139 | MemberList(MemberListState, OwnedRoomId), | |
| 133 | 140 | Room(RoomState), |
| 134 | 141 | VerifyList(VerifyListState), |
| 135 | 142 | RoomList(RoomListState), |
| @@ -146,19 +153,41 @@ impl IambWindow { | ||
| 146 | 153 | } |
| 147 | 154 | } |
| 148 | 155 | |
| 156 | pub fn room_command( | |
| 157 | &mut self, | |
| 158 | act: RoomAction, | |
| 159 | ctx: ProgramContext, | |
| 160 | store: &mut ProgramStore, | |
| 161 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { | |
| 162 | if let IambWindow::Room(w) = self { | |
| 163 | w.room_command(act, ctx, store) | |
| 164 | } else { | |
| 165 | let msg = "No room currently focused!"; | |
| 166 | let err = UIError::Failure(msg.into()); | |
| 167 | ||
| 168 | return Err(err); | |
| 169 | } | |
| 170 | } | |
| 171 | ||
| 149 | 172 | pub fn get_title(&self, store: &mut ProgramStore) -> String { |
| 150 | 173 | match self { |
| 151 | IambWindow::Room(w) => w.get_title(store), | |
| 152 | 174 | IambWindow::DirectList(_) => "Direct Messages".to_string(), |
| 153 | 175 | IambWindow::RoomList(_) => "Rooms".to_string(), |
| 154 | 176 | IambWindow::SpaceList(_) => "Spaces".to_string(), |
| 155 | 177 | IambWindow::VerifyList(_) => "Verifications".to_string(), |
| 156 | 178 | IambWindow::Welcome(_) => "Welcome to iamb".to_string(), |
| 179 | ||
| 180 | IambWindow::Room(w) => w.get_title(store), | |
| 181 | IambWindow::MemberList(_, room_id) => { | |
| 182 | let title = store.application.get_room_title(room_id.as_ref()); | |
| 183 | format!("Room Members: {}", title) | |
| 184 | }, | |
| 157 | 185 | } |
| 158 | 186 | } |
| 159 | 187 | } |
| 160 | 188 | |
| 161 | 189 | pub type DirectListState = ListState<DirectItem, IambInfo>; |
| 190 | pub type MemberListState = ListState<MemberItem, IambInfo>; | |
| 162 | 191 | pub type RoomListState = ListState<RoomItem, IambInfo>; |
| 163 | 192 | pub type SpaceListState = ListState<SpaceItem, IambInfo>; |
| 164 | 193 | pub type VerifyListState = ListState<VerifyItem, IambInfo>; |
| @@ -263,13 +292,35 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 263 | 292 | let dms = store.application.worker.direct_messages(); |
| 264 | 293 | let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store)); |
| 265 | 294 | state.set(items.collect()); |
| 266 | state.draw(inner, buf, focused, store); | |
| 295 | ||
| 296 | List::new(store) | |
| 297 | .empty_message("No direct messages yet!") | |
| 298 | .empty_alignment(Alignment::Center) | |
| 299 | .focus(focused) | |
| 300 | .render(inner, buf, state); | |
| 301 | }, | |
| 302 | IambWindow::MemberList(state, room_id) => { | |
| 303 | if let Ok(mems) = store.application.worker.members(room_id.clone()) { | |
| 304 | let items = mems.into_iter().map(MemberItem::new); | |
| 305 | state.set(items.collect()); | |
| 306 | } | |
| 307 | ||
| 308 | List::new(store) | |
| 309 | .empty_message("No users here yet!") | |
| 310 | .empty_alignment(Alignment::Center) | |
| 311 | .focus(focused) | |
| 312 | .render(inner, buf, state); | |
| 267 | 313 | }, |
| 268 | 314 | IambWindow::RoomList(state) => { |
| 269 | 315 | let joined = store.application.worker.joined_rooms(); |
| 270 | 316 | let items = joined.into_iter().map(|(id, name)| RoomItem::new(id, name, store)); |
| 271 | 317 | state.set(items.collect()); |
| 272 | state.draw(inner, buf, focused, store); | |
| 318 | ||
| 319 | List::new(store) | |
| 320 | .empty_message("You haven't joined any rooms yet") | |
| 321 | .empty_alignment(Alignment::Center) | |
| 322 | .focus(focused) | |
| 323 | .render(inner, buf, state); | |
| 273 | 324 | }, |
| 274 | 325 | IambWindow::SpaceList(state) => { |
| 275 | 326 | let spaces = store.application.worker.spaces(); |
| @@ -277,6 +328,12 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 277 | 328 | spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store)); |
| 278 | 329 | state.set(items.collect()); |
| 279 | 330 | state.draw(inner, buf, focused, store); |
| 331 | ||
| 332 | List::new(store) | |
| 333 | .empty_message("You haven't joined any spaces yet") | |
| 334 | .empty_alignment(Alignment::Center) | |
| 335 | .focus(focused) | |
| 336 | .render(inner, buf, state); | |
| 280 | 337 | }, |
| 281 | 338 | IambWindow::VerifyList(state) => { |
| 282 | 339 | let verifications = &store.application.verifications; |
| @@ -286,14 +343,29 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 286 | 343 | items.sort(); |
| 287 | 344 | |
| 288 | 345 | state.set(items); |
| 289 | state.draw(inner, buf, focused, store); | |
| 346 | ||
| 347 | List::new(store) | |
| 348 | .empty_message("No in-progress verifications") | |
| 349 | .empty_alignment(Alignment::Center) | |
| 350 | .focus(focused) | |
| 351 | .render(inner, buf, state); | |
| 290 | 352 | }, |
| 291 | 353 | IambWindow::Welcome(state) => state.draw(inner, buf, focused, store), |
| 292 | 354 | } |
| 293 | 355 | } |
| 294 | 356 | |
| 295 | 357 | fn dup(&self, store: &mut ProgramStore) -> Self { |
| 296 | delegate!(self, w => w.dup(store).into()) | |
| 358 | match self { | |
| 359 | IambWindow::Room(w) => w.dup(store).into(), | |
| 360 | IambWindow::DirectList(w) => w.dup(store).into(), | |
| 361 | IambWindow::MemberList(w, room_id) => { | |
| 362 | IambWindow::MemberList(w.dup(store), room_id.clone()) | |
| 363 | }, | |
| 364 | IambWindow::RoomList(w) => w.dup(store).into(), | |
| 365 | IambWindow::SpaceList(w) => w.dup(store).into(), | |
| 366 | IambWindow::VerifyList(w) => w.dup(store).into(), | |
| 367 | IambWindow::Welcome(w) => w.dup(store).into(), | |
| 368 | } | |
| 297 | 369 | } |
| 298 | 370 | |
| 299 | 371 | fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool { |
| @@ -314,6 +386,7 @@ impl Window<IambInfo> for IambWindow { | ||
| 314 | 386 | match self { |
| 315 | 387 | IambWindow::Room(room) => IambId::Room(room.id().to_owned()), |
| 316 | 388 | IambWindow::DirectList(_) => IambId::DirectList, |
| 389 | IambWindow::MemberList(_, room_id) => IambId::MemberList(room_id.clone()), | |
| 317 | 390 | IambWindow::RoomList(_) => IambId::RoomList, |
| 318 | 391 | IambWindow::SpaceList(_) => IambId::SpaceList, |
| 319 | 392 | IambWindow::VerifyList(_) => IambId::VerifyList, |
| @@ -334,6 +407,13 @@ impl Window<IambInfo> for IambWindow { | ||
| 334 | 407 | |
| 335 | 408 | return Ok(list.into()); |
| 336 | 409 | }, |
| 410 | IambId::MemberList(room_id) => { | |
| 411 | let id = IambBufferId::MemberList(room_id.clone()); | |
| 412 | let list = MemberListState::new(id, vec![]); | |
| 413 | let win = IambWindow::MemberList(list, room_id); | |
| 414 | ||
| 415 | return Ok(win); | |
| 416 | }, | |
| 337 | 417 | IambId::RoomList => { |
| 338 | 418 | let list = RoomListState::new(IambBufferId::RoomList, vec![]); |
| 339 | 419 | |
| @@ -412,6 +492,10 @@ impl ListItem<IambInfo> for RoomItem { | ||
| 412 | 492 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { |
| 413 | 493 | selected_text(self.name.as_str(), selected) |
| 414 | 494 | } |
| 495 | ||
| 496 | fn get_word(&self) -> Option<String> { | |
| 497 | self.room.room_id().to_string().into() | |
| 498 | } | |
| 415 | 499 | } |
| 416 | 500 | |
| 417 | 501 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for RoomItem { |
| @@ -451,6 +535,10 @@ impl ListItem<IambInfo> for DirectItem { | ||
| 451 | 535 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { |
| 452 | 536 | selected_text(self.name.as_str(), selected) |
| 453 | 537 | } |
| 538 | ||
| 539 | fn get_word(&self) -> Option<String> { | |
| 540 | self.room.room_id().to_string().into() | |
| 541 | } | |
| 454 | 542 | } |
| 455 | 543 | |
| 456 | 544 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for DirectItem { |
| @@ -490,6 +578,10 @@ impl ListItem<IambInfo> for SpaceItem { | ||
| 490 | 578 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { |
| 491 | 579 | selected_text(self.name.as_str(), selected) |
| 492 | 580 | } |
| 581 | ||
| 582 | fn get_word(&self) -> Option<String> { | |
| 583 | self.room.room_id().to_string().into() | |
| 584 | } | |
| 493 | 585 | } |
| 494 | 586 | |
| 495 | 587 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for SpaceItem { |
| @@ -667,6 +759,10 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 667 | 759 | |
| 668 | 760 | Text { lines } |
| 669 | 761 | } |
| 762 | ||
| 763 | fn get_word(&self) -> Option<String> { | |
| 764 | None | |
| 765 | } | |
| 670 | 766 | } |
| 671 | 767 | |
| 672 | 768 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem { |
| @@ -694,3 +790,77 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem { | ||
| 694 | 790 | } |
| 695 | 791 | } |
| 696 | 792 | } |
| 793 | ||
| 794 | #[derive(Clone)] | |
| 795 | pub struct MemberItem { | |
| 796 | member: RoomMember, | |
| 797 | } | |
| 798 | ||
| 799 | impl MemberItem { | |
| 800 | fn new(member: RoomMember) -> Self { | |
| 801 | Self { member } | |
| 802 | } | |
| 803 | } | |
| 804 | ||
| 805 | impl ToString for MemberItem { | |
| 806 | fn to_string(&self) -> String { | |
| 807 | self.member.user_id().to_string() | |
| 808 | } | |
| 809 | } | |
| 810 | ||
| 811 | impl ListItem<IambInfo> for MemberItem { | |
| 812 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { | |
| 813 | let mut style = user_style(self.member.user_id().as_str()); | |
| 814 | ||
| 815 | if selected { | |
| 816 | style = style.add_modifier(StyleModifier::REVERSED); | |
| 817 | } | |
| 818 | ||
| 819 | let user = Span::styled(self.to_string(), style); | |
| 820 | ||
| 821 | let state = match self.member.membership() { | |
| 822 | MembershipState::Ban => Span::raw(" (banned)").into(), | |
| 823 | MembershipState::Invite => Span::raw(" (invited)").into(), | |
| 824 | MembershipState::Knock => Span::raw(" (wants to join)").into(), | |
| 825 | MembershipState::Leave => Span::raw(" (left)").into(), | |
| 826 | MembershipState::Join => None, | |
| 827 | _ => None, | |
| 828 | }; | |
| 829 | ||
| 830 | if let Some(state) = state { | |
| 831 | Spans(vec![user, state]).into() | |
| 832 | } else { | |
| 833 | user.into() | |
| 834 | } | |
| 835 | } | |
| 836 | ||
| 837 | fn get_word(&self) -> Option<String> { | |
| 838 | self.member.user_id().to_string().into() | |
| 839 | } | |
| 840 | } | |
| 841 | ||
| 842 | impl Promptable<ProgramContext, ProgramStore, IambInfo> for MemberItem { | |
| 843 | fn prompt( | |
| 844 | &mut self, | |
| 845 | act: &PromptAction, | |
| 846 | _: &ProgramContext, | |
| 847 | _: &mut ProgramStore, | |
| 848 | ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> { | |
| 849 | match act { | |
| 850 | PromptAction::Submit => Ok(vec![]), | |
| 851 | PromptAction::Abort(_) => { | |
| 852 | let msg = "Cannot abort entry inside a list"; | |
| 853 | let err = EditError::Failure(msg.into()); | |
| 854 | ||
| 855 | Err(err) | |
| 856 | }, | |
| 857 | PromptAction::Recall(_, _) => { | |
| 858 | let msg = "Cannot recall history inside a list"; | |
| 859 | let err = EditError::Failure(msg.into()); | |
| 860 | ||
| 861 | Err(err) | |
| 862 | }, | |
| 863 | _ => Err(EditError::Unimplemented("unknown prompt action".to_string())), | |
| 864 | } | |
| 865 | } | |
| 866 | } | |
src/windows/room/chat.rs −4
| @@ -94,10 +94,6 @@ impl ChatState { | ||
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | if matches!(act, EditorAction::History(_)) { | |
| 98 | return; | |
| 99 | } | |
| 100 | ||
| 101 | 97 | if !store.application.settings.tunables.typing_notice { |
| 102 | 98 | return; |
| 103 | 99 | } |
src/windows/room/mod.rs +42 −9
| @@ -6,6 +6,7 @@ use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget}; | ||
| 6 | 6 | |
| 7 | 7 | use modalkit::{ |
| 8 | 8 | editing::action::{ |
| 9 | Action, | |
| 9 | 10 | EditInfo, |
| 10 | 11 | EditResult, |
| 11 | 12 | Editable, |
| @@ -15,11 +16,29 @@ use modalkit::{ | ||
| 15 | 16 | Promptable, |
| 16 | 17 | Scrollable, |
| 17 | 18 | }, |
| 18 | editing::base::{CloseFlags, MoveDir1D, PositionList, ScrollStyle, WordStyle}, | |
| 19 | editing::base::{ | |
| 20 | Axis, | |
| 21 | CloseFlags, | |
| 22 | Count, | |
| 23 | MoveDir1D, | |
| 24 | OpenTarget, | |
| 25 | PositionList, | |
| 26 | ScrollStyle, | |
| 27 | WordStyle, | |
| 28 | }, | |
| 29 | input::InputContext, | |
| 19 | 30 | widgets::{TermOffset, TerminalCursor, WindowOps}, |
| 20 | 31 | }; |
| 21 | 32 | |
| 22 | use crate::base::{IambInfo, IambResult, ProgramAction, ProgramContext, ProgramStore}; | |
| 33 | use crate::base::{ | |
| 34 | IambId, | |
| 35 | IambInfo, | |
| 36 | IambResult, | |
| 37 | ProgramAction, | |
| 38 | ProgramContext, | |
| 39 | ProgramStore, | |
| 40 | RoomAction, | |
| 41 | }; | |
| 23 | 42 | |
| 24 | 43 | use self::chat::ChatState; |
| 25 | 44 | use self::space::{Space, SpaceState}; |
| @@ -67,14 +86,28 @@ impl RoomState { | ||
| 67 | 86 | } |
| 68 | 87 | } |
| 69 | 88 | |
| 89 | pub fn room_command( | |
| 90 | &mut self, | |
| 91 | act: RoomAction, | |
| 92 | _: ProgramContext, | |
| 93 | _: &mut ProgramStore, | |
| 94 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { | |
| 95 | match act { | |
| 96 | RoomAction::Members(mut cmd) => { | |
| 97 | let width = Count::Exact(30); | |
| 98 | let act = | |
| 99 | cmd.default_axis(Axis::Vertical).default_relation(MoveDir1D::Next).window( | |
| 100 | OpenTarget::Application(IambId::MemberList(self.id().to_owned())), | |
| 101 | width.into(), | |
| 102 | ); | |
| 103 | ||
| 104 | Ok(vec![(act, cmd.context.take())]) | |
| 105 | }, | |
| 106 | } | |
| 107 | } | |
| 108 | ||
| 70 | 109 | pub fn get_title(&self, store: &mut ProgramStore) -> String { |
| 71 | store | |
| 72 | .application | |
| 73 | .rooms | |
| 74 | .get(self.id()) | |
| 75 | .and_then(|i| i.name.as_ref()) | |
| 76 | .map(String::from) | |
| 77 | .unwrap_or_else(|| "Untitled Matrix Room".to_string()) | |
| 110 | store.application.get_room_title(self.id()) | |
| 78 | 111 | } |
| 79 | 112 | |
| 80 | 113 | pub fn focus_toggle(&mut self) { |
src/windows/welcome.md +2 −1
| @@ -3,8 +3,8 @@ | ||
| 3 | 3 | ## Useful Keybindings |
| 4 | 4 | |
| 5 | 5 | - `<Enter>` will send a typed message |
| 6 | - `^V^J` can be used in Insert mode to enter a newline without submitting | |
| 6 | 7 | - `O`/`o` can be used to insert blank lines before and after the cursor line |
| 7 | - `^O` can be used in Insert mode to enter a single Normal mode keybinding sequence | |
| 8 | 8 | - `^Wm` can be used to toggle whether the message bar or scrollback is selected |
| 9 | 9 | - `^Wz` can be used to toggle whether the current window takes up the full screen |
| 10 | 10 | |
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | |
| 13 | 13 | - `:dms` will open a list of direct messages |
| 14 | 14 | - `:rooms` will open a list of joined rooms |
| 15 | - `:members` will open a list of members for the currently focused room or space | |
| 15 | 16 | - `:spaces` will open a list of joined spaces |
| 16 | 17 | - `:join` can be used to switch to join a new room or start a direct message |
| 17 | 18 | - `:split` and `:vsplit` can be used to open rooms in a new window |
src/worker.rs +22 −1
| @@ -15,7 +15,7 @@ use matrix_sdk::{ | ||
| 15 | 15 | encryption::verification::{SasVerification, Verification}, |
| 16 | 16 | event_handler::Ctx, |
| 17 | 17 | reqwest, |
| 18 | room::{Messages, MessagesOptions, Room as MatrixRoom}, | |
| 18 | room::{Messages, MessagesOptions, Room as MatrixRoom, RoomMember}, | |
| 19 | 19 | ruma::{ |
| 20 | 20 | api::client::{ |
| 21 | 21 | room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, |
| @@ -102,6 +102,7 @@ pub enum WorkerTask { | ||
| 102 | 102 | GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>), |
| 103 | 103 | JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>), |
| 104 | 104 | JoinedRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>), |
| 105 | Members(OwnedRoomId, ClientReply<IambResult<Vec<RoomMember>>>), | |
| 105 | 106 | SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), |
| 106 | 107 | Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), |
| 107 | 108 | SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>), |
| @@ -187,6 +188,14 @@ impl Requester { | ||
| 187 | 188 | return response.recv(); |
| 188 | 189 | } |
| 189 | 190 | |
| 191 | pub fn members(&self, room_id: OwnedRoomId) -> IambResult<Vec<RoomMember>> { | |
| 192 | let (reply, response) = oneshot(); | |
| 193 | ||
| 194 | self.tx.send(WorkerTask::Members(room_id, reply)).unwrap(); | |
| 195 | ||
| 196 | return response.recv(); | |
| 197 | } | |
| 198 | ||
| 190 | 199 | pub fn space_members(&self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { |
| 191 | 200 | let (reply, response) = oneshot(); |
| 192 | 201 | |
| @@ -327,6 +336,10 @@ impl ClientWorker { | ||
| 327 | 336 | assert!(self.initialized); |
| 328 | 337 | reply.send(self.login_and_sync(style).await); |
| 329 | 338 | }, |
| 339 | WorkerTask::Members(room_id, reply) => { | |
| 340 | assert!(self.initialized); | |
| 341 | reply.send(self.members(room_id).await); | |
| 342 | }, | |
| 330 | 343 | WorkerTask::SpaceMembers(space, reply) => { |
| 331 | 344 | assert!(self.initialized); |
| 332 | 345 | reply.send(self.space_members(space).await); |
| @@ -744,6 +757,14 @@ impl ClientWorker { | ||
| 744 | 757 | } |
| 745 | 758 | } |
| 746 | 759 | |
| 760 | async fn members(&mut self, room_id: OwnedRoomId) -> IambResult<Vec<RoomMember>> { | |
| 761 | if let Some(room) = self.client.get_room(room_id.as_ref()) { | |
| 762 | Ok(room.active_members().await.map_err(IambError::from)?) | |
| 763 | } else { | |
| 764 | Err(IambError::UnknownRoom(room_id).into()) | |
| 765 | } | |
| 766 | } | |
| 767 | ||
| 747 | 768 | async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { |
| 748 | 769 | let mut req = SpaceHierarchyRequest::new(&space); |
| 749 | 770 | req.limit = Some(1000u32.into()); |