Skip to content

Commit

Permalink
Edited help text and examples in explore for readability (nushell#7324
Browse files Browse the repository at this point in the history
)

# Description

* Various help messages were edited for clarity/grammar/etc.
* Some examples were made more interesting or relevant

# User-Facing Changes

See above.

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
  • Loading branch information
webbedspace committed Dec 2, 2022
1 parent fcdc474 commit 5762489
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 62 deletions.
29 changes: 17 additions & 12 deletions crates/nu-command/src/viewers/explore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ impl Command for Explore {
.named(
"head",
SyntaxShape::Boolean,
"Setting it to false makes it doesn't show column headers",
"Show or hide column headers (default true)",
None,
)
.switch("index", "A flag to show a index beside the rows", Some('i'))
.switch("index", "Show row indexes when viewing a list", Some('i'))
.switch(
"reverse",
"Makes it start from the end. (like `more`)",
"Start with the viewport scrolled to the bottom",
Some('r'),
)
.switch("peek", "Return a last seen cell content", Some('p'))
.switch(
"peek",
"When quitting, output the value of the cell the cursor was on",
Some('p'),
)
.category(Category::Viewers)
}

Expand Down Expand Up @@ -90,23 +94,24 @@ impl Command for Explore {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "List the files in current directory, an looking at them via explore.",
example: r#"ls | explore"#,
description: "Explore the system information record",
example: r#"sys | explore"#,
result: None,
},
Example {
description: "Inspect system information (explore with index).",
example: r#"sys | explore -i"#,
description: "Explore the output of `ls` without column names",
example: r#"ls | explore --head false"#,
result: None,
},
Example {
description: "Inspect $nu information (explore with no column names).",
example: r#"$nu | explore --head false"#,
description: "Explore a list of Markdown files' contents, with row indexes",
example: r#"glob *.md | each { open } | explore -i"#,
result: None,
},
Example {
description: "Inspect $nu information and return an entity where you've stopped.",
example: r#"$nu | explore --peek"#,
description:
"Explore a JSON file, then save the last visited sub-structure to a file",
example: r#"open file.json | explore -p | to json | save part.json"#,
result: None,
},
]
Expand Down
34 changes: 17 additions & 17 deletions crates/nu-explore/src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ impl ViewCommand for HelpCmd {
fn help(&self) -> Option<HelpManual> {
Some(HelpManual {
name: "help",
description: "Looks up a help information about a command or a `explore`",
description: "Explore the help page for `explore`",
arguments: vec![],
examples: vec![
HelpExample {
example: "help",
description: "Open a help information about the `explore`",
description: "Open the help page for all of `explore`",
},
HelpExample {
example: "help nu",
description: "Find a help list of `nu` command",
description: "Open the help page for the `nu` explore command",
},
HelpExample {
example: "help help",
Expand Down Expand Up @@ -161,20 +161,20 @@ fn help_frame_data(

#[rustfmt::skip]
let shortcuts = [
(":", "view", commands, "Run a command"),
("/", "view", null!(), "Search via pattern"),
("?", "view", null!(), "Search via pattern but results will be reversed when you press <n>"),
("n", "view", null!(), "Gets to the next found element in search"),
("i", "view", null!(), "Turn on a cursor mode so you can inspect values"),
("t", "view", null!(), "Transpose table, so columns became rows and vice versa"),
("Up", "", null!(), "Moves to an element above"),
("Down", "", null!(), "Moves to an element bellow"),
("Left", "", null!(), "Moves to an element to the left"),
("Right", "", null!(), "Moves to an element to the right"),
("PgDown", "view", null!(), "Moves to an a bunch of elements bellow"),
("PgUp", "view", null!(), "Moves to an a bunch of elements above"),
("Esc", "", null!(), "Exits a cursor mode. Exists an expected element."),
("Enter", "cursor", null!(), "Inspect a chosen element"),
(":", "view", commands, "Run an explore command (explore the 'information' cell of this row to list commands)"),
("/", "view", null!(), "Search for a pattern"),
("?", "view", null!(), "Search for a pattern, but the <n> key now scrolls to the previous result"),
("n", "view", null!(), "When searching, scroll to the next search result"),
("i", "view", null!(), "Enters cursor mode to inspect individual cells"),
("t", "view", null!(), "Transpose table, so that columns become rows and vice versa"),
("Up", "", null!(), "Moves the cursor or viewport one row up"),
("Down", "", null!(), "Moves the cursor or viewport one row down"),
("Left", "", null!(), "Moves the cursor or viewport one column left"),
("Right", "", null!(), "Moves the cursor or viewport one column right"),
("PgDown", "view", null!(), "Moves the cursor or viewport one page of rows down"),
("PgUp", "view", null!(), "Moves the cursor or viewport one page of rows up"),
("Esc", "", null!(), "Exits cursor mode. Exits the currently explored data."),
("Enter", "cursor", null!(), "In cursor mode, explore the data of the selected cell"),
];

let headers = headers.iter().map(|s| s.to_string()).collect();
Expand Down
9 changes: 5 additions & 4 deletions crates/nu-explore/src/commands/nu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ impl ViewCommand for NuCmd {
fn help(&self) -> Option<HelpManual> {
Some(HelpManual {
name: "nu",
description: "Run a nu command. You can use a presented table as an input",
description:
"Run a Nushell command. The data currently being explored is piped into it.",
arguments: vec![],
examples: vec![
HelpExample {
example: "where type == 'file'",
description: "Filter data to get only entries with a type being a 'file'",
description: "Filter data to show only rows whose type is 'file'",
},
HelpExample {
example: "get scope | get examples",
description: "Get a inner values",
example: "get scope.examples",
description: "Navigate to a deeper value inside the data",
},
HelpExample {
example: "open Cargo.toml",
Expand Down
3 changes: 2 additions & 1 deletion crates/nu-explore/src/commands/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ impl ViewCommand for PreviewCmd {
fn help(&self) -> Option<HelpManual> {
Some(HelpManual {
name: "preview",
description: "Preview current value/table if any is currently in use",
description:
"View the currently selected cell's data using the `table` Nushell command",
arguments: vec![],
examples: vec![],
})
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-explore/src/commands/quit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl SimpleCommand for QuitCmd {
fn help(&self) -> Option<HelpManual> {
Some(HelpManual {
name: "quit",
description: "Quit",
description: "Quit and return to Nushell",
arguments: vec![],
examples: vec![],
})
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-explore/src/commands/try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ impl ViewCommand for TryCmd {
fn help(&self) -> Option<HelpManual> {
Some(HelpManual {
name: "try",
description: "Opens a dynamic REPL to run nu commands",
description: "Opens a panel in which to run Nushell commands and explore their output",
arguments: vec![],
examples: vec![HelpExample {
example: "try open Cargo.toml",
description: "Optionally you can provide a command which will be run right away",
description: "Optionally, you can provide a command which will be run immediately",
}],
})
}
Expand Down
30 changes: 10 additions & 20 deletions crates/nu-explore/src/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn render_status_bar(f: &mut Frame, area: Rect, report: Report, theme: &StyleCon
}

fn report_msg_style(report: &Report, theme: &StyleConfig, style: NuStyle) -> NuStyle {
if matches!(report.level, Severentity::Info) {
if matches!(report.level, Severity::Info) {
style
} else {
report_level_style(report.level, theme)
Expand Down Expand Up @@ -834,11 +834,11 @@ impl Widget for StatusBar {
}
}

fn report_level_style(level: Severentity, theme: &StyleConfig) -> NuStyle {
fn report_level_style(level: Severity, theme: &StyleConfig) -> NuStyle {
match level {
Severentity::Info => theme.status_info,
Severentity::Warn => theme.status_warn,
Severentity::Err => theme.status_error,
Severity::Info => theme.status_info,
Severity::Warn => theme.status_warn,
Severity::Err => theme.status_error,
}
}

Expand Down Expand Up @@ -935,13 +935,13 @@ pub struct ViewInfo {
#[derive(Debug, Clone)]
pub struct Report {
pub message: String,
pub level: Severentity,
pub level: Severity,
pub context: String,
pub context2: String,
}

impl Report {
pub fn new(message: String, level: Severentity, context: String, context2: String) -> Self {
pub fn new(message: String, level: Severity, context: String, context2: String) -> Self {
Self {
message,
level,
Expand All @@ -951,28 +951,18 @@ impl Report {
}

pub fn error(message: impl Into<String>) -> Self {
Self::new(
message.into(),
Severentity::Err,
String::new(),
String::new(),
)
Self::new(message.into(), Severity::Err, String::new(), String::new())
}
}

impl Default for Report {
fn default() -> Self {
Self::new(
String::new(),
Severentity::Info,
String::new(),
String::new(),
)
Self::new(String::new(), Severity::Info, String::new(), String::new())
}
}

#[derive(Debug, Clone, Copy)]
pub enum Severentity {
pub enum Severity {
Info,
#[allow(dead_code)]
Warn,
Expand Down
6 changes: 3 additions & 3 deletions crates/nu-explore/src/views/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tui::layout::Rect;

use crate::{
nu_common::{NuSpan, NuText},
pager::{Frame, Report, Severentity, Transition, ViewConfig, ViewInfo},
pager::{Frame, Report, Severity, Transition, ViewConfig, ViewInfo},
};

use super::{coloredtextw::ColoredTextW, Layout, View};
Expand Down Expand Up @@ -105,7 +105,7 @@ impl View for Preview {
if is_end {
let report = Report::new(
String::from("END"),
Severentity::Info,
Severity::Info,
String::new(),
String::new(),
);
Expand Down Expand Up @@ -137,7 +137,7 @@ impl View for Preview {
if is_end {
let report = Report::new(
String::from("END"),
Severentity::Info,
Severity::Info,
String::new(),
String::new(),
);
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-explore/src/views/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tui::{layout::Rect, widgets::Block};
use crate::{
nu_common::{collect_input, NuConfig, NuSpan, NuStyleTable, NuText},
pager::{
make_styled_string, nu_style_to_tui, Frame, Position, Report, Severentity, StyleConfig,
make_styled_string, nu_style_to_tui, Frame, Position, Report, Severity, StyleConfig,
TableConfig, Transition, ViewConfig, ViewInfo,
},
views::ElementInfo,
Expand Down Expand Up @@ -584,7 +584,7 @@ fn create_records_report(
message: title,
context: covered_percent,
context2: cursor,
level: Severentity::Info,
level: Severity::Info,
}
}

Expand Down

0 comments on commit 5762489

Please sign in to comment.