diff --git a/src/kamp.rs b/src/kamp.rs index 96cbcc8..aa061be 100644 --- a/src/kamp.rs +++ b/src/kamp.rs @@ -77,7 +77,19 @@ impl Dispatcher for SubCommand { fn dispatch(self, ctx: Context, mut writer: W) -> Result<()> { match self { SubCommand::Attach(opt) => cmd::attach(ctx, opt.buffer), - SubCommand::Edit(opt) => cmd::edit(ctx, opt.focus, opt.files), + SubCommand::Edit(opt) => { + let session = ctx.session(); + let client = ctx.client(); + let scratch = cmd::edit(ctx, opt.focus, opt.files)?; + if let (Some(client), false) = (client, opt.focus) { + writeln!( + writer, + "{} is opened in client: {client}, session: {session}", + if scratch { "scratch" } else { "file" } + )?; + } + Ok(()) + } SubCommand::Send(opt) => { if opt.command.is_empty() { return Err(Error::CommandRequired); diff --git a/src/kamp/cmd/edit.rs b/src/kamp/cmd/edit.rs index 5d5281b..326594b 100644 --- a/src/kamp/cmd/edit.rs +++ b/src/kamp/cmd/edit.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use super::{Context, Error, Result}; -pub(crate) fn edit(ctx: Context, focus: bool, files: Vec) -> Result<()> { +pub(crate) fn edit(ctx: Context, focus: bool, files: Vec) -> Result { let mut buf = String::new(); let mut pair = [None; 2]; let mut coord = None; @@ -47,7 +47,8 @@ pub(crate) fn edit(ctx: Context, focus: bool, files: Vec) -> Result<()> } } - if buf.is_empty() { + let is_scratch = buf.is_empty(); + if is_scratch { buf.push_str("edit -scratch"); } @@ -55,11 +56,12 @@ pub(crate) fn edit(ctx: Context, focus: bool, files: Vec) -> Result<()> if focus { buf.push_str("\nfocus"); } - ctx.send(None, &buf).map(drop) + ctx.send(None, &buf).map(|_| is_scratch) } else if focus { Err(anyhow::Error::msg("no client in context").into()) } else { - ctx.connect(&buf) // this one acts like attach + // this one acts like attach + ctx.connect(&buf).map(|_| is_scratch) } }