[erlang-questions] Can't update xterm title bar from Erlang
Thomas Lange
thomas@REDACTED
Tue May 30 16:34:44 CEST 2017
Hi Roger,
I can see two issues here.
Firstly, "\a" does not seem to be supported by erlang.
\a is supposed to translate to BEL, i.e. ASCII 7. It's not:
----
Eshell V8.2.1 (abort with ^G)
1> A = "\a".
"a"
2> length(A).
1
3> hd(A).
97
----
Secondly, writing BEL to stdout does not seem to work either.
It seems to be internally replaced with "^G":
---------------
Eshell V8.2.1 (abort with ^G)
1> io:put_chars("\007").
^Gok
2> io:put_chars([7]).
^Gok
3>
----
And this is from the strace of commands above:
----
[pid 28365] writev(0, [{iov_base="^G", iov_len=2}], 1) = 2
[pid 28365] writev(0, [{iov_base="^G", iov_len=2}], 1) = 2
-----
I suspect this could have something to do with ^G (BEL) being
the shell abort command.
I have successfully tried a workaround using a port opened
with nouse_stdio flag:
xterm_title(T) ->
S = "\e]0;" ++ T ++ "\007",
open_port({spawn, "echo -ne \"" ++ S ++ "\""}, [nouse_stdio]),
ok.
/Thomas
On May 15 13:17:41 CEST 2017, Roger Lipscombe wrote:
> I don't need the line feed from the shell:
>
> echo -ne '\e]0;Hello\a' ; sleep 5
>
> ...works fine.
>
> But, in terms of line-feed-flushes-buffers, maybe.
>
> Except that I immediately output something else with a line feed, and the
> terminal (gnome-terminal, Linux Mint) shows *something* for the escape
> sequence. It looks almost-correct, but it's hard to tell.
>
> I suspect something to do with how Erlang has configured the tty for
> (maybe) raw mode, but I don't understand enough about how that works.
>
> On 15 May 2017 at 11:17, Alex S. <> wrote:
>
>> What I’ve noticed is you don’t output the line feed, which might mean that
>> the IO buffer isn’t getting flushed by default. Although I am not sure.
>>
>> 12 мая 2017 г., в 22:28, Roger Lipscombe <>
>> написал(а):
>>
>> I have the following:
>>
>> put_progress(Format, Args) ->
>> io:put_chars(user,
>> [tsl(), io_lib:format(Format, Args), fsl()]),
>> io:put_chars(user,
>> [colored(), io_lib:format(Format, Args), reset(),
>> "\n"]),
>> ok.
>>
>> tsl() -> "\e]0;".
>> fsl() -> "\a".
>> colored() -> "\e[1;44m".
>> reset() -> "\e[0m".
>>
>> That is: output the same message to the title bar (tsl, fsl are the tput
>> capability names; see https://serverfault.com/a/23998/7027), and then
>> (for now) also output it in colour, so that I can see if it's being called
>> correctly.
>>
>> Unfortunately, something is messing with my tsl() and fsl() escape codes.
>> The coloured text is coming out correctly, but the other stuff's garbage.
>> The escape codes are correct; I've tested them at the bash prompt with
>> "echo -e '\e]0;Hello\a'".
>>
>> So... what's screwing with them when they're output from ct_run?
>>
>> Interestingly, if I try the same at the Erlang prompt, it hangs the shell
>> until I press Ctrl+C twice, at which point the text is output, but still
>> messed up.
>>
More information about the erlang-questions
mailing list