Skip to content

Commit

Permalink
fix: Fix some UI issues. (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Dec 27, 2024
1 parent 314a246 commit 35984ca
Show file tree
Hide file tree
Showing 27 changed files with 205 additions and 103 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
- [Rust](https://github.com/moonrepo/tools/blob/master/tools/rust/CHANGELOG.md)
- [Schema (TOML, JSON, YAML)](https://github.com/moonrepo/tools/blob/master/tools/internal-schema/CHANGELOG.md)

## Unreleased

#### 🐞 Fixes

- Fixed some minor UI layout issues.

## 0.44.0

This is a unique release that focused primarily on cleaning up our current commands, either by removing arguments, or merging functionality. On top of that, we've refactored all the terminal output using a new UI library powered by [iocraft](https://docs.rs/iocraft/latest/iocraft/). Read the blog post for more information!
Expand All @@ -27,6 +33,7 @@ This is a unique release that focused primarily on cleaning up our current comma
- Added a `--yes` option to `proto outdated`, that skips confirmation prompts.
- Added a `--json` option to `proto clean`, to capture the cleaned result as JSON.
- Added a new command, `proto versions <tool>`, that lists all available remote and installed versions/aliases.
- Added a confirmation prompt to `proto uninstall` flows.
- Updated `proto clean` to accept a target in which to clean as the 1st argument. For example, `proto clean cache`.
- Moved the `--json` and `--yes` options into global options.

Expand Down
38 changes: 30 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ iocraft = "0.5.2"
miette = "7.4.0"
once_cell = "1.20.2"
regex = { version = "1.11.1", default-features = false, features = ["std"] }
reqwest = { version = "0.12.9", default-features = false, features = [
reqwest = { version = "0.12.10", default-features = false, features = [
"charset",
"http2",
"macos-system-configuration",
Expand Down Expand Up @@ -50,10 +50,10 @@ starbase_archive = { version = "0.9.0", features = [
"zip",
"zip-deflate",
] }
starbase_console = { version = "0.3.1", features = ["ui"] }
starbase_console = { version = "0.4.0", features = ["ui"] }
starbase_sandbox = { version = "0.8.0" }
starbase_shell = { version = "0.6.9", features = ["miette"] }
starbase_styles = { version = "0.4.9" }
starbase_styles = { version = "0.4.10" }
starbase_utils = { version = "0.9.1", default-features = false, features = [
"json",
"miette",
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn alias(session: ProtoSession, args: AliasArgs) -> AppResult {
Notice(variant: Variant::Success) {
StyledText(
content: format!(
"Added <id>{}</id> alias <id>{}</id> <mutedlight>({})</mutedlight> to config <path>{}</path>",
"Added <id>{}</id> alias <id>{}</id> <mutedlight>(with specification <versionalt>{}</versionalt>)</mutedlight> to config <path>{}</path>",
args.id,
args.alias,
args.spec.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub async fn clean_tool(
tool.get_name(),
versions_to_clean
.iter()
.map(|v| format!("<hash>{v}</hash>"))
.map(|v| format!("<version>{v}</version>"))
.collect::<Vec<_>>()
.join(", ")
),
Expand Down
38 changes: 8 additions & 30 deletions crates/cli/src/commands/debug/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::session::{ProtoConsole, ProtoSession};
use crate::components::CodeBlock;
use crate::session::ProtoSession;
use iocraft::prelude::*;
use proto_core::{ProtoConfig, ProtoConfigFile};
use serde::Serialize;
use starbase::AppResult;
use starbase_console::ui::*;
use starbase_styles::color;
use starbase_utils::{json, toml};

#[derive(Serialize)]
Expand All @@ -13,30 +13,6 @@ struct DebugConfigResult<'a> {
files: Vec<&'a ProtoConfigFile>,
}

fn print_toml(console: &ProtoConsole, value: impl Serialize) -> miette::Result<()> {
let contents = toml::format(&value, true)?
.lines()
.map(|line| {
let indented_line = format!(" {line}");

if line.starts_with('[') {
indented_line
} else {
color::muted_light(indented_line)
}
})
.collect::<Vec<_>>()
.join("\n");

// TOML output is far too large to render with iocraft,
// so we unfortunately need to do all this manually
console.out.write_newline()?;
console.out.write_line(contents)?;
console.out.write_newline()?;

Ok(())
}

#[tracing::instrument(skip_all)]
pub async fn config(session: ProtoSession) -> AppResult {
let env = &session.env;
Expand All @@ -62,28 +38,30 @@ pub async fn config(session: ProtoSession) -> AppResult {
continue;
}

let code = toml::format(&file.config, true)?;

session.console.render(element! {
Container {
Section(
title: file.path.to_string_lossy(),
title_color: style_to_color(Style::Path)
)
CodeBlock(code, format: "toml")
}
})?;

print_toml(&session.console, &file.config)?;
}

let code = toml::format(config, true)?;

session.console.render(element! {
Container {
Section(
title: "Final configuration",
title_color: style_to_color(Style::Shell), // pink brand
)
CodeBlock(code, format: "toml")
}
})?;

print_toml(&session.console, config)?;

Ok(None)
}
10 changes: 5 additions & 5 deletions crates/cli/src/commands/diagnose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::components::{Issue, IssuesList};
use crate::helpers::fetch_latest_version;
use crate::session::ProtoSession;
use clap::Args;
use iocraft::prelude::{element, Box, Text};
use iocraft::prelude::{element, Box, FlexDirection, Text};
use serde::Serialize;
use starbase::AppResult;
use starbase_console::ui::*;
Expand Down Expand Up @@ -80,7 +80,7 @@ pub async fn diagnose(session: ProtoSession, args: DiagnoseArgs) -> AppResult {

session.console.render(element! {
Container {
Box(margin_bottom: 1) {
Box(margin_bottom: 1, flex_direction: FlexDirection::Column) {
Entry(
name: "Shell",
value: element! {
Expand Down Expand Up @@ -174,9 +174,9 @@ async fn gather_errors(
"Ensure the shims path comes before the bin path in your shell".into(),
),
comment: Some(
"Runtime version detection will not work correctly unless shims are used".into(),
"Runtime version detection will not work correctly unless shims take priority".into(),
),
})
});
}

Ok(errors)
Expand All @@ -195,7 +195,7 @@ async fn gather_warnings(
if current_version < &latest_version {
warnings.push(Issue {
issue: format!(
"Current proto version <hash>{current_version}</hash> is outdated, latest is <hash>{latest_version}</hash>",
"Current proto version <version>{current_version}</version> is outdated, latest is <version>{latest_version}</version>",
),
resolution: Some("Run <shell>proto upgrade</shell> to update".into()),
comment: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub async fn install_one(session: ProtoSession, args: InstallArgs, id: Id) -> Ap
Notice(variant: Variant::Success) {
StyledText(
content: format!(
"{} <hash>{}</hash> has been installed to <path>{}</path>!",
"{} <version>{}</version> has been installed to <path>{}</path>!",
tool.get_name(),
tool.get_resolved_version(),
tool.get_product_dir().display(),
Expand All @@ -158,7 +158,7 @@ pub async fn install_one(session: ProtoSession, args: InstallArgs, id: Id) -> Ap
Notice(variant: Variant::Info) {
StyledText(
content: format!(
"{} <hash>{}</hash> has already been installed at <path>{}</path>!",
"{} <version>{}</version> has already been installed at <path>{}</path>!",
tool.get_name(),
tool.get_resolved_version(),
tool.get_product_dir().display(),
Expand Down
16 changes: 9 additions & 7 deletions crates/cli/src/commands/outdated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,17 @@ pub async fn outdated(session: ProtoSession, args: OutdatedArgs) -> AppResult {
return Ok(None);
}

let id_width = items.keys().fold(0, |acc, id| acc.max(id.as_str().len()));

session.console.render(element! {
Container {
Table(
headers: vec![
TableHeader::new("Tool", Size::Percent(10.0)),
TableHeader::new("Current", Size::Percent(8.0)),
TableHeader::new("Newest", Size::Percent(8.0)),
TableHeader::new("Latest", Size::Percent(8.0)),
TableHeader::new("Config", Size::Percent(66.0)),
TableHeader::new("Tool", Size::Length((id_width + 3).max(10) as u32)),
TableHeader::new("Current", Size::Length(10)),
TableHeader::new("Newest", Size::Length(10)),
TableHeader::new("Latest", Size::Length(10)),
TableHeader::new("Config", Size::Auto),
]
) {
#(items.iter().enumerate().map(|(i, (id, item))| {
Expand Down Expand Up @@ -250,9 +252,9 @@ pub async fn outdated(session: ProtoSession, args: OutdatedArgs) -> AppResult {
.render_interactive(element! {
Confirm(
label: if args.latest {
"Update config files with latest versions?"
"Update config files with <label>latest</label> versions?"
} else {
"Update config files with newest versions?"
"Update config files with <label>newest</label> versions?"
},
on_confirm: &mut confirmed,
)
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ pub async fn pin(session: ProtoSession, args: PinArgs) -> AppResult {
StyledText(
content: if spec != args.spec {
format!(
"Pinned <id>{}</id> version <hash>{}</hash> (resolved from <hash>{}</hash>) to config <path>{}</path>",
"Pinned <id>{}</id> version <version>{}</version> (resolved from <versionalt>{}</versionalt>) to config <path>{}</path>",
args.id,
spec,
args.spec,
config_path.display()
)
} else {
format!(
"Pinned <id>{}</id> version <hash>{}</hash> to config <path>{}</path>",
"Pinned <id>{}</id> version <version>{}</version> to config <path>{}</path>",
args.id,
args.spec,
config_path.display()
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/plugin/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub async fn info(session: ProtoSession, args: InfoPluginArgs) -> AppResult {
value: element! {
StyledText(
content: version.to_string(),
style: Style::Hash
style: Style::Shell
)
}.into_any()
)
Expand Down
24 changes: 14 additions & 10 deletions crates/cli/src/commands/plugin/search.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::session::ProtoSession;
use clap::Args;
use iocraft::prelude::{element, Box, FlexDirection, Size, Text};
use proto_core::registry::{PluginAuthor, PluginFormat};
use proto_core::registry::PluginFormat;
use proto_core::PluginLocator;
use starbase::AppResult;
use starbase_console::ui::*;
Expand Down Expand Up @@ -49,6 +49,13 @@ pub async fn search(session: ProtoSession, args: SearchPluginArgs) -> AppResult
return Ok(Some(1));
}

let (name_width, author_width) = queried_plugins.iter().fold((0, 0), |acc, plugin| {
(
acc.0.max(plugin.name.len()),
acc.1.max(plugin.author.get_name().len()),
)
});

session.console.render(element! {
Container {
Box(padding_top: 1, padding_left: 1, flex_direction: FlexDirection::Column) {
Expand All @@ -61,11 +68,11 @@ pub async fn search(session: ProtoSession, args: SearchPluginArgs) -> AppResult
}
Table(
headers: vec![
TableHeader::new("Plugin", Size::Percent(10.0)),
TableHeader::new("Author", Size::Percent(8.0)),
TableHeader::new("Format", Size::Percent(5.0)),
TableHeader::new("Description", Size::Percent(20.0)),
TableHeader::new("Locator", Size::Percent(57.0)),
TableHeader::new("Plugin", Size::Length(name_width.max(6) as u32)),
TableHeader::new("Author", Size::Length(author_width.max(6) as u32)),
TableHeader::new("Format", Size::Length(6)),
TableHeader::new("Description", Size::Percent(30.0)),
TableHeader::new("Locator", Size::Auto),
]
) {
#(queried_plugins.into_iter().enumerate().map(|(i, plugin)| {
Expand All @@ -79,10 +86,7 @@ pub async fn search(session: ProtoSession, args: SearchPluginArgs) -> AppResult
}
TableCol(col: 1) {
Text(
content: match &plugin.author {
PluginAuthor::String(name) => name,
PluginAuthor::Object(author) => &author.name,
}
content: plugin.author.get_name()
)
}
TableCol(col: 2) {
Expand Down
Loading

0 comments on commit 35984ca

Please sign in to comment.