Show list as the same table as search
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
abd0dfca1e
commit
58e271967b
2 files changed
+70
-30
No files matched your search
+61
-17
@@ -732,11 +732,19 @@ fn cmd_list(ctx : Ctx) -> Unit {
|
|||||||
println("no packages installed")
|
println("no packages installed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let rows : Array[Array[String]] = []
|
||||||
for name, p in ctx.state {
|
for name, p in ctx.state {
|
||||||
let kind = if p.explicit { "" } else { " (dependency)" }
|
rows.push(
|
||||||
let from = if p.channel == MAIN_CHANNEL { "" } else { " [\{p.channel}]" }
|
package_row(
|
||||||
println("\{name} \{p.version}\{from}\{kind}")
|
name,
|
||||||
|
p.channel,
|
||||||
|
p.version,
|
||||||
|
p.description,
|
||||||
|
dependency=!p.explicit,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
print_packages(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -950,24 +958,48 @@ fn printable(s : String) -> String {
|
|||||||
sb.to_string()
|
sb.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// A row of the table that search and list share.
|
||||||
|
fn package_row(
|
||||||
|
name : String,
|
||||||
|
channel : String,
|
||||||
|
version : String,
|
||||||
|
description : String,
|
||||||
|
dependency? : Bool = false,
|
||||||
|
) -> Array[String] {
|
||||||
|
let desc = printable(description)
|
||||||
|
[
|
||||||
|
name,
|
||||||
|
channel,
|
||||||
|
if version == "" {
|
||||||
|
"-"
|
||||||
|
} else {
|
||||||
|
printable(version)
|
||||||
|
},
|
||||||
|
match (desc, dependency) {
|
||||||
|
("", true) => "(dependency)"
|
||||||
|
("", false) => "-"
|
||||||
|
(d, true) => d + " (dependency)"
|
||||||
|
(d, false) => d
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn print_packages(rows : Array[Array[String]]) -> Unit {
|
||||||
|
let table = [["PACKAGE", "CHANNEL", "VERSION", "DESCRIPTION"]]
|
||||||
|
table.append(rows)
|
||||||
|
print_table(table)
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
async fn cmd_search(
|
async fn cmd_search(
|
||||||
ctx : Ctx,
|
ctx : Ctx,
|
||||||
term : String,
|
term : String,
|
||||||
refresh? : Bool = false,
|
refresh? : Bool = false,
|
||||||
) -> Unit raise OrbitError {
|
) -> Unit raise OrbitError {
|
||||||
let rows : Array[Array[String]] = [
|
let rows : Array[Array[String]] = []
|
||||||
["PACKAGE", "CHANNEL", "VERSION", "DESCRIPTION"],
|
|
||||||
]
|
|
||||||
let mut listed = 0
|
let mut listed = 0
|
||||||
let add = fn(name : String, ch : Channel, version : String, desc : String) {
|
|
||||||
rows.push([
|
|
||||||
name,
|
|
||||||
ch.name,
|
|
||||||
if version == "" { "-" } else { printable(version) },
|
|
||||||
if desc == "" { "-" } else { printable(desc) },
|
|
||||||
])
|
|
||||||
}
|
|
||||||
let term_lower = ascii_lower(term)
|
let term_lower = ascii_lower(term)
|
||||||
for ch in ctx.channels {
|
for ch in ctx.channels {
|
||||||
let entries = match channel_listing(ctx.root, ch, term_lower, refresh) {
|
let entries = match channel_listing(ctx.root, ch, term_lower, refresh) {
|
||||||
@@ -978,7 +1010,7 @@ async fn cmd_search(
|
|||||||
for e in entries {
|
for e in entries {
|
||||||
if contains_str(e.name, term_lower) ||
|
if contains_str(e.name, term_lower) ||
|
||||||
contains_str(ascii_lower(e.description), term_lower) {
|
contains_str(ascii_lower(e.description), term_lower) {
|
||||||
add(e.name, ch, e.version, e.description)
|
rows.push(package_row(e.name, ch.name, e.version, e.description))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -987,7 +1019,7 @@ async fn cmd_search(
|
|||||||
"no channel could be listed; if you know the package name, try `orbit versions <name>`",
|
"no channel could be listed; if you know the package name, try `orbit versions <name>`",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if rows.length() == 1 {
|
if rows.is_empty() {
|
||||||
if term == "" {
|
if term == "" {
|
||||||
println("no packages found")
|
println("no packages found")
|
||||||
} else {
|
} else {
|
||||||
@@ -995,7 +1027,7 @@ async fn cmd_search(
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
print_table(rows)
|
print_packages(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -1045,3 +1077,15 @@ test "table columns line up" {
|
|||||||
assert_eq(pad_right("ab", 4), "ab ")
|
assert_eq(pad_right("ab", 4), "ab ")
|
||||||
assert_eq(pad_right("abcd", 2), "abcd")
|
assert_eq(pad_right("abcd", 2), "abcd")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "list and search rows mark dependencies and blanks" {
|
||||||
|
assert_eq(package_row("a", "main", "1.0.0", "A tool"), [
|
||||||
|
"a", "main", "1.0.0", "A tool",
|
||||||
|
])
|
||||||
|
assert_eq(package_row("a", "main", "", ""), ["a", "main", "-", "-"])
|
||||||
|
assert_eq(package_row("a", "main", "1.0.0", "A\u001btool", dependency=true), [
|
||||||
|
"a", "main", "1.0.0", "A tool (dependency)",
|
||||||
|
])
|
||||||
|
assert_eq(package_row("a", "main", "1.0.0", "", dependency=true)[3], "(dependency)")
|
||||||
|
}
|
||||||
+9
-13
@@ -1549,19 +1549,15 @@ async fn cmd_project_list(
|
|||||||
if lock.packages.length() == 0 {
|
if lock.packages.length() == 0 {
|
||||||
println("no packages in \{lock_path}")
|
println("no packages in \{lock_path}")
|
||||||
} else {
|
} else {
|
||||||
for p in lock.packages {
|
print_packages(
|
||||||
let kind = if m.dependencies.contains(p.name) {
|
lock.packages.map(p => package_row(
|
||||||
""
|
p.name,
|
||||||
} else {
|
p.channel,
|
||||||
" (dependency)"
|
p.version,
|
||||||
}
|
p.description,
|
||||||
let from = if p.channel == MAIN_CHANNEL {
|
dependency=!m.dependencies.contains(p.name),
|
||||||
""
|
)),
|
||||||
} else {
|
)
|
||||||
" [\{p.channel}]"
|
|
||||||
}
|
|
||||||
println("\{p.name} \{p.version}\{from}\{kind}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user