Update files
This commit is contained in:
1 parent
ca918a4a34
commit
3bdf874584
4 files changed
+146
-31
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
# Default: list available recipes
|
||||||
|
default:
|
||||||
|
@just --list
|
||||||
|
|
||||||
|
# Run moonfetch
|
||||||
|
run *args:
|
||||||
|
moon run cmd/main --target native -- {{args}}
|
||||||
|
|
||||||
|
# Type-check the project
|
||||||
|
check:
|
||||||
|
moon check --target native
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
test:
|
||||||
|
moon test --target native
|
||||||
|
|
||||||
|
# Build release binary
|
||||||
|
build:
|
||||||
|
moon build --target native --release
|
||||||
|
|
||||||
|
# Update interface files and format code
|
||||||
|
fmt:
|
||||||
|
moon info && moon fmt
|
||||||
@@ -38,18 +38,18 @@ pub fn get_logo(name : String) -> Logo {
|
|||||||
"ubuntu" =>
|
"ubuntu" =>
|
||||||
{
|
{
|
||||||
name: "ubuntu",
|
name: "ubuntu",
|
||||||
primary_color: "\u001b[1;33m",
|
primary_color: "\u001b[1;31m",
|
||||||
secondary_color: "\u001b[1;31m",
|
secondary_color: "\u001b[1;37m",
|
||||||
lines: [
|
lines: [
|
||||||
" .-/+oossssoo+/-. ", " `:+ssssssssssssssssss+:` ",
|
"$1 .-/+oossssoo+/-. ", " `:+ssssssssssssssssss+:` ",
|
||||||
" -+ssssssssssssssssssyyssss+- ", " .ossssssssssssssssssdMMMNysssso. ",
|
" -+ssssssssssssssssss$2yy$1ssss+- ", " .ossssssssssssssssss$2dMMMNy$1sssso. ",
|
||||||
" /ssssssssssshdmmNNmmyNMMMMhssssss/ ", " +ssssssssshmydMMMMMMMNddddyssssssss+ ",
|
" /sssssssssss$2hdmmNNmmyNMMMMh$1ssssss/ ", " +sssssssss$2hmydMMMMMMMNddddy$1ssssssss+ ",
|
||||||
" /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ ", ".ssssssssdMMMNhsssssssssshNMMMdssssssss. ",
|
" /ssssssss$2hNMMMyhhyyyyhmNMMMNh$1ssssssss/ ", ".ssssssss$2dMMMNh$1ssssssssss$2hNMMMd$1ssssssss. ",
|
||||||
"+sssshhhyNMMNyssssssssssssyNMMMysssssss+ ", "ossyNMMMNyMMhsssssssssssssshmmmhssssssso ",
|
"+ssss$2hhhyNMMNy$1ssssssssssss$2yNMMMy$1sssssss+ ", "oss$2yNMMMNyMMh$1ssssssssssssss$2hmmmh$1ssssssso ",
|
||||||
"ossyNMMMNyMMhsssssssssssssshmmmhssssssso ", "+sssshhhyNMMNyssssssssssssyNMMMysssssss+ ",
|
"oss$2yNMMMNyMMh$1ssssssssssssss$2hmmmh$1ssssssso ", "+ssss$2hhhyNMMNy$1ssssssssssss$2yNMMMy$1sssssss+ ",
|
||||||
".ssssssssdMMMNhsssssssssshNMMMdssssssss. ", " /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ ",
|
".ssssssss$2dMMMNh$1ssssssssss$2hNMMMd$1ssssssss. ", " /ssssssss$2hNMMMyhhyyyyhdNMMMNh$1ssssssss/ ",
|
||||||
" +sssssssssdmydMMMMMMMMddddyssssssss+ ", " /ssssssssssshdmNNNNmyNMMMMhssssss/ ",
|
" +sssssssss$2dmydMMMMMMMMddddy$1ssssssss+ ", " /sssssssssss$2hdmNNNNmyNMMMMh$1ssssss/ ",
|
||||||
" .ossssssssssssssssssdMMMNysssso. ", " -+sssssssssssssssssyyyssss+- ",
|
" .ossssssssssssssssss$2dMMMNy$1sssso. ", " -+sssssssssssssssss$2yyy$1ssss+- ",
|
||||||
" `:+ssssssssssssssssss+:` ", " .-/+oossssoo+/-. ",
|
" `:+ssssssssssssssssss+:` ", " .-/+oossssoo+/-. ",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -59,11 +59,11 @@ pub fn get_logo(name : String) -> Logo {
|
|||||||
primary_color: "\u001b[1;36m",
|
primary_color: "\u001b[1;36m",
|
||||||
secondary_color: "\u001b[36m",
|
secondary_color: "\u001b[36m",
|
||||||
lines: [
|
lines: [
|
||||||
" -` ", " .o+` ",
|
"$1 -` ", " .o+` ",
|
||||||
" `ooo/ ", " `+oooo: ",
|
" `ooo/ ", " `+oooo: ",
|
||||||
" `+oooooo: ", " -+oooooo+: ",
|
" `+oooooo: ", " -+oooooo+: ",
|
||||||
" `/:-:++oooo+: ", " `/++++/+++++++: ",
|
" `/:-:++oooo+: ", " `/++++/+++++++: ",
|
||||||
" `/++++++++++++++: ", " `/+++ooooooooooooo/` ",
|
"$2 `/++++++++++++++: ", " `/+++ooooooooooooo/` ",
|
||||||
" ./ooosssso++osssssso+` ", " .oossssso-````/ossssss+` ",
|
" ./ooosssso++osssssso+` ", " .oossssso-````/ossssss+` ",
|
||||||
" -osssssso. :ssssssso. ", " :osssssss/ osssso+++. ",
|
" -osssssso. :ssssssso. ", " :osssssss/ osssso+++. ",
|
||||||
" /ossssssss/ +ssssooo/- ", " `/ossssso+/:- -:/+osssso+- ",
|
" /ossssssss/ +ssssooo/- ", " `/ossssso+/:- -:/+osssso+- ",
|
||||||
@@ -75,16 +75,16 @@ pub fn get_logo(name : String) -> Logo {
|
|||||||
{
|
{
|
||||||
name: "fedora",
|
name: "fedora",
|
||||||
primary_color: "\u001b[1;34m",
|
primary_color: "\u001b[1;34m",
|
||||||
secondary_color: "\u001b[34m",
|
secondary_color: "\u001b[1;37m",
|
||||||
lines: [
|
lines: [
|
||||||
" .',;::::;,'. ", " .';:cccccccccccc:;,. ",
|
"$1 .',;::::;,'. ", " .';:cccccccccccc:;,. ",
|
||||||
" .;cccccccccccccccccccccc;. ", " .:cccccccccccccccccccccccccc:. ",
|
" .;cccccccccccccccccccccc;. ", " .:cccccccccccccccccccccccccc:. ",
|
||||||
" .;ccccccccccccc;.:dddl:.;ccccccc;. ", " .:ccccccccccccc;OWMKOOXMWd;ccccccc:. ",
|
" .;ccccccccccccc;.:$2dddl$1:.;ccccccc;. ", " .:ccccccccccccc;$2OWMKOOXMWd$1;ccccccc:. ",
|
||||||
".:ccccccccccccc;KMMc;cc;xMMc;ccccccc:. ", ",cccccccccccccc;MMM.;cc;;WW:;cccccccc, ",
|
".:ccccccccccccc;$2KMM$1c;cc;$2xMM$1c;ccccccc:. ", ",cccccccccccccc;$2MMM$1.;cc;;$2WW$1:;cccccccc, ",
|
||||||
":cccccccccccccc;MMM.;cccccccccccccccc: ", ":ccccccc;oxOOOo;MMM0OOk.;cccccccccccc: ",
|
":cccccccccccccc;$2MMM$1.;cccccccccccccccc: ", ":ccccccc;$2oxOOOo$1;$2MMM0OOk$1.;cccccccccccc: ",
|
||||||
"cccccc;0MMKxdd:;MMMkddc.;cccccccccccc; ", "ccccc;XM0';cccc;MMM.;cccccccccccccccc' ",
|
"cccccc;$20MMKxdd$1:;$2MMMkddc$1.;cccccccccccc; ", "ccccc;$2XM0$1';cccc;$2MMM$1.;cccccccccccccccc' ",
|
||||||
"ccccc;MMo;ccccc;MMW.;ccccccccccccccc; ", "ccccc;0MNc.ccc.xMMd;ccccccccccccccc; ",
|
"ccccc;$2MMo$1;ccccc;$2MMW$1.;ccccccccccccccc; ", "ccccc;$20MNc$1.ccc.$2xMMd$1;ccccccccccccccc; ",
|
||||||
"cccccc;dNMWXXXWM0:;cccccccccccccc:, ", "cccccccc;.:odl:.;cccccccccccccc:,. ",
|
"cccccc;$2dNMWXXXWM0$1:;cccccccccccccc:, ", "cccccccc;.:$2odl$1:.;cccccccccccccc:,. ",
|
||||||
":cccccccccccccccccccccccccccc:'. ", ".:cccccccccccccccccccccc:;,.. ",
|
":cccccccccccccccccccccccccccc:'. ", ".:cccccccccccccccccccccc:;,.. ",
|
||||||
" '::cccccccccccccc::;,. ",
|
" '::cccccccccccccc::;,. ",
|
||||||
],
|
],
|
||||||
@@ -126,10 +126,10 @@ pub fn get_logo(name : String) -> Logo {
|
|||||||
primary_color: "\u001b[1;35m",
|
primary_color: "\u001b[1;35m",
|
||||||
secondary_color: "\u001b[1;33m",
|
secondary_color: "\u001b[1;33m",
|
||||||
lines: [
|
lines: [
|
||||||
" _..._ ", " .:::::::. * ", " ::::::::::: ",
|
"$1 _..._ ", " .:::::::. $2* ", "$1 ::::::::::: ",
|
||||||
" ::::::::::::: . ", " ::::::' `::: ", " :::::' `:: ",
|
" ::::::::::::: $2. ", "$1 ::::::' `::: ", " :::::' `:: ",
|
||||||
" ::::: .: * ", " :::::. .:: ", " ::::::. .::: ",
|
" ::::: .: $2* ", "$1 :::::. .:: ", " ::::::. .::: ",
|
||||||
" ::::::::::::' . ", " ':::::::::' ", " `'::::'' * ",
|
" ::::::::::::' $2. ", "$1 ':::::::::' ", " `'::::'' $2* ",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,3 +170,45 @@ test "visible_len and render_fetch no_color" {
|
|||||||
assert_true(json_out.contains("\"username\": \"alice\""))
|
assert_true(json_out.contains("\"username\": \"alice\""))
|
||||||
assert_true(json_out.contains("\"os\": \"Debian 12 x86_64\""))
|
assert_true(json_out.contains("\"os\": \"Debian 12 x86_64\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "ubuntu logo multi-color and no_color" {
|
||||||
|
let info : @lib.SystemInfo = {
|
||||||
|
username: "alice",
|
||||||
|
hostname: "box",
|
||||||
|
os_id: "ubuntu",
|
||||||
|
os_name: "Ubuntu 26.04.1 LTS x86_64",
|
||||||
|
host_model: "KVM",
|
||||||
|
kernel: "Linux 6.12",
|
||||||
|
arch: "x86_64",
|
||||||
|
uptime: "10 mins",
|
||||||
|
uptime_secs: 600,
|
||||||
|
packages: "100 (dpkg)",
|
||||||
|
shell: "bash 5.2",
|
||||||
|
terminal: "xterm (80x24)",
|
||||||
|
de_wm: "Headless / TTY",
|
||||||
|
cpu: "Test CPU (4)",
|
||||||
|
memory: "1.00 GiB / 4.00 GiB (25%)",
|
||||||
|
mem_used_kib: 1048576UL,
|
||||||
|
mem_total_kib: 4194304UL,
|
||||||
|
disk: "2.00 GiB / 10.00 GiB (20%)",
|
||||||
|
disk_used_bytes: 2147483648UL,
|
||||||
|
disk_total_bytes: 10737418240UL,
|
||||||
|
local_ip: "10.0.0.2",
|
||||||
|
locale: "C.UTF-8",
|
||||||
|
}
|
||||||
|
let colored = @lib.render_fetch(
|
||||||
|
info,
|
||||||
|
@lib.parse_args(["--structure", "title"]),
|
||||||
|
)
|
||||||
|
assert_true(colored.contains("\u001b[1;31m"))
|
||||||
|
assert_true(colored.contains("\u001b[1;37m"))
|
||||||
|
assert_true(!colored.contains("$1") && !colored.contains("$2"))
|
||||||
|
|
||||||
|
let plain = @lib.render_fetch(
|
||||||
|
info,
|
||||||
|
@lib.parse_args(["--no-color", "--structure", "title"]),
|
||||||
|
)
|
||||||
|
assert_true(!plain.contains("\u001b["))
|
||||||
|
assert_true(!plain.contains("$1") && !plain.contains("$2"))
|
||||||
|
}
|
||||||
+56
-6
@@ -127,6 +127,50 @@ pub fn render_info_lines(
|
|||||||
lines
|
lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn render_logo_line(line : String, logo : Logo, no_color : Bool) -> String {
|
||||||
|
if line.is_empty() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
let buf = StringBuilder()
|
||||||
|
let mut has_color = false
|
||||||
|
if !no_color &&
|
||||||
|
!logo.primary_color.is_empty() &&
|
||||||
|
!line.has_prefix("$1") &&
|
||||||
|
!line.has_prefix("$2") {
|
||||||
|
buf.write_string(logo.primary_color)
|
||||||
|
has_color = true
|
||||||
|
}
|
||||||
|
let mut i = 0
|
||||||
|
let len = line.length()
|
||||||
|
while i < len {
|
||||||
|
if i + 1 < len && line[i] == '$' {
|
||||||
|
let next = line[i + 1]
|
||||||
|
if next == '1' {
|
||||||
|
if !no_color && !logo.primary_color.is_empty() {
|
||||||
|
buf.write_string(logo.primary_color)
|
||||||
|
has_color = true
|
||||||
|
}
|
||||||
|
i += 2
|
||||||
|
continue
|
||||||
|
} else if next == '2' {
|
||||||
|
if !no_color && !logo.secondary_color.is_empty() {
|
||||||
|
buf.write_string(logo.secondary_color)
|
||||||
|
has_color = true
|
||||||
|
}
|
||||||
|
i += 2
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf.write_char(Int32::unsafe_to_char(line[i].to_int()))
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
if has_color {
|
||||||
|
buf.write_string("\u001b[0m")
|
||||||
|
}
|
||||||
|
buf.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
pub fn render_fetch(info : SystemInfo, opts : CliOptions) -> String {
|
pub fn render_fetch(info : SystemInfo, opts : CliOptions) -> String {
|
||||||
if opts.json {
|
if opts.json {
|
||||||
@@ -146,26 +190,32 @@ pub fn render_fetch(info : SystemInfo, opts : CliOptions) -> String {
|
|||||||
if opts.no_logo {
|
if opts.no_logo {
|
||||||
return info_lines.join("\n")
|
return info_lines.join("\n")
|
||||||
}
|
}
|
||||||
|
let rendered_logo : Array[String] = []
|
||||||
let mut logo_width = 0
|
let mut logo_width = 0
|
||||||
for l in logo.lines {
|
for l in logo.lines {
|
||||||
let w = visible_len(l)
|
let rl = render_logo_line(l, logo, opts.no_color)
|
||||||
|
rendered_logo.push(rl)
|
||||||
|
let w = visible_len(rl)
|
||||||
if w > logo_width {
|
if w > logo_width {
|
||||||
logo_width = w
|
logo_width = w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let gap = 3
|
let gap = 3
|
||||||
let total_rows = if logo.lines.length() > info_lines.length() {
|
let total_rows = if rendered_logo.length() > info_lines.length() {
|
||||||
logo.lines.length()
|
rendered_logo.length()
|
||||||
} else {
|
} else {
|
||||||
info_lines.length()
|
info_lines.length()
|
||||||
}
|
}
|
||||||
let out : Array[String] = []
|
let out : Array[String] = []
|
||||||
for i in 0..<total_rows {
|
for i in 0..<total_rows {
|
||||||
let left_raw = if i < logo.lines.length() { logo.lines[i] } else { "" }
|
let left_raw = if i < rendered_logo.length() {
|
||||||
|
rendered_logo[i]
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
let left_padded = pad_right_visible(left_raw, logo_width + gap)
|
let left_padded = pad_right_visible(left_raw, logo_width + gap)
|
||||||
let left_colored = colorize(left_padded, logo.primary_color, opts.no_color)
|
|
||||||
let right = if i < info_lines.length() { info_lines[i] } else { "" }
|
let right = if i < info_lines.length() { info_lines[i] } else { "" }
|
||||||
out.push("\{left_colored}\{right}")
|
out.push("\{left_padded}\{right}")
|
||||||
}
|
}
|
||||||
out.join("\n")
|
out.join("\n")
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user