7

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
Elod
  • 383
  • 2
  • 12
  • 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
  • @Elod sure, `less -R` will show color codes but it doesn't let you edit. [Emacs can](http://stackoverflow.com/questions/23378271/how-do-i-display-ansi-color-codes-in-emacs-for-any-mode), and `vim` probably can (it is also very powerful, indeed a close second to emacs) but I don't know how since I don't use it. A better question is _why_ you would want or need this functionality. What's the point? Do you just want error log files to be syntax highlighted in gedit? If so, what kind of files are you thinking of? – terdon Oct 22 '15 at 12:56
  • @terdon, I'm mostly curios if it is possible, personally I'm interested not only in error msgs, but all kind of messages to be colored differently similarly as it appears in the terminal (not necessarily in with the same color) – Elod Oct 22 '15 at 13:04
  • You could write an syntax highlighter for your files. gedit uses `libgtksourceview`. Updated my answer. – A.B. Oct 22 '15 at 13:06
  • 2
    @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

1 Answers1

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.

Fabby
  • 34,341
  • 38
  • 97
  • 191
A.B.
  • 89,123
  • 21
  • 245
  • 323