Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "default" table theme #11072

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/nu-command/src/viewers/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,20 @@ fn get_theme_flag(
state: &EngineState,
stack: &mut Stack,
) -> Result<Option<TableMode>, ShellError> {
call.get_flag(state, stack, "theme")?
let theme_name = call.get_flag(state, stack, "theme")?;
theme_name
.clone()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the temporary and clone if we rearrange the .map_err into the .map before the .transpose

.map(|theme: String| TableMode::from_str(&theme))
.transpose()
.map_err(|err| ShellError::CantConvert {
to_type: String::from("theme"),
from_type: String::from("string"),
span: call.span(),
help: Some(String::from(err)),
help: Some(format!(
"{}, but found '{}'.",
String::from(err),
theme_name.unwrap_or("".to_string())
)),
})
}

Expand Down
3 changes: 3 additions & 0 deletions crates/nu-protocol/src/config/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum TableMode {
Compact,
WithLove,
CompactDouble,
Default,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to move the #[default] annotation to change the impl Default

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these changes in #11076

#[default]
Rounded,
Reinforced,
Expand All @@ -35,6 +36,7 @@ impl FromStr for TableMode {
"compact" => Ok(Self::Compact),
"with_love" => Ok(Self::WithLove),
"compact_double" => Ok(Self::CompactDouble),
"default" => Ok(Self::Rounded),
"rounded" => Ok(Self::Rounded),
"reinforced" => Ok(Self::Reinforced),
"heavy" => Ok(Self::Heavy),
Expand All @@ -60,6 +62,7 @@ impl ReconstructVal for TableMode {
TableMode::Compact => "compact",
TableMode::WithLove => "with_love",
TableMode::CompactDouble => "compact_double",
TableMode::Default => "rounded",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it reports "rounded" anyways, you could just drop TableMode::Default entirely and only add the line "default" => Ok(TableMode::default()) to the impl FromStr. Then there is no chance for that to get out of step in nu-table's load_theme()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, did that too. i sincerely hope you're out of ideas of other things to change here. 🤣

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm done 😄

TableMode::Rounded => "rounded",
TableMode::Reinforced => "reinforced",
TableMode::Heavy => "heavy",
Expand Down
1 change: 1 addition & 0 deletions crates/nu-table/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub fn load_theme(mode: TableMode) -> TableTheme {
TableMode::Compact => TableTheme::compact(),
TableMode::WithLove => TableTheme::with_love(),
TableMode::CompactDouble => TableTheme::compact_double(),
TableMode::Default => TableTheme::rounded(),
TableMode::Rounded => TableTheme::rounded(),
TableMode::Reinforced => TableTheme::reinforced(),
TableMode::Heavy => TableTheme::heavy(),
Expand Down