Skip to content

Commit

Permalink
print message when no client is focused
Browse files Browse the repository at this point in the history
address issue #15
  • Loading branch information
vbauerster committed Nov 13, 2024
1 parent dbea64d commit 20b2cbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/kamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,19 @@ impl Dispatcher for SubCommand {
fn dispatch<W: Write>(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);
Expand Down
10 changes: 6 additions & 4 deletions src/kamp/cmd/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;

use super::{Context, Error, Result};

pub(crate) fn edit(ctx: Context, focus: bool, files: Vec<String>) -> Result<()> {
pub(crate) fn edit(ctx: Context, focus: bool, files: Vec<String>) -> Result<bool> {
let mut buf = String::new();
let mut pair = [None; 2];
let mut coord = None;
Expand Down Expand Up @@ -47,19 +47,21 @@ pub(crate) fn edit(ctx: Context, focus: bool, files: Vec<String>) -> Result<()>
}
}

if buf.is_empty() {
let is_scratch = buf.is_empty();
if is_scratch {
buf.push_str("edit -scratch");
}

if !ctx.is_draft() {
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)
}
}

Expand Down

0 comments on commit 20b2cbe

Please sign in to comment.