译注:

  1. 原文档地址SettingsSchema.md.
  2. 为使显示效果一致,原文略有修改,但只修改格式不修改文字意思,并且会适当添加帮助理解的内容。另外,有些翻译不是直译而是根据功能产生的更贴切的解释型翻译;
  3. 本人英文造诣高,足够很好翻译该文档。提问和讨论可以,胡乱指手画脚、故意抬杠请自重;
  4. profiles.json毕竟是json文档,所以所有内容语法要求符合json,不熟悉语法可用IDE代为检查;
  5. 重复内容只在第一次出现时进行翻译。常见单词不翻译;
  6. 全文中Windows Terminal将被简写为WT
  7. 大小写敏感内容后面会有⭐️标记(大写写成小写不会报错,但会失去效果);
  8. GUID:全局唯一标识符Globally Unique Identifier,这是微软常用的一种身份标识技术,比如注册表中就可以看到。不同设备GUID可能会不一样。可通过VS或者VSCode的guid插件、自己写程序、GUID GEN手动生成。
  9. 绝大多数可选项在初始的Profiles.json中并没有,需要自己添加。
  10. 如无特注,所有颜色设定都是十六进制(如#FFFFFF)。
  11. 技巧一则:如何在当前目录打开WT?将下文所述profiles.json中的staringDirectory属性设置为".",之后只需在Explorer的地址栏中输入“wt”即可。

Globals:全局变量

Properties listed below affect the entire window, regardless of the profile settings.

下列属性对所有标签均生效,不受到配置的单独控制。

Globals属性表格

Profiles:配置文件

Properties listed below are specific to each unique profile.

下述属性特定控制单独唯一配置文件。

Profiles属性表格

Schemes:(预设配色)方案

Properties listed below are specific to each color scheme. ColorTool is a great tool you can use to create and explore new color schemes. All colors use hex color format.

下面列出的属性特定于每种配色方案。ColorTool是一个很棒的工具,可用于创建和探索新的配色方案。所有颜色均使用十六进制颜色格式。

译注:

  1. 关于配色设计这里还推荐一个很好用的工具:terminal.sexy.该网站通过预设、可视化、随机生成等多种方法制作个性化的文本字体搭配方案,支持编程语言、终端、编辑器(如vim)等多种应用场景,支持iTerm2、Terminal.app、Termite等多种格式的导入、Gnome Terminal等多种常见终端配色格式的导出。最有特色的功能是实时可视化预览,能够随心所欲调整配色,找到最适合自己的、最喜欢的配色。
  2. 上一条不是广告。原文推荐的ColorTool 试用过,交互性不佳,全英文控制能劝退不少人。另外,在wt 中要调整配色方案,必须用颜色的十六进制控制,ColorTool 虽然能生成不同配色方案,但不支持直接输出颜色数值,需要手动导出,甚至还要手动转换进制。而terminal.sexy 可以直接显示颜色的数值,方便用在wt 中。
  3. 配色思路:显示最多的内容的颜色建议不要太亮也不能太暗、所以尽量选稍微亮一点的暖色,警告内容、需要重点显示的内容正好跟前者相反,同时,不同颜色之间要有足够差异,太相近会增加眼睛分辨不同内容的压力,增加视觉疲劳。
  4. 下表中前2~5行前文有提到,直接搜索不再翻译。
  5. 从第6行开始都是各种颜色的设置,颜色名称不翻译。表格只保留到第6行,余下各行的Necessity、Type均与第6行相同,Description与第6行相比只改变了最后的描述颜色的单词,所以不再列出表格,只单独列出余下的Property(属性名称)
  6. 颜色设置共计16种,8种普通颜色,8种普通颜色对应的亮色。虽然亮色的必要性都是必须,但在译者使用过程中发现缺少几个并不会报错,缺少紫色、青色也不会报错,不知道是不是BUG。

Property⭐️NecessityTypeDescription
nameRequiredStringName of the color scheme.
foregroundRequiredStringSets the foreground color of the color scheme.
backgroundRequiredStringSets the background color of the color scheme.
selectionBackgroundOptionalStringSets the selection background color of the color scheme.
cursorColorOptionalStringSets the cursor color of the color scheme.
blackRequiredStringSets the color used as ANSI black.将颜色设置为ANSI黑色。

余下Propertyblue, brightBlack, brightBlue, brightCyan(亮青色), brightGreen, brightPurple, brightRed, brightWhite, brightYellow, cyan, green, purple, red, white, yellow.

Keybindings:按键绑定(自定义快捷键)

Properties listed below are specific to each custom key binding.

下述属性专用于按键绑定功能。

Property⭐️NecessityTypeDescription
command 指令(名称)RequiredStringThe command executed when the associated key bindings are pressed. 设置的快捷键所实现的功能(名称)。
keys 按键RequiredArray[String]Defines the key combinations used to call the command. 实现快捷键功能所要按的(组合)按键。
action 行为OptionalStringAdds additional functionality to certain commands. 向某些快捷键添加其他功能。

Implemented Commands and Actions:已实现的命令和动作(默认存在的快捷键)

Commands listed below are per the implementation in src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp.

下列命令是根据这个文件实现的。

Keybindings can be structured in the following manners:

以下为构造快捷键的方法:

For commands without arguments:对于不带参数的命令: { "command": "commandName", "keys": [ "modifiers+key" ] }

For commands with arguments:对于带有参数的命令: { "command": { "action": "commandName", "argument": "value" }, "keys": ["modifiers+key"] }

图片keybindings预留位置。

Accepted Modifiers and Keys:可用的修饰键和普通按键

Modifiers:修饰键

Ctrl+, Shift+, Alt+

Keys:普通按键

Type 类型Keys
Function and Alphanumeric Keys 功能键键、字母键和数字键f1-f24, a-z, 0-9
Symbols 符号键`, -, =, [, ], \, ;, ', ,, ., /
Arrow Keys 方向键down, left, right, up, pagedown, pageup, pgdn, pgup, end, home, plus
Action Keys 动作键tab, enter, esc, escape, space, backspace, delete, insert
Numpad Keys 数字键盘按键numpad_0-numpad_9, numpad0-numpad9, numpad_add, numpad_plus, numpad_decimal, numpad_period, numpad_divide, numpad_minus, numpad_subtract, numpad_multiply
译注:数字键盘按键和其他键是不同的,比如splitPane要配合加减号使用,但数字键盘的加减号可能不行,必须退格键左边的那两个。

Background Images and Icons:背景图片和图标

Some Terminal settings allow you to specify custom background images and icons. It is recommended that custom images and icons are stored in system-provided folders and are referred to using the correct URI Schemes. URI Schemes provide a way to reference files independent of their physical paths (which may change in the future). 某些终端设置允许您指定自定义背景图像和图标。建议将自定义图像和图标存储在系统提供的文件夹中,并使用正确的URI方案进行引用。URI方案提供了一种独立于文件的物理路径(将来可能会更改)引用文件的方法。

译注:绝对路径也可以。记得json绝对路径格式为双斜杠。

The most useful URI schemes to remember when customizing background images and icons are: 自定义背景图片和图标最有用的URI方案:

URI Scheme URI方案Corresponding Physical Path 对应物理路径Use / description 用法/说明
ms-appdata:///Local/%localappdata%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\Per-machine files 每台设备的文件
ms-appdata:///Roaming/%localappdata%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState\Common files 共同文件
⚠ Note: Do not rely on file references using the ms-appx URI Scheme (i.e. icons). These files are considered an internal implementation detail and may change name/location or may be omitted in the future.
⚠注意:请勿依赖使用ms-appxURI方案的文件引用(即图标)。这些文件被视为内部实现细节,并且可能会更改名称/位置,或者将来可能会省略。

Icons:图标

Terminal displays icons for each of your profiles which Terminal generates for any built-in shells - PowerShell Core, PowerShell, and any installed Linux/WSL distros. Each profile refers to a stock icon via the ms-appx URI Scheme.

wt将会根据配置文件显示每一个终端的图标,不论是PowerShell Core,PowerShell或是其他安装的Linux/WSL发行版终端。每个配置文件需要通过ms-appx的URI方案存储图标文件。

⚠ Note: Do not rely on the files referenced by the ms-appx URI Scheme - they are considered an internal implementation detail and may change name/location or may be omitted in the future.

⚠注意:请勿依赖ms-appxURI方案引用的文件-它们被视为内部实现细节,并且可能会更改名称/位置或将来可能被省略。

You can refer to you own icons if you wish, e.g.: 用户可以根据自身需要引用特定的图标,如:

 "icon" : "C:\\Users\\richturn\\OneDrive\\WindowsTerminal\\icon-ubuntu-32.png",

👉 Tip: Icons should be sized to 32x32px in an appropriate raster image format (e.g. .PNG, .GIF, or .ICO) to avoid having to scale your icons during runtime (causing a noticeable delay and loss of quality.).

👉 提示:在适当的光栅图像格式(例如.PNG,.GIF或.ICO)中,图标的大小应调整为32x32px,以避免在运行时缩放图标(造成明显的延迟和质量损失)。

Custom Background Images:自定义背景图像

You can apply a background image to each of your profiles, allowing you to configure/brand/style each of your profiles independently from one another if you wish.

您可以将背景图片应用于每个配置文件,如果需要,可以彼此独立地配置/铭刻/样式化每个配置文件。

To do so, specify your preferred backgroundImage, position it using backgroundImageAlignment, set its opacity with backgroundImageOpacity, and/or specify how your image fill the available space using backgroundImageStretchMode.

为此,请指定您的首选backgroundImage,使用backgroundImageAlignment控制背景图的显示位置,使用backgroundImageOpacity设置其不透明度,和/或使用指定图像如何填充可用空间backgroundImageStretchMode

For example:

例如:

     "backgroundImage": "C:\\Users\\richturn\\OneDrive\\WindowsTerminal\\bg-ubuntu-256.png",
     "backgroundImageAlignment": "bottomRight",
     "backgroundImageOpacity": 0.1,
     "backgroundImageStretchMode": "none"

👉 Tip: You can easily roam your collection of images and icons across all your machines by storing your icons and images in OneDrive (as shown above).

👉 提示:通过将图标和图像存储在OneDrive中,可以轻松地在所有计算机上漫游图像和图标集合(如上示例所示)。硬核OneDrive广告

With these settings, your Terminal's Ubuntu profile would look similar to this:

通过这些设置,您终端的Ubuntu配置文件将类似于以下内容:

译注:这里有张示例图我怎么都加载不出来,大家可以自己点开看看。Custom icon and background image.

profiles.json配置样例一个

这是译者自己做的一个样例,仅供参考:

{
   //各个属性没有先后顺序要求
   //只需要符合json语法,且填写在正确的区域内
   //Globals全局变量不需要中括号单独填写
   "defaultProfile": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}",
   //一大堆必选项可选项我就省略了
   //注意每一项结尾都要有逗号
   "profiles":
  [//配置设置,注意每一项用大括号和逗号隔开,最后一项不要加逗号
       //一堆如cmd、powershell、Azure等默认配置就不写了
       //示例一个ssh的profile
      {
           "guid": "{nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}",
           "name": "Kali",
           "commandline": "ssh root@anydomain.com -p anyport"
           //相当于打开标签页时自动运行上面的代码
           //具体代码格式:ssh 主机名@主机ip或域名 -p 端口号
           //如:ssh root@192.168.222.130 -p 22
           //然后自行添加一大堆有的没的可选项必选项,比如icons,hidden
           //免密登录的实现:
           //1.手动生成ssh或open-ssh的公私钥对,比如用git的ssh-keygen
           //2.在目标主机的初始目录(~目录)创建.ssh目录并在其中创建authorized_keys文件,且目录和文件够给予权限
           //3.将之前生成的公钥(id_rsa.pub)添加到autorized_keys中。注意是添加,不要删除了里面已经有的其他公钥,之后重启Windowsterminal
      }
  ],
   "schemes":
  [
      {
           "name":"test",
           "selectionBackground":"#000000",
           "background":"#137ae1",
           "foreground": "#c5c8c6",
           "black":"#f40000"
      }
  ],
   "keybindings":
  [
       //演示一个禁用快捷键的设置方法
      { "unbound": "closePane", "keys": "ctrl+shift+w" }
       //command换成unbound即可
  ]
}
 ​