-1

I'm programming a script that outputs tab characters. The users of this script expect to be able to copy and paste the output of this script from Windows Terminal into a spreadsheet program, and have the tab characters interpreted as dividers between cells. However, this breaks, because the tab characters get converted to spaces. How can I fix my script to force Windows Terminal to output tab characters instead of spaces?

For example, if I have a Python script that outputs "one\ttwo\tthree", this is what gets output to Windows Terminal:

one     two     three

The tab characters (U+0009) get converted to space characters (U+0020) by Windows Terminal. If I copy and paste this line into a text editor or a spreadsheet program, it will see space characters, not tab characters, which is not what I want.

Flimm
  • 136,138
  • 45
  • 251
  • 267
  • @Flimm Btw, you aren't missing anything on that `tabToSpaces` setting. That user is posting ChatGPT output here and in other answers. Flagged that. ChatGPT is great (err, *bad*) at coming up with "imaginary settings" that just don't exist. – NotTheDr01ds Jan 04 '23 at 21:30
  • @NotTheDr01ds Thanks! That's the first time I came across ChatGPT being used like that in the wild. – Flimm Jan 06 '23 at 08:38
  • And for yours! And yes, I'm getting fairly good at spotting the (current, at least) ChatGPT output. I have a "Save" collection of 27 "answers" on Ask Ubuntu (and a scattering on other sites) that were generated by ChatGPT. The fact that the comment was an "imaginary setting" was my first clue here, then another answer from the user confirmed that they were using ChatGPT. – NotTheDr01ds Jan 06 '23 at 08:56

2 Answers2

2

As you've confirmed via that Github issue, there's no way to have Windows Terminal itself maintain the tabs (at least not yet). As a programmatic workaround for your script, consider offering the user the ability to output the results directly to the clipboard (assuming the output is "focused"/small enough) using something like this answer (Python-based, since that's the MRE you provided).

The user can, of course, also redirect the output to the clipboard using Windows clip.exe. E.g.:

python3 -c 'print("one\\ttwo\\tthree")' | clip.exe

I confirmed that the tabs are maintained in this case.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
0

Unfortunately, there isn't a way to configure Windows Terminal to preserve tab characters. And I don't think there is a way for a script to force Windows Terminal to preserve tab characters.

See this bug report.

Flimm
  • 136,138
  • 45
  • 251
  • 267