Closed ale5000-git closed 4 months ago
It looks as though the issue is with the Terminal: it doesn't work in PowerShell either:
Write-Output "$([char]27)]0;hello$([char]7)"
works, but
Write-Output "$([char]27)]0;$([char]7)"
doesn't.
If the problem isn't in busybox, then as even better alternative is it possible to support this?
printf '\033[22;0t' # Save current title on stack
printf '\033[23;0t' # Restore title from stack
How would that work? Isn't the stack of titles a property of the terminal?
This is my suggestion:
A real way would be to find the hWnd
of the window where busybox is hosted and get the title directly but I think it would be too much complicated and unneded since Windows Terminal set automatically the title as Command Prompt - command
(example: Command Prompt - busybox ash
).
So the simplest way is to keep track of it in 2 variables.
The first variable is the last_title
:
Command Prompt - command_used_to_run_busybox
printf '\033]0;%s\007'
is executed it store the new titleThe second variable is the title_saved
:
printf '\033[22;0t'
is executed it use the title in last_title
and copy it in title_saved
.The rest goes without saying.
Emulating a stack of title in BusyBox isn't going to work without support from the underlying terminal.
Perhaps it would help if you could explain what you're trying to do. You've spoken of wanting to set the title to an empty string and of fetching/saving titles to a stack, but it isn't clear how these are related.
The empty title was only a workaround (I just reported the problem in case was an easy fix).
Mainly I want:
So I just need to restore the titles that are set during the lifetime of the busybox executable (I don't care about the titles before).
It seems that fetching the title of a terminal isn't a very well supported operation.
As a bit of a hack I've added a title
built-in to the shell in busybox-w32.
This is completely non-portable. If it works for you, good. If not, I refer you to the 'NO WARRANTY' clause of the licence ;-)
There's a new prerelease, of course.
It works perfectly, thanks.
To have enough portability I have used these:
set_title()
{
if test "${CI:-false}" != 'false'; then return 1; fi
if command 1> /dev/null -v title; then
PREVIOUS_TITLE="$(title)" # Save current title
title "${1:?}" # Set new title
elif test -t 1; then
printf '\033[22;0t\r' && printf ' \r' # Save current title on stack
printf '\033]0;%s\007\r' "${1:?}" && printf ' %*s \r' "${#1}" '' # Set new title
elif test -t 2; then
printf 1>&2 '\033[22;0t\r' && printf 1>&2 ' \r' # Save current title on stack
printf 1>&2 '\033]0;%s\007\r' "${1:?}" && printf 1>&2 ' %*s \r' "${#1}" '' # Set new title
fi
}
restore_title()
{
if test "${CI:-false}" != 'false'; then return 1; fi
if command 1> /dev/null -v title; then
title "${PREVIOUS_TITLE?}" # Restore saved title
PREVIOUS_TITLE=''
elif test -t 1; then
printf '\033]0;\007\r' && printf ' \r' # Set empty title (fallback in case saving/restoring title doesn't work)
printf '\033[23;0t\r' && printf ' \r' # Restore title from stack
elif test -t 2; then
printf 1>&2 '\033]0;\007\r' && printf 1>&2 ' \r' # Set empty title (fallback in case saving/restoring title doesn't work)
printf 1>&2 '\033[23;0t\r' && printf 1>&2 ' \r' # Restore title from stack
fi
}
Hi, setting an empty title using
printf '\033]0;\007\r'
works oncmd.exe
but not onWindows Terminal
.