Suggestion about new feature for Crystal language

Hi, I just would like, accordance to this topic I made in the past, to suggest to add the setproctitle support.

Do you know if actually an external project for Crystal implement that ?

Assuming you’re in an ANSI-compatible terminal (like pretty much any Linux or OSX terminal), and it supports XTerm stuff (most do), you can just output an ANSI control sequence. This won’t change the name in things like the output of ps, but it will change the title shown in your terminal as long as it supports that sequence.

title = "Neat Program Title"
STDOUT << "\e]0; #{title}\e\\"

If you really want a library for this, then my personal libremiliacr library can do it.

3 Likes

Oh thanks a lot !

1 Like

Hi again MistressRemilia, I have an another question. Is it possible to show back the first terminal title ? How can I do that ? I guess if I do an exit 0 (or other number), it doesn’t reset the terminal title ?

Yeah, it won’t magically reset the terminal title. But you can tell the terminal to remember the current title, then recall it later. Again, this is assuming an Xterm-compatible terminal (I tried it in xterm, terminology, and xfce4-terminal, and they all worked).

# Store the current title in an internal stack.
# This stack is managed by the terminal itself.
STDOUT << "\e[22t"

# ... your code here...
# ...including the code that changes the terminal title...

# Pop the topmost value on the internal stack.
# The previous title gets restored.
STDOUT << "\e[23t" 

There’s also apparently a way to actually get the title programatically using an escape sequence, but I’ve never gotten this to work.

If you really need to get the title, I suppose one way would be to use some Xlib bindings, but that sounds like more trouble than it’s worth.

1 Like