Skip to content

Commit

Permalink
print last line when cat-ting interactively (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Sep 8, 2024
1 parent b77493a commit af25f25
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/deno_task_shell/src/shell/commands/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
use anyhow::Result;
use futures::future::LocalBoxFuture;
use std::fs::File;
use std::io::IsTerminal;
use std::io::Read;

use crate::shell::types::ExecuteResult;
use crate::ShellPipeWriter;

use super::args::parse_arg_kinds;
use super::args::ArgKind;
Expand Down Expand Up @@ -56,6 +58,14 @@ fn execute_cat(mut context: ShellCommandContext) -> Result<ExecuteResult> {
} else {
context.stdout.write_all(&buf[..size])?;
}

if let ShellPipeWriter::Stdout = context.stdout {
// check if it's interactive
if buf[size - 1] != b'\n' && std::io::stdout().is_terminal() {
// make sure that we end up on a new line
context.stdout.write_all(b"%\n")?;
}
}
},
Err(err) => {
context.stderr.write_line(&format!("cat: {path}: {err}"))?;
Expand Down

0 comments on commit af25f25

Please sign in to comment.