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 26, 2024
1 parent 9b310da commit cfc6fc6
Show file tree
Hide file tree
Showing 2 changed files with 59 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
56 changes: 56 additions & 0 deletions tests/lscompatible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
extern crate assert_cmd;
extern crate predicates;

use assert_cmd::prelude::*;
use assert_fs::prelude::*;
use predicates::prelude::*;

Check failure on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Style (macos-latest)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / MinSRV

unused import: `predicates::prelude::*`

Check failure on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Style (ubuntu-latest)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

unused import: `predicates::prelude::*`

Check failure on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, use-cross)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-gnu, use-cross)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-musl, use-cross)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-musl, use-cross)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unused import: `predicates::prelude::*`

Check warning on line 6 in tests/lscompatible.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-gnu)

unused import: `predicates::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 cfc6fc6

Please sign in to comment.