Skip to content

🩹 [Patch]: Color the token expiration date in contexts based on validity #430

@MariusStorhaug

Description

@MariusStorhaug
Member

Describe the change

Green if above 4h
Yellow if between 1 and 4 hours
Orange between 0 and 1 hour,
else
red

function Get-ColoredText {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [double]$MaxValue,

        [Parameter(Mandatory)]
        [double]$Value,

        [Parameter(Mandatory)]
        [string]$Text
    )

    $ratio = [Math]::Min(($Value / $MaxValue), 1)

    # Calculate RGB color based on ratio (Green -> Yellow -> Orange -> Red)
    if ($ratio -le 0.5) {
        # Green to Yellow
        $r = [Math]::Round(255 * (2 * $ratio))
        $g = 255
    }
    else {
        # Yellow to Red
        $r = 255
        $g = [Math]::Round(255 * (2 - 2 * $ratio))
    }

    $b = 0

    $color = $PSStyle.Foreground.FromRgb($r, $g, $b)

    # Output colored text
    "$color$Text$($PSStyle.Reset)"
}

Metadata

Metadata

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

    Participants

    @MariusStorhaug

    Issue actions

      🩹 [Patch]: Color the token expiration date in contexts based on validity · Issue #430 · PSModule/GitHub