Skip to content

Commit

Permalink
feat(title-templates): add some new effects and formatting style
Browse files Browse the repository at this point in the history
- Style: `"Blink", "Bold", "Italic", "Regular", "Strikethrough", "Underline"`
- Color: `"Black", "Blue", "DarkBlue", "DarkCyan", "DarkGray", "DarkGreen", "DarkMagenta", "DarkRed", "DarkYellow", "Cyan", "Gray", "Green", "Red", "Magenta", "White", "Yellow"`
  • Loading branch information
LeDragoX committed Feb 26, 2023
1 parent 10add76 commit 2f4a776
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 153 deletions.
8 changes: 4 additions & 4 deletions src/lib/manage-software.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function Install-Software() {
If ($PackageProvider -eq 'MsStore') {
Write-Status -Types "?" -Status "Reminder: Press 'Y' and ENTER to continue if stuck (1st time only) ..." -Warning
$PackageName = (winget search --source 'msstore' --exact $Package)[-1].Replace("$Package Unknown", '').Trim(' ')
$Private:Counter = Write-TitleCounter -Text "$Package - $PackageName" -Counter $Counter -MaxLength $Packages.Length
$Private:Counter = Write-TitleCounter "$Package - $PackageName" -Counter $Counter -MaxLength $Packages.Length
} Else {
$Private:Counter = Write-TitleCounter -Text "$Package" -Counter $Counter -MaxLength $Packages.Length
$Private:Counter = Write-TitleCounter "$Package" -Counter $Counter -MaxLength $Packages.Length
}

Try {
Expand Down Expand Up @@ -105,9 +105,9 @@ function Uninstall-Software() {
ForEach ($Package in $Packages) {
If ($PackageProvider -eq 'MsStore') {
$PackageName = (winget search --source 'msstore' --exact $Package)[-1].Replace("$Package Unknown", '').Trim(' ')
$Private:Counter = Write-TitleCounter -Text "$Package - $PackageName" -Counter $Counter -MaxLength $Packages.Length
$Private:Counter = Write-TitleCounter "$Package - $PackageName" -Counter $Counter -MaxLength $Packages.Length
} Else {
$Private:Counter = Write-TitleCounter -Text "$Package" -Counter $Counter -MaxLength $Packages.Length
$Private:Counter = Write-TitleCounter "$Package" -Counter $Counter -MaxLength $Packages.Length
}

Try {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/open-file.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Open-PowerShellFilesCollection {

ForEach ($FileName in $Scripts) {
$LastAccessUtc = "v$((Get-Item "$FileName").LastWriteTimeUtc | Get-Date -Format "yyyy-MM-dd")"
$Private:Counter = Write-TitleCounter -Text "$FileName ($LastAccessUtc)" -Counter $Counter -MaxLength $Scripts.Length
$Private:Counter = Write-TitleCounter "$FileName ($LastAccessUtc)" -Counter $Counter -MaxLength $Scripts.Length
If ($OpenFromGUI) {
Import-Module -DisableNameChecking .\"$FileName" -Force
} Else {
Expand Down Expand Up @@ -48,7 +48,7 @@ function Open-RegFilesCollection {

ForEach ($FileName in $Scripts) {
$LastAccessUtc = "v$((Get-Item "$FileName").LastWriteTimeUtc | Get-Date -Format "yyyy-MM-dd")"
$Private:Counter = Write-TitleCounter -Text "$FileName ($LastAccessUtc)" -Counter $Counter -MaxLength $Scripts.Length
$Private:Counter = Write-TitleCounter "$FileName ($LastAccessUtc)" -Counter $Counter -MaxLength $Scripts.Length
regedit /s "$FileName"
}

Expand Down
174 changes: 121 additions & 53 deletions src/lib/title-templates.psm1
Original file line number Diff line number Diff line change
@@ -1,36 +1,63 @@
function Write-Title() {
function Get-AllStyle() {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[String] $Text = "No Text"
[System.Object] $Object = "Yay!"
)

Write-Host "`n<•••••••••••••••••••••••••••••••••••••••••••••••••••••••>" -ForegroundColor Blue -BackgroundColor Black
Write-Host " $Text" -ForegroundColor White -BackgroundColor Black
Write-Host "<•••••••••••••••••••••••••••••••••••••••••••••••••••••••>" -ForegroundColor Blue -BackgroundColor Black
for ($i = 0; $i -le 110; $i++) {
<# Action that will repeat until the condition is met #>
Write-Host "$([char]0x1b)[$i`m [$i] $Object"
}
}

function Write-Section() {
function Write-Caption() {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[String] $Text = "No Text"
[System.Object] $Object = "No Text"
)

Write-Host "`n<••••••••••{ " -NoNewline -ForegroundColor Cyan -BackgroundColor Black
Write-Host "$Text " -NoNewline -ForegroundColor White -BackgroundColor Black
Write-Host "}••••••••••>`n" -ForegroundColor Cyan -BackgroundColor Black
Write-Style "••> " -Style Bold -Color Cyan -NoNewline
Write-Style "$Object" -Style Italic -Color White
}

function Write-Caption() {
function Write-ScriptLogo() {
[CmdletBinding()] param ()

# Font: ANSI FIGlet Fonts > ANSI Shadow
$ASCIIText = @"
██╗ ██╗██╗███╗ ██╗ ██████╗ ███████╗██████╗ ██╗ ██████╗ █████╗ ████████╗
██║ ██║██║████╗ ██║ ██╔══██╗██╔════╝██╔══██╗██║ ██╔═══██╗██╔══██╗╚══██╔══╝
██║ █╗ ██║██║██╔██╗ ██║ ██║ ██║█████╗ ██████╔╝██║ ██║ ██║███████║ ██║
██║███╗██║██║██║╚██╗██║ ██║ ██║██╔══╝ ██╔══██╗██║ ██║ ██║██╔══██║ ██║
╚███╔███╔╝██║██║ ╚████║ ██████╔╝███████╗██████╔╝███████╗╚██████╔╝██║ ██║ ██║
╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
████████╗ ██████╗ ██████╗ ██╗ ███████╗
╚══██╔══╝██╔═══██╗██╔═══██╗██║ ██╔════╝
██║ ██║ ██║██║ ██║██║ ███████╗
██║ ██║ ██║██║ ██║██║ ╚════██║
██║ ╚██████╔╝╚██████╔╝███████╗███████║
╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝
"@
Write-Style $ASCIIText -Style Blink -Color Green
Write-Style "`n<•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••>" -Color White
Write-Style " It's Time to Debloat Windows!" -Style Blink -Color Cyan
}

function Write-Section() {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[String] $Text = "No Text"
[System.Object] $Object = "No Text"
)

Write-Host "••> " -NoNewline -ForegroundColor Cyan -BackgroundColor Black
Write-Host "$Text" -ForegroundColor White -BackgroundColor Black
$Art = @('<••••••••••{', '}••••••••••>')

Write-Style "`n$($Art[0]) " -Style Bold -Color Cyan -NoNewline
Write-Style "$Object " -Style Italic -Color White -NoNewline
Write-Style "$($Art[1])`n" -Style Bold -Color Cyan
}

function Write-Status() {
Expand All @@ -44,68 +71,109 @@ function Write-Status() {
)

ForEach ($Type in $Types) {
Write-Host "[" -NoNewline -ForegroundColor Blue -BackgroundColor Black
Write-Host "$Type" -NoNewline -ForegroundColor White -BackgroundColor Black
Write-Host "] " -NoNewline -ForegroundColor Blue -BackgroundColor Black
Write-Style "$([char]0x1b)[94m[$([char]0x1b)[97m$Type$([char]0x1b)[94m] " -Style Bold -NoNewline
}

If ($Warning) {
Write-Host "$Status" -ForegroundColor Yellow -BackgroundColor Black
Write-Style "$Status" -Color Yellow
} Else {
Write-Host "$Status" -ForegroundColor Green -BackgroundColor Black
Write-Style "$Status" -Color Green
}
}

function Write-TitleCounter() {
function Write-Style() {
[CmdletBinding()]
[OutputType([System.Int32])]
param (
[Parameter(Position = 0)]
[String] $Text = "No Text",
[System.Object] $Object = "No Text",
[Parameter(Position = 1)]
[Int] $Counter = 0,
[ValidateSet("Blink", "Bold", "Italic", "Regular", "Strikethrough", "Underline")]
[String] $Style = "Regular",
[Parameter(Position = 2)]
[Int] $MaxLength
[ValidateSet("Black", "Blue", "DarkBlue", "DarkCyan", "DarkGray", "DarkGreen", "DarkMagenta", "DarkRed", "DarkYellow", "Cyan", "Gray", "Green", "Red", "Magenta", "White", "Yellow")]
[String] $Color = "White",
[Parameter(Position = 3)]
[Switch] $NoNewline
)

$Counter += 1
Write-Title -Text "($Counter/$MaxLength) - $Text"
$Colors = @{
"Black" = "$([char]0x1b)[30m"
"DarkBlue" = "$([char]0x1b)[34m"
"DarkGreen" = "$([char]0x1b)[32m"
"DarkCyan" = "$([char]0x1b)[36m"
"DarkGray" = "$([char]0x1b)[90m"
"DarkRed" = "$([char]0x1b)[31m"
"DarkMagenta" = "$([char]0x1b)[35m" # Doesn't work on PowerShell, but works on the Terminal
"DarkYellow" = "$([char]0x1b)[33m"
"Gray" = "$([char]0x1b)[37m"
"Blue" = "$([char]0x1b)[94m"
"Green" = "$([char]0x1b)[92m"
"Cyan" = "$([char]0x1b)[96m"
"Red" = "$([char]0x1b)[91m"
"Magenta" = "$([char]0x1b)[95m"
"Yellow" = "$([char]0x1b)[93m"
"White" = "$([char]0x1b)[97m"
}

return $Counter
$Styles = @{
"Blink" = "$([char]0x1b)[5m"
"Bold" = "$([char]0x1b)[1m"
"Italic" = "$([char]0x1b)[3m"
"Regular" = "$([char]0x1b)[0m"
"Strikethrough" = "$([char]0x1b)[9m"
"Underline" = "$([char]0x1b)[4m"
}

If ($NoNewline) {
return Write-Host "$($Styles.$Style)$($Colors.$Color)$Object" -NoNewline
}

Write-Host "$($Styles.$Style)$($Colors.$Color)$Object"
}

function Write-ScriptLogo() {
[CmdletBinding()] param ()
function Write-Title() {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[System.Object] $Object = "No Text"
)

# Font: ANSI FIGlet Fonts > ANSI Shadow
$ASCIIText = @"
██╗ ██╗██╗███╗ ██╗ ██████╗ ███████╗██████╗ ██╗ ██████╗ █████╗ ████████╗
██║ ██║██║████╗ ██║ ██╔══██╗██╔════╝██╔══██╗██║ ██╔═══██╗██╔══██╗╚══██╔══╝
██║ █╗ ██║██║██╔██╗ ██║ ██║ ██║█████╗ ██████╔╝██║ ██║ ██║███████║ ██║
██║███╗██║██║██║╚██╗██║ ██║ ██║██╔══╝ ██╔══██╗██║ ██║ ██║██╔══██║ ██║
╚███╔███╔╝██║██║ ╚████║ ██████╔╝███████╗██████╔╝███████╗╚██████╔╝██║ ██║ ██║
╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
$Art = "<•••••••••••••••••••••••••••••••••••••••••••••••••••••••>"

████████╗ ██████╗ ██████╗ ██╗ ███████╗
╚══██╔══╝██╔═══██╗██╔═══██╗██║ ██╔════╝
██║ ██║ ██║██║ ██║██║ ███████╗
██║ ██║ ██║██║ ██║██║ ╚════██║
██║ ╚██████╔╝╚██████╔╝███████╗███████║
╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚══════╝
"@
Write-Host $ASCIIText -ForegroundColor Green -BackgroundColor Black
Write-Host "`n<•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••>" -ForegroundColor White -BackgroundColor Black
Write-Host " It's Time to Debloat Windows!" -ForegroundColor Cyan -BackgroundColor Black
Write-Style "`n$([char]0x1b)[94m$Art" -Style Bold -NoNewline
Write-Style "`n$([char]0x1b)[97m $Object" -Style Italic -NoNewline
Write-Style "`n$([char]0x1b)[94m$Art" -Style Bold
}

function Write-TitleCounter() {
[CmdletBinding()]
[OutputType([System.Int32])]
param (
[Parameter(Position = 0)]
[System.Object] $Object = "No Text",
[Parameter(Position = 1)]
[Int] $Counter = 0,
[Parameter(Position = 2)]
[Int] $MaxLength
)

$Counter += 1
Write-Title "($Counter/$MaxLength) - $Object"

return $Counter
}

<#
Example:
Write-Title -Text "Text" # Used to print Tweak introduction
Write-Section -Text "Text" # Used to print Tweak Section
Write-Caption -Text "Text" # Used to print Tweak Category
Write-Caption -Object "Text" # Used to print Tweak Category
Write-ScriptLogo # Used at the start of the Script
Write-Section -Object "Text" # Used to print Tweak Section
Write-Status -Types "?", ... -Status "Doing something"
Write-Status -Types "?", ... -Status "Doing something" -Warning
$Private:Counter = Write-TitleCounter -Text "Text" -Counter $Counter -MaxLenght 100 # Used to print when working with collections # No need to iterate $Counter before, as long it's private
$Private:Counter = Write-TitleCounter -Text "Text" -Counter $Counter -MaxLenght 100 # Used to print when working with collections # No need to iterate $Counter before, as long it's private
Write-ScriptLogo # Used at the start of the Script
Write-Title -Object "Text" # Used to print Tweak introduction
$Private:Counter = Write-TitleCounter -Object "Text" -Counter $Counter -MaxLenght 100 # Used to print when working with collections # No need to iterate $Counter before, as long it's private
$Private:Counter = Write-TitleCounter -Object "Text" -Counter $Counter -MaxLenght 100 # Used to print when working with collections # No need to iterate $Counter before, as long it's private
#>

# [enum]::GetValues([System.ConsoleColor]) | Foreach-Object {Write-Host $_ -ForegroundColor $_ }
18 changes: 9 additions & 9 deletions src/scripts/optimize-performance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function Optimize-Performance() {
$PathToCUControlPanelDesktop = "HKCU:\Control Panel\Desktop"
$PathToCUGameBar = "HKCU:\SOFTWARE\Microsoft\GameBar"

Write-Title -Text "Performance Tweaks"
Write-Title "Performance Tweaks"

Write-Section -Text "System"
Write-Caption -Text "Display"
Write-Section "System"
Write-Caption "Display"
Write-Status -Types "+", $TweakType -Status "Enable Hardware Accelerated GPU Scheduling... (Windows 10 20H1+ - Needs Restart)"
Set-ItemPropertyVerified -Path "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers" -Name "HwSchMode" -Type DWord -Value 2

Expand All @@ -69,7 +69,7 @@ function Optimize-Performance() {
Remove-ItemProperty -Path "$PathToLMPoliciesWindowsStore" -Name "AutoDownload" # [@] (2 = Disable, 4 = Enable)
}

Write-Section -Text "Power Plan Tweaks"
Write-Section "Power Plan Tweaks"

Write-Status -Types "+", $TweakType -Status "Setting Power Plan to High Performance..."
powercfg -SetActive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
Expand All @@ -85,12 +85,12 @@ function Optimize-Performance() {
Write-Status -Types "+", $TweakType -Status "Setting Hibernate size to reduced (hides hibernate option as hiberfil.sys takes less size)..."
powercfg -Hibernate -Type Reduced

Write-Section -Text "Network & Internet"
Write-Section "Network & Internet"
Write-Status -Types "+", $TweakType -Status "Unlimiting your network bandwidth for all your system..." # Based on this Chris Titus video: https://youtu.be/7u1miYJmJ_4
Set-ItemPropertyVerified -Path "$PathToLMPoliciesPsched" -Name "NonBestEffortLimit" -Type DWord -Value 0
Set-ItemPropertyVerified -Path "$PathToLMMultimediaSystemProfile" -Name "NetworkThrottlingIndex" -Type DWord -Value 0xffffffff

Write-Section -Text "System & Apps Timeout behaviors"
Write-Section "System & Apps Timeout behaviors"
Write-Status -Types "+", $TweakType -Status "Reducing Time to services app timeout to 2s to ALL users..."
Set-ItemPropertyVerified -Path "HKLM:\SYSTEM\CurrentControlSet\Control" -Name "WaitToKillServiceTimeout" -Type DWord -Value 2000 # Default: 20000 / 5000
Write-Status -Types "*", $TweakType -Status "Don't clear page file at shutdown (takes more time) to ALL users..."
Expand All @@ -103,9 +103,9 @@ function Optimize-Performance() {
ForEach ($DesktopRegistryPath in @($PathToUsersControlPanelDesktop, $PathToCUControlPanelDesktop)) {
<# $DesktopRegistryPath is the path related to all users and current user configuration #>
If ($DesktopRegistryPath -eq $PathToUsersControlPanelDesktop) {
Write-Caption -Text "TO ALL USERS"
Write-Caption "TO ALL USERS"
} ElseIf ($DesktopRegistryPath -eq $PathToCUControlPanelDesktop) {
Write-Caption -Text "TO CURRENT USER"
Write-Caption "TO CURRENT USER"
}

Write-Status -Types "+", $TweakType -Status "Don't prompt user to end tasks on shutdown..."
Expand All @@ -124,7 +124,7 @@ function Optimize-Performance() {
Set-ItemPropertyVerified -Path "$DesktopRegistryPath" -Name "WaitToKillAppTimeout" -Type DWord -Value 5000 # Default: 20000
}

Write-Section -Text "Gaming Responsiveness Tweaks"
Write-Section "Gaming Responsiveness Tweaks"

If (!$Revert) {
Disable-XboxGameBarDVRandMode
Expand Down
Loading

0 comments on commit 2f4a776

Please sign in to comment.