get try mostly working

This commit is contained in:
Reilly Wood 2024-06-05 19:23:44 -07:00
parent fa3594bac8
commit 197eec39e5
5 changed files with 35 additions and 59 deletions

View File

@ -119,4 +119,11 @@ impl View for NuView<'_> {
NuView::Preview(v) => v.exit(),
}
}
fn setup(&mut self, config: ViewConfig<'_>) {
match self {
NuView::Records(v) => v.setup(config),
NuView::Preview(v) => v.setup(config),
}
}
}

View File

@ -151,7 +151,7 @@ pub struct ExploreConfig {
pub cmd_bar_background: Style,
pub highlight: Style,
/// if true, the explore view will immediately try to run the command as it is typed
pub try_immediate: bool,
pub try_reactive: bool,
}
impl Default for ExploreConfig {
@ -171,7 +171,7 @@ impl Default for ExploreConfig {
cmd_bar_text: color(Some(Color::Rgb(196, 201, 198)), None),
cmd_bar_background: color(None, None),
highlight: color(Some(Color::Black), Some(Color::Yellow)),
try_immediate: false,
try_reactive: false,
}
}
}
@ -230,6 +230,14 @@ impl ExploreConfig {
}
}
if let Some(hm) = explore_cfg_hash_map.get("try").and_then(create_map) {
if let Some(reactive) = hm.get("reactive") {
if let Ok(b) = reactive.as_bool() {
ret.try_reactive = b;
}
}
}
ret
}
}

View File

@ -440,13 +440,15 @@ fn run_command(
Command::View { mut cmd, stackable } => {
// what we do we just replace the view.
let value = view_stack.curr_view.as_mut().and_then(|p| p.view.exit());
let new_view = cmd.spawn(engine_state, stack, value)?;
let mut new_view = cmd.spawn(engine_state, stack, value)?;
if let Some(view) = view_stack.curr_view.take() {
if !view.stackable {
view_stack.stack.push(view);
}
}
setup_view(&mut new_view, &pager.config);
view_stack.curr_view = Some(Page::raw(new_view, stackable));
Ok(CmdResult::new(false, true, cmd.name().to_owned()))
@ -454,6 +456,16 @@ fn run_command(
}
}
fn setup_view(view: &mut Box<dyn View>, cfg: &PagerConfig<'_>) {
let cfg = ViewConfig::new(
cfg.nu_config,
cfg.explore_config,
cfg.style_computer,
cfg.lscolors,
);
view.setup(cfg);
}
fn set_cursor_cmd_bar(f: &mut Frame, area: Rect, pager: &Pager) {
if pager.cmd_buf.is_cmd_input {
// todo: deal with a situation where we exceed the bar width

View File

@ -770,53 +770,3 @@ fn _transpose_table(
data
}
// fn theme_from_config(config: &ConfigMap) -> TableTheme {
// let mut theme = TableTheme::default();
// let colors = get_color_map(config);
// if let Some(s) = colors.get("separator") {
// theme.table.separator_style = *s;
// }
// theme.cursor.selected_cell = colors.get("selected_cell").cloned();
// theme.cursor.selected_row = colors.get("selected_row").cloned();
// theme.cursor.selected_column = colors.get("selected_column").cloned();
// theme.table.show_header = config_get_bool(config, "show_head", true);
// theme.table.show_index = config_get_bool(config, "show_index", false);
// theme.table.column_padding_left = config_get_usize(config, "column_padding_left", 1);
// theme.table.column_padding_right = config_get_usize(config, "column_padding_right", 1);
// theme
// }
// fn config_get_bool(config: &ConfigMap, key: &str, default: bool) -> bool {
// config
// .get(key)
// .and_then(|v| v.as_bool().ok())
// .unwrap_or(default)
// }
// fn config_get_usize(config: &ConfigMap, key: &str, default: usize) -> usize {
// config
// .get(key)
// .and_then(|v| v.coerce_str().ok())
// .and_then(|s| s.parse::<usize>().ok())
// .unwrap_or(default)
// }
// #[derive(Debug, Default, Clone)]
// pub struct TableTheme {
// table: TableStyle,
// cursor: CursorStyle,
// }
// #[derive(Debug, Default, Clone)]
// struct CursorStyle {
// selected_cell: Option<NuStyle>,
// selected_column: Option<NuStyle>,
// selected_row: Option<NuStyle>,
// }

View File

@ -20,7 +20,7 @@ use std::cmp::min;
pub struct TryView<'a> {
input: Value,
command: String,
immediate: bool,
reactive: bool,
table: Option<RecordView<'a>>,
table_theme: TableConfig,
view_mode: bool,
@ -33,7 +33,7 @@ impl<'a> TryView<'a> {
Self {
input,
table: None,
immediate: false,
reactive: false,
table_theme: TableConfig::default(),
border_color: Style::default(),
highlighted_color: Style::default(),
@ -183,7 +183,7 @@ impl View for TryView<'_> {
if !self.command.is_empty() {
self.command.pop();
if self.immediate {
if self.reactive {
match self.try_run(engine_state, stack) {
Ok(_) => info.report = Some(Report::default()),
Err(err) => info.report = Some(Report::error(format!("Error: {err}"))),
@ -196,7 +196,7 @@ impl View for TryView<'_> {
KeyCode::Char(c) => {
self.command.push(*c);
if self.immediate {
if self.reactive {
match self.try_run(engine_state, stack) {
Ok(_) => info.report = Some(Report::default()),
Err(err) => info.report = Some(Report::error(format!("Error: {err}"))),
@ -241,8 +241,7 @@ impl View for TryView<'_> {
fn setup(&mut self, config: ViewConfig<'_>) {
self.border_color = nu_style_to_tui(config.explore_config.table.separator_style);
self.highlighted_color = nu_style_to_tui(config.explore_config.highlight);
// TODO: make sure this is set based on try.reactive setting
self.immediate = config.explore_config.try_immediate;
self.reactive = config.explore_config.try_reactive;
let mut r = RecordView::new(vec![], vec![]);
r.setup(config);