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"
253253
254254[[package]]
255255name = "bitflags"
256version = "2.0.2"
256version = "2.4.0"
257257source = "registry+https://github.com/rust-lang/crates.io-index"
258checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1"
258checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
259259
260260[[package]]
261261name = "blake3"
@@ -420,7 +420,7 @@ version = "4.1.12"
420420source = "registry+https://github.com/rust-lang/crates.io-index"
421421checksum = "76e21918af71fb4bcd813230cf549e33d14f73d0326b932b630ce2930332b131"
422422dependencies = [
423 "bitflags 2.0.2",
423 "bitflags 2.4.0",
424424 "clap_derive",
425425 "clap_lex",
426426 "is-terminal",
@@ -961,6 +961,16 @@ dependencies = [
961961 "zeroize",
962962]
963963
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
964974[[package]]
965975name = "either"
966976version = "1.8.1"
@@ -1010,13 +1020,13 @@ dependencies = [
10101020
10111021[[package]]
10121022name = "errno"
1013version = "0.3.0"
1023version = "0.3.3"
10141024source = "registry+https://github.com/rust-lang/crates.io-index"
1015checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0"
1025checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd"
10161026dependencies = [
10171027 "errno-dragonfly",
10181028 "libc",
1019 "windows-sys 0.45.0",
1029 "windows-sys 0.48.0",
10201030]
10211031
10221032[[package]]
@@ -1071,6 +1081,12 @@ dependencies = [
10711081 "regex",
10721082]
10731083
1084[[package]]
1085name = "fastrand"
1086version = "2.0.0"
1087source = "registry+https://github.com/rust-lang/crates.io-index"
1088checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
1089
10741090[[package]]
10751091name = "flate2"
10761092version = "1.0.25"
@@ -1431,6 +1447,15 @@ dependencies = [
14311447 "digest 0.10.6",
14321448]
14331449
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
14341459[[package]]
14351460name = "html5ever"
14361461version = "0.26.0"
@@ -1518,7 +1543,7 @@ dependencies = [
15181543
15191544[[package]]
15201545name = "iamb"
1521version = "0.0.8"
1546version = "0.0.9-alpha.1"
15221547dependencies = [
15231548 "arboard",
15241549 "bitflags 1.3.2",
@@ -1527,6 +1552,7 @@ dependencies = [
15271552 "comrak",
15281553 "css-color-parser",
15291554 "dirs",
1555 "edit",
15301556 "emojis",
15311557 "futures",
15321558 "gethostname 0.4.1",
@@ -1772,9 +1798,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
17721798
17731799[[package]]
17741800name = "libc"
1775version = "0.2.140"
1801version = "0.2.147"
17761802source = "registry+https://github.com/rust-lang/crates.io-index"
1777checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
1803checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
17781804
17791805[[package]]
17801806name = "line-wrap"
@@ -1812,6 +1838,12 @@ version = "0.3.1"
18121838source = "registry+https://github.com/rust-lang/crates.io-index"
18131839checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f"
18141840
1841[[package]]
1842name = "linux-raw-sys"
1843version = "0.4.7"
1844source = "registry+https://github.com/rust-lang/crates.io-index"
1845checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128"
1846
18151847[[package]]
18161848name = "lock_api"
18171849version = "0.4.9"
@@ -2379,7 +2411,7 @@ dependencies = [
23792411 "cfg-if",
23802412 "instant",
23812413 "libc",
2382 "redox_syscall",
2414 "redox_syscall 0.2.16",
23832415 "smallvec",
23842416 "winapi",
23852417]
@@ -2392,7 +2424,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
23922424dependencies = [
23932425 "cfg-if",
23942426 "libc",
2395 "redox_syscall",
2427 "redox_syscall 0.2.16",
23962428 "smallvec",
23972429 "windows-sys 0.45.0",
23982430]
@@ -2925,6 +2957,15 @@ dependencies = [
29252957 "bitflags 1.3.2",
29262958]
29272959
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
29282969[[package]]
29292970name = "redox_users"
29302971version = "0.4.3"
@@ -2932,7 +2973,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
29322973checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
29332974dependencies = [
29342975 "getrandom 0.2.8",
2935 "redox_syscall",
2976 "redox_syscall 0.2.16",
29362977 "thiserror",
29372978]
29382979
@@ -3167,13 +3208,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
31673208checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d"
31683209dependencies = [
31693210 "bitflags 1.3.2",
3170 "errno 0.3.0",
3211 "errno 0.3.3",
31713212 "io-lifetimes",
31723213 "libc",
31733214 "linux-raw-sys 0.3.1",
31743215 "windows-sys 0.45.0",
31753216]
31763217
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
31773231[[package]]
31783232name = "rustls"
31793233version = "0.20.8"
@@ -3594,6 +3648,19 @@ dependencies = [
35943648 "yaml-rust",
35953649]
35963650
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
35973664[[package]]
35983665name = "tendril"
35993666version = "0.4.3"
@@ -4238,6 +4305,18 @@ version = "0.1.7"
42384305source = "registry+https://github.com/rust-lang/crates.io-index"
42394306checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
42404307
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
42414320[[package]]
42424321name = "wildmatch"
42434322version = "2.1.1"
Cargo.toml +2 −1
@@ -1,6 +1,6 @@
11[package]
22name = "iamb"
3version = "0.0.8"
3version = "0.0.9-alpha.1"
44edition = "2018"
55authors = ["Ulyssa <git@ulyssa.dev>"]
66repository = "https://github.com/ulyssa/iamb"
@@ -51,6 +51,7 @@ tracing-subscriber = "0.3.16"
5151unicode-segmentation = "^1.7"
5252unicode-width = "0.1.10"
5353url = {version = "^2.2.2", features = ["serde"]}
54edit = "0.1.4"
5455
5556[dependencies.modalkit]
5657version = "0.0.16"
src/base.rs +11
@@ -202,6 +202,7 @@ pub enum RoomAction {
202202#[derive(Clone, Debug, Eq, PartialEq)]
203203pub enum SendAction {
204204 Submit,
205 SubmitFromEditor,
205206 Upload(String),
206207 UploadImage(usize, usize, Cow<'static, [u8]>),
207208}
@@ -222,6 +223,16 @@ pub enum IambAction {
222223 ToggleScrollbackFocus,
223224}
224225
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
225236impl From<HomeserverAction> for IambAction {
226237 fn from(act: HomeserverAction) -> Self {
227238 IambAction::Homeserver(act)
src/commands.rs +17
@@ -266,6 +266,18 @@ fn iamb_reply(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
266266 return Ok(step);
267267}
268268
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
269281fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
270282 if !desc.arg.text.is_empty() {
271283 return Result::Err(CommandError::InvalidArgument);
@@ -537,6 +549,11 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
537549 aliases: vec![],
538550 f: iamb_welcome,
539551 });
552 cmds.add_command(ProgramCommand {
553 name: "editor".into(),
554 aliases: vec![],
555 f: iamb_editor,
556 });
540557}
541558
542559pub fn setup_commands() -> ProgramCommands {
src/main.rs +10 −1
@@ -224,6 +224,9 @@ struct Application {
224224
225225 /// The tab layout before the last executed [TabAction].
226226 last_layout: Option<TabLayoutDescription<IambInfo>>,
227
228 /// Whether we need to do a full redraw (e.g., after running a subprocess).
229 dirty: bool,
227230}
228231
229232impl Application {
@@ -263,6 +266,7 @@ impl Application {
263266 screen,
264267 focused: true,
265268 last_layout: None,
269 dirty: true,
266270 })
267271 }
268272
@@ -314,7 +318,8 @@ impl Application {
314318
315319 async fn step(&mut self) -> Result<TerminalKey, std::io::Error> {
316320 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;
318323
319324 if !poll(Duration::from_secs(1))? {
320325 // Redraw in case there's new messages to show.
@@ -479,6 +484,10 @@ impl Application {
479484 ctx: ProgramContext,
480485 store: &mut ProgramStore,
481486 ) -> IambResult<EditInfo> {
487 if action.scribbles() {
488 self.dirty = true;
489 }
490
482491 let info = match action {
483492 IambAction::ToggleScrollbackFocus => {
484493 self.screen.current_window_mut()?.focus_toggle();
src/windows/room/chat.rs +9 −4
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
77use modalkit::editing::store::RegisterError;
88use std::process::Command;
99use tokio;
10use edit::edit as external_edit;
1011
1112use matrix_sdk::{
1213 attachment::AttachmentConfig,
@@ -429,14 +430,18 @@ impl ChatState {
429430 let mut show_echo = true;
430431
431432 let (event_id, msg) = match act {
432 SendAction::Submit => {
433 SendAction::Submit | SendAction::SubmitFromEditor => {
433434 let msg = self.tbox.get();
434435
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() {
436439 return Ok(None);
437 }
440 } else {
441 msg.trim_end().to_string()
442 };
438443
439 let mut msg = text_to_message(msg.trim_end().to_string());
444 let mut msg = text_to_message(msg);
440445
441446 if let Some((_, event_id)) = &self.editing {
442447 msg.relates_to = Some(Relation::Replacement(Replacement::new(