Detect Windows Terminal

Code:
     _x64: 1
   _admin: 1
_elevated: 1

TCC  26.02.42 x64   Windows 10 [Version 10.0.18363.959]

1597886077939.png


Here's my method of determining if I am running TCC.EXE from Windows Terminal;
Code:
function WinTerm=`%@execstr[echo %@pidcommand[%_ppid] |! ffind /t"WindowsTerminal" > nul & echo %_ffind_matches]`

1597886026253.png


Joe

Edit: Corrected function, which should have been wrapped in @execstr
Edit: Used _ppid per suggestion by Vince
 
Last edited:
May 20, 2008
11,285
95
Syracuse, NY, USA
Code:
function WinTerm=`echo %@pidcommand[%@ppid[%_pid]] |! ffind /t"WindowsTerminal" > nul & echo %_ffind_matches`
That's a funny-looking UDF; it looks more like an alias.

It doesn't work here because I launch it as WT.EXE.

_PPID should be the same as %@ppid[%_pid]

@REGEX is made for the job. Here's one.

1597938632085.png
 
May 20, 2008
11,285
95
Syracuse, NY, USA
Joe, in your terminal pic, it looks like there are icons in the tab. Do they do anything and how did they get there?

1597947071840.png
 
Joe, in your terminal pic, it looks like there are icons in the tab. Do they do anything and how did they get there?

View attachment 3034

Right-click the tab, and choose rename tab;
1597952820361.png


Adjust the cursor to desired location, then press WIN+.
Select the icon(s) that you want displayed in the tab title.

1597952943278.png


The TITLE command in CMD EXE can also be used to programmatically add icons to the name of a tab;

1597953667779.png


So, I now have a warning icon included with the tab name.

1597953693287.png


I could not get this to work with the TCC Title command. As Rex has said he will not be supporting Windows Terminal, I did not bother to pursue getting this to work any further.

For PowerShell, the same thing can be accomplished as follows;

1597953925348.png


I was going to provide a screen capture of the "PowerShell 64-bit ⚠" tab, but apparently the forum only allows a maximum of 5 attachements.

Joe
 
May 20, 2008
11,285
95
Syracuse, NY, USA
Thanks, Joe. After spending quite a while figuring out how to dig the icon out of TCC.EXE I managed this.

1597954941856.png


by doing this in settings.json.

Code:
"icon": "d:\\tc26\\icon1.ico"

I wanted to try it your way but NOTHING happens when I right-click on a tab. Is that a newer feature ... or does it have to be enabled?
 
I wanted to try it your way but NOTHING happens when I right-click on a tab. Is that a newer feature ... or does it have to be enabled?

I'm using the Windows Store version of Windows Terminal, but if I remember correctly, you are using the non-store version (possibly from GitHub).

Renaming the tab is a default option, AFAIK, and does not need to be enabled (at least in the Windows Store version).

I update the Windows Store version of Windows Terminal via the Windows Store, but your version will probably have to be downloaded again, or refreshed via GitHub.

Here's the link to Microsoft Documentation in regards to renaming a tab, along with a link to the Tab Title Tutorial.

Joe
 
May 20, 2008
11,285
95
Syracuse, NY, USA
I updated from GitHub (rather easily). Now I have the right-click pop-up menu on tabs.

Does the store version update itself automatically, and let you know when that happens?
 
May 20, 2008
11,285
95
Syracuse, NY, USA
There are these in the environment, but they don't provide a foolproof way of determining whether TCC is running in Terminal.

WSLENV=WT_SESSION::WT_PROFILE_ID
WT_PROFILE_ID={ecfa30ac-7c15-41c5-9f0f-886fff57c6ba}
WT_SESSION=e0a34120-48fd-425f-a319-ae27250bde53
 
May 20, 2008
11,285
95
Syracuse, NY, USA
Yet another way: get the console's HWND and send it WM_GETICON (127). conhost will return a valid HANDLE; openconsole will return 0.

Code:
set _wt=`%@if[%@winapi[user32,SendMessage,%@winapi[kernel32,GetConsoleWindow],127,0,0]==0,1,0]`

1598373365422.png
 
There are these in the environment, but they don't provide a foolproof way of determining whether TCC is running in Terminal.

WSLENV=WT_SESSION::WT_PROFILE_ID
WT_PROFILE_ID={ecfa30ac-7c15-41c5-9f0f-886fff57c6ba}
WT_SESSION=e0a34120-48fd-425f-a319-ae27250bde53

Actually, WT_PROFILE_ID works great in both TCC and PowerShell;
1598379789289.png

Note that the WT_PROFILE_ID matches the GUID of the Profile in settings.json

From TCC in Windows Terminal, the PSHELL command shows;
Code:
e:\utils>pshell /s "$env:wt_profile_id"
{35f8afbd-df78-4f1b-a658-451210ef5caa}
which shows that I am in a TCC PSHELL session under Windows Terminal.

From PowerShell in Windows Terminal, if I run TCC or TCCRT;
Code:
PS E:\Utils> tcc set wt*
WT_PROFILE_ID={61c54bbd-c2c6-5271-96e7-009a87ff44bf}
WT_SESSION=5ef89f6d-f8f9-4228-abb5-bd8e438d2767
PS E:\Utils>
PS E:\Utils> tccrt set wt*
WT_PROFILE_ID={61c54bbd-c2c6-5271-96e7-009a87ff44bf}
WT_SESSION=5ef89f6d-f8f9-4228-abb5-bd8e438d2767
I can see that TCC or TCCRT is running in the PowerShell Profile under Windows Terminal.

From Ubuntu in Windows Terminal, if I run TCC or TCCRT;
Code:
jlc@DESKTOP-H2JFFTF:/mnt/c/Program Files/JPSoft/TCC_RT_26$ tcc.exe /c set wt*
WT_PROFILE_ID={2c4de342-38b7-51cf-b940-2309a097f518}
WT_SESSION=7e21e9b2-4cfa-4a36-8f69-3ada03b695bb
I can see that TCC or TCCRT is running in the Ubuntu Profile under Windows Terminal.

Joe
 
May 20, 2008
11,285
95
Syracuse, NY, USA
Yeah but if from TCC, CMD, or PowerShell in Terminal you START any CUI program (e.g., TCC) it'll start in a console and inherit all those variables (and they'll be misleading).
 
  • Like
Reactions: Joe Caverly
May 20, 2008
11,285
95
Syracuse, NY, USA
Thus, it would seem that your WinAPI Solution is the preferred method.
In a BTM or at the command line it probably doesn't matter, your FFIND one, the @REGEX one, the @WINAPI one ...

I also did this with a plugin. There, the SendMessage one was easiest, and possibly fastest.

Code:
INT WINAPI _WT (LPWSTR psz)
{
    wsprintf(psz, L"%lu", !((BOOL) SendMessage(global.hWndConsole, WM_GETICON, 0, 0)) );
    return 0;
}
 
Similar threads

Similar threads