Commit 0565b6eb05

0565b6eb05ee0250ad7a23f0c1fa7dba8e1c53b5

parent: 47e650c2be

Unregistered key

Leonid Dyachkov <emireljer@gmail.com> · 2023-09-10 13:45 UTC
committer: <git@ulyssa.dev>

Support composing messages in an external editor (#155)

Layout: unified · split

Cargo.lock +92 −13
@@ -253,9 +253,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
253 253
254[[package]] 254[[package]]
255name = "bitflags" 255name = "bitflags"
256version = "2.0.2" 256version = "2.4.0"
257source = "registry+https://github.com/rust-lang/crates.io-index" 257source = "registry+https://github.com/rust-lang/crates.io-index"
258checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" 258checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
259 259
260[[package]] 260[[package]]
261name = "blake3" 261name = "blake3"
@@ -420,7 +420,7 @@ version = "4.1.12"
420source = "registry+https://github.com/rust-lang/crates.io-index" 420source = "registry+https://github.com/rust-lang/crates.io-index"
421checksum = "76e21918af71fb4bcd813230cf549e33d14f73d0326b932b630ce2930332b131" 421checksum = "76e21918af71fb4bcd813230cf549e33d14f73d0326b932b630ce2930332b131"
422dependencies = [ 422dependencies = [
423 "bitflags 2.0.2", 423 "bitflags 2.4.0",
424 "clap_derive", 424 "clap_derive",
425 "clap_lex", 425 "clap_lex",
426 "is-terminal", 426 "is-terminal",
@@ -961,6 +961,16 @@ dependencies = [
961 "zeroize", 961 "zeroize",
962] 962]
963 963
964[[package]]
965name = "edit"
966version = "0.1.4"
967source = "registry+https://github.com/rust-lang/crates.io-index"
968checksum = "c562aa71f7bc691fde4c6bf5f93ae5a5298b617c2eb44c76c87832299a17fbb4"
969dependencies = [
970 "tempfile",
971 "which",
972]
973
964[[package]] 974[[package]]
965name = "either" 975name = "either"
966version = "1.8.1" 976version = "1.8.1"
@@ -1010,13 +1020,13 @@ dependencies = [
1010 1020
1011[[package]] 1021[[package]]
1012name = "errno" 1022name = "errno"
1013version = "0.3.0" 1023version = "0.3.3"
1014source = "registry+https://github.com/rust-lang/crates.io-index" 1024source = "registry+https://github.com/rust-lang/crates.io-index"
1015checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" 1025checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd"
1016dependencies = [ 1026dependencies = [
1017 "errno-dragonfly", 1027 "errno-dragonfly",
1018 "libc", 1028 "libc",
1019 "windows-sys 0.45.0", 1029 "windows-sys 0.48.0",
1020] 1030]
1021 1031
1022[[package]] 1032[[package]]
@@ -1071,6 +1081,12 @@ dependencies = [
1071 "regex", 1081 "regex",
1072] 1082]
1073 1083
1084[[package]]
1085name = "fastrand"
1086version = "2.0.0"
1087source = "registry+https://github.com/rust-lang/crates.io-index"
1088checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
1089
1074[[package]] 1090[[package]]
1075name = "flate2" 1091name = "flate2"
1076version = "1.0.25" 1092version = "1.0.25"
@@ -1431,6 +1447,15 @@ dependencies = [
1431 "digest 0.10.6", 1447 "digest 0.10.6",
1432] 1448]
1433 1449
1450[[package]]
1451name = "home"
1452version = "0.5.5"
1453source = "registry+https://github.com/rust-lang/crates.io-index"
1454checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb"
1455dependencies = [
1456 "windows-sys 0.48.0",
1457]
1458
1434[[package]] 1459[[package]]
1435name = "html5ever" 1460name = "html5ever"
1436version = "0.26.0" 1461version = "0.26.0"
@@ -1518,7 +1543,7 @@ dependencies = [
1518 1543
1519[[package]] 1544[[package]]
1520name = "iamb" 1545name = "iamb"
1521version = "0.0.8" 1546version = "0.0.9-alpha.1"
1522dependencies = [ 1547dependencies = [
1523 "arboard", 1548 "arboard",
1524 "bitflags 1.3.2", 1549 "bitflags 1.3.2",
@@ -1527,6 +1552,7 @@ dependencies = [
1527 "comrak", 1552 "comrak",
1528 "css-color-parser", 1553 "css-color-parser",
1529 "dirs", 1554 "dirs",
1555 "edit",
1530 "emojis", 1556 "emojis",
1531 "futures", 1557 "futures",
1532 "gethostname 0.4.1", 1558 "gethostname 0.4.1",
@@ -1772,9 +1798,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
1772 1798
1773[[package]] 1799[[package]]
1774name = "libc" 1800name = "libc"
1775version = "0.2.140" 1801version = "0.2.147"
1776source = "registry+https://github.com/rust-lang/crates.io-index" 1802source = "registry+https://github.com/rust-lang/crates.io-index"
1777checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" 1803checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
1778 1804
1779[[package]] 1805[[package]]
1780name = "line-wrap" 1806name = "line-wrap"
@@ -1812,6 +1838,12 @@ version = "0.3.1"
1812source = "registry+https://github.com/rust-lang/crates.io-index" 1838source = "registry+https://github.com/rust-lang/crates.io-index"
1813checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" 1839checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f"
1814 1840
1841[[package]]
1842name = "linux-raw-sys"
1843version = "0.4.7"
1844source = "registry+https://github.com/rust-lang/crates.io-index"
1845checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128"
1846
1815[[package]] 1847[[package]]
1816name = "lock_api" 1848name = "lock_api"
1817version = "0.4.9" 1849version = "0.4.9"
@@ -2379,7 +2411,7 @@ dependencies = [
2379 "cfg-if", 2411 "cfg-if",
2380 "instant", 2412 "instant",
2381 "libc", 2413 "libc",
2382 "redox_syscall", 2414 "redox_syscall 0.2.16",
2383 "smallvec", 2415 "smallvec",
2384 "winapi", 2416 "winapi",
2385] 2417]
@@ -2392,7 +2424,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
2392dependencies = [ 2424dependencies = [
2393 "cfg-if", 2425 "cfg-if",
2394 "libc", 2426 "libc",
2395 "redox_syscall", 2427 "redox_syscall 0.2.16",
2396 "smallvec", 2428 "smallvec",
2397 "windows-sys 0.45.0", 2429 "windows-sys 0.45.0",
2398] 2430]
@@ -2925,6 +2957,15 @@ dependencies = [
2925 "bitflags 1.3.2", 2957 "bitflags 1.3.2",
2926] 2958]
2927 2959
2960[[package]]
2961name = "redox_syscall"
2962version = "0.3.5"
2963source = "registry+https://github.com/rust-lang/crates.io-index"
2964checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
2965dependencies = [
2966 "bitflags 1.3.2",
2967]
2968
2928[[package]] 2969[[package]]
2929name = "redox_users" 2970name = "redox_users"
2930version = "0.4.3" 2971version = "0.4.3"
@@ -2932,7 +2973,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2932checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" 2973checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
2933dependencies = [ 2974dependencies = [
2934 "getrandom 0.2.8", 2975 "getrandom 0.2.8",
2935 "redox_syscall", 2976 "redox_syscall 0.2.16",
2936 "thiserror", 2977 "thiserror",
2937] 2978]
2938 2979
@@ -3167,13 +3208,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
3167checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" 3208checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d"
3168dependencies = [ 3209dependencies = [
3169 "bitflags 1.3.2", 3210 "bitflags 1.3.2",
3170 "errno 0.3.0", 3211 "errno 0.3.3",
3171 "io-lifetimes", 3212 "io-lifetimes",
3172 "libc", 3213 "libc",
3173 "linux-raw-sys 0.3.1", 3214 "linux-raw-sys 0.3.1",
3174 "windows-sys 0.45.0", 3215 "windows-sys 0.45.0",
3175] 3216]
3176 3217
3218[[package]]
3219name = "rustix"
3220version = "0.38.12"
3221source = "registry+https://github.com/rust-lang/crates.io-index"
3222checksum = "bdf14a7a466ce88b5eac3da815b53aefc208ce7e74d1c263aabb04d88c4abeb1"
3223dependencies = [
3224 "bitflags 2.4.0",
3225 "errno 0.3.3",
3226 "libc",
3227 "linux-raw-sys 0.4.7",
3228 "windows-sys 0.48.0",
3229]
3230
3177[[package]] 3231[[package]]
3178name = "rustls" 3232name = "rustls"
3179version = "0.20.8" 3233version = "0.20.8"
@@ -3594,6 +3648,19 @@ dependencies = [
3594 "yaml-rust", 3648 "yaml-rust",
3595] 3649]
3596 3650
3651[[package]]
3652name = "tempfile"
3653version = "3.8.0"
3654source = "registry+https://github.com/rust-lang/crates.io-index"
3655checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
3656dependencies = [
3657 "cfg-if",
3658 "fastrand",
3659 "redox_syscall 0.3.5",
3660 "rustix 0.38.12",
3661 "windows-sys 0.48.0",
3662]
3663
3597[[package]] 3664[[package]]
3598name = "tendril" 3665name = "tendril"
3599version = "0.4.3" 3666version = "0.4.3"
@@ -4238,6 +4305,18 @@ version = "0.1.7"
4238source = "registry+https://github.com/rust-lang/crates.io-index" 4305source = "registry+https://github.com/rust-lang/crates.io-index"
4239checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" 4306checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
4240 4307
4308[[package]]
4309name = "which"
4310version = "4.4.2"
4311source = "registry+https://github.com/rust-lang/crates.io-index"
4312checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
4313dependencies = [
4314 "either",
4315 "home",
4316 "once_cell",
4317 "rustix 0.38.12",
4318]
4319
4241[[package]] 4320[[package]]
4242name = "wildmatch" 4321name = "wildmatch"
4243version = "2.1.1" 4322version = "2.1.1"
Cargo.toml +2 −1
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "iamb" 2name = "iamb"
3version = "0.0.8" 3version = "0.0.9-alpha.1"
4edition = "2018" 4edition = "2018"
5authors = ["Ulyssa <git@ulyssa.dev>"] 5authors = ["Ulyssa <git@ulyssa.dev>"]
6repository = "https://github.com/ulyssa/iamb" 6repository = "https://github.com/ulyssa/iamb"
@@ -51,6 +51,7 @@ tracing-subscriber = "0.3.16"
51unicode-segmentation = "^1.7" 51unicode-segmentation = "^1.7"
52unicode-width = "0.1.10" 52unicode-width = "0.1.10"
53url = {version = "^2.2.2", features = ["serde"]} 53url = {version = "^2.2.2", features = ["serde"]}
54edit = "0.1.4"
54 55
55[dependencies.modalkit] 56[dependencies.modalkit]
56version = "0.0.16" 57version = "0.0.16"
src/base.rs +11
@@ -202,6 +202,7 @@ pub enum RoomAction {
202#[derive(Clone, Debug, Eq, PartialEq)] 202#[derive(Clone, Debug, Eq, PartialEq)]
203pub enum SendAction { 203pub enum SendAction {
204 Submit, 204 Submit,
205 SubmitFromEditor,
205 Upload(String), 206 Upload(String),
206 UploadImage(usize, usize, Cow<'static, [u8]>), 207 UploadImage(usize, usize, Cow<'static, [u8]>),
207} 208}
@@ -222,6 +223,16 @@ pub enum IambAction {
222 ToggleScrollbackFocus, 223 ToggleScrollbackFocus,
223} 224}
224 225
226impl IambAction {
227 /// Indicates whether this action will draw over the screen.
228 pub fn scribbles(&self) -> bool {
229 match self {
230 IambAction::Send(SendAction::SubmitFromEditor) => true,
231 _ => false,
232 }
233 }
234}
235
225impl From<HomeserverAction> for IambAction { 236impl From<HomeserverAction> for IambAction {
226 fn from(act: HomeserverAction) -> Self { 237 fn from(act: HomeserverAction) -> Self {
227 IambAction::Homeserver(act) 238 IambAction::Homeserver(act)
src/commands.rs +17
@@ -266,6 +266,18 @@ fn iamb_reply(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
266 return Ok(step); 266 return Ok(step);
267} 267}
268 268
269fn iamb_editor(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
270 if !desc.arg.text.is_empty() {
271 return Result::Err(CommandError::InvalidArgument);
272 }
273
274
275 let sact = IambAction::from(SendAction::SubmitFromEditor);
276 let step = CommandStep::Continue(sact.into(), ctx.context.take());
277
278 return Ok(step);
279}
280
269fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { 281fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
270 if !desc.arg.text.is_empty() { 282 if !desc.arg.text.is_empty() {
271 return Result::Err(CommandError::InvalidArgument); 283 return Result::Err(CommandError::InvalidArgument);
@@ -537,6 +549,11 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
537 aliases: vec![], 549 aliases: vec![],
538 f: iamb_welcome, 550 f: iamb_welcome,
539 }); 551 });
552 cmds.add_command(ProgramCommand {
553 name: "editor".into(),
554 aliases: vec![],
555 f: iamb_editor,
556 });
540} 557}
541 558
542pub fn setup_commands() -> ProgramCommands { 559pub fn setup_commands() -> ProgramCommands {
src/main.rs +10 −1
@@ -224,6 +224,9 @@ struct Application {
224 224
225 /// The tab layout before the last executed [TabAction]. 225 /// The tab layout before the last executed [TabAction].
226 last_layout: Option<TabLayoutDescription<IambInfo>>, 226 last_layout: Option<TabLayoutDescription<IambInfo>>,
227
228 /// Whether we need to do a full redraw (e.g., after running a subprocess).
229 dirty: bool,
227} 230}
228 231
229impl Application { 232impl Application {
@@ -263,6 +266,7 @@ impl Application {
263 screen, 266 screen,
264 focused: true, 267 focused: true,
265 last_layout: None, 268 last_layout: None,
269 dirty: true,
266 }) 270 })
267 } 271 }
268 272
@@ -314,7 +318,8 @@ impl Application {
314 318
315 async fn step(&mut self) -> Result<TerminalKey, std::io::Error> { 319 async fn step(&mut self) -> Result<TerminalKey, std::io::Error> {
316 loop { 320 loop {
317 self.redraw(false, self.store.clone().lock().await.deref_mut())?; 321 self.redraw(self.dirty, self.store.clone().lock().await.deref_mut())?;
322 self.dirty = false;
318 323
319 if !poll(Duration::from_secs(1))? { 324 if !poll(Duration::from_secs(1))? {
320 // Redraw in case there's new messages to show. 325 // Redraw in case there's new messages to show.
@@ -479,6 +484,10 @@ impl Application {
479 ctx: ProgramContext, 484 ctx: ProgramContext,
480 store: &mut ProgramStore, 485 store: &mut ProgramStore,
481 ) -> IambResult<EditInfo> { 486 ) -> IambResult<EditInfo> {
487 if action.scribbles() {
488 self.dirty = true;
489 }
490
482 let info = match action { 491 let info = match action {
483 IambAction::ToggleScrollbackFocus => { 492 IambAction::ToggleScrollbackFocus => {
484 self.screen.current_window_mut()?.focus_toggle(); 493 self.screen.current_window_mut()?.focus_toggle();
src/windows/room/chat.rs +9 −4
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
7use modalkit::editing::store::RegisterError; 7use modalkit::editing::store::RegisterError;
8use std::process::Command; 8use std::process::Command;
9use tokio; 9use tokio;
10use edit::edit as external_edit;
10 11
11use matrix_sdk::{ 12use matrix_sdk::{
12 attachment::AttachmentConfig, 13 attachment::AttachmentConfig,
@@ -429,14 +430,18 @@ impl ChatState {
429 let mut show_echo = true; 430 let mut show_echo = true;
430 431
431 let (event_id, msg) = match act { 432 let (event_id, msg) = match act {
432 SendAction::Submit => { 433 SendAction::Submit | SendAction::SubmitFromEditor => {
433 let msg = self.tbox.get(); 434 let msg = self.tbox.get();
434 435
435 if msg.is_blank() { 436 let msg = if let SendAction::SubmitFromEditor = act {
437 external_edit(msg.trim_end().to_string())?
438 } else if msg.is_blank() {
436 return Ok(None); 439 return Ok(None);
437 } 440 } else {
441 msg.trim_end().to_string()
442 };
438 443
439 let mut msg = text_to_message(msg.trim_end().to_string()); 444 let mut msg = text_to_message(msg);
440 445
441 if let Some((_, event_id)) = &self.editing { 446 if let Some((_, event_id)) = &self.editing {
442 msg.relates_to = Some(Relation::Replacement(Replacement::new( 447 msg.relates_to = Some(Relation::Replacement(Replacement::new(