7
  1. I am trying to set up color prompt in asterisk CLI. In the documentation I have found this:

    %Cn[;n] Change terminal foreground (and optional background) color to specified. A full list of colors may be found in include/asterisk/term.h*

    But nowhere could I find what format the color code should be. I have tried all possible permutations, none of them works:

    ASTERISK_PROMPT="%Cn[COLOR_BLUE] %H: " asterisk -vvvvvvr
    ASTERISK_PROMPT="%Cn[32;128] %H: " asterisk -vvvvvvr
    ASTERISK_PROMPT="%Cn[32;] %H: " asterisk -vvvvvvr
    ASTERISK_PROMPT="%Cn[;32] %H: " asterisk -vvvvvvr
    ASTERISK_PROMPT="%Cn[;COLOR_CYAN] %H: " asterisk -vvvvvvr
    ASTERISK_PROMPT="%Cn[32|128] %H: " asterisk -vvvvvvr 
    

    can somebody please tell me how to make my asterisk prompt red, for example?

  2. Also, I have another issue with the CLI prompt:

    I am using Asterisk 11.13 on Debian Wheezy. When I am in asterisk CLI, I can use command history and "readline-like" functions such as CTRL+r to search. But not all functions are available. For example, the alternate mappings for "page up" and "page down" to search the history do not work. They work in everything else (bash, mysql, ..)

    $ cat /etc/inputrc
    "\e[5~": history-search-forward
    "\e[6~": history-search-backward
    

    is there a way to make it work in asterisk ?

msrd0
  • 240
  • 3
  • 13
user1968963
  • 101
  • 1
  • 5
  • I know nothing of asterisk, but is it possible that the documentation is trying to say "%C32", with the brackets indicating the optional background color? i.e, "%C32;128" – jbsmith Dec 05 '14 at 21:24

3 Answers3

2

The "ASTERISK_PROMPT" is an environment variable and should be set prior to starting the CLI for it to take affect.

i.e.

export ASTERISK_PROMPT="%C31%H*CLI%#"
asterisk -r

As for your specific version, (Asterisk 11 branch) The reasons for not displaying colors is as follows:

  1. The command-line options to connect to the server includes the "no-color" flag.
  2. No "term" environment variable is defined.
  3. If the terminfo database exists, and either does not include a max_colors definition, or the value = 0.
  4. The "term" environment variable does not include one of the following:
    • "xterm"
    • "xterm-color"
    • "xterm-256color"
    • "Eterm"
    • "vt100"
    • "crt"

If any of those criteria are met... you won't get vt100 colors.

This information is taken directly from the source-code.

TheCompWiz
  • 7,349
  • 16
  • 23
  • the `export` statement does not make any difference. When I prepend `ASTERISK_PROMPT=` before the `asterisk` command I can set prompt as well. I can change the text of the prompt, use `%H`, but the colors still do not work. – user1968963 Dec 06 '14 at 11:04
  • There are only a few things that would keep your console from displaying colors. 1) you did specify the "-n" (no color) parameter. 2) You are connecting using the "-c" (console) parameter. 3) you specified the "-f" (no-fork) parameter. 4) your shell does not support colors... or is missing the correct "TERM" environment variable. I believe the "TERM" needs to be set to one of the following: "linux", "xterm", "Eterm", "crt", or "vt"... and it also needs to be able to support vt100 colorings. – TheCompWiz Dec 08 '14 at 19:31
  • The specifics can be found in the term.c source-code. Specifically, look in the "term_init" function. http://doxygen.asterisk.org/trunk/d5/de5/term_8c.html#1997b4ca4fdf17e715fddf00f44c9651 – TheCompWiz Dec 08 '14 at 19:33
  • The list is changed from 1.0 slightly. in trunk it looks for "TERM" to be set to: "linux", "xterm", "xterm-color", "xterm-256color", "Eterm", "vt100", or "crt". – TheCompWiz Dec 08 '14 at 19:40
  • I have TERM set to "xterm-256color". But even when I change it to "linux" it does not make any difference. I still get no color, even when I start asterisk as `/usr/sbin/asterisk -r` (to make sure there are no aliases) – user1968963 Dec 08 '14 at 23:57
  • lets back up a bit first. What version of asterisk. (including build number if possible) – TheCompWiz Dec 10 '14 at 22:01
  • I am using Asterisk 11.13. from Debian package (wheezy-backports). The exact (Debian) version is: 11.13.0~dfsg-1~bpo70+1 – user1968963 Dec 10 '14 at 22:54
1

About color issue.

  1. First thing to try:
    • kill all asterisk:

      killall safe_asterisk

      killall asterisk

    • set your TERM: export TERM=xterm-256color

    • run asterisk from terminal: /usr/sbin/asterisk -c (path may differ)

I'm sure you'll see it colorful.

  1. If 1. was OK, then dig into how is asterisk run from system. The only issue I have was when asterisk init script was /etc/init.d/asterisk, but was run with systemctl. Looks to me, that systemctl somehow has it's own TERM preferences used at the moment asterisk starts. But, I forced things and added COLOR=yes in /etc/init.d/asterisk. And this may be forced even more if you put in this script export TERM=xterm-256color, but usability is up to you.
Alexo Po.
  • 11
  • 2
0

For configuring the "readline-like" functionality check out what libedit offers You to configure in editrc (https://manpages.debian.org/jessie/libedit-dev/editrc.5.en.html).
Program name for configuration should be "asterisk" (if You want to change settings specially for this program).

EOhm
  • 795
  • 2
  • 7