Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ pub struct App {
sorter: Option<Arc<sort::Sorter>>,
sort_order: SortOrder,
wrap_mode: WrapMode,
column_format_config: Option<Arc<crate::format::ColumnFormatConfig>>,
#[cfg(feature = "clipboard")]
clipboard: Result<Clipboard>,
_seekable_file: SeekableFile,
Expand All @@ -206,6 +207,7 @@ impl App {
wrap_mode: Option<WrapMode>,
auto_reload: bool,
no_streaming_stdin: bool,
column_format_config: Option<crate::format::ColumnFormatConfig>,
) -> CsvlensResult<Self> {
// TODO: pass a base_config to wait for header properly?
let seekable_file = SeekableFile::new(&original_filename, no_streaming_stdin)?;
Expand Down Expand Up @@ -270,6 +272,15 @@ impl App {
Err(e) => Err(anyhow::anyhow!(e)),
};

// Warn if --column-format is used with --no-headers: named column formats will never match.
if no_headers {
if let Some(ref cfg) = column_format_config {
if cfg.has_named() {
eprintln!("Warning: --column-format has no effect when --no-headers is used (columns have no names)");
}
}
}

let mut app = App {
input_handler,
num_rows_not_visible,
Expand All @@ -288,6 +299,7 @@ impl App {
sorter: None,
sort_order: SortOrder::Ascending,
wrap_mode: WrapMode::default(),
column_format_config: column_format_config.map(Arc::new),
#[cfg(feature = "clipboard")]
clipboard,
_seekable_file: seekable_file,
Expand Down Expand Up @@ -1093,6 +1105,7 @@ impl App {

let rows = self.rows_view.rows();
let csv_table = CsvTable::new(self.rows_view.headers(), rows);
self.csv_table_state.column_format_config = self.column_format_config.clone();
f.render_stateful_widget(csv_table, size, &mut self.csv_table_state);
if let Some((x, y)) = self.csv_table_state.cursor_xy {
f.set_cursor_position(Position::new(x, y));
Expand Down Expand Up @@ -1131,6 +1144,7 @@ mod tests {
find_regex: Option<String>,
prompt: Option<String>,
wrap_mode: Option<WrapMode>,
column_format_config: Option<crate::format::ColumnFormatConfig>,
}

impl AppBuilder {
Expand All @@ -1147,6 +1161,7 @@ mod tests {
find_regex: None,
prompt: Some("stdin".to_owned()),
wrap_mode: None,
column_format_config: None,
}
}

Expand All @@ -1167,6 +1182,7 @@ mod tests {
self.wrap_mode,
false,
false,
self.column_format_config,
)
}

Expand Down Expand Up @@ -1214,6 +1230,11 @@ mod tests {
self.wrap_mode = wrap_mode;
self
}

pub fn column_format_config(mut self, config: crate::format::ColumnFormatConfig) -> Self {
self.column_format_config = Some(config);
self
}
}

fn to_lines(buf: &Buffer) -> Vec<String> {
Expand Down
Loading