Skip to content

Instantly share code, notes, and snippets.

@y-ack
Created November 16, 2021 16:51
Show Gist options
  • Save y-ack/bd286bc3e3427857ddb7ec6cbf5c5dd8 to your computer and use it in GitHub Desktop.
Save y-ack/bd286bc3e3427857ddb7ec6cbf5c5dd8 to your computer and use it in GitHub Desktop.
sep 16, 2016
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)] [String]$filepath
)
$Window = $Host.UI.rawUI.WindowSize
[String]$file = Get-Item $filepath
[bool]$allIsWell = 1
[int]$line = 0
[int]$endline = $line + $Window.Height - 3
[int]$numLinesInFile = (Get-Content $file).Length
[ValidateRange(0,2147483647)][int]$offset = 0
$numerical = [regex]'[0-9]*'
[String]$Space
while($Window.Width-gt$Space.Length){$Space+=" "}
function Spacing{
Write-Host "".PadRight($Window.Width - $Host.UI.RawUI.CursorPosition.X) -BackgroundColor DarkCyan
}
while ($allIsWell) {
Clear-Host
$t=0;ForEach($o in Get-Content $file){$t+=$o.Length}
Write-Host " $file ($t bytes)".PadRight($Window.Width - $Host.UI.RawUI.CursorPosition.X) -BackgroundColor DarkCyan -ForegroundColor Black
#Spacing
(Get-Content $file)[$offset .. ($endline + $offset)] | Write-Host
for($i=0;$i -lt $Window.Height - $Host.UI.RawUI.CursorPosition.Y - 1){Write-Host}
Write-Host ":" -BackgroundColor White -ForegroundColor Black -NoNewline
$command = (Read-Host)
$multiplier = (($numerical.Match($command).value,1)[!$numerical.Match($command).value])
switch -regex ($command) {
"^v[0-9]*" {$offset += 1 + (($command.Substring(1) - 1),0)[!$command.Substring(1)]}
"^f[0-9]*" {$offset -= 1 + (($command.Substring(1) - 1),0)[!$command.Substring(1)]}
"^(exit|quit)$" {$allIsWell = $false}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment