Page 1 of 1

Terminal Escape Sequences expected behavior?

Posted: 22 Nov 2021 07:23
by atfon
I've noticed a discrepancy between the behavior of certain terminal escape sequences when another instance of cmd.exe or powershell is invoked. I'll provide a couple brief examples.

1. Let's say you want to stop the cursor from blinking:

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%e in ('echo prompt $E^|cmd') do set "\e=%%e"
echo Hi
echo %\e%[?12l
powershell /command "Get-Host | Select Version"
cmd /k echo Hi
In this instance, the cursor stops blinking and remains regardless if I invoke cmd.exe or powershell.

2. Lets say you want to change the title and Run the script as Administrator:

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%e in ('echo prompt $E^|cmd') do set "\e=%%e"
for /f %%g in ('%__APPDIR__%forfiles.exe /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "bel=%%g"
echo %\e%]0;Test Title%BEL%
pause
powershell /command "Get-Host | Select Version"
or

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%e in ('echo prompt $E^|cmd') do set "\e=%%e"
for /f %%g in ('%__APPDIR__%forfiles.exe /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "bel=%%g"
echo %\e%]0;Test Title%BEL%
pause
cmd /k echo Hi
In each case here, invoking cmd.exe or powershell changes the title to include Administrator.

Is that expected behavior for a Operating System Command (OSC) sequence as opposed to a Control Sequence Introducer (CSI)?

Re: Terminal Escape Sequences expected behavior?

Posted: 22 Nov 2021 10:51
by aGerman
I believe it's intented to always have Administrator in the title if you run it elevated. It's rather UB or a bug if you are able to bypass it.
viewtopic.php?f=3&t=9931&p=63866#p63776

FWIW There's a PR for the terminal app which turns the Administrator title into a shield icon instead. Already in the 1.12 preview.
https://github.com/microsoft/terminal/pull/11224

Steffen

Re: Terminal Escape Sequences expected behavior?

Posted: 22 Nov 2021 11:39
by atfon
aGerman wrote:
22 Nov 2021 10:51
I believe it's intented to always have Administrator in the title if you run it elevated.
So, you're suspicion is that the sequence provided here is not supposed to remove the word "Administrator" from an elevated batch script?

https://docs.microsoft.com/en-us/window ... ndow-title

The current behavior [version Version 10.0.19044.1348 on my system] is that it does, until another command process or powershell is invoked. There may be other situations which causes the title to revert, but I've seen it in those two.

Re: Terminal Escape Sequences expected behavior?

Posted: 22 Nov 2021 12:26
by aGerman
I didn't find any official statement. However, apparently the only reason why the Administrator title exists is to warn/remind the user. The fact that even a successfully updated title is turned back into the Administrator title at the next opportunity makes me believe that this is the intended behavior. Guessing might not be satisfactory though. Consider to file a new issue over in the terminal repository and see what the core team replies.

Steffen