From b36652e81bef431cd8c10f85421989fa2ba28e0a Mon Sep 17 00:00:00 2001 From: blazemalan <11034821+blazemalan@users.noreply.github.com> Date: Fri, 31 Jul 2026 01:35:51 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Remove=20truncate=5Fpct=20functi?= =?UTF-8?q?on=20and=20use=20inline=20replacements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- statusline.ps1 | 20 +++++++------------- tests/ps-tests.ps1 | 16 ---------------- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/statusline.ps1 b/statusline.ps1 index dc7c004..129070a 100644 --- a/statusline.ps1 +++ b/statusline.ps1 @@ -82,15 +82,9 @@ function fmt_when($epoch) { return '' } -function truncate_pct($pct) { - if ([string]::IsNullOrEmpty($pct)) { return '' } - if ($pct -isnot [string]) { $pct = $pct.ToString() }; $idx = $pct.LastIndexOf('.') - if ($idx -ge 0) { return $pct.Substring(0, $idx) } - return $pct -} function ctx_circle($pctraw) { - $pct = truncate_pct $pctraw + $pct = [string]$pctraw -replace '\..*' if ([string]::IsNullOrEmpty($pct)) { return '' } $n = 0 if ([long]::TryParse($pct, [ref]$n)) { @@ -104,12 +98,12 @@ function ctx_circle($pctraw) { } function limit_pegged() { - $five = truncate_pct $script:five_pct + $five = [string]$script:five_pct -replace '\..*' if (-not [string]::IsNullOrEmpty($five)) { $n = 0; if (-not [long]::TryParse($five, [ref]$n)) { $n = 0 } if ($n -ge 100) { return $true } } - $week = truncate_pct $script:week_pct + $week = [string]$script:week_pct -replace '\..*' if (-not [string]::IsNullOrEmpty($week)) { $n = 0; if (-not [long]::TryParse($week, [ref]$n)) { $n = 0 } if ($n -ge 100) { return $true } @@ -333,7 +327,7 @@ function paint_sep() { } function tier_color($pctraw) { - $pct = truncate_pct $pctraw + $pct = [string]$pctraw -replace '\..*' if ([string]::IsNullOrEmpty($pct)) { return '' } $n = 0 if ([long]::TryParse($pct, [ref]$n)) { @@ -347,7 +341,7 @@ function tier_color($pctraw) { function cost_tier_color($usd) { if ([string]::IsNullOrEmpty($usd)) { return '' } - $dollars = truncate_pct $usd + $dollars = [string]$usd -replace '\..*' if ([string]::IsNullOrEmpty($dollars)) { $dollars = '0' } $n = 0 if ([long]::TryParse($dollars, [ref]$n)) { @@ -370,7 +364,7 @@ function span_sgr($sgr, $tier) { } function seg_rate($label, $pctraw, $reset_str) { - $pct = truncate_pct $pctraw + $pct = [string]$pctraw -replace '\..*' $n = 0 if ([long]::TryParse($pct, [ref]$n) -and $n -ge 100) { return egg $label $reset_str @@ -391,7 +385,7 @@ function seg_rate($label, $pctraw, $reset_str) { } function seg_ctx($pctraw, $size) { - $pct = truncate_pct $pctraw + $pct = [string]$pctraw -replace '\..*' $tier = tier_color $pct $res = "" $res += paint (span_sgr $script:CIRCLE_SGR $tier) (ctx_circle $pct) diff --git a/tests/ps-tests.ps1 b/tests/ps-tests.ps1 index 162bf73..00006f5 100644 --- a/tests/ps-tests.ps1 +++ b/tests/ps-tests.ps1 @@ -23,22 +23,6 @@ if ($null -eq (Get-Command fmt_size -ErrorAction SilentlyContinue)) { # --- Test fmt helpers --- -$truncateTests = @( - @{in='42.9'; out='42'} - @{in='100'; out='100'} - @{in='0.5'; out='0'} - @{in='.5'; out=''} - @{in=''; out=''} - @{in=$null; out=''} - @{in='no_dot'; out='no_dot'} - @{in=42.9; out='42'} -) -foreach ($t in $truncateTests) { - $res = truncate_pct $t.in - if ($res -ne $t.out) { Fail "truncate_pct" "Expected '$($t.out)', got '$res' for $($t.in)" } -} -Pass "truncate_pct" - $costTests = @( @{in=1.009058; out='$1.01'} @{in=0; out='$0.00'}