Skip to content

Enable coloring of Select-String output #2905

Closed

Description

Jason Shirk (@lzybkr) bkr added a gist adding coloring formatdata for MatchInfo.

I played a bit with it and added coloring of regex groups and after having used it for a few months, I have to say that it is very useful. Instead of a wall of text, it is really easy to distinguish the things you're looking for.

matchinfo

How about making some version of this ship with the platform?

Activity

  1. iSazonov commented on Dec 19, 2016

    @iSazonov
    Collaborator

    Looks superb!
    We must help our eyes.
    It would be nice to paint all output.
    Maybe make the individual format color views for other types?

  2. added
    WG-Cmdlets
    Up-for-Grabs
    on Dec 20, 2016
  3. lzybkr commented on Dec 22, 2016

    @lzybkr
    Contributor

    Most won't notice, but there is a small issue that we should consider in the formatting engine before using color in any default formatting.

    If you change your foreground/background colors, the "reset color" ANSI escape sequence (CSI 0 m) doesn't work as expected. For example, I have the following in my profile (using my unpublished module ConsoleUtilities)

    Import-Module -Name ConsoleUtilities
    
    Set-ConsoleColorTable -ColorTable @{
        Black       = '#141414'
        Blue        = '#004bff'
        Cyan        = '#00ffff'
        DarkBlue    = '#374b80'
        DarkCyan    = '#008080'
        DarkGray    = '#808080'
        DarkGreen   = '#008000'
        DarkMagenta = '#800080'
        DarkRed     = '#C81010'
        DarkYellow  = '#808000'
        Gray        = '#c0c0c0'
        Green       = '#00ff00'
        Magenta     = '#ff00ff'
        Red         = '#ff0000'
        White       = '#ffffff'
        Yellow      = '#ffff00'
    } -TextForegroundColor Gray -TextBackgroundColor Black

    If I start PowerShell from the regular shortcut that has the royal blue background, my suggested implementation for highlighting matches causes weird things to happen.

    I'm not sure if this issue should be considered a PowerShell bug or conhost bug, but I do think PowerShell needs to provide a good experience for folks that customize their consoles like I do.

  4. powercode commented on Dec 22, 2016

    @powercode
    CollaboratorAuthor

    And how should we think about the new console with full RGB support?
    Seems wrong to limit ourselves to the small set of named console colors.

    Should there be a set of named, configurable, 'highlight' colors?
    They could be configured to work well on what is shipping out of the box, but tweakers could set them according to their preferences.

  5. lzybkr commented on Dec 22, 2016

    @lzybkr
    Contributor

    Discussion about color support is in #2381

  6. added
    Hacktoberfest
    on Sep 30, 2017
  7. HumanEquivalentUnit commented on Oct 3, 2017

    @HumanEquivalentUnit
    Contributor

    I saw this recently https://twitter.com/LincolnAtkinson/status/907708171728257024 (Code here) and it's related.

    It couldn't be just formatting because it changes the output and has multiple lines, but it does go usefully further in explaining how the group names match up against the input test.

    e.g. Select-String could get an -ExplainMatch switch which makes it take the first match and output something like this.

  8. derek-xia commented on Feb 23, 2019

    @derek-xia
    Contributor

    I'm at HackIllinois right now and I'd like to take a look at this issue.

  9. itpropaul commented on Aug 27, 2019

    @itpropaul

    Get this out the door. Color highlighting with Select-String should have been included from the beginning. Please Please make this a priority!

    This is the top hit in Google when searching: "select-string highlighting" https://copdips.com/2018/05/grep-like-powershell-colorful-select-string.html

  10. ThomasNieto commented on Feb 26, 2020

    @ThomasNieto
    Contributor

    Ilya (@iSazonov) the emphasis logic was merged, can this issue be closed?

  11. added
    Resolution-Fixed
    and removed
    Hacktoberfest
    Up-for-Grabs
    on Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions