Community
    • Login

    Reading typescript of terminal session

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 4 Posters 267 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      collingsjj
      last edited by PeterJones

      I like to use the script command to record sessions in my linux terminal for review and documentation later. Usually I just cat 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 by script.

      The problem I’m facing is that NPP garbles the coloring and other such special characters used by the terminal:
      df52722a-c2bd-4795-82d1-ab5d86e4e35d-image.png

      For reference, it looks like this in the terminal:
      120fd61b-747e-4a4e-aa59-63a3a0c107e0-image.png

      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

      PeterJonesP C 2 Replies Last reply Reply Quote 1
      • C
        collingsjj @collingsjj
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @collingsjj
          last edited by PeterJones

          @collingsjj ,

          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)

          PeterJonesP C 2 Replies Last reply Reply Quote 2
          • PeterJonesP
            PeterJones @PeterJones
            last edited by PeterJones

            @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.

            1 Reply Last reply Reply Quote 1
            • C
              collingsjj @PeterJones
              last edited by

              @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.

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @collingsjj
                last edited by PeterJones

                @collingsjj ,

                (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:

                915d9c49-9a1c-4c84-899a-585f1de24fd6-image.png

                … 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

                C 1 Reply Last reply Reply Quote 2
                • C
                  collingsjj @PeterJones
                  last edited by

                  @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.

                  Screenshot 2025-04-23 102302.png
                  (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.

                  1 Reply Last reply Reply Quote 3
                  • Alan KilbornA
                    Alan Kilborn
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • guy038G
                      guy038
                      last edited by guy038

                      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 between 20 and 100 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 :

                       | 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 .
                       | 
                      

                      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 :

                      Too late !

                      Best Regards,

                      guy038

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors