devblackops / Terminal-Icons

A PowerShell module to show file and folder icons in the terminal
MIT License
2.48k stars 109 forks source link

PowerShell Redirection also outputs Terminal Icons code #65

Open RBruce31B opened 2 years ago

RBruce31B commented 2 years ago

When Redirecting output with Terminal-Icons enabled, the output also has Terminal-Icons and code within the output.

Expected Behavior

When Terminal-Icons is disabled, code and Icons do not appear in redirected outputs: image

Current Behavior

While Terminal-Icons are enabled, redirected output has left over code and if the font is not applied in text editors the icon does not appear: image

Possible Solution

I'm wondering if there is a way to disable Terminal-Icons when redirection operators are used? Or a way to parse the code out? Other than that, I have no idea how to fix this.

Steps to Reproduce (for bugs)

  1. Import-Module Terminal-Icons
  2. gci | select -First 5 >> filename.txt (Tee, ">" and Out-File also output same thing) (Export-CSV does not display Terminal-Icons which is what I am looking for when redirecting output.)
  3. ". filename.txt"

Context

I work a lot with CSVs and redirect data a lot using PowerShell. Finding a fix or workaround will make my life easier while still having a cool prompt!

Your Environment

Same Behavior in Windows Terminal version 1.11.3471.0

manuel-fernandez-rodriguez commented 2 years ago

@RBruce31B As a workaround, you can do something like this:

Set-TerminalIconsTheme -DisableColorTheme -DisableIconTheme
gci | select -First 5 >> filename.txt
Set-TerminalIconsTheme -IconTheme devblackops -ColorTheme devblackops

Not sure if this will help the developers, but maybe conditionally rendering the ANSI sequences and/or the icons depending on the value of $PSStyle.OutputRendering could be something to consider.

gwenreynolds94 commented 1 year ago

I'm having the same issue using powershell as my shell in neovim. Anything shown in the builtin pager will display any ansi sequences that are there. Using the -DisableColorTheme and/or -DisableIconTheme flags actually makes it so much worse, because it just wraps everything in ansi ( ^[[0m )

:!Set-TerminalIconsTheme -DisableIconTheme -DisableColortheme ; ls

        Directory: C:\Users\<User>\Documents\<Directory>

^[[32;1mMode   ^[[0m^[[32;1m             LastWriteTime^[[0m ^[[32;1;3m        Length^[[0m^[[32;1m Name^[[0m
^[[32;1m----   ^[[0m ^[[32;1m            -------------^[[0m ^[[32;1m        ------^[[0m ^[[32;1m----^[[0m
d----        2023-07-06   2:39 PM                ^[[0m.bak^[[0m
d----        2023-08-06   1:46 AM                ^[[0m.vim^[[0m
d----        2023-09-01   4:44 PM                ^[[0mApps^[[0m
d----        2023-07-11   1:09 AM                ^[[0mGEnv^[[0m
d----        2023-08-17   1:23 PM                ^[[0mLib^[[0m
d----        2023-06-29  11:31 AM                ^[[0mProggers^[[0m
d----        2023-06-19  11:45 AM                ^[[0mTst^[[0m
-a---        2023-08-28   1:36 PM            592 ^[[0m.ahkonf^[[0m
-a---        2023-07-06   2:57 PM           2851 ^[[0m.scratch.0.ahk^[[0m
-a---        2023-08-06   1:46 AM            297 ^[[0m.scratch.1.ahk^[[0m
-a---        2023-09-01   4:57 PM          25197 ^[[0mmain.ahk^[[0m
-a---        2023-06-16  10:13 AM             50 ^[[0mREADME.md^[[0m