Skip to content

Commit

Permalink
🐛 layout: should use oneline layout when pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Jul 28, 2024
1 parent 9b310da commit e518a0e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::color::Colors;
use crate::display;
use crate::flags::{
ColorOption, Display, Flags, HyperlinkOption, Layout, Literal, SortOrder, ThemeOption,
ColorOption, Display, Flags, Header, HyperlinkOption, Layout, Literal, SortOrder, ThemeOption,
};
use crate::git::GitCache;
use crate::icon::Icons;
Expand Down Expand Up @@ -44,8 +44,6 @@ impl Core {
#[cfg(target_os = "windows")]
let console_color_ok = crossterm::ansi_support::supports_ansi();

let mut inner_flags = flags.clone();

let color_theme = match (tty_available && console_color_ok, flags.color.when) {
(_, ColorOption::Never) | (false, ColorOption::Auto) => ThemeOption::NoColor,
_ => flags.color.theme.clone(),
Expand All @@ -71,8 +69,8 @@ impl Core {
//
// Most of the programs does not handle correctly the ansi colors
// or require a raw output (like the `wc` command).
inner_flags.layout = Layout::OneLine;

flags.layout = Layout::OneLine;
flags.header = Header(false);
flags.literal = Literal(true);
};

Expand Down
55 changes: 55 additions & 0 deletions tests/lscompatible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
extern crate assert_cmd;
extern crate predicates;

use assert_cmd::prelude::*;
use assert_fs::prelude::*;
use std::process::{Command, Stdio};

fn cmd() -> Command {
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
}

fn tempdir() -> assert_fs::TempDir {
assert_fs::TempDir::new().unwrap()
}

#[test]
fn test_pipe_should_use_line() {
let dir = tempdir();
dir.child("one").touch().unwrap();
dir.child("two").touch().unwrap();

let lsd = cmd()
.arg("--ignore-config")
.arg(dir.path())
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start lsd process");
let lsd_out = lsd.stdout.expect("Failed to open ls stdout");

let cat_lsd = Command::new("cat")
.stdin(Stdio::from(lsd_out))
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start cat process");
let output_lsd = cat_lsd
.wait_with_output()
.expect("Failed to wait on cat lsd");

let ls = Command::new("ls")
.arg(dir.path())
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start ls process");
let ls_out = ls.stdout.expect("Failed to open ls stdout");

let cat_ls = Command::new("cat")
.stdin(Stdio::from(ls_out))
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start cat process");

let output_ls = cat_ls.wait_with_output().expect("Failed to wait on cat ls");

assert_eq!(output_ls.stdout, output_lsd.stdout);
}

0 comments on commit e518a0e

Please sign in to comment.