最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does a Windows terminal have an API which can be called from scripts? - Stack Overflow

programmeradmin2浏览0评论

I recently switched to a Windows PC for development and have for years been used to navigating between vim splits and terminal splits using the same key binding, I had this working very well using kitty on macOS. I am on a corporate machine now and I have to use Windows Terminal. Windows Terminal has splits, and I can control it using key bindings. However, I was wondering whether Windows Terminal has an API, so that I can implement Navigator.nvim for Windows Terminal, and get my old Vim/terminal split integration working again.

Is this possible in Windows Terminal?

I recently switched to a Windows PC for development and have for years been used to navigating between vim splits and terminal splits using the same key binding, I had this working very well using kitty on macOS. I am on a corporate machine now and I have to use Windows Terminal. Windows Terminal has splits, and I can control it using key bindings. However, I was wondering whether Windows Terminal has an API, so that I can implement Navigator.nvim for Windows Terminal, and get my old Vim/terminal split integration working again.

Is this possible in Windows Terminal?

Share Improve this question edited Mar 2 at 1:25 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Jan 26 at 21:10 Benjamin Hammer NørgaardBenjamin Hammer Nørgaard 8371 gold badge9 silver badges26 bronze badges 2
  • 1 Windows default terminal if very limited, maybe use PowerShell instead? – Je Campos Commented Feb 24 at 20:49
  • 1 @JeCampos Windows Terminal (the default in new Windows 11 installs) is a pretty feature-rich terminal; it's pretty new and in active development. The previous default was Windows Console Host, a ~20 year old, pretty limited app. PowerShell is a shell that runs in either Windows Terminal, Windows Console Host, or any other terminal in Windows. – NotTheDr01ds Commented Mar 3 at 23:11
Add a comment  | 

2 Answers 2

Reset to default 2

While there's not an API, the wt.exe command itself gives you a lot of control over existing Windows Terminal sessions. It seems to me that you would be able to set up Neovim keybindings to run any of the following commands. See Using command line arguments for Windows Terminal for a complete list of commands.

For instance, to create a new vertical split with the default profile:

wt.exe -w last split-pane

The --window/-w last sends the command to the most recently used Windows Terminal instance.

Some other examples:

# New horizontal split
wt.exe -w last split-pane -H

# Move up a pane when you have a horizontal split
wt.exe -w last mf up
wt.exe -w last move-focus up

# Move right a pane when you have a vertical split
wt.exe -w last mf right
wt.exe -w last move-focus right

# Open a new tab with the default WSL distribution in the WSL user's home directory
wt.exe -w last new-tab wsl.exe '~'

If you are using WSL, you'll need to use the full wt.exe. PowerShell and CMD can just use wt (or the alternative versions listed in the doc linked above).

Not an API per se, but most Windows (Desktop) GUI applications run on the same event messaging structure/queue architecture. The same is likely true for the console windows.

You would FindWindow or EnumWindows to get the HWND and PostMessage to it.

It's a bit annoying since many of the complicated messages need pointers to objects in the original process.

发布评论

评论列表(0)

  1. 暂无评论