Giter Site home page Giter Site logo

evotecit / pswritecolor Goto Github PK

View Code? Open in Web Editor NEW
150.0 11.0 25.0 87 KB

Write-Color is a wrapper around Write-Host allowing you to create nice looking scripts, with colorized output.

License: MIT License

PowerShell 100.00%
powershell write-color write-host color write-output wrapper hacktoberfest

pswritecolor's Introduction

PSWriteColor - PowerShell module

Write-Color is a wrapper around Write-Host allowing you to create nice looking scripts, with colorized output. More information for this project at my Evotec website.

Support This Project

If you find this project helpful, please consider supporting its development. Your sponsorship will help the maintainers dedicate more time to maintenance and new feature development for everyone.

It takes a lot of time and effort to create and maintain this project. By becoming a sponsor, you can help ensure that it stays free and accessible to everyone who needs it.

To become a sponsor, you can choose from the following options:

Your sponsorship is completely optional and not required for using this project. We want this project to remain open-source and available for anyone to use for free, regardless of whether they choose to sponsor it or not.

If you work for a company that uses our .NET libraries or PowerShell Modules, please consider asking your manager or marketing team if your company would be interested in supporting this project. Your company's support can help us continue to maintain and improve this project for the benefit of everyone.

Thank you for considering supporting this project!

ChangeLog

  • 1.0.1 - 2023.04.30

    • 🐛 Fixes UTF8 issue when publishing to PowerShell Gallery
  • 1.0.0 - 2023.04.23

    • 📃 Converted tabs to spaces in code (no difference in output)
    • 📃 Updated documentation
    • 💡 Added NoConsoleOutput to allow only writting to file, and skipping console output
    • 🐛 Removed throwing exceptions when couldn't write to file (Write-Warning will be triggered instead)
  • 0.87.3 - 2021.04.12

    • 💡 Disabled WhatIf functionality for Out-File which would prevent logging to file
    • 💡 Added LogRetry (2) to provide option to retry logging to file up to X number of times in case issue with saving to file occurs (race condition)
  • 0.87.2 - 2020.07.20

    • 📦 Added a space for LogTime and ShowTime
    • 📦 Signed module
  • 0.87.1 - 2020.06.19

    • 🐛 Resolves issue with nuget download (changed version from 0.87 to 0.87.1). As per link it requires version to be longer.
  • 0.87.0 - 2020.01.12

    • 🐛 Throw errors when can't save to file with LogFile. Before it would use Write-Output which could deliver unpredictable results

Quick install

Install-Module -Name "PSWriteColor" -Force

Examples

Image

# Example 1
Write-Color "[i] ", "Parameter in configuration of ", "EmailParameters.EmailFrom", " exists." -Color White, White, Green, White -ShowTime
Write-Color "[i] ", "Parameter in configuration of ", "EmailParameters.EmailTo", " exists." -Color White, White, Green, White -ShowTime
# Example 2
Write-Color "[i] ", "I will send email soon...", "Get ready.." -Color White
Write-Color "[i] ", "Sending email...." -Color White, White -NoNewLine
<#
    Do Something....
#>
if ($true) {
    Write-Color -Text "OK" -Color Green
}
# Example 3
Write-Color -Text "Red ", "Green ", "Yellow " -Color Red, Green, Yellow
Write-Color -Text "This is text in Green ",
"followed by red ",
"and then we have Magenta... ",
"isn't it fun? ",
"Here goes DarkCyan" -Color Green, Red, Magenta, White, DarkCyan
Write-Color -Text "This is text in Green ",
"followed by red ",
"and then we have Magenta... ",
"isn't it fun? ",
"Here goes DarkCyan" -Color Green, Red, Magenta, White, DarkCyan -StartTab 3 -LinesBefore 1 -LinesAfter 1
Write-Color "1. ", "Option 1" -Color Yellow, Green
Write-Color "2. ", "Option 2" -Color Yellow, Green
Write-Color "3. ", "Option 3" -Color Yellow, Green
Write-Color "4. ", "Option 4" -Color Yellow, Green
Write-Color "9. ", "Press 9 to exit" -Color Yellow, Gray -LinesBefore 1
Write-Color -LinesBefore 2 -Text "This little ", "message is ", "written to log ", "file as well." `
        -Color Yellow, White, Green, Red, Red -LogFile "C:\testing.txt" -TimeFormat "yyyy-MM-dd HH:mm:ss"
Write-Color -Text "This can get ", "handy if ", "want to display things, and log actions to file ", "at the same time." `
        -Color Yellow, White, Green, Red, Red -LogFile "C:\testing.txt"
# Example 4 with backgrund colors and usage of aliases
Write-Color -T "My text", " is ", "all colorful" -C Yellow, Red, Green -B Green, Green, Yellow
Write-Color -T "My text", " is ", "all colorful" -C Yellow, Red, Green -B Red, Green, Green
# Example 5 with aliases
wc -t "my text" -C Red

pswritecolor's People

Contributors

przemyslawklys avatar vexx32 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pswritecolor's Issues

NuGet package does not install properly (v.0.85.0)

When manually downloading and installing the package, it installs, but then can not be imported (or seen with Get-Module -ListAvailable). This appears to be as the Module Version in the Manifest does not match the folder name. Error message:
`import-module : The ModuleVersion key in module manifest 'C:\Program
Files\WindowsPowerShell\Modules\PSWriteColor\0.85.0\PSWriteColor.psd1' specifies module version '0.85' which does not
match its version folder name at 'C:\Program Files\WindowsPowerShell\Modules\PSWriteColor\0.85.0'. Change the value of
the ModuleVersion key to match the version folder name.
At line:1 char:1

  • import-module 'C:\Program Files\WindowsPowerShell\Modules\PSWriteColo ...
  •   + CategoryInfo          : InvalidArgument: (C:\Program File...WriteColor.psd1:String) [Import-Module], InvalidOper
     ationException
      + FullyQualifiedErrorId : Modules_InvalidModuleManifestVersion,Microsoft.PowerShell.Commands.ImportModuleCommand`
    

Transcript with Write-Color

Hi,
I'm looking for a way to combine powershell transcript and write-color function.

In PS console, the result is displayed as expected but passing through the transcript each element between "" inserts a new line of the transcript log (between time and text).

Is there a way around this issue without using the -LogFile parameter?

firefox_2021-01-22_18-16-21


> **********************
> Windows PowerShell transcript start
> Start time: 20210122181054
> Username: xxxxxx
> RunAs User: xxxxx
> Configuration Name: 
> Machine: xxxxx
> Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
> Process ID: xxxx
> PSVersion: 5.1.17763.1490
> PSEdition: Desktop
> PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.1490
> BuildVersion: 10.0.17763.1490
> CLRVersion: 4.0.30319.42000
> WSManStackVersion: 3.0
> PSRemotingProtocolVersion: 2.3
> SerializationVersion: 1.1.0.1
> **********************
> [22/01/21 18:10:54]
> Script name : Test-Transcript.ps1
> 
> [22/01/21 18:10:54]
> Sed eveniet neque aut rerum perspiciati
> 
> [22/01/21 18:10:54]
> voluptas est dolorem error et similique
> 
> [22/01/21 18:10:54]
> End script!
> 
> [22/01/21 18:10:54]
> Elapsed Time: 0 hours 0 minutes 0 seconds
> 
> **********************
> Windows PowerShell transcript end
> End time: 20210122181054
> **********************

Thanks for your help and your work !

show text like a progressbar

Could you provide a switch to control the display position, such as the progress bar, the text is only displayed on one line and can be updated. I know that the vt100 control character can realize this function, but I don't know how to modularize it.

It would be even better if the time display function could be integrated.❤️ such as:
write-color "you have waited " -c green -b blue -NoNewLine -NoAppend -ShowClock

$esc=[char]27
$rp="$esc[50G"

$sw=[Diagnostics.StopWatch]::StartNew()
$tm=New-Object System.Timers.Timer
$tm.Interval=1000
Register-ObjectEvent -InputObject $tm -EventName Elapsed -Action {
    #$dt=(get-date).tostring("yyyyMMdd HHmmss");
    $ep=$sw.Elapsed
    #$host.ui.RawUI.WindowTitle = $ep; 
    write-color "$rp$ep" -C Yellow -B Blue -NoNewline
}|Out-Null
$tm.AutoReset=$true
$tm.Enabled=$true

1..10|foreach-object {$host.ui.RawUI.WindowTitle = $_;start-sleep 1;}
$tm.Enabled=$false
$sw.stop()

read-host "done"

abc

request: support multiline split with separator

$foo = "Execution Path exists"
Command:`Write-Color "[info]  ", $foo -Color Yellow, Yellow -ShowTime`

results in

[2020-09-18 13:27:22] [info]  Execution Path exists

New separate lines when using a parameter such as -SplitLines [Separator]
example 1

$foo = "Execution Path exists `n2. Line `n3. Line"
Write-Color "[info]  ", $foo -Color Yellow, Yellow -ShowTime`  -SplitLines "`n"

results in

[2020-09-18 13:27:22] [info]  Execution Path exists
                              2. Line 
                              3. Line`

example 2

$foo = "Execution Path exists `n2. Line `n3. Line"
`Write-Color "[info]  ", $foo -Color Yellow, Yellow -SplitLines "`n"

results in

[info]  Execution Path exists
        2. Line 
        3. Line`

Extra Spaces in Log Files

recently, when i try and add a og file, i get extra spaces in it. Any ideas why this could be happening?

the Powershell script has this line:
Write-Colour "##################", " Create Contributor and Reader Security Groups ", "################## " -Color Cyan, Yellow, Cyan -LogFile $Logfile

the output in visual studio shows:
################## Create Contributor and Reader Security Groups ##################

and the log file has this in it:
[ 2 0 2 3 - 0 4 - 2 0 1 6 : 2 0 : 0 2 ] # # # # # # # # # # # # # # # # # # C r e a t e C o n t r i b u t o r a n d R e a d e r S e c u r i t y G r o u p s # # # # # # # # # # # # # # # # # #

Doesn't seem to accept parameters when passed

Great code but may have a personal issue -

Tried many combinations to get Write-Color to display a $($var)

Typically Write-Host ("Accepts values passed as $($suchhere)") but cannot seem to make this happen here. The ( )s outside of the "" quotes help display $($vars) but no combo in our out of quotes like write-color "(" text $($var) ")" or (" text $($var) ") work.

Help, coffee is running out!

Output is multiple line in transcript

Hi !

This module is amazing and I use it in a few of my recent scripts.
I have one question though (not a huge problem I suppose):

When I use this within a script...
image

...the console output is as intended...
image

...but if the script is transcripted, the transcript results in line breaks for each color.
image

Is there any way to add a switch that prevents this?

write-color transcript output showing up on different lines

When using start-transcript the log files shows, write-color using multiple colors on one line on multiple lines.

Example:
Write-Color "Updating Group: ",$Group -Color Gray,Green -StartTab 1

Output:
Updating Group:
Test Group

Is there a way to fix this issue with start-transcript so one line on write-color will be one line in the transcript file?

Thank you.

Improvment

Hi
Great Module ! I'm thinking if it's possible when we're enabling logging to :

  • generate a log file formated like a .csv. Of course, we should be able to choose the separator (comma is not always the best separator)

  • You might even consider having additional information : Category (Inf - War, Error)

A single Cmdlet for a pretty console display and a file output that can be used easily later.

There is a module called Ezlog (https://github.com/apetitjean/ezlog), which already does it, but it doesn't have the facilities that Write-Color for console display with several colors in the same text block.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.