How do I prevent Windows Terminal from converting tab characters to spaces? - windows-terminal

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.

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.

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.

Related

Read current terminal

Is it possible to read what's currently displayed on the windows terminal pragmatically using any available API?
For example, I've got an app that tail's some log files. I'd like to be able to hit a key and open a text editor at the line that is currently being viewed. The problem is the terminal also has scroll bars.
Not easy. Perhaps you could capture the screen and use OCR to identify its contents, or make a shortcut to some sort of macro that selects all the screen and copies the text. But there is no API available to perform the task you ask.
Of course, you can tee the command you're running in the console to a file, and open such file with an editor whenever you like, however it will show the full output of the command and not the visible part. If you like more information on that topic, it is answered in SO - Displaying Windows command prompt output and redirecting it to a file
.

How can I change the newline code for fish shell

I'm using windows 10 and installed cmder, using the fish shell with omf Theme fishface.
But every new row, it will show a new row Mark as this picture. Screenshot for new row mark
How can I get rid of this mark?
** didn't work if I change to another theme too.
Additional information without cmder.
Screenshot with cmd.exe + bash + fish
You can't disable that feature. The fish shell uses a heuristic (inherited from zsh) to determine if the output of the preceding command ended with a newline. If it doesn't it displays the Unicode U+23CE symbol (what you're seeing) or a tilde. Search the code for the symbol PROMPT_SP. Commit 58347d49 that I wrote and merged 2016-12-23 fixed that behavior for the Windows ConEmu terminal emulator. See issue 789. Based on your problem description it appears that heuristic does not work correctly in the cmder terminal. This probably means that terminal emulator has a bug since it doesn't behave like nearly all the terminals that fish runs on. Feel free to open an issue

Need OSX terminal application that can save file as non-binary

I am currently using Sublime Text 3 and iTerm2. Whenever I save a log from iTerm2, it contains characters that indicate things like backspaces and such. These characters make the file non-searchable (with find in files) in Sublime. Is anyone aware of a terminal application that will not store these keypresses in logs, or a way to prevent iTerm2 from storing these keypresses?
Thanks
You can filter the backspaces out after saving it. That aspect has been discussed several times. For example
Can I programmatically “burn in” ANSI control codes to a file using unix utils?
format output from Unix “script” command: remove backspaces, linefeeds and deleted chars?

tabs in Windows console

My command-line apps often output brief reports to the console. These reports contains TAB characters. If I later copy the output from the console to a text file, I find that the Windows console converted TAB into spaces.
Is there a setting (or an alternative console I can use in Windows) which actually keeps the TAB character in the console window (so I can copy it), but still displays it as if it corresponds to a certain number of spaces?

Is there a way to make a link clickable in the OSX Terminal?

I am planning on developing an Mxmlc to Textmate formatter, one that formats mxmlc errors as clickable links, so you can open them up quickly in Textmate as Textmate has a url scheme e.g.: txmt://open/?url=file://~/.bash_profile&line=11&column=2.
I am wondering if it is possible to display links in your OSX terminal, that are also clickable, e.g. by changing the PS1 variable or so.
ps. I don't want to use HTML that runs in the Textmate environment.
Before OSX Lion:
cmd+shift+double-click on a URL in Terminal.app and it will open in the default program.
OSX Lion:
cmd+double-click (otherwise you will enter fullscreen mode).
You can right click on a URL in Terminal and the first option in the context-sensitive menu is "Open URL". Not perfect, but maybe good enough ?
Others have discussed how you can select and Command-click on text which is a valid URI. As for Command-clicking on an embedded hyperlink, just like an anchor in hypertext (i.e., where the displayed text is not the URI itself), I believe the short answer is: Terminal cannot do it, but iTerm2 can.
Bash (or any other program that prints to a tty) can output the appropriate escape sequence to create a clickable hyperlink: it is \x1B]8;;URI\x1B\\TEXT\x1B]8;;\x1B\\, where \x1B represents the escape character, \\ represents a literal backslash, URI is the URI you want to link to (starting with https://, file:///, or whatever), and TEXT is the text you want to actually appear, for the user to Command-click on. (You can also use \a, the alert or bell character, instead of both instances of \x1B\\, but I understand this is less standard.) For example:
See \x1B]8;;file:///path/to/help/file\x1B\\the help file\x1B]8;;\x1B\\ for details.
In Mac OS(X), under El Capitan in my case, this works perfectly with iTerm2, and shows:
See the help file for details.
except that the linked text the help file has a dotted underline instead of being in italics. Command-clicking anywhere on the linked text opens the specified URI in the default browser. (Incidentally, this is also the behaviour in the Terminal program in Ubuntu Linux.)
In Mac OS(X) Terminal, you just get:
See the help file for details.
with no special typography and no ability to Command-click on any part of it.
You can get the full detail, including a list of supporting terminals, at https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda.
Pipe your output to lynx:
your_command | lynx -use_mouse -stdin

Resources