mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Support completing commands, usernames, and room names (#44)
This commit is contained in:
parent
e3be8c16cb
commit
0ed1d53946
13 changed files with 491 additions and 91 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -860,6 +860,12 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "endian-type"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "errno"
|
name = "errno"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
|
@ -1302,7 +1308,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iamb"
|
name = "iamb"
|
||||||
version = "0.0.4"
|
version = "0.0.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
@ -1876,9 +1882,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "modalkit"
|
name = "modalkit"
|
||||||
version = "0.0.11"
|
version = "0.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bd7bd7d02d65842dab4cea53016cf29c16cde197131dd6d9eea95662deb77778"
|
checksum = "9a4e5226a5d33a7bdf5b4fc067baa211c94f21aa6667af5eec8b357a8af5e4ba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anymap2",
|
"anymap2",
|
||||||
"arboard",
|
"arboard",
|
||||||
|
@ -1888,10 +1894,12 @@ dependencies = [
|
||||||
"intervaltree",
|
"intervaltree",
|
||||||
"libc",
|
"libc",
|
||||||
"nom",
|
"nom",
|
||||||
|
"radix_trie",
|
||||||
"regex",
|
"regex",
|
||||||
"ropey",
|
"ropey",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tui",
|
"tui",
|
||||||
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1900,6 +1908,15 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
|
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nibble_vec"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43"
|
||||||
|
dependencies = [
|
||||||
|
"smallvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.24.3"
|
version = "0.24.3"
|
||||||
|
@ -2344,6 +2361,16 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "radix_trie"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd"
|
||||||
|
dependencies = [
|
||||||
|
"endian-type",
|
||||||
|
"nibble_vec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
|
|
|
@ -39,7 +39,7 @@ unicode-width = "0.1.10"
|
||||||
url = {version = "^2.2.2", features = ["serde"]}
|
url = {version = "^2.2.2", features = ["serde"]}
|
||||||
|
|
||||||
[dependencies.modalkit]
|
[dependencies.modalkit]
|
||||||
version = "0.0.11"
|
version = "0.0.12"
|
||||||
|
|
||||||
[dependencies.matrix-sdk]
|
[dependencies.matrix-sdk]
|
||||||
version = "0.6"
|
version = "0.6"
|
||||||
|
|
228
src/base.rs
228
src/base.rs
|
@ -1,8 +1,11 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use emojis::Emoji;
|
||||||
use tokio::sync::Mutex as AsyncMutex;
|
use tokio::sync::Mutex as AsyncMutex;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
|
@ -23,6 +26,7 @@ use matrix_sdk::{
|
||||||
AnyMessageLikeEvent,
|
AnyMessageLikeEvent,
|
||||||
MessageLikeEvent,
|
MessageLikeEvent,
|
||||||
},
|
},
|
||||||
|
presence::PresenceState,
|
||||||
EventId,
|
EventId,
|
||||||
OwnedEventId,
|
OwnedEventId,
|
||||||
OwnedRoomId,
|
OwnedRoomId,
|
||||||
|
@ -42,11 +46,15 @@ use modalkit::{
|
||||||
ApplicationStore,
|
ApplicationStore,
|
||||||
ApplicationWindowId,
|
ApplicationWindowId,
|
||||||
},
|
},
|
||||||
|
base::{CommandType, WordStyle},
|
||||||
|
completion::{complete_path, CompletionMap},
|
||||||
context::EditContext,
|
context::EditContext,
|
||||||
|
cursor::Cursor,
|
||||||
|
rope::EditRope,
|
||||||
store::Store,
|
store::Store,
|
||||||
},
|
},
|
||||||
env::vim::{
|
env::vim::{
|
||||||
command::{CommandContext, VimCommand, VimCommandMachine},
|
command::{CommandContext, CommandDescription, VimCommand, VimCommandMachine},
|
||||||
keybindings::VimMachine,
|
keybindings::VimMachine,
|
||||||
VimContext,
|
VimContext,
|
||||||
},
|
},
|
||||||
|
@ -66,6 +74,20 @@ use crate::{
|
||||||
ApplicationSettings,
|
ApplicationSettings,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const MATRIX_ID_WORD: WordStyle = WordStyle::CharSet(is_mxid_char);
|
||||||
|
|
||||||
|
/// Find the boundaries for a Matrix username, room alias, or room ID.
|
||||||
|
///
|
||||||
|
/// Technically "[" and "]" should be here since IPv6 addresses are allowed
|
||||||
|
/// in the server name, but in practice that should be uncommon, and people
|
||||||
|
/// can just use `gf` and friends in Visual mode instead.
|
||||||
|
fn is_mxid_char(c: char) -> bool {
|
||||||
|
return c >= 'a' && c <= 'z' ||
|
||||||
|
c >= 'A' && c <= 'Z' ||
|
||||||
|
c >= '0' && c <= '9' ||
|
||||||
|
":-./@_#!".contains(c);
|
||||||
|
}
|
||||||
|
|
||||||
const ROOM_FETCH_DEBOUNCE: Duration = Duration::from_secs(2);
|
const ROOM_FETCH_DEBOUNCE: Duration = Duration::from_secs(2);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
@ -528,13 +550,28 @@ impl RoomInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn emoji_map() -> CompletionMap<String, &'static Emoji> {
|
||||||
|
let mut emojis = CompletionMap::default();
|
||||||
|
|
||||||
|
for emoji in emojis::iter() {
|
||||||
|
for shortcode in emoji.shortcodes() {
|
||||||
|
emojis.insert(shortcode.to_string(), emoji);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return emojis;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ChatStore {
|
pub struct ChatStore {
|
||||||
|
pub cmds: ProgramCommands,
|
||||||
pub worker: Requester,
|
pub worker: Requester,
|
||||||
pub rooms: HashMap<OwnedRoomId, RoomInfo>,
|
pub rooms: CompletionMap<OwnedRoomId, RoomInfo>,
|
||||||
pub names: HashMap<String, OwnedRoomId>,
|
pub names: CompletionMap<String, OwnedRoomId>,
|
||||||
|
pub presences: CompletionMap<OwnedUserId, PresenceState>,
|
||||||
pub verifications: HashMap<String, SasVerification>,
|
pub verifications: HashMap<String, SasVerification>,
|
||||||
pub settings: ApplicationSettings,
|
pub settings: ApplicationSettings,
|
||||||
pub need_load: HashSet<OwnedRoomId>,
|
pub need_load: HashSet<OwnedRoomId>,
|
||||||
|
pub emojis: CompletionMap<String, &'static Emoji>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatStore {
|
impl ChatStore {
|
||||||
|
@ -543,10 +580,13 @@ impl ChatStore {
|
||||||
worker,
|
worker,
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
|
cmds: crate::commands::setup_commands(),
|
||||||
names: Default::default(),
|
names: Default::default(),
|
||||||
rooms: Default::default(),
|
rooms: Default::default(),
|
||||||
|
presences: Default::default(),
|
||||||
verifications: Default::default(),
|
verifications: Default::default(),
|
||||||
need_load: Default::default(),
|
need_load: Default::default(),
|
||||||
|
emojis: emoji_map(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,10 +627,10 @@ impl ChatStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_older(&mut self, limit: u32) {
|
pub fn load_older(&mut self, limit: u32) {
|
||||||
let ChatStore { need_load, rooms, worker, .. } = self;
|
let ChatStore { need_load, presences, rooms, worker, .. } = self;
|
||||||
|
|
||||||
for room_id in std::mem::take(need_load).into_iter() {
|
for room_id in std::mem::take(need_load).into_iter() {
|
||||||
let info = rooms.entry(room_id.clone()).or_default();
|
let info = rooms.get_or_default(room_id.clone());
|
||||||
|
|
||||||
if info.recently_fetched() {
|
if info.recently_fetched() {
|
||||||
need_load.insert(room_id);
|
need_load.insert(room_id);
|
||||||
|
@ -610,6 +650,9 @@ impl ChatStore {
|
||||||
match res {
|
match res {
|
||||||
Ok((fetch_id, msgs)) => {
|
Ok((fetch_id, msgs)) => {
|
||||||
for msg in msgs.into_iter() {
|
for msg in msgs.into_iter() {
|
||||||
|
let sender = msg.sender().to_owned();
|
||||||
|
let _ = presences.get_or_default(sender);
|
||||||
|
|
||||||
match msg {
|
match msg {
|
||||||
AnyMessageLikeEvent::RoomMessage(msg) => {
|
AnyMessageLikeEvent::RoomMessage(msg) => {
|
||||||
info.insert(msg);
|
info.insert(msg);
|
||||||
|
@ -639,11 +682,11 @@ impl ChatStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_room_info(&mut self, room_id: OwnedRoomId) -> &mut RoomInfo {
|
pub fn get_room_info(&mut self, room_id: OwnedRoomId) -> &mut RoomInfo {
|
||||||
self.rooms.entry(room_id).or_default()
|
self.rooms.get_or_default(room_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_room_name(&mut self, room_id: &RoomId, name: &str) {
|
pub fn set_room_name(&mut self, room_id: &RoomId, name: &str) {
|
||||||
self.rooms.entry(room_id.to_owned()).or_default().name = name.to_string().into();
|
self.rooms.get_or_default(room_id.to_owned()).name = name.to_string().into();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_sas(&mut self, sas: SasVerification) {
|
pub fn insert_sas(&mut self, sas: SasVerification) {
|
||||||
|
@ -686,7 +729,7 @@ impl RoomFocus {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||||
pub enum IambBufferId {
|
pub enum IambBufferId {
|
||||||
Command,
|
Command(CommandType),
|
||||||
Room(OwnedRoomId, RoomFocus),
|
Room(OwnedRoomId, RoomFocus),
|
||||||
DirectList,
|
DirectList,
|
||||||
MemberList(OwnedRoomId),
|
MemberList(OwnedRoomId),
|
||||||
|
@ -699,7 +742,7 @@ pub enum IambBufferId {
|
||||||
impl IambBufferId {
|
impl IambBufferId {
|
||||||
pub fn to_window(&self) -> Option<IambId> {
|
pub fn to_window(&self) -> Option<IambId> {
|
||||||
match self {
|
match self {
|
||||||
IambBufferId::Command => None,
|
IambBufferId::Command(_) => None,
|
||||||
IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())),
|
IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())),
|
||||||
IambBufferId::DirectList => Some(IambId::DirectList),
|
IambBufferId::DirectList => Some(IambId::DirectList),
|
||||||
IambBufferId::MemberList(room) => Some(IambId::MemberList(room.clone())),
|
IambBufferId::MemberList(room) => Some(IambId::MemberList(room.clone())),
|
||||||
|
@ -719,6 +762,133 @@ impl ApplicationInfo for IambInfo {
|
||||||
type Action = IambAction;
|
type Action = IambAction;
|
||||||
type WindowId = IambId;
|
type WindowId = IambId;
|
||||||
type ContentId = IambBufferId;
|
type ContentId = IambBufferId;
|
||||||
|
|
||||||
|
fn complete(
|
||||||
|
text: &EditRope,
|
||||||
|
cursor: &mut Cursor,
|
||||||
|
content: &IambBufferId,
|
||||||
|
store: &mut ProgramStore,
|
||||||
|
) -> Vec<String> {
|
||||||
|
match content {
|
||||||
|
IambBufferId::Command(CommandType::Command) => complete_cmdbar(text, cursor, store),
|
||||||
|
IambBufferId::Command(CommandType::Search) => vec![],
|
||||||
|
|
||||||
|
IambBufferId::Room(_, RoomFocus::MessageBar) => {
|
||||||
|
complete_matrix_names(text, cursor, store)
|
||||||
|
},
|
||||||
|
IambBufferId::Room(_, RoomFocus::Scrollback) => vec![],
|
||||||
|
|
||||||
|
IambBufferId::DirectList => vec![],
|
||||||
|
IambBufferId::MemberList(_) => vec![],
|
||||||
|
IambBufferId::RoomList => vec![],
|
||||||
|
IambBufferId::SpaceList => vec![],
|
||||||
|
IambBufferId::VerifyList => vec![],
|
||||||
|
IambBufferId::Welcome => vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn content_of_command(ct: CommandType) -> IambBufferId {
|
||||||
|
IambBufferId::Command(ct)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complete_users(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> Vec<String> {
|
||||||
|
let id = text
|
||||||
|
.get_prefix_word_mut(cursor, &MATRIX_ID_WORD)
|
||||||
|
.unwrap_or_else(EditRope::empty);
|
||||||
|
let id = Cow::from(&id);
|
||||||
|
|
||||||
|
store
|
||||||
|
.application
|
||||||
|
.presences
|
||||||
|
.complete(id.as_ref())
|
||||||
|
.into_iter()
|
||||||
|
.map(|i| i.to_string())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complete_matrix_names(
|
||||||
|
text: &EditRope,
|
||||||
|
cursor: &mut Cursor,
|
||||||
|
store: &ProgramStore,
|
||||||
|
) -> Vec<String> {
|
||||||
|
let id = text
|
||||||
|
.get_prefix_word_mut(cursor, &MATRIX_ID_WORD)
|
||||||
|
.unwrap_or_else(EditRope::empty);
|
||||||
|
let id = Cow::from(&id);
|
||||||
|
|
||||||
|
let list = store.application.names.complete(id.as_ref());
|
||||||
|
if !list.is_empty() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
let list = store.application.presences.complete(id.as_ref());
|
||||||
|
if !list.is_empty() {
|
||||||
|
return list.into_iter().map(|i| i.to_string()).collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
store
|
||||||
|
.application
|
||||||
|
.rooms
|
||||||
|
.complete(id.as_ref())
|
||||||
|
.into_iter()
|
||||||
|
.map(|i| i.to_string())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complete_emoji(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> Vec<String> {
|
||||||
|
let sc = text.get_prefix_word_mut(cursor, &WordStyle::Little);
|
||||||
|
let sc = sc.unwrap_or_else(EditRope::empty);
|
||||||
|
let sc = Cow::from(&sc);
|
||||||
|
|
||||||
|
store.application.emojis.complete(sc.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complete_cmdarg(
|
||||||
|
desc: CommandDescription,
|
||||||
|
text: &EditRope,
|
||||||
|
cursor: &mut Cursor,
|
||||||
|
store: &ProgramStore,
|
||||||
|
) -> Vec<String> {
|
||||||
|
let cmd = match store.application.cmds.get(desc.command.as_str()) {
|
||||||
|
Ok(cmd) => cmd,
|
||||||
|
Err(_) => return vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
match cmd.name.as_str() {
|
||||||
|
"cancel" | "dms" | "edit" | "redact" | "reply" => vec![],
|
||||||
|
"members" | "rooms" | "spaces" | "welcome" => vec![],
|
||||||
|
"download" | "open" | "upload" => complete_path(text, cursor),
|
||||||
|
"react" | "unreact" => complete_emoji(text, cursor, store),
|
||||||
|
|
||||||
|
"invite" => complete_users(text, cursor, store),
|
||||||
|
"join" => complete_matrix_names(text, cursor, store),
|
||||||
|
"room" => vec![],
|
||||||
|
"verify" => vec![],
|
||||||
|
_ => panic!("unknown command {}", cmd.name.as_str()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complete_cmdbar(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> Vec<String> {
|
||||||
|
let eo = text.cursor_to_offset(cursor);
|
||||||
|
let slice = text.slice(0.into(), eo, false);
|
||||||
|
let cow = Cow::from(&slice);
|
||||||
|
|
||||||
|
match CommandDescription::from_str(cow.as_ref()) {
|
||||||
|
Ok(desc) => {
|
||||||
|
if desc.arg.untrimmed.is_empty() {
|
||||||
|
// Complete command name and set cursor position.
|
||||||
|
let _ = text.get_prefix_word_mut(cursor, &WordStyle::Little);
|
||||||
|
store.application.cmds.complete_name(desc.command.as_str())
|
||||||
|
} else {
|
||||||
|
// Complete command argument.
|
||||||
|
complete_cmdarg(desc, text, cursor, store)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Can't parse command text, so return zero completions.
|
||||||
|
Err(_) => vec![],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -804,4 +974,44 @@ pub mod tests {
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_complete_cmdbar() {
|
||||||
|
let store = mock_store().await;
|
||||||
|
|
||||||
|
let text = EditRope::from("invite ");
|
||||||
|
let mut cursor = Cursor::new(0, 7);
|
||||||
|
let id = text
|
||||||
|
.get_prefix_word_mut(&mut cursor, &MATRIX_ID_WORD)
|
||||||
|
.unwrap_or_else(EditRope::empty);
|
||||||
|
assert_eq!(id.to_string(), "");
|
||||||
|
assert_eq!(cursor, Cursor::new(0, 7));
|
||||||
|
|
||||||
|
let text = EditRope::from("invite ");
|
||||||
|
let mut cursor = Cursor::new(0, 7);
|
||||||
|
let res = complete_cmdbar(&text, &mut cursor, &store);
|
||||||
|
assert_eq!(res, vec![
|
||||||
|
"@user1:example.com",
|
||||||
|
"@user2:example.com",
|
||||||
|
"@user3:example.com",
|
||||||
|
"@user4:example.com",
|
||||||
|
"@user5:example.com"
|
||||||
|
]);
|
||||||
|
|
||||||
|
let text = EditRope::from("invite ignored");
|
||||||
|
let mut cursor = Cursor::new(0, 7);
|
||||||
|
let res = complete_cmdbar(&text, &mut cursor, &store);
|
||||||
|
assert_eq!(res, vec![
|
||||||
|
"@user1:example.com",
|
||||||
|
"@user2:example.com",
|
||||||
|
"@user3:example.com",
|
||||||
|
"@user4:example.com",
|
||||||
|
"@user5:example.com"
|
||||||
|
]);
|
||||||
|
|
||||||
|
let text = EditRope::from("invite @user1ignored");
|
||||||
|
let mut cursor = Cursor::new(0, 13);
|
||||||
|
let res = complete_cmdbar(&text, &mut cursor, &store);
|
||||||
|
assert_eq!(res, vec!["@user1:example.com"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -395,24 +395,76 @@ fn iamb_open(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_iamb_commands(cmds: &mut ProgramCommands) {
|
fn add_iamb_commands(cmds: &mut ProgramCommands) {
|
||||||
cmds.add_command(ProgramCommand { names: vec!["cancel".into()], f: iamb_cancel });
|
cmds.add_command(ProgramCommand {
|
||||||
cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms });
|
name: "cancel".into(),
|
||||||
cmds.add_command(ProgramCommand { names: vec!["download".into()], f: iamb_download });
|
aliases: vec![],
|
||||||
cmds.add_command(ProgramCommand { names: vec!["open".into()], f: iamb_open });
|
f: iamb_cancel,
|
||||||
cmds.add_command(ProgramCommand { names: vec!["edit".into()], f: iamb_edit });
|
});
|
||||||
cmds.add_command(ProgramCommand { names: vec!["invite".into()], f: iamb_invite });
|
cmds.add_command(ProgramCommand { name: "dms".into(), aliases: vec![], f: iamb_dms });
|
||||||
cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join });
|
cmds.add_command(ProgramCommand {
|
||||||
cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members });
|
name: "download".into(),
|
||||||
cmds.add_command(ProgramCommand { names: vec!["react".into()], f: iamb_react });
|
aliases: vec![],
|
||||||
cmds.add_command(ProgramCommand { names: vec!["redact".into()], f: iamb_redact });
|
f: iamb_download,
|
||||||
cmds.add_command(ProgramCommand { names: vec!["reply".into()], f: iamb_reply });
|
});
|
||||||
cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms });
|
cmds.add_command(ProgramCommand { name: "open".into(), aliases: vec![], f: iamb_open });
|
||||||
cmds.add_command(ProgramCommand { names: vec!["room".into()], f: iamb_room });
|
cmds.add_command(ProgramCommand { name: "edit".into(), aliases: vec![], f: iamb_edit });
|
||||||
cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces });
|
cmds.add_command(ProgramCommand {
|
||||||
cmds.add_command(ProgramCommand { names: vec!["unreact".into()], f: iamb_unreact });
|
name: "invite".into(),
|
||||||
cmds.add_command(ProgramCommand { names: vec!["upload".into()], f: iamb_upload });
|
aliases: vec![],
|
||||||
cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify });
|
f: iamb_invite,
|
||||||
cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome });
|
});
|
||||||
|
cmds.add_command(ProgramCommand { name: "join".into(), aliases: vec![], f: iamb_join });
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "members".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_members,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "react".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_react,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "redact".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_redact,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "reply".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_reply,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "rooms".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_rooms,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand { name: "room".into(), aliases: vec![], f: iamb_room });
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "spaces".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_spaces,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "unreact".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_unreact,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "upload".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_upload,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "verify".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_verify,
|
||||||
|
});
|
||||||
|
cmds.add_command(ProgramCommand {
|
||||||
|
name: "welcome".into(),
|
||||||
|
aliases: vec![],
|
||||||
|
f: iamb_welcome,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_commands() -> ProgramCommands {
|
pub fn setup_commands() -> ProgramCommands {
|
||||||
|
|
|
@ -1,34 +1,21 @@
|
||||||
use modalkit::{
|
use modalkit::{
|
||||||
editing::action::WindowAction,
|
editing::action::WindowAction,
|
||||||
editing::base::WordStyle,
|
|
||||||
env::vim::keybindings::{InputStep, VimBindings},
|
env::vim::keybindings::{InputStep, VimBindings},
|
||||||
env::vim::VimMode,
|
env::vim::VimMode,
|
||||||
input::bindings::{EdgeEvent, EdgeRepeat, InputBindings},
|
input::bindings::{EdgeEvent, EdgeRepeat, InputBindings},
|
||||||
input::key::TerminalKey,
|
input::key::TerminalKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::base::{IambAction, IambInfo, Keybindings};
|
use crate::base::{IambAction, IambInfo, Keybindings, MATRIX_ID_WORD};
|
||||||
|
|
||||||
type IambStep = InputStep<IambInfo>;
|
type IambStep = InputStep<IambInfo>;
|
||||||
|
|
||||||
/// Find the boundaries for a Matrix username, room alias, or room ID.
|
|
||||||
///
|
|
||||||
/// Technically "[" and "]" should be here since IPv6 addresses are allowed
|
|
||||||
/// in the server name, but in practice that should be uncommon, and people
|
|
||||||
/// can just use `gf` and friends in Visual mode instead.
|
|
||||||
fn is_mxid_char(c: char) -> bool {
|
|
||||||
return c >= 'a' && c <= 'z' ||
|
|
||||||
c >= 'A' && c <= 'Z' ||
|
|
||||||
c >= '0' && c <= '9' ||
|
|
||||||
":-./@_#!".contains(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn setup_keybindings() -> Keybindings {
|
pub fn setup_keybindings() -> Keybindings {
|
||||||
let mut ism = Keybindings::empty();
|
let mut ism = Keybindings::empty();
|
||||||
|
|
||||||
let vim = VimBindings::default()
|
let vim = VimBindings::default()
|
||||||
.submit_on_enter()
|
.submit_on_enter()
|
||||||
.cursor_open(WordStyle::CharSet(is_mxid_char));
|
.cursor_open(MATRIX_ID_WORD.clone());
|
||||||
|
|
||||||
vim.setup(&mut ism);
|
vim.setup(&mut ism);
|
||||||
|
|
||||||
|
|
|
@ -54,13 +54,11 @@ use crate::{
|
||||||
AsyncProgramStore,
|
AsyncProgramStore,
|
||||||
ChatStore,
|
ChatStore,
|
||||||
IambAction,
|
IambAction,
|
||||||
IambBufferId,
|
|
||||||
IambError,
|
IambError,
|
||||||
IambId,
|
IambId,
|
||||||
IambInfo,
|
IambInfo,
|
||||||
IambResult,
|
IambResult,
|
||||||
ProgramAction,
|
ProgramAction,
|
||||||
ProgramCommands,
|
|
||||||
ProgramContext,
|
ProgramContext,
|
||||||
ProgramStore,
|
ProgramStore,
|
||||||
},
|
},
|
||||||
|
@ -116,7 +114,6 @@ struct Application {
|
||||||
terminal: Terminal<CrosstermBackend<Stdout>>,
|
terminal: Terminal<CrosstermBackend<Stdout>>,
|
||||||
bindings: KeyManager<TerminalKey, ProgramAction, RepeatType, ProgramContext>,
|
bindings: KeyManager<TerminalKey, ProgramAction, RepeatType, ProgramContext>,
|
||||||
actstack: VecDeque<(ProgramAction, ProgramContext)>,
|
actstack: VecDeque<(ProgramAction, ProgramContext)>,
|
||||||
cmds: ProgramCommands,
|
|
||||||
screen: ScreenState<IambWindow, IambInfo>,
|
screen: ScreenState<IambWindow, IambInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +135,6 @@ impl Application {
|
||||||
|
|
||||||
let bindings = crate::keybindings::setup_keybindings();
|
let bindings = crate::keybindings::setup_keybindings();
|
||||||
let bindings = KeyManager::new(bindings);
|
let bindings = KeyManager::new(bindings);
|
||||||
let cmds = crate::commands::setup_commands();
|
|
||||||
|
|
||||||
let mut locked = store.lock().await;
|
let mut locked = store.lock().await;
|
||||||
|
|
||||||
|
@ -149,7 +145,7 @@ impl Application {
|
||||||
.or_else(|| IambWindow::open(IambId::Welcome, locked.deref_mut()).ok())
|
.or_else(|| IambWindow::open(IambId::Welcome, locked.deref_mut()).ok())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let cmd = CommandBarState::new(IambBufferId::Command, locked.deref_mut());
|
let cmd = CommandBarState::new(locked.deref_mut());
|
||||||
let screen = ScreenState::new(win, cmd);
|
let screen = ScreenState::new(win, cmd);
|
||||||
|
|
||||||
let worker = locked.application.worker.clone();
|
let worker = locked.application.worker.clone();
|
||||||
|
@ -163,7 +159,6 @@ impl Application {
|
||||||
terminal,
|
terminal,
|
||||||
bindings,
|
bindings,
|
||||||
actstack,
|
actstack,
|
||||||
cmds,
|
|
||||||
screen,
|
screen,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -321,7 +316,7 @@ impl Application {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
Action::Command(act) => {
|
Action::Command(act) => {
|
||||||
let acts = self.cmds.command(&act, &ctx)?;
|
let acts = store.application.cmds.command(&act, &ctx)?;
|
||||||
self.action_prepend(acts);
|
self.action_prepend(acts);
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
|
@ -208,6 +208,14 @@ pub async fn mock_store() -> ProgramStore {
|
||||||
let worker = Requester { tx, client };
|
let worker = Requester { tx, client };
|
||||||
|
|
||||||
let mut store = ChatStore::new(worker, mock_settings());
|
let mut store = ChatStore::new(worker, mock_settings());
|
||||||
|
|
||||||
|
// Add presence information.
|
||||||
|
store.presences.get_or_default(TEST_USER1.clone());
|
||||||
|
store.presences.get_or_default(TEST_USER2.clone());
|
||||||
|
store.presences.get_or_default(TEST_USER3.clone());
|
||||||
|
store.presences.get_or_default(TEST_USER4.clone());
|
||||||
|
store.presences.get_or_default(TEST_USER5.clone());
|
||||||
|
|
||||||
let room_id = TEST_ROOM1_ID.clone();
|
let room_id = TEST_ROOM1_ID.clone();
|
||||||
let info = mock_room();
|
let info = mock_room();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::cmp::{Ord, Ordering, PartialOrd};
|
use std::cmp::{Ord, Ordering, PartialOrd};
|
||||||
use std::collections::hash_map::Entry;
|
|
||||||
|
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
encryption::verification::{format_emojis, SasVerification},
|
encryption::verification::{format_emojis, SasVerification},
|
||||||
|
@ -45,7 +44,9 @@ use modalkit::{
|
||||||
ScrollStyle,
|
ScrollStyle,
|
||||||
ViewportContext,
|
ViewportContext,
|
||||||
WordStyle,
|
WordStyle,
|
||||||
|
WriteFlags,
|
||||||
},
|
},
|
||||||
|
completion::CompletionList,
|
||||||
},
|
},
|
||||||
widgets::{
|
widgets::{
|
||||||
list::{List, ListCursor, ListItem, ListState},
|
list::{List, ListCursor, ListItem, ListState},
|
||||||
|
@ -469,6 +470,19 @@ impl WindowOps<IambInfo> for IambWindow {
|
||||||
delegate!(self, w => w.close(flags, store))
|
delegate!(self, w => w.close(flags, store))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write(
|
||||||
|
&mut self,
|
||||||
|
path: Option<&str>,
|
||||||
|
flags: WriteFlags,
|
||||||
|
store: &mut ProgramStore,
|
||||||
|
) -> IambResult<EditInfo> {
|
||||||
|
delegate!(self, w => w.write(path, flags, store))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_completions(&self) -> Option<CompletionList> {
|
||||||
|
delegate!(self, w => w.get_completions())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
||||||
delegate!(self, w => w.get_cursor_word(style))
|
delegate!(self, w => w.get_cursor_word(style))
|
||||||
}
|
}
|
||||||
|
@ -575,21 +589,18 @@ impl Window<IambInfo> for IambWindow {
|
||||||
fn find(name: String, store: &mut ProgramStore) -> IambResult<Self> {
|
fn find(name: String, store: &mut ProgramStore) -> IambResult<Self> {
|
||||||
let ChatStore { names, worker, .. } = &mut store.application;
|
let ChatStore { names, worker, .. } = &mut store.application;
|
||||||
|
|
||||||
match names.entry(name) {
|
if let Some(room) = names.get_mut(&name) {
|
||||||
Entry::Vacant(v) => {
|
let id = IambId::Room(room.clone());
|
||||||
let room_id = worker.join_room(v.key().to_string())?;
|
|
||||||
v.insert(room_id.clone());
|
IambWindow::open(id, store)
|
||||||
|
} else {
|
||||||
|
let room_id = worker.join_room(name.clone())?;
|
||||||
|
names.insert(name, room_id.clone());
|
||||||
|
|
||||||
let (room, name, tags) = store.application.worker.get_room(room_id)?;
|
let (room, name, tags) = store.application.worker.get_room(room_id)?;
|
||||||
let room = RoomState::new(room, name, tags, store);
|
let room = RoomState::new(room, name, tags, store);
|
||||||
|
|
||||||
Ok(room.into())
|
Ok(room.into())
|
||||||
},
|
|
||||||
Entry::Occupied(o) => {
|
|
||||||
let id = IambId::Room(o.get().clone());
|
|
||||||
|
|
||||||
IambWindow::open(id, store)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,11 +631,16 @@ impl RoomItem {
|
||||||
store: &mut ProgramStore,
|
store: &mut ProgramStore,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let name = name.to_string();
|
let name = name.to_string();
|
||||||
|
let room_id = room.room_id();
|
||||||
|
|
||||||
let info = store.application.get_room_info(room.room_id().to_owned());
|
let info = store.application.get_room_info(room_id.to_owned());
|
||||||
info.name = name.clone().into();
|
info.name = name.clone().into();
|
||||||
info.tags = tags.clone();
|
info.tags = tags.clone();
|
||||||
|
|
||||||
|
if let Some(alias) = room.canonical_alias() {
|
||||||
|
store.application.names.insert(alias.to_string(), room_id.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
RoomItem { room, tags, name }
|
RoomItem { room, tags, name }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -772,8 +788,13 @@ pub struct SpaceItem {
|
||||||
impl SpaceItem {
|
impl SpaceItem {
|
||||||
fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self {
|
fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self {
|
||||||
let name = name.to_string();
|
let name = name.to_string();
|
||||||
|
let room_id = room.room_id();
|
||||||
|
|
||||||
store.application.set_room_name(room.room_id(), name.as_str());
|
store.application.set_room_name(room_id, name.as_str());
|
||||||
|
|
||||||
|
if let Some(alias) = room.canonical_alias() {
|
||||||
|
store.application.names.insert(alias.to_string(), room_id.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
SpaceItem { room, name }
|
SpaceItem { room, name }
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,8 @@ use modalkit::editing::{
|
||||||
Scrollable,
|
Scrollable,
|
||||||
UIError,
|
UIError,
|
||||||
},
|
},
|
||||||
base::{CloseFlags, Count, MoveDir1D, PositionList, ScrollStyle, WordStyle},
|
base::{CloseFlags, Count, MoveDir1D, PositionList, ScrollStyle, WordStyle, WriteFlags},
|
||||||
|
completion::CompletionList,
|
||||||
context::Resolve,
|
context::Resolve,
|
||||||
history::{self, HistoryList},
|
history::{self, HistoryList},
|
||||||
rope::EditRope,
|
rope::EditRope,
|
||||||
|
@ -154,7 +155,7 @@ impl ChatState {
|
||||||
let client = &store.application.worker.client;
|
let client = &store.application.worker.client;
|
||||||
|
|
||||||
let settings = &store.application.settings;
|
let settings = &store.application.settings;
|
||||||
let info = store.application.rooms.entry(self.room_id.clone()).or_default();
|
let info = store.application.rooms.get_or_default(self.room_id.clone());
|
||||||
|
|
||||||
let msg = self
|
let msg = self
|
||||||
.scrollback
|
.scrollback
|
||||||
|
@ -389,7 +390,7 @@ impl ChatState {
|
||||||
.client
|
.client
|
||||||
.get_joined_room(self.id())
|
.get_joined_room(self.id())
|
||||||
.ok_or(IambError::NotJoined)?;
|
.ok_or(IambError::NotJoined)?;
|
||||||
let info = store.application.rooms.entry(self.id().to_owned()).or_default();
|
let info = store.application.rooms.get_or_default(self.id().to_owned());
|
||||||
let mut show_echo = true;
|
let mut show_echo = true;
|
||||||
|
|
||||||
let (event_id, msg) = match act {
|
let (event_id, msg) = match act {
|
||||||
|
@ -550,6 +551,21 @@ impl WindowOps<IambInfo> for ChatState {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write(
|
||||||
|
&mut self,
|
||||||
|
_: Option<&str>,
|
||||||
|
_: WriteFlags,
|
||||||
|
_: &mut ProgramStore,
|
||||||
|
) -> IambResult<EditInfo> {
|
||||||
|
// XXX: what's the right writing behaviour for a room?
|
||||||
|
// Should write send a message?
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_completions(&self) -> Option<CompletionList> {
|
||||||
|
delegate!(self, w => w.get_completions())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
||||||
delegate!(self, w => w.get_cursor_word(style))
|
delegate!(self, w => w.get_cursor_word(style))
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ use modalkit::{
|
||||||
PositionList,
|
PositionList,
|
||||||
ScrollStyle,
|
ScrollStyle,
|
||||||
WordStyle,
|
WordStyle,
|
||||||
|
WriteFlags,
|
||||||
},
|
},
|
||||||
|
editing::completion::CompletionList,
|
||||||
input::InputContext,
|
input::InputContext,
|
||||||
widgets::{TermOffset, TerminalCursor, WindowOps},
|
widgets::{TermOffset, TerminalCursor, WindowOps},
|
||||||
};
|
};
|
||||||
|
@ -383,10 +385,30 @@ impl WindowOps<IambInfo> for RoomState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close(&mut self, _: CloseFlags, _: &mut ProgramStore) -> bool {
|
fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
|
||||||
// XXX: what's the right closing behaviour for a room?
|
match self {
|
||||||
// Should write send a message?
|
RoomState::Chat(chat) => chat.close(flags, store),
|
||||||
true
|
RoomState::Space(space) => space.close(flags, store),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(
|
||||||
|
&mut self,
|
||||||
|
path: Option<&str>,
|
||||||
|
flags: WriteFlags,
|
||||||
|
store: &mut ProgramStore,
|
||||||
|
) -> IambResult<EditInfo> {
|
||||||
|
match self {
|
||||||
|
RoomState::Chat(chat) => chat.write(path, flags, store),
|
||||||
|
RoomState::Space(space) => space.write(path, flags, store),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_completions(&self) -> Option<CompletionList> {
|
||||||
|
match self {
|
||||||
|
RoomState::Chat(chat) => chat.get_completions(),
|
||||||
|
RoomState::Space(space) => space.get_completions(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
||||||
|
|
|
@ -32,6 +32,9 @@ use modalkit::editing::{
|
||||||
base::{
|
base::{
|
||||||
Axis,
|
Axis,
|
||||||
CloseFlags,
|
CloseFlags,
|
||||||
|
CompletionDisplay,
|
||||||
|
CompletionSelection,
|
||||||
|
CompletionType,
|
||||||
Count,
|
Count,
|
||||||
EditRange,
|
EditRange,
|
||||||
EditTarget,
|
EditTarget,
|
||||||
|
@ -51,7 +54,9 @@ use modalkit::editing::{
|
||||||
TargetShape,
|
TargetShape,
|
||||||
ViewportContext,
|
ViewportContext,
|
||||||
WordStyle,
|
WordStyle,
|
||||||
|
WriteFlags,
|
||||||
},
|
},
|
||||||
|
completion::CompletionList,
|
||||||
context::{EditContext, Resolve},
|
context::{EditContext, Resolve},
|
||||||
cursor::{CursorGroup, CursorState},
|
cursor::{CursorGroup, CursorState},
|
||||||
history::HistoryList,
|
history::HistoryList,
|
||||||
|
@ -60,7 +65,7 @@ use modalkit::editing::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
base::{IambBufferId, IambInfo, ProgramContext, ProgramStore, RoomFocus, RoomInfo},
|
base::{IambBufferId, IambInfo, IambResult, ProgramContext, ProgramStore, RoomFocus, RoomInfo},
|
||||||
config::ApplicationSettings,
|
config::ApplicationSettings,
|
||||||
message::{Message, MessageCursor, MessageKey, Messages},
|
message::{Message, MessageCursor, MessageKey, Messages},
|
||||||
};
|
};
|
||||||
|
@ -515,6 +520,23 @@ impl WindowOps<IambInfo> for ScrollbackState {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write(
|
||||||
|
&mut self,
|
||||||
|
_: Option<&str>,
|
||||||
|
flags: WriteFlags,
|
||||||
|
_: &mut ProgramStore,
|
||||||
|
) -> IambResult<EditInfo> {
|
||||||
|
if flags.contains(WriteFlags::FORCE) {
|
||||||
|
Ok(None)
|
||||||
|
} else {
|
||||||
|
Err(EditError::ReadOnly.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_completions(&self) -> Option<CompletionList> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn get_cursor_word(&self, _: &WordStyle) -> Option<String> {
|
fn get_cursor_word(&self, _: &WordStyle) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -532,7 +554,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||||
ctx: &ProgramContext,
|
ctx: &ProgramContext,
|
||||||
store: &mut ProgramStore,
|
store: &mut ProgramStore,
|
||||||
) -> EditResult<EditInfo, IambInfo> {
|
) -> EditResult<EditInfo, IambInfo> {
|
||||||
let info = store.application.rooms.entry(self.room_id.clone()).or_default();
|
let info = store.application.rooms.get_or_default(self.room_id.clone());
|
||||||
let key = if let Some(k) = self.cursor.to_key(info) {
|
let key = if let Some(k) = self.cursor.to_key(info) {
|
||||||
k.clone()
|
k.clone()
|
||||||
} else {
|
} else {
|
||||||
|
@ -762,6 +784,17 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn complete(
|
||||||
|
&mut self,
|
||||||
|
_: &CompletionType,
|
||||||
|
_: &CompletionSelection,
|
||||||
|
_: &CompletionDisplay,
|
||||||
|
_: &ProgramContext,
|
||||||
|
_: &mut ProgramStore,
|
||||||
|
) -> EditResult<EditInfo, IambInfo> {
|
||||||
|
Err(EditError::ReadOnly)
|
||||||
|
}
|
||||||
|
|
||||||
fn insert_text(
|
fn insert_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &InsertTextAction,
|
_: &InsertTextAction,
|
||||||
|
@ -867,9 +900,9 @@ impl Editable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||||
EditorAction::Mark(name) => self.mark(ctx.resolve(name), ctx, store),
|
EditorAction::Mark(name) => self.mark(ctx.resolve(name), ctx, store),
|
||||||
EditorAction::Selection(act) => self.selection_command(act, ctx, store),
|
EditorAction::Selection(act) => self.selection_command(act, ctx, store),
|
||||||
|
|
||||||
EditorAction::Complete(_, _) => {
|
EditorAction::Complete(_, _, _) => {
|
||||||
let msg = "";
|
let msg = "Nothing to complete in message scrollback";
|
||||||
let err = EditError::Unimplemented(msg.into());
|
let err = EditError::Failure(msg.into());
|
||||||
|
|
||||||
Err(err)
|
Err(err)
|
||||||
},
|
},
|
||||||
|
@ -991,7 +1024,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||||
ctx: &ProgramContext,
|
ctx: &ProgramContext,
|
||||||
store: &mut ProgramStore,
|
store: &mut ProgramStore,
|
||||||
) -> EditResult<EditInfo, IambInfo> {
|
) -> EditResult<EditInfo, IambInfo> {
|
||||||
let info = store.application.rooms.entry(self.room_id.clone()).or_default();
|
let info = store.application.rooms.get_or_default(self.room_id.clone());
|
||||||
let settings = &store.application.settings;
|
let settings = &store.application.settings;
|
||||||
let mut corner = self.viewctx.corner.clone();
|
let mut corner = self.viewctx.corner.clone();
|
||||||
|
|
||||||
|
@ -1105,7 +1138,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
|
||||||
Err(err)
|
Err(err)
|
||||||
},
|
},
|
||||||
Axis::Vertical => {
|
Axis::Vertical => {
|
||||||
let info = store.application.rooms.entry(self.room_id.clone()).or_default();
|
let info = store.application.rooms.get_or_default(self.room_id.clone());
|
||||||
let settings = &store.application.settings;
|
let settings = &store.application.settings;
|
||||||
|
|
||||||
if let Some(key) = self.cursor.to_key(info).cloned() {
|
if let Some(key) = self.cursor.to_key(info).cloned() {
|
||||||
|
@ -1193,7 +1226,7 @@ impl<'a> StatefulWidget for Scrollback<'a> {
|
||||||
type State = ScrollbackState;
|
type State = ScrollbackState;
|
||||||
|
|
||||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||||
let info = self.store.application.rooms.entry(state.room_id.clone()).or_default();
|
let info = self.store.application.rooms.get_or_default(state.room_id.clone());
|
||||||
let settings = &self.store.application.settings;
|
let settings = &self.store.application.settings;
|
||||||
let area = info.render_typing(area, buf, &self.store.application.settings);
|
let area = info.render_typing(area, buf, &self.store.application.settings);
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,11 @@ use modalkit::{
|
||||||
widgets::{TermOffset, TerminalCursor},
|
widgets::{TermOffset, TerminalCursor},
|
||||||
};
|
};
|
||||||
|
|
||||||
use modalkit::editing::base::{CloseFlags, WordStyle};
|
use modalkit::editing::action::EditInfo;
|
||||||
|
use modalkit::editing::base::{CloseFlags, WordStyle, WriteFlags};
|
||||||
|
use modalkit::editing::completion::CompletionList;
|
||||||
|
|
||||||
use crate::base::{IambBufferId, IambInfo, ProgramStore};
|
use crate::base::{IambBufferId, IambInfo, IambResult, ProgramStore};
|
||||||
|
|
||||||
const WELCOME_TEXT: &str = include_str!("welcome.md");
|
const WELCOME_TEXT: &str = include_str!("welcome.md");
|
||||||
|
|
||||||
|
@ -63,6 +65,19 @@ impl WindowOps<IambInfo> for WelcomeState {
|
||||||
self.tbox.close(flags, store)
|
self.tbox.close(flags, store)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write(
|
||||||
|
&mut self,
|
||||||
|
path: Option<&str>,
|
||||||
|
flags: WriteFlags,
|
||||||
|
store: &mut ProgramStore,
|
||||||
|
) -> IambResult<EditInfo> {
|
||||||
|
self.tbox.write(path, flags, store)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_completions(&self) -> Option<CompletionList> {
|
||||||
|
self.tbox.get_completions()
|
||||||
|
}
|
||||||
|
|
||||||
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
||||||
self.tbox.get_cursor_word(style)
|
self.tbox.get_cursor_word(style)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ use matrix_sdk::{
|
||||||
start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent},
|
start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent},
|
||||||
VerificationMethod,
|
VerificationMethod,
|
||||||
},
|
},
|
||||||
|
presence::PresenceEvent,
|
||||||
reaction::ReactionEventContent,
|
reaction::ReactionEventContent,
|
||||||
room::{
|
room::{
|
||||||
message::{MessageType, RoomMessageEventContent},
|
message::{MessageType, RoomMessageEventContent},
|
||||||
|
@ -503,6 +504,15 @@ impl ClientWorker {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let _ =
|
||||||
|
self.client
|
||||||
|
.add_event_handler(|ev: PresenceEvent, store: Ctx<AsyncProgramStore>| {
|
||||||
|
async move {
|
||||||
|
let mut locked = store.lock().await;
|
||||||
|
locked.application.presences.insert(ev.sender, ev.content.presence);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let _ = self.client.add_event_handler(
|
let _ = self.client.add_event_handler(
|
||||||
|ev: SyncStateEvent<RoomNameEventContent>,
|
|ev: SyncStateEvent<RoomNameEventContent>,
|
||||||
room: MatrixRoom,
|
room: MatrixRoom,
|
||||||
|
@ -513,8 +523,7 @@ impl ClientWorker {
|
||||||
let room_id = room.room_id().to_owned();
|
let room_id = room.room_id().to_owned();
|
||||||
let room_name = Some(room_name.to_string());
|
let room_name = Some(room_name.to_string());
|
||||||
let mut locked = store.lock().await;
|
let mut locked = store.lock().await;
|
||||||
let mut info =
|
let mut info = locked.application.rooms.get_or_default(room_id.clone());
|
||||||
locked.application.rooms.entry(room_id.to_owned()).or_default();
|
|
||||||
info.name = room_name;
|
info.name = room_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -529,8 +538,6 @@ impl ClientWorker {
|
||||||
store: Ctx<AsyncProgramStore>| {
|
store: Ctx<AsyncProgramStore>| {
|
||||||
async move {
|
async move {
|
||||||
let room_id = room.room_id();
|
let room_id = room.room_id();
|
||||||
let room_name = room.display_name().await.ok();
|
|
||||||
let room_name = room_name.as_ref().map(ToString::to_string);
|
|
||||||
|
|
||||||
if let Some(msg) = ev.as_original() {
|
if let Some(msg) = ev.as_original() {
|
||||||
if let MessageType::VerificationRequest(_) = msg.content.msgtype {
|
if let MessageType::VerificationRequest(_) = msg.content.msgtype {
|
||||||
|
@ -545,8 +552,11 @@ impl ClientWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut locked = store.lock().await;
|
let mut locked = store.lock().await;
|
||||||
let mut info = locked.application.get_room_info(room_id.to_owned());
|
|
||||||
info.name = room_name;
|
let sender = ev.sender().to_owned();
|
||||||
|
let _ = locked.application.presences.get_or_default(sender);
|
||||||
|
|
||||||
|
let info = locked.application.get_room_info(room_id.to_owned());
|
||||||
info.insert(ev.into_full_event(room_id.to_owned()));
|
info.insert(ev.into_full_event(room_id.to_owned()));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -560,6 +570,10 @@ impl ClientWorker {
|
||||||
let room_id = room.room_id();
|
let room_id = room.room_id();
|
||||||
|
|
||||||
let mut locked = store.lock().await;
|
let mut locked = store.lock().await;
|
||||||
|
|
||||||
|
let sender = ev.sender().to_owned();
|
||||||
|
let _ = locked.application.presences.get_or_default(sender);
|
||||||
|
|
||||||
let info = locked.application.get_room_info(room_id.to_owned());
|
let info = locked.application.get_room_info(room_id.to_owned());
|
||||||
info.insert_reaction(ev.into_full_event(room_id.to_owned()));
|
info.insert_reaction(ev.into_full_event(room_id.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue