WindowsTerminal折騰記


背景

Windows Terminal最近出了1.0版本,界面非常美觀,但要配置好還是要下一番功夫,而且網上的教程都是互相抄,所以特將我的配置過程記錄如下。

字體

首先是字體,默認字體英文不錯,但中文挺不好看的,而Windows Terminal不支持單字節字符和雙字節字符配置不同的字體,所以我找到了一個合成字體的網站,將英文的Consolas字體和和中文的楷體合並成了一個字體,然后雙擊安裝。在配置文件的defaults標簽下修改fontFace為字體的名字,fontSize為字體的大小,這是使用了合成字體的界面:

背景圖片

接着是背景圖片,在配置文件的defaults標簽下添加如下屬性:

"backgroundImage": "D:\\images\\image.jpg",
"backgroundImageOpacity": 0.2,
"backgroundImageStretchMode": "uniformToFill",

第一個屬性是路徑,第二個是透明度,第三個是拉伸方式,拉伸方式有四種取值,可以參考微軟官方文檔,建議使用uniformToFill,它能在保持圖片分辨率的同時將圖片拉伸充滿窗口。

主題

Windows Terminal自帶可以更換的主題可以在官方github上面看到,因為我的背景圖是暖色調的,所以我選擇了Solarized Light這一主題,不過使用該主題會造成一些地方的顏色看不太清楚,比如此主題下運行vim的查找字符串高亮顯示背景和文字的顏色就過於接近,看不清楚;我所使用的文件管理器vifm的當前行高亮也看不太清楚,PowerShell的一些字符也被背景掩蓋,所以需要自己修改一下。這是我自己定制的Solarized Light主題:

        {
            "name": "My Solarized Light",
            "black": "#073642",
            "red": "#dc322f",
            "green": "#859900",
            "yellow": "#b58900",
            "blue": "#268bd2",
            "purple": "#d33682",
            "cyan": "#2aa198",
            "white": "#eee8d5",
            "brightBlack": "#002b36",
            "brightRed": "#cb4b16",
            "brightGreen": "#586e75",
            "brightYellow": "#657b83",
            "brightBlue": "#9ce3f8",
            "brightPurple": "#6c71c4",
            "brightCyan": "#859595",
            "brightWhite": "#fae7b3",
            "background": "#fdf6e3",
            "foreground": "#657b83"
        }

修改了brightBlue和brightCyan屬性,同時將cursorColor屬性改成了#657b83使得光標文字保持同個顏色,這個屬性既可以出現在主題中也可以出現在前面的全局配置中,我放在前面了。如果還有顯示不清楚的地方,可以用QQ的截圖功能對想要修改的顏色區域進行取色,切換成十六進制后在主題中查找它對應的屬性名然后修改。
以上可以解決各種程序的顯示不清楚問題,但Powershell的問題本質上是Powershell語法高亮的問題,和Windows Terminal的主題無關,所以需要在PowerShell的配置文件里面修改。進入PowerShell,運行gvim $profile(gvim可以改成notepad等編輯器),然后輸入下面的命令,保存退出:

Set-PSReadLineOption -Colors @{
    Number = 'DarkBlue'
    Member = 'DarkBlue'
} -EditMode 'Vi'

其中將Number和Member這兩個token的顏色改成藍色,因為原來的顏色就是黃色,和Solarized Light的背景顏色混起來看不清楚,如果還有顯示不清楚的token,可以參考MSDN進行修改,editmode參數的修改屬於我的個人喜好,Emacs黨可以把Vi換成Emacs,都不是的就去掉這個參數即可。

完整配置

// This file was initially generated by Windows Terminal 1.0.1401.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{0a920985-e2e7-4fe2-8610-f29c814c920a}",

    // You can add more global application settings here.
    // To learn more about global settings, visit https://aka.ms/terminal-global-settings

    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": true,

    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": true,
    "initialRows": 25,
    "initialCols": 80,

    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
            "fontFace": "KaiConsolas",
            "fontSize": 16,
            "cursorShape": "filledBox",
            "cursorColor": "#657b83",
            "backgroundImage": "D:\\images\\image.jpg",
            "backgroundImageOpacity": 0.2,
            "colorScheme": "My Solarized Light"
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                "guid": "{0a920985-e2e7-4fe2-8610-f29c814c920a}",
                "hidden": false,
                "name": "Vifm",
                "commandline": "D:\\Apps\\vifm-w64-se-0.10.1-binary\\vifm.exe",
                "startingDirectory" : "D:\\"
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "命令提示符",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [
        {
            "name": "My Solarized Light",
            "black": "#073642",
            "red": "#dc322f",
            "green": "#859900",
            "yellow": "#b58900",
            "blue": "#268bd2",
            "purple": "#d33682",
            "cyan": "#2aa198",
            "white": "#eee8d5",
            "brightBlack": "#002b36",
            "brightRed": "#cb4b16",
            "brightGreen": "#586e75",
            "brightYellow": "#657b83",
            "brightBlue": "#9ce3f8",
            "brightPurple": "#6c71c4",
            "brightCyan": "#859595",
            "brightWhite": "#fae7b3",
            "background": "#fdf6e3",
            "foreground": "#657b83"
        }
    ],

    // Add custom keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about keybindings, visit https://aka.ms/terminal-keybindings
    "keybindings":
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        // { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
        // { "command": "paste", "keys": "ctrl+v" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find", "keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
    ]
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM