From 3bdf8745846ca10da30f6bdef5380f8fb63c8a26 Mon Sep 17 00:00:00 2001 From: Sprite Date: Thu, 19 Nov 2026 10:03:28 +0000 Subject: [PATCH] Update files --- justfile | 23 +++++++++++++++++ logos.mbt | 50 ++++++++++++++++++------------------- moonfetch_test.mbt | 42 +++++++++++++++++++++++++++++++ render.mbt | 62 +++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 146 insertions(+), 31 deletions(-) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 0000000..5bdeecc --- /dev/null +++ b/justfile @@ -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 diff --git a/logos.mbt b/logos.mbt index bde371f..93dacc9 100644 --- a/logos.mbt +++ b/logos.mbt @@ -38,18 +38,18 @@ pub fn get_logo(name : String) -> Logo { "ubuntu" => { name: "ubuntu", - primary_color: "\u001b[1;33m", - secondary_color: "\u001b[1;31m", + primary_color: "\u001b[1;31m", + secondary_color: "\u001b[1;37m", lines: [ - " .-/+oossssoo+/-. ", " `:+ssssssssssssssssss+:` ", - " -+ssssssssssssssssssyyssss+- ", " .ossssssssssssssssssdMMMNysssso. ", - " /ssssssssssshdmmNNmmyNMMMMhssssss/ ", " +ssssssssshmydMMMMMMMNddddyssssssss+ ", - " /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ ", ".ssssssssdMMMNhsssssssssshNMMMdssssssss. ", - "+sssshhhyNMMNyssssssssssssyNMMMysssssss+ ", "ossyNMMMNyMMhsssssssssssssshmmmhssssssso ", - "ossyNMMMNyMMhsssssssssssssshmmmhssssssso ", "+sssshhhyNMMNyssssssssssssyNMMMysssssss+ ", - ".ssssssssdMMMNhsssssssssshNMMMdssssssss. ", " /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ ", - " +sssssssssdmydMMMMMMMMddddyssssssss+ ", " /ssssssssssshdmNNNNmyNMMMMhssssss/ ", - " .ossssssssssssssssssdMMMNysssso. ", " -+sssssssssssssssssyyyssss+- ", + "$1 .-/+oossssoo+/-. ", " `:+ssssssssssssssssss+:` ", + " -+ssssssssssssssssss$2yy$1ssss+- ", " .ossssssssssssssssss$2dMMMNy$1sssso. ", + " /sssssssssss$2hdmmNNmmyNMMMMh$1ssssss/ ", " +sssssssss$2hmydMMMMMMMNddddy$1ssssssss+ ", + " /ssssssss$2hNMMMyhhyyyyhmNMMMNh$1ssssssss/ ", ".ssssssss$2dMMMNh$1ssssssssss$2hNMMMd$1ssssssss. ", + "+ssss$2hhhyNMMNy$1ssssssssssss$2yNMMMy$1sssssss+ ", "oss$2yNMMMNyMMh$1ssssssssssssss$2hmmmh$1ssssssso ", + "oss$2yNMMMNyMMh$1ssssssssssssss$2hmmmh$1ssssssso ", "+ssss$2hhhyNMMNy$1ssssssssssss$2yNMMMy$1sssssss+ ", + ".ssssssss$2dMMMNh$1ssssssssss$2hNMMMd$1ssssssss. ", " /ssssssss$2hNMMMyhhyyyyhdNMMMNh$1ssssssss/ ", + " +sssssssss$2dmydMMMMMMMMddddy$1ssssssss+ ", " /sssssssssss$2hdmNNNNmyNMMMMh$1ssssss/ ", + " .ossssssssssssssssss$2dMMMNy$1sssso. ", " -+sssssssssssssssss$2yyy$1ssss+- ", " `:+ssssssssssssssssss+:` ", " .-/+oossssoo+/-. ", ], } @@ -59,11 +59,11 @@ pub fn get_logo(name : String) -> Logo { primary_color: "\u001b[1;36m", secondary_color: "\u001b[36m", lines: [ - " -` ", " .o+` ", + "$1 -` ", " .o+` ", " `ooo/ ", " `+oooo: ", " `+oooooo: ", " -+oooooo+: ", " `/:-:++oooo+: ", " `/++++/+++++++: ", - " `/++++++++++++++: ", " `/+++ooooooooooooo/` ", + "$2 `/++++++++++++++: ", " `/+++ooooooooooooo/` ", " ./ooosssso++osssssso+` ", " .oossssso-````/ossssss+` ", " -osssssso. :ssssssso. ", " :osssssss/ osssso+++. ", " /ossssssss/ +ssssooo/- ", " `/ossssso+/:- -:/+osssso+- ", @@ -75,16 +75,16 @@ pub fn get_logo(name : String) -> Logo { { name: "fedora", primary_color: "\u001b[1;34m", - secondary_color: "\u001b[34m", + secondary_color: "\u001b[1;37m", lines: [ - " .',;::::;,'. ", " .';:cccccccccccc:;,. ", + "$1 .',;::::;,'. ", " .';:cccccccccccc:;,. ", " .;cccccccccccccccccccccc;. ", " .:cccccccccccccccccccccccccc:. ", - " .;ccccccccccccc;.:dddl:.;ccccccc;. ", " .:ccccccccccccc;OWMKOOXMWd;ccccccc:. ", - ".:ccccccccccccc;KMMc;cc;xMMc;ccccccc:. ", ",cccccccccccccc;MMM.;cc;;WW:;cccccccc, ", - ":cccccccccccccc;MMM.;cccccccccccccccc: ", ":ccccccc;oxOOOo;MMM0OOk.;cccccccccccc: ", - "cccccc;0MMKxdd:;MMMkddc.;cccccccccccc; ", "ccccc;XM0';cccc;MMM.;cccccccccccccccc' ", - "ccccc;MMo;ccccc;MMW.;ccccccccccccccc; ", "ccccc;0MNc.ccc.xMMd;ccccccccccccccc; ", - "cccccc;dNMWXXXWM0:;cccccccccccccc:, ", "cccccccc;.:odl:.;cccccccccccccc:,. ", + " .;ccccccccccccc;.:$2dddl$1:.;ccccccc;. ", " .:ccccccccccccc;$2OWMKOOXMWd$1;ccccccc:. ", + ".:ccccccccccccc;$2KMM$1c;cc;$2xMM$1c;ccccccc:. ", ",cccccccccccccc;$2MMM$1.;cc;;$2WW$1:;cccccccc, ", + ":cccccccccccccc;$2MMM$1.;cccccccccccccccc: ", ":ccccccc;$2oxOOOo$1;$2MMM0OOk$1.;cccccccccccc: ", + "cccccc;$20MMKxdd$1:;$2MMMkddc$1.;cccccccccccc; ", "ccccc;$2XM0$1';cccc;$2MMM$1.;cccccccccccccccc' ", + "ccccc;$2MMo$1;ccccc;$2MMW$1.;ccccccccccccccc; ", "ccccc;$20MNc$1.ccc.$2xMMd$1;ccccccccccccccc; ", + "cccccc;$2dNMWXXXWM0$1:;cccccccccccccc:, ", "cccccccc;.:$2odl$1:.;cccccccccccccc:,. ", ":cccccccccccccccccccccccccccc:'. ", ".:cccccccccccccccccccccc:;,.. ", " '::cccccccccccccc::;,. ", ], @@ -126,10 +126,10 @@ pub fn get_logo(name : String) -> Logo { primary_color: "\u001b[1;35m", secondary_color: "\u001b[1;33m", lines: [ - " _..._ ", " .:::::::. * ", " ::::::::::: ", - " ::::::::::::: . ", " ::::::' `::: ", " :::::' `:: ", - " ::::: .: * ", " :::::. .:: ", " ::::::. .::: ", - " ::::::::::::' . ", " ':::::::::' ", " `'::::'' * ", + "$1 _..._ ", " .:::::::. $2* ", "$1 ::::::::::: ", + " ::::::::::::: $2. ", "$1 ::::::' `::: ", " :::::' `:: ", + " ::::: .: $2* ", "$1 :::::. .:: ", " ::::::. .::: ", + " ::::::::::::' $2. ", "$1 ':::::::::' ", " `'::::'' $2* ", ], } } diff --git a/moonfetch_test.mbt b/moonfetch_test.mbt index c054d31..9e452dd 100644 --- a/moonfetch_test.mbt +++ b/moonfetch_test.mbt @@ -170,3 +170,45 @@ test "visible_len and render_fetch no_color" { assert_true(json_out.contains("\"username\": \"alice\"")) 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")) +} diff --git a/render.mbt b/render.mbt index 76b1777..820cf3c 100644 --- a/render.mbt +++ b/render.mbt @@ -127,6 +127,50 @@ pub fn render_info_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 { if opts.json { @@ -146,26 +190,32 @@ pub fn render_fetch(info : SystemInfo, opts : CliOptions) -> String { if opts.no_logo { return info_lines.join("\n") } + let rendered_logo : Array[String] = [] let mut logo_width = 0 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 { logo_width = w } } let gap = 3 - let total_rows = if logo.lines.length() > info_lines.length() { - logo.lines.length() + let total_rows = if rendered_logo.length() > info_lines.length() { + rendered_logo.length() } else { info_lines.length() } let out : Array[String] = [] for i in 0..