Emacs shell: set TERM to ansi instead of dumb

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Emacs shell: set TERM to ansi instead of dumb

Trevor Spiteri
Hello,

Since the terminal for M-x shell seems to support ansi colors and cursor
movement, would it make sense to set TERM to ansi instead of dumb? I
currently have an init_bash.sh containing the line TERM=ansi, but it
seems to me that it would be better for that to be the default.

Regards.

Trevor


Reply | Threaded
Open this post in threaded view
|

Re: Emacs shell: set TERM to ansi instead of dumb

Colin Baxter
>>>>> Trevor Spiteri <[hidden email]> writes:

    > Hello, Since the terminal for M-x shell seems to support ansi
    > colors and cursor movement, would it make sense to set TERM to
    > ansi instead of dumb? I currently have an init_bash.sh containing
    > the line TERM=ansi, but it seems to me that it would be better for
    > that to be the default.

    > Regards.

    > Trevor

You can also get colours if you just add "TERM dumb" to your
~/.dircolors file.

Best wishes,



--
Colin Baxter
www.Colin-Baxter.com

Reply | Threaded
Open this post in threaded view
|

Re: Emacs shell: set TERM to ansi instead of dumb

Juri Linkov-2
In reply to this post by Trevor Spiteri
> Since the terminal for M-x shell seems to support ansi colors and cursor
> movement, would it make sense to set TERM to ansi instead of dumb? I
> currently have an init_bash.sh containing the line TERM=ansi, but it seems
> to me that it would be better for that to be the default.

Thanks for suggestion.  I tried to use "TERM=ansi" together with
customizing 'comint-terminfo-terminal' to "ansi", and it works fine
everywhere, except compilation mode.  In compilation buffers
it inserts unhandled escape sequences that break fontification.
Had to disable ansi in compilation by customizing
'compilation-environment' to '("TERM=dumb")'.

Reply | Threaded
Open this post in threaded view
|

Re: Emacs shell: set TERM to ansi instead of dumb

Andrés Ramírez-2
Hi Juri.

Juri> Thanks for suggestion.  I tried to use "TERM=ansi" together with
Juri> customizing 'comint-terminfo-terminal' to "ansi", and it works
Juri> fine everywhere, except compilation mode.  In compilation
Juri> buffers it inserts unhandled escape sequences that break
Juri> fontification.  Had to disable ansi in compilation by
Juri> customizing 'compilation-environment' to '("TERM=dumb")'.

I am still seeing the "unhandled escape sequences" on "*compilation*"
buffer see:
--8<---------------cut here---------------start------------->8---
-*- mode: compilation; default-directory: "/ssh:aramirez@x220c:/home/aramirez/dev/wxwidgets/mamacha/src/tests/build/" -*-
Compilation started at Wed Dec  4 01:34:34

cd build && make -k -j4   && cd -
[35m[1mScanning dependencies of target invcross_tests[0m
make: Target 'default_target' not remade because of errors.
...
Compilation exited abnormally with code 2 at Wed Dec  4 01:34:36
--8<---------------cut here---------------end--------------->8---

BTW, above is compilation by tramp.

Those were my customizations:
--8<---------------cut here---------------start------------->8---
(progn (setq comint-terminfo-terminal "ansi") (add-to-list 'compilation-environment "TERM=dumb"))
--8<---------------cut here---------------end--------------->8---

Is there something else. I should customize?

BR
ps: probably the escape sequences are going to be replaced when sending
email. In that case https://termbin.com/41th

Reply | Threaded
Open this post in threaded view
|

Re: Emacs shell: set TERM to ansi instead of dumb

Juri Linkov-2
> cd build && make -k -j4   && cd -
> [35m[1mScanning dependencies of target invcross_tests[0m
> make: Target 'default_target' not remade because of errors.
> ...
> Compilation exited abnormally with code 2 at Wed Dec  4 01:34:36
>
>
> BTW, above is compilation by tramp.
>
> Those were my customizations:
>
> (progn (setq comint-terminfo-terminal "ansi") (add-to-list 'compilation-environment "TERM=dumb"))
>
> Is there something else. I should customize?

Please try to add "TERM=dumb" to 'tramp-remote-process-environment'.

Reply | Threaded
Open this post in threaded view
|

tramp compilation buffer also affected (was: Emacs shell: set TERM to ansi instead of dumb)

Andrés Ramírez-2
Hi Juri.

Juri> Please try to add "TERM=dumb" to
Juri> 'tramp-remote-process-environment'.

Same issue after adding the item to the list:
--8<---------------cut here---------------start------------->8---
-*- mode: compilation; default-directory: "/ssh:aramirez@x220c:/home/olla/dev/wxwidgets/mamacha/src/tests/build/" -*-
Compilation started at Thu Dec  5 00:03:36

cd build && make -k -j4 && cd -
[  0%] [32mBuilding C object CMakeFiles/invcross_tests.dir/test_runner.c.o[0m
[100%] [32m[1mLinking C executable ../invcross_tests[0m
[100%] Built target invcross_tests
/home/olla/dev/wxwidgets/mamacha/src/tests

Compilation finished at Thu Dec  5 00:03:43
--8<---------------cut here---------------end--------------->8---

BTW: I also did (tramp-cleanup-this-connection, tramp-cleanup-all-buffers)
AR

Reply | Threaded
Open this post in threaded view
|

Re: tramp compilation buffer also affected

Juri Linkov-2
> BTW: I also did (tramp-cleanup-this-connection, tramp-cleanup-all-buffers)

Actually, tramp-cleanup-... don't update the existing process-environment.
You need restart Emacs after customizing tramp-remote-process-environment.

It's easier to check whether TERM has the right value in Tramp by simply:

  M-x compile RET
  echo $TERM
  RET

For testing compilation highlighting, I just touch xterm.c and compile it,
because compilation of xterm.o always produces warnings:

  M-x compile RET
  touch xterm.c; TERM=ansi make xterm.o
  RET

It produces unhandled escape sequences in the compilation output buffer:

  touch xterm.c; TERM=ansi make xterm.o
    GEN      globals.h
    CC       xterm.o
  ^[[01m^[[Kxterm.c:^[[m^[[K In function '^[[01m^[[Kx_parse_color^[[m^[[K':
  ^[[01m^[[Kxterm.c:2425:61:^[[m^[[K ^[[01;35m^[[Kwarning: ^[[m^[[K'^[[01m^[[K%.*s^[[m^[[K' directive output may be truncated writing up to 2147483647 bytes into a region of size 28 [^[[01;35m^[[K-Wformat-truncation=^[[m^[[K]
         snprintf (rgb_color_name, sizeof rgb_color_name, "rgb:^[[01;35m^[[K%.*s^[[m^[[K/%.*s/%.*s",
                                                               ^[[01;35m^[[K^~~~^[[m^[[K
  ^[[01m^[[Kxterm.c:2425:56:^[[m^[[K ^[[01;36m^[[Knote: ^[[m^[[Kassuming directive output of 1 byte
         snprintf (rgb_color_name, sizeof rgb_color_name, ^[[01;36m^[[K"rgb:%.*s/%.*s/%.*s"^[[m^[[K,
                                                          ^[[01;36m^[[K^~~~~~~~~~~~~~~~~~~~^[[m^[[K
  ^[[01m^[[Kxterm.c:2425:56:^[[m^[[K ^[[01;36m^[[Knote: ^[[m^[[Kassuming directive output of 1 byte
  ^[[01m^[[Kxterm.c:2425:56:^[[m^[[K ^[[01;36m^[[Knote: ^[[m^[[Kassuming directive output of 1 byte
  ^[[01m^[[Kxterm.c:2425:7:^[[m^[[K ^[[01;36m^[[Knote: ^[[m^[[K'^[[01m^[[Ksnprintf^[[m^[[K' output between 7 and 6442450948 bytes into a destination of size 32
         ^[[01;36m^[[Ksnprintf (rgb_color_name, sizeof rgb_color_name, "rgb:%.*s/%.*s/%.*s",^[[m^[[K
         ^[[01;36m^[[K^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^[[m^[[K
   ^[[01;36m^[[K  digits_per_channel, color_name + 1,^[[m^[[K
     ^[[01;36m^[[K~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^[[m^[[K
   ^[[01;36m^[[K  digits_per_channel, color_name + digits_per_channel + 1,^[[m^[[K
     ^[[01;36m^[[K~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^[[m^[[K
   ^[[01;36m^[[K  digits_per_channel, color_name + 2 * digits_per_channel + 1)^[[m^[[K;
     ^[[01;36m^[[K~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^[[m^[[K

But running compile with a prefix arg processes escape sequences and produces
nice output even when Tramp process-environment is not customized:

  C-u M-x compile RET
  touch xterm.c; TERM=ansi make xterm.o
  RET

Reply | Threaded
Open this post in threaded view
|

Re: tramp compilation buffer also affected

Andrés Ramírez-2
Hi Juri.

Juri> Actually, tramp-cleanup-... don't update the existing
Juri> process-environment.  You need restart Emacs after customizing
Juri> tramp-remote-process-environment.

Juri> It's easier to check whether TERM has the right value in Tramp
Juri> by simply:

Juri>   M-x compile RET echo $TERM RET
--8<---------------cut here---------------start------------->8---
-*- mode: compilation; default-directory: "/ssh:aramirez@x220c:/home/aramirez/dev/wxwidgets/mamacha/src/tests/" -*-
Compilation started at Mon Dec  9 05:49:33

echo $TERM
ansi

Compilation finished at Mon Dec  9 05:49:34
--8<---------------cut here---------------end--------------->8---

It seems my snippet is not working then:
--8<---------------cut here---------------start------------->8---
(progn (setq comint-terminfo-terminal "ansi") (require
'compile)(add-to-list 'compilation-environment "TERM=dumb") (require
'tramp)(add-to-list 'tramp-remote-process-environment "TERM=dumb"))
--8<---------------cut here---------------end--------------->8---

Juri> For testing compilation highlighting, I just touch xterm.c and
Juri> compile it, because compilation of xterm.o always produces
Juri> warnings:

Juri>   M-x compile RET touch xterm.c; TERM=ansi make xterm.o RET

Juri> It produces unhandled escape sequences in the compilation output
Juri> buffer:

Same case for me.

Juri> But running compile with a prefix arg processes escape sequences
Juri> and produces nice output even when Tramp process-environment is
Juri> not customized:

Juri>   C-u M-x compile RET touch xterm.c; TERM=ansi make xterm.o RET

This workaround works for me. Actually IMO It should not be necessary to
restart emacs. after customizing tramp-remote-process-environment.

Thanks for the workaround. Best Regards