Reading typescript of terminal session
-
I like to use the
script
command to record sessions in my linux terminal for review and documentation later. Usually I justcat
the file in my terminal to look at it, but I was hoping Notepad++ (NPP) could read the files to give me better tools than a basic terminal output for reading and reviewing the.txt
file generated byscript
.The problem I’m facing is that NPP garbles the coloring and other such special characters used by the terminal:
For reference, it looks like this in the terminal:
I imagine this is a language or encoding issue; I’ve tried searching for answers before posting but most everything comes up with “how to run script in NPP” or “how to output terminal to NPP” instead of this (admittedly very specific) issue.
Any help or insight would be much appreciated!
Notepad++ v8.7.5 (64-bit) Build time : Dec 21 2024 - 05:13:03 Path : C:\Program Files\Notepad++\notepad++.exe Command Line : Admin mode : OFF Local Conf mode : OFF Cloud Config : OFF Periodic Backup : ON Placeholders : OFF DirectWrite : ON Multi-instance Mode : monoInst File Status Auto-Detection : cdEnabledNew (for current file/tab only) Dark Mode : ON OS Name : Windows 11 Pro (64-bit) OS Version : 24H2 OS Build : 26100.3775 Current ANSI codepage : 1252 Plugins : ComparePlugin (2.0.2) DSpellCheck (1.5) MarkdownViewerPlusPlus (0.8.2) mimeTools (3.1) NppConverter (4.6) NppExec (0.8.8) NppExport (0.4)
moderator edit: embedded the images directly, instead of trying to link to imgur; imgur doesn’t reliably allow us to show their images in the forum, so just paste images into the post rather than using them as a host
-
I forgot to note that I did redact both views before taking the screenshots, so the random “<□□□>” in the file are not normally there; they’re manually entered by me to remove any PII. (I assumed the red boxes were obvious enough to not need mentioning though…). Again, thanks for any help.
-
It hasn’t garbled anything. Linux terminals use ANSI escape sequences to position text on screen, change colors, and make things bold.
Notepad++ correctly shows you the underlying characters, because Notepad++ is a text (character) editor, not a linux terminal.
There have been discussions which give examples of how to highlight those ANSI escape sequences (like keywords and operators are highlighted in other languages), but it will still show you the underlying characters even if they are highlighted, because Notepad++ is a text editor, not a linux terminal. (
I haven’t been able to dig up any of those previous discussions yet; if I find any, I’ll either update or reply.)It would be possible to record some search-and-replace actions as a macro, which would strip out all the ANSI escape sequences… but it would take some effort to figure out all the replacements needed (because the number of characters that need to be deleted depends on the exact escape sequence)
-
@PeterJones said in Reading typescript of terminal session:
I haven’t been able to dig up any of those previous discussions yet; if I find any, I’ll either update or reply.
This is the discussion I was thinking of. (In 2022, when that was posted, the EnhanceAnyLexer plugin wasn’t in Plugins Admin; but it is now, so you can easily install it from the Plugins Admin.)
But, like I said, I don’t think that’s really what you want.
-
@PeterJones Thanks! I figured it would be something like that but wanted to ask just in case. With all the plugins and capabilities of NPP I wasn’t sure if I was messing something up or if there was some plugin that could resolve things, etc. I appreciate the insight and confirmation! Very helpful, especially with the link to dig into it more.
-
(I did an update to my last post, but then you posted before I finished, so I moved it to a separate reply)
I found another one, which is even better: in this discussion, @Ekopalypse brings up the errorlist lexer, which is technically inside Notepad++, but isn’t made available by default. The script linked to, here, uses the PythonScript plugin to enable the errorlist lexer. It’s more work, because you have to install the PythonScript plugin and set it up to run that script, but based on the results shown:
… my guess is that’s exactly what you want.
To use it, you would follow the instructions in this FAQ to install the plugin and run the script. Once it’s run, when you open a
.txt
or.log
file (the script could be edited to choose whatever file extension you want), it will try to apply that errrorlist-style lexing -
@PeterJones This is excellent! I installed and gave it a shot; while it’s not perfect, it vastly improves the readability of the file within NPP. I can now easily search and find what I need within NPP; if I have a specific bit of output I need to pull, I can reference the line numbers from NPP and then pull them in my terminal using
sed
. This is much easier than having to dig through everything from the terminal itself.
(Again it’s been cleaned of PII)Thanks again! I greatly appreciate you taking the time and effort to find this. This is a lifesaver going forward.
-
Another “success story” using the script to get a better look at this type of data: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/16437#issuecomment-2827278358
-
Hello, @collingsjj, @peterjones, @alan-kilborn and All,
@collingsjj, if you don’t mind to study a simple plain text, just send me, by e-mail,
-
An example of your code containing the
ESC
sequences and similar codes. If possible, a text between20
and100
lines ! -
A snapshot of your corresponding code on your terminal
I’ll try to find out a regex search which could delete ALL these codes
For example, as a first approach, the following regex :
FIND
(?-i)\x1b\[\d*(;\d+)?m
REPLACE
Leave EMPTY
Would modify this INPUT text, taken from your GitHub issue
#16437
:[31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m[31;1m[31;1m[36;1m | [31;1mCannot find path 'E:\SharedData\jDownloader\cfg\downloadList4838991.zip' because it does not exist.[0m [31;1mGet-ItemProperty: [0mP:\Backup\BackupScripts\ArchiveAttributeUpdate.ps1:3[0m [31;1m[0m[36;1mLine |[0m [31;1m[0m[36;1m[36;1m 3 | [0m . es -ea SilentlyContinue -value (([36;1mGet-ItemProperty $_.fullname[0m).Attrib .[0m [31;1m[0m[36;1m[36;1m[0m[36;1m[0m[36;1m | [31;1m
Into this clean OUTPUT text :
| Cannot find path 'E:\SharedData\jDownloader\cfg\downloadList4838991.zip' because it does not exist. Get-ItemProperty: P:\Backup\BackupScripts\ArchiveAttributeUpdate.ps1:3 Line | 3 | . es -ea SilentlyContinue -value ((Get-ItemProperty $_.fullname).Attrib . |
My temporary e-mail address is :
tguy.038@gmail.com
Best Regards,
guy038
-