6

I run a script in terminal and the output printed in the terminal I also save in a text file. How can I display that text in Gedit colored similar to what I can see in the terminal?

I thought there could be a plugin.

Update

I might not have been as clear as I planed, so I would like to see similar coloring changes in the plain text file as appears in terminal, not for shell scripts but if I have an error message (e.g. compiler error) than those line to be differentiated from other printouts in terminal.

$ rosrun my_pkg my_node >> terminal_printout

Update 2

My gedit version is 3.10.4

ii  libgtksourceview-3.0-1:amd64   3.10.2-0ubuntu1 amd64 sared libraries for the GTK+ syntax highlighting widget
ii  libgtksourceview-3.0-common    3.10.2-0ubuntu1 all common files for the GTK+ syntax highlighting widget
  • Does it have to be gedit? Emacs can do this and, presumably, vim as well. So can tools like less. – terdon Oct 22 '15 at 12:12
  • I would give a try if other tools are capable to do this. Are they? – Elod Oct 22 '15 at 12:47
  • What's your gedit version? – A.B. Oct 22 '15 at 12:51
  • And the output of dpkg -l | grep libgtksourceview please – A.B. Oct 22 '15 at 12:54
  • 1
    @Elod yes, but each one has different styles and the colors are arbitrarily chosen by the program that prints them to your terminal. It is a personal choice of the author of the program. More to the point, why would you be opening error messages in gedit? Just pipe the output to less instead: command_that_prints_color | less -R. That way, you can use the wheel to scroll up and down and have a look and don't need to load a GUI program for it. – terdon Oct 22 '15 at 13:11
2

Answer for the second version of the question

To add a highlighting for your log files, you have to write your own syntax highlighter. But that's a lot of work. Or try an existing syntax highlighter.

Open your file in gedit and click on Plain Text as you can see in the next screen shot:

    enter image description here

Predefined syntax highlighter can you find in

/usr/share/gtksourceview-3.0/

Answer for the first version of the question

A simple text (Plain Text) file hasn't a syntax highlighting in gedit

    enter image description here

Add some code in the file and save. Now the syntax highlighting for bash (sh) is active. You can see this in the status bar in the screen shot below

    enter image description here

The colours of a shell script in a terminal is possible with escape sequences, see the next screen shots

    enter image description here

    enter image description here

As you can see, those are completely different things. In gedit you have colours via syntax highlighting and in a terminal with escape sequences.

  • I understand now, thanks. I updated my question. Is it somehow possible to use syntax highlighting as escape sequences? – Elod Oct 22 '15 at 12:44
  • That's gonna be useful. Thanks for a good answer ! – Sergiy Kolodyazhnyy Oct 24 '15 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.