Skip to content

Instantly share code, notes, and snippets.

@mxro
Created April 21, 2026 05:57
Show Gist options
  • Select an option

  • Save mxro/f5579b9fe6e3feed48b8eb8e6ab6a5eb to your computer and use it in GitHub Desktop.

Select an option

Save mxro/f5579b9fe6e3feed48b8eb8e6ab6a5eb to your computer and use it in GitHub Desktop.
Windows Time TUI in PowerShell
$ErrorActionPreference = "Continue"
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
try {
$ScriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
. "$ScriptDir/config.ps1"
$ESC = [char]27
$HideCursor = "$ESC[?25l"
$ShowCursor = "$ESC[?25h"
$ClearScreen = "$ESC[2J"
$ClearLine = "$ESC[2K"
$ColorLabel = "$ESC[1;36m" # Bold Cyan
$ColorTime = "$ESC[1;32m" # Bold Green
$ColorDate = "$ESC[90m" # Gray
$ColorLine = "$ESC[38;5;237m" # Dark Gray
$ResetColor = "$ESC[0m"
$IconLocation = [char]::ConvertFromUtf32(0xED00)
$IconClock = [char]::ConvertFromUtf32(0xF43A)
$IconCalendar = [char]::ConvertFromUtf32(0xF00ED)
function Write-TimeZones {
$labels = @($TimeZones.Keys)
$screenWidth = $host.UI.RawUI.WindowSize.Width
$contentWidth = 40
$padding = [Math]::Max(0, [Math]::Floor(($screenWidth - $contentWidth) / 2))
$indent = " " * $padding
for ($i = 0; $i -lt $labels.Count; $i++) {
$label = $labels[$i]
$tz = $TimeZones[$label]
$time = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId((Get-Date), $tz)
$date = $time.ToString("yyyy-MM-dd")
$timeStr = if ($Use12HourFormat) { $time.ToString("hh:mm tt") } else { $time.ToString("HH:mm") }
Write-Host "$ClearLine$indent$ColorLabel$IconLocation $label$ResetColor"
Write-Host "$ClearLine$indent $ColorTime$IconClock $timeStr$ResetColor"
Write-Host "$ClearLine$indent $ColorDate$IconCalendar $date$ResetColor"
if ($i -lt $labels.Count - 1) {
Write-Host "$ClearLine$indent$ColorLine$('-' * 28)$ResetColor"
}
}
}
function Get-LineCount {
return $TimeZones.Count * 3 + ($TimeZones.Count - 1)
}
function Main {
$host.UI.RawUI.WindowTitle = "Time TUI"
Write-Host $HideCursor -NoNewline
Write-Host $ClearScreen -NoNewline
$lastHeight = 0
while ($true) {
$lastLines = Get-LineCount
$screenHeight = $host.UI.RawUI.WindowSize.Height
if ($screenHeight -le 0) { $screenHeight = 24 }
if ($screenHeight -ne $lastHeight) {
Write-Host $ClearScreen -NoNewline
$lastHeight = $screenHeight
}
$topPadding = [Math]::Max(0, [Math]::Floor(($screenHeight - $lastLines) / 2))
[Console]::SetCursorPosition(0, 0)
if ($topPadding -gt 0) {
Write-Host ("$ClearLine`n" * $topPadding) -NoNewline
}
Write-TimeZones
Start-Sleep -Seconds $UpdateIntervalSeconds
}
}
Main
}
catch {
Write-Host "Error: $_" -ForegroundColor Red
}
finally {
if ($ShowCursor) { Write-Host "$ShowCursor" -NoNewline }
Write-Host ""
Read-Host "Press Enter to exit"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment