From ab2cea7c8b987d2bdcdb40d6a3d69f56c1d647cb Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Wed, 16 Jul 2025 23:56:25 +0200 Subject: [PATCH 1/9] update readme --- README.md | 58 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index ec733b0..49224a7 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -## WT64 +# WT64 ![alt text](https://github.com/KillerFeature/WT64/raw/master/WT64_hero.png) A Commodore 64 Experience for Windows Terminal ![Video](https://github.com/KillerFeature/WT64/raw/master/video.gif "Video") -### Features -- Native C64 style commands like LOAD "$",8 -- Native C64 LIST layout for directory listing with size reporting and Blocks free indication. +### FEATURES +- Native C64 style commands like `LOAD "$",8` +- Native C64 LIST layout for directory listing with size reporting and Blocks free indication - Startup screen with actual PowerShell version and memory reporting -### Supported commands: -1. LIST [Lists the files in local or path directory in C64 disk style] -2. LOAD "$",8 [Shows the classic loading sequence] -3. SYS64738 [Shows the opening prompt] -4. EDIT [Shorthand for nano] +### SUPPORTED COMMANDS +- **`LIST `** Lists the files in local or path directory in C64 disk style +- **`LOAD "$",8`** Shows the classic loading sequence +- **`SYS64738`** Shows the opening prompt +- **`EDIT `** Alias for Nano ### PREREQUISITES 1. [Windows Terminal](https://aka.ms/terminal) © Microsoft @@ -21,26 +21,30 @@ A Commodore 64 Experience for Windows Terminal 3. [C64 font](https://www.dafont.com/commodore-64.font) © Devin Cook ### INSTALLATION +0. Make sure the prerequisites are installed 1. Clone the repo -2. Open Profile.json and cut paste the list item and colorschemen into your Windows Terminal Settings file -3. Change the places in your WT Settings where it says [INSERT YOUR REPO PATH HERE] -4. Start Windows Terminal open the WT64 teminal +2. Move or copy the files `commands.ps1`, `icon.png`, `P64_bg.png` & `reset.ps1` to a folder of your liking +I use a folder `WT64` in `Program Files` +3. Open `Profile.json`, cut & paste the **list item** and **colorscheme** into your Windows Terminal Settings file +`%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json` +4. Replace where it says `[INSERT YOUR REPO PATH HERE]` with the path of the folder you created in step 2 and save +5. Start Windows Terminal & open a WT64 terminal -### BACKGROUND -The standard background doesn't always scale properly, you can use the `P64_bg.svg` to create a new background that will have a 75px border and fit your screenresolution by followin these steps: -**1. Edit SVG** -Open the SVG in any text-editor and edit the width and height on the first in the viewBox & third line in the width and height attributes -It should be your screen width and your screen height minus taskbar (40px) and window header (36px) -If you don't use the taskbar or have it on the side of your screen adjust the height and width in the SVG accordingly -**2. Convert the SVG to PNG** -Open the SVG in an SVG capable photo-editor and save as P64_bg.png. -I use photopea.com for this, online, easy & free! -* Drag SVG onto center area or use `File > Open...` -* Select `File > Export as > PNG` -* Click `Save` -* If necessary rename the PNG-file to P64_bg.png +### BACKGROUND ISSUES +The standard background doesn’t always scale properly, you can use the `P64_bg.svg` to create a new background that will have a 75px border and fit your screenresolution by following these steps: +#### 1. Edit SVG +Open the SVG in any text-editor, edit the width and height on the first line in the viewBox attribute & third line in the width and height attributes and save +It should be your full screen width and height minus taskbar (40px) and window header (36px) +If you don’t use the taskbar or have it on the side of your screen adjust the height and width in the SVG accordingly +#### 2. Convert the SVG to PNG +Open the updated SVG in an SVG capable photo-editor and save as `P64_bg.png` -**3. Replace the background** +I use [PhotoPea](https://photopea.com) for this, online, easy & free! +- Drag the SVG-file onto center area or use `File > Open...` +- Select `File > Export as > PNG` +- Click `Save` +- If necessary rename the PNG-file to `P64_bg.png` +#### 3. Replace the background Replace the current background with this newly created one by overwriting the current one in the location you have stored WT64 -**4. Done!** +#### 4. Done! Restart Windows Terminal and see the new background in action \ No newline at end of file From 5049859538ea91453454142af252af1f5e9e2418 Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 29 Jul 2025 22:38:09 +0200 Subject: [PATCH 2/9] Code cleanup --- commands.ps1 | 166 +++++++++++++++++++++++++++++++-------------------- reset.ps1 | 37 +++++++----- 2 files changed, 122 insertions(+), 81 deletions(-) diff --git a/commands.ps1 b/commands.ps1 index 29fecf9..e10d782 100644 --- a/commands.ps1 +++ b/commands.ps1 @@ -1,122 +1,157 @@ $e = "$([char]27)" -function CenterText([string]$inputLine,[int]$textWidth,[string]$wrapChar) { - If (($inputLine.length + ($wrapChar.Length *2)) -ge $textWidth) { - - return -join($wrapChar,$inputLine.Substring(0,$textWidth-2*$wrapChar.Length),$wrapChar)} - else { - $diff = ($textWidth+(2*$wrapChar.Length)) - $inputLine.Length - $spaceCount = [math]::Floor($diff/2) +function CenterText([string]$inputLine, [int]$textWidth, [string]$wrapChar) +{ + If (($inputLine.length + ($wrapChar.Length * 2)) -ge $textWidth) + { + return -join($wrapChar, $inputLine.Substring(0, $textWidth - 2 * $wrapChar.Length), $wrapChar) + } + else + { + $diff = ($textWidth + (2 * $wrapChar.Length)) - $inputLine.Length + $spaceCount = [math]::Floor($diff / 2) $leadingSpaces = $(" " * $spaceCount) - if (-join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces,$wrapChar).Length -lt $textWidth) { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces,$wrapChar, " ") - } else { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces,$wrapChar) - + + if (-join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar).Length -lt $textWidth) + { + return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar, " ") + } + else + { + return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar) } } } -function LeftText([string]$inputLine,[int]$textWidth,[string]$wrapChar) { - If ($inputLine.length -ge $textWidth) { - return -join($inputLine.Substring(0,$textWidth)) + +function LeftText([string]$inputLine, [int]$textWidth, [string]$wrapChar) +{ + If ($inputLine.length -ge $textWidth) + { + return -join($inputLine.Substring(0, $textWidth)) } - else { - $diff = $textWidth- $inputLine.Length + else + { + $diff = $textWidth - $inputLine.Length $leadingSpaces = $(" " * $diff) - return -join($inputLine,$leadingSpaces) - } + return -join($inputLine, $leadingSpaces) + } } -function RightText([string]$inputLine,[int]$textWidth,[string]$wrapChar) { - If (($inputLine.length+(2*$wrapChar.Length)) -ge $textWidth-1) { - $trimmed = $textWidth - (2*$wrapChar.Length) - return -join($wrapChar,$inputLine.Substring(0, $trimmed-2),$wrapChar," ") - } - else { - $diff = $textWidth - ($inputLine.Length+(2*$wrapChar.Length)) +function RightText([string]$inputLine, [int]$textWidth, [string]$wrapChar) +{ + If (($inputLine.length + (2 * $wrapChar.Length)) -ge $textWidth - 1) + { + $trimmed = $textWidth - (2 * $wrapChar.Length) + return -join($wrapChar, $inputLine.Substring(0, $trimmed - 2), $wrapChar, " ") + } + else + { + $diff = $textWidth - ($inputLine.Length + (2 * $wrapChar.Length)) $leadingSpaces = $(" " * $diff) + return -join($wrapChar, $inputLine, $wrapChar, $leadingSpaces) } - } -function LIST ([string]$dirName){ + +function LIST([string]$dirName) +{ $midWidth = [int] (Get-Host).UI.RawUI.MaxWindowSize.Width - 4 - if ($dirName.Length -gt 0) { + + if ($dirName.Length -gt 0) + { $folderName = [System.IO.Path]::GetDirectoryName($dirName).toUpper().split("\")[-1] - } else { + } + else + { $folderName = (Get-Location).toString().toUpper().split("\")[-1] } - $e = "$([char]27)" - -join("0 $e[44m$e[94m$e[7m",(CenterText $folderName ($midWidth-6)),"$e[27m$e[0m") -Get-ChildItem $dirName| ForEach-Object { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper().Split(".")[0] ($midWidth-14) '"')," ", (RightText $_.name.toUpper().Split(".")[1] 10 ))} --join((Get-PSDrive c).Free, " BLOCKS FREE.") -"READY." + + $e = "$([char]27)" + -join("0 $e[44m$e[94m$e[7m", (CenterText $folderName ($midWidth - 6)), "$e[27m$e[0m") + Get-ChildItem $dirName | ForEach-Object { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper().Split(".")[0] ($midWidth - 14) '"'), " ", (RightText $_.name.toUpper().Split(".")[1] 10)) } + -join((Get-PSDrive c).Free, " BLOCKS FREE.") + "READY." } -function SYS64738() { -"$e[0m" + +function SYS64738() +{ + "$e[0m" Clear-Host -"" -$line1 = "**** WINDOWS TERMINAL POWERSHELL V" + $PSVersionTable.PSVersion.Major + "." + $PSVersionTable.PSVersion.Minor + " ****" -$line2 = " " + $mem + "K SYSTEM RAM "+ $free +"000 BASIC BYTES FREE" - -CenterText $line1 ((Get-Host).UI.RawUI.MaxWindowSize.Width) -" " -CenterText $line2 ((Get-Host).UI.RawUI.MaxWindowSize.Width) -" " -"READY." + "" + $line1 = "**** WINDOWS TERMINAL POWERSHELL V" + $PSVersionTable.PSVersion.Major + "." + $PSVersionTable.PSVersion.Minor + " ****" + $line2 = " " + $mem + "K SYSTEM RAM " + $free + "000 BASIC BYTES FREE" + + CenterText $line1 ((Get-Host).UI.RawUI.MaxWindowSize.Width) + " " + CenterText $line2 ((Get-Host).UI.RawUI.MaxWindowSize.Width) + " " + "READY." } -function LOAD([string]$inputLn) { - if ($inputLn -eq '$ 8') { +function LOAD([string]$inputLn) +{ + if ($inputLn -eq '$ 8') + { "SEARCHING FOR $" Start-Sleep -Seconds 2 "LOADING" Start-Sleep -Seconds 1 "READY." - - } else { + } + else + { "SYNTAX ERROR" } } -function EDIT ($File){ -$File = $File -replace “\\”, “/” -replace “ “, “\ “ -bash -c "nano $File" -} +function EDIT($File) +{ + $File = $File -replace “\\”, “/” -replace “ “, “\ “ + bash -c "nano $File" +} # # Internal commands (should be hidden inside of a module) # -$varNameRegEx='([a-zA-Z]+)([\$|\%]?)' # returns name and type -$expressionRegEx='\s*(\S+)\s*' # returns expression +$varNameRegEx = '([a-zA-Z]+)([\$|\%]?)' # returns name and type +$expressionRegEx = '\s*(\S+)\s*' # returns expression -function _CalculateExpressionValue([string]$Expression) { +function _CalculateExpressionValue([string]$Expression) +{ # TODO: Hide this in module - while ($Expression -match $varNameRegEx) { + while ($Expression -match $varNameRegEx) + { $Expression = $Expression -replace $Matches[0], [string](Get-Variable -Name $Matches[1] -ValueOnly -Scope Global) } - try { + + try + { return (Invoke-Expression $Expression) - } catch { + } + catch + { "SYNTAX ERROR" } } - # # Public functions = C64 commands # -function RUN ($File){ +function RUN($File) +{ Invoke-Item $File } -function LET([string]$inputLn) { +function LET([string]$inputLn) +{ $regex = "^\s*$varNameRegEx\s*=\s*$expressionRegEx\s*" - if ($inputLn -notmatch $regex) { + + if ($inputLn -notmatch $regex) + { "SYNTAX ERROR" exit } @@ -129,6 +164,7 @@ function LET([string]$inputLn) { # TODO: Include Type also } -function PRINT([string]$inputLn) { +function PRINT([string]$inputLn) +{ Write-Host (_CalculateExpressionValue $inputLn) } diff --git a/reset.ps1 b/reset.ps1 index a3a3e1e..7894204 100644 --- a/reset.ps1 +++ b/reset.ps1 @@ -1,31 +1,36 @@ "LOADING PLEASE WAIT ..." $e = "$([char]27)" -$mem = [regex]::Match((wmic OS get TotalVisibleMemorySize /Value),'[0-9]+').Value + '' -$free = [regex]::Match((wmic OS get FreePhysicalMemory /Value),'[0-9]+').Value + '' +$mem = [regex]::Match((wmic OS get TotalVisibleMemorySize /Value), '[0-9]+').Value + '' +$free = [regex]::Match((wmic OS get FreePhysicalMemory /Value), '[0-9]+').Value + '' # This will display READY.\n as prompt # function prompt {"READY.`n"} function prompt {"`r"} -function CenterText([string]$inputLine,[int]$textWidth,[string]$wrapChar) { - If (($inputLine.length + ($wrapChar.Length *2)) -ge $textWidth) { - return -join($wrapChar,$inputLine.Substring(0,$textWidth-2*$wrapChar.Length),$wrapChar)} - else { - $diff = ($textWidth+(2*$wrapChar.Length)) - $inputLine.Length - $spaceCount = [math]::Floor($diff/2) +function CenterText([string]$inputLine, [int]$textWidth, [string]$wrapChar) +{ + If (($inputLine.length + ($wrapChar.Length * 2)) -ge $textWidth) + { + return -join($wrapChar, $inputLine.Substring(0, $textWidth - 2 * $wrapChar.Length), $wrapChar) + } + else + { + $diff = ($textWidth + (2 * $wrapChar.Length)) - $inputLine.Length + $spaceCount = [math]::Floor($diff / 2) $leadingSpaces = $(" " * $spaceCount) - if (-join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces,$wrapChar).Length -lt $textWidth) { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces,$wrapChar, " ") - - } else { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces,$wrapChar) - + + if (-join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar).Length -lt $textWidth) + { + return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar, " ") + } + else + { + return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar) } } - } + $scriptRoot = Split-Path -parent $PSCommandPath . "$scriptRoot\commands.ps1" SYS64738 - From fa444f383a4907ed84b145ed83d73ebe69468c39 Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 29 Jul 2025 22:51:27 +0200 Subject: [PATCH 3/9] Add run command to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 49224a7..9d06369 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ A Commodore 64 Experience for Windows Terminal - **`LOAD "$",8`** Shows the classic loading sequence - **`SYS64738`** Shows the opening prompt - **`EDIT `** Alias for Nano +- **`RUN `** Run a file ### PREREQUISITES 1. [Windows Terminal](https://aka.ms/terminal) © Microsoft From 0d8f01998a2618b26d4c2f2a2eea23de68e9cf89 Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 29 Jul 2025 22:52:52 +0200 Subject: [PATCH 4/9] improve output of list command --- commands.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands.ps1 b/commands.ps1 index e10d782..0a17fe1 100644 --- a/commands.ps1 +++ b/commands.ps1 @@ -68,9 +68,10 @@ function LIST([string]$dirName) $folderName = (Get-Location).toString().toUpper().split("\")[-1] } - $e = "$([char]27)" -join("0 $e[44m$e[94m$e[7m", (CenterText $folderName ($midWidth - 6)), "$e[27m$e[0m") - Get-ChildItem $dirName | ForEach-Object { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper().Split(".")[0] ($midWidth - 14) '"'), " ", (RightText $_.name.toUpper().Split(".")[1] 10)) } + Get-ChildItem $dirName -directory | ForEach-Object { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper() ($midWidth - 14) '"')) } + Get-ChildItem $dirName -file .* | ForEach-Object { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper() ($midWidth - 14) '"')) } + Get-ChildItem $dirName -file *.* | ForEach-Object { if ($_.name.toUpper().Split(".")[0] -gt 0) { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper().Split(".")[0] ($midWidth - 14) '"'), " ", (RightText $_.name.toUpper().Split(".")[1] 10 )) } } -join((Get-PSDrive c).Free, " BLOCKS FREE.") "READY." } From 70b0ea6f36a2743914e80d5b7acbdd42bd7cb9ac Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 29 Jul 2025 23:08:09 +0200 Subject: [PATCH 5/9] improve let command --- commands.ps1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/commands.ps1 b/commands.ps1 index 0a17fe1..da2a713 100644 --- a/commands.ps1 +++ b/commands.ps1 @@ -154,15 +154,16 @@ function LET([string]$inputLn) if ($inputLn -notmatch $regex) { "SYNTAX ERROR" - exit } - - $varName = $Matches[1] - $varType = $Matches[2] - $varCalculus = $Matches[3] - $varValue = (_CalculateExpressionValue $varCalculus) - Set-Variable -Name $varName -Value $varValue -Scope Global - # TODO: Include Type also + else + { + $varName = $Matches[1] + $varType = $Matches[2] + $varCalculus = $Matches[3] + $varValue = (_CalculateExpressionValue $varCalculus) + Set-Variable -Name $varName -Value $varValue -Scope Global + # TODO: Include Type also + } } function PRINT([string]$inputLn) From 649f9d6b590501a46b1dc6b4b340136a6e4b6016 Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 29 Jul 2025 23:18:06 +0200 Subject: [PATCH 6/9] remove CenterText function from reset.ps1 --- reset.ps1 | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/reset.ps1 b/reset.ps1 index 7894204..03b46ec 100644 --- a/reset.ps1 +++ b/reset.ps1 @@ -7,29 +7,6 @@ $free = [regex]::Match((wmic OS get FreePhysicalMemory /Value), '[0-9]+').Value # function prompt {"READY.`n"} function prompt {"`r"} -function CenterText([string]$inputLine, [int]$textWidth, [string]$wrapChar) -{ - If (($inputLine.length + ($wrapChar.Length * 2)) -ge $textWidth) - { - return -join($wrapChar, $inputLine.Substring(0, $textWidth - 2 * $wrapChar.Length), $wrapChar) - } - else - { - $diff = ($textWidth + (2 * $wrapChar.Length)) - $inputLine.Length - $spaceCount = [math]::Floor($diff / 2) - $leadingSpaces = $(" " * $spaceCount) - - if (-join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar).Length -lt $textWidth) - { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar, " ") - } - else - { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar) - } - } -} - $scriptRoot = Split-Path -parent $PSCommandPath . "$scriptRoot\commands.ps1" From 82c5a31a1c4b26ff5370ae892773f7e186fc6859 Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 29 Jul 2025 23:18:32 +0200 Subject: [PATCH 7/9] reorder functions in public and internal sections --- commands.ps1 | 149 +++++++++++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/commands.ps1 b/commands.ps1 index da2a713..dd2686a 100644 --- a/commands.ps1 +++ b/commands.ps1 @@ -1,59 +1,6 @@ -$e = "$([char]27)" - -function CenterText([string]$inputLine, [int]$textWidth, [string]$wrapChar) -{ - If (($inputLine.length + ($wrapChar.Length * 2)) -ge $textWidth) - { - return -join($wrapChar, $inputLine.Substring(0, $textWidth - 2 * $wrapChar.Length), $wrapChar) - } - else - { - $diff = ($textWidth + (2 * $wrapChar.Length)) - $inputLine.Length - $spaceCount = [math]::Floor($diff / 2) - $leadingSpaces = $(" " * $spaceCount) - - if (-join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar).Length -lt $textWidth) - { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar, " ") - } - else - { - return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar) - } - } -} - -function LeftText([string]$inputLine, [int]$textWidth, [string]$wrapChar) -{ - If ($inputLine.length -ge $textWidth) - { - return -join($inputLine.Substring(0, $textWidth)) - } - else - { - $diff = $textWidth - $inputLine.Length - $leadingSpaces = $(" " * $diff) - - return -join($inputLine, $leadingSpaces) - } -} - -function RightText([string]$inputLine, [int]$textWidth, [string]$wrapChar) -{ - If (($inputLine.length + (2 * $wrapChar.Length)) -ge $textWidth - 1) - { - $trimmed = $textWidth - (2 * $wrapChar.Length) - - return -join($wrapChar, $inputLine.Substring(0, $trimmed - 2), $wrapChar, " ") - } - else - { - $diff = $textWidth - ($inputLine.Length + (2 * $wrapChar.Length)) - $leadingSpaces = $(" " * $diff) - - return -join($wrapChar, $inputLine, $wrapChar, $leadingSpaces) - } -} +# +# Public functions = C64 commands +# function LIST([string]$dirName) { @@ -113,10 +60,40 @@ function EDIT($File) bash -c "nano $File" } +function RUN($File) +{ + Invoke-Item $File +} + +function LET([string]$inputLn) +{ + $regex = "^\s*$varNameRegEx\s*=\s*$expressionRegEx\s*" + + if ($inputLn -notmatch $regex) + { + "SYNTAX ERROR" + } + else + { + $varName = $Matches[1] + $varType = $Matches[2] + $varCalculus = $Matches[3] + $varValue = (_CalculateExpressionValue $varCalculus) + Set-Variable -Name $varName -Value $varValue -Scope Global + # TODO: Include Type also + } +} + +function PRINT([string]$inputLn) +{ + Write-Host (_CalculateExpressionValue $inputLn) +} + # # Internal commands (should be hidden inside of a module) # +$e = "$([char]27)" $varNameRegEx = '([a-zA-Z]+)([\$|\%]?)' # returns name and type $expressionRegEx = '\s*(\S+)\s*' # returns expression @@ -138,35 +115,57 @@ function _CalculateExpressionValue([string]$Expression) } } -# -# Public functions = C64 commands -# - -function RUN($File) +function CenterText([string]$inputLine, [int]$textWidth, [string]$wrapChar) { - Invoke-Item $File + If (($inputLine.length + ($wrapChar.Length * 2)) -ge $textWidth) + { + return -join($wrapChar, $inputLine.Substring(0, $textWidth - 2 * $wrapChar.Length), $wrapChar) + } + else + { + $diff = ($textWidth + (2 * $wrapChar.Length)) - $inputLine.Length + $spaceCount = [math]::Floor($diff / 2) + $leadingSpaces = $(" " * $spaceCount) + + if (-join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar).Length -lt $textWidth) + { + return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar, " ") + } + else + { + return -join( $wrapChar, $leadingSpaces, $inputLine, $leadingSpaces, $wrapChar) + } + } } -function LET([string]$inputLn) +function LeftText([string]$inputLine, [int]$textWidth, [string]$wrapChar) { - $regex = "^\s*$varNameRegEx\s*=\s*$expressionRegEx\s*" - - if ($inputLn -notmatch $regex) + If ($inputLine.length -ge $textWidth) { - "SYNTAX ERROR" + return -join($inputLine.Substring(0, $textWidth)) } else { - $varName = $Matches[1] - $varType = $Matches[2] - $varCalculus = $Matches[3] - $varValue = (_CalculateExpressionValue $varCalculus) - Set-Variable -Name $varName -Value $varValue -Scope Global - # TODO: Include Type also + $diff = $textWidth - $inputLine.Length + $leadingSpaces = $(" " * $diff) + + return -join($inputLine, $leadingSpaces) } } -function PRINT([string]$inputLn) +function RightText([string]$inputLine, [int]$textWidth, [string]$wrapChar) { - Write-Host (_CalculateExpressionValue $inputLn) + If (($inputLine.length + (2 * $wrapChar.Length)) -ge $textWidth - 1) + { + $trimmed = $textWidth - (2 * $wrapChar.Length) + + return -join($wrapChar, $inputLine.Substring(0, $trimmed - 2), $wrapChar, " ") + } + else + { + $diff = $textWidth - ($inputLine.Length + (2 * $wrapChar.Length)) + $leadingSpaces = $(" " * $diff) + + return -join($wrapChar, $inputLine, $wrapChar, $leadingSpaces) + } } From d01aaddd3a35a7e71ada9a3797061a295ce75acd Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 5 Aug 2025 00:41:44 +0200 Subject: [PATCH 8/9] Code cleanup --- commands.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/commands.ps1 b/commands.ps1 index dd2686a..b1375b3 100644 --- a/commands.ps1 +++ b/commands.ps1 @@ -56,7 +56,8 @@ function LOAD([string]$inputLn) function EDIT($File) { - $File = $File -replace “\\”, “/” -replace “ “, “\ “ + $File = $File -replace "\\", "/" -replace " ", "\ " + bash -c "nano $File" } @@ -117,7 +118,7 @@ function _CalculateExpressionValue([string]$Expression) function CenterText([string]$inputLine, [int]$textWidth, [string]$wrapChar) { - If (($inputLine.length + ($wrapChar.Length * 2)) -ge $textWidth) + if (($inputLine.length + ($wrapChar.Length * 2)) -ge $textWidth) { return -join($wrapChar, $inputLine.Substring(0, $textWidth - 2 * $wrapChar.Length), $wrapChar) } @@ -140,7 +141,7 @@ function CenterText([string]$inputLine, [int]$textWidth, [string]$wrapChar) function LeftText([string]$inputLine, [int]$textWidth, [string]$wrapChar) { - If ($inputLine.length -ge $textWidth) + if ($inputLine.length -ge $textWidth) { return -join($inputLine.Substring(0, $textWidth)) } @@ -155,7 +156,7 @@ function LeftText([string]$inputLine, [int]$textWidth, [string]$wrapChar) function RightText([string]$inputLine, [int]$textWidth, [string]$wrapChar) { - If (($inputLine.length + (2 * $wrapChar.Length)) -ge $textWidth - 1) + if (($inputLine.length + (2 * $wrapChar.Length)) -ge $textWidth - 1) { $trimmed = $textWidth - (2 * $wrapChar.Length) From c6ba7c8f8f9517843931b61d68ede48a16f23dbb Mon Sep 17 00:00:00 2001 From: Niko Halink Date: Tue, 5 Aug 2025 00:48:06 +0200 Subject: [PATCH 9/9] further improve output of list command --- commands.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.ps1 b/commands.ps1 index b1375b3..d77dc3c 100644 --- a/commands.ps1 +++ b/commands.ps1 @@ -18,7 +18,7 @@ function LIST([string]$dirName) -join("0 $e[44m$e[94m$e[7m", (CenterText $folderName ($midWidth - 6)), "$e[27m$e[0m") Get-ChildItem $dirName -directory | ForEach-Object { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper() ($midWidth - 14) '"')) } Get-ChildItem $dirName -file .* | ForEach-Object { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper() ($midWidth - 14) '"')) } - Get-ChildItem $dirName -file *.* | ForEach-Object { if ($_.name.toUpper().Split(".")[0] -gt 0) { -join((LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText $_.name.toUpper().Split(".")[0] ($midWidth - 14) '"'), " ", (RightText $_.name.toUpper().Split(".")[1] 10 )) } } + Get-ChildItem $dirName -file *.* | ForEach-Object { if ($_.name.toUpper().Split('.')[0].Length -gt 0) { -join( (LeftText ([math]::Round($_.Length/100)).ToString() 6), ' ', (RightText ($_.BaseName.toUpper() -replace $_.Extension, '') ($midWidth - 14) '"'), ' ', $_.Extension.toUpper().TrimStart('.') ) } } -join((Get-PSDrive c).Free, " BLOCKS FREE.") "READY." }