Skip to content

Commit

Permalink
Support --no-headers option
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Feb 22, 2024
1 parent 133a80c commit 7fc63d2
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 35 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Key | Action
* `--echo-column <column_name>`: Print the value of this column at the selected
row to stdout on `Enter` key and then exit.

* `--no-headers`: Do not interpret the first row as headers.

## Installation

### Direct download
Expand Down
58 changes: 57 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl App {
show_stats: bool,
echo_column: Option<String>,
ignore_case: bool,
no_headers: bool,
) -> Result<Self> {
let input_handler = InputHandler::new();

Expand All @@ -132,7 +133,7 @@ impl App {
Delimiter::Character(d) => d,
Delimiter::Auto => sniff_delimiter(filename).unwrap_or(b','),
};
let config = csv::CsvConfig::new(filename, delimiter);
let config = csv::CsvConfig::new(filename, delimiter, no_headers);
let shared_config = Arc::new(config);

let csvlens_reader = csv::CsvLensReader::new(shared_config.clone())
Expand All @@ -151,6 +152,7 @@ impl App {
rows_view.headers().len(),
&echo_column,
ignore_case,
no_headers,
);

let finder: Option<find::Finder> = None;
Expand Down Expand Up @@ -710,6 +712,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -751,6 +754,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -819,6 +823,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -857,6 +862,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -895,6 +901,7 @@ mod tests {
false,
None,
true,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -935,6 +942,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -969,6 +977,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1003,6 +1012,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1094,6 +1104,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1138,6 +1149,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1174,6 +1186,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1211,6 +1224,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1269,6 +1283,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1351,6 +1366,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1390,6 +1406,7 @@ mod tests {
false,
None,
false,
false,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));
Expand Down Expand Up @@ -1430,4 +1447,43 @@ mod tests {
];
assert_eq!(lines, expected);
}

#[test]
fn test_no_headers() {
let mut app = App::new(
"tests/data/no_headers.csv",
Delimiter::Default,
None,
false,
None,
false,
true,
)
.unwrap();
thread::sleep(time::Duration::from_millis(100));

let backend = TestBackend::new(30, 10);
let mut terminal = Terminal::new(backend).unwrap();

step_and_draw(&mut app, &mut terminal, Control::Nothing);
for _ in 0..7 {
step_and_draw(&mut app, &mut terminal, Control::ScrollDown);
}

let expected = vec![
"──────────────────────────────",
" 1 2 ",
"───┬──────────────┬───────────",
"4 │ A4 B4 │ ",
"5 │ A5 B5 │ ",
"6 │ A6 B6 │ ",
"7 │ A7 B7 │ ",
"8 │ A8 B8 │ ",
"───┴──────────────┴───────────",
"stdin [Row 8/20, Col 1/2] ",
];
let actual_buffer = terminal.backend().buffer().clone();
let lines = to_lines(&actual_buffer);
assert_eq!(lines, expected);
}
}
Loading

0 comments on commit 7fc63d2

Please sign in to comment.