Chapter 06

Globalsのプロパティの読み解き方

MURAOKA Taro
MURAOKA Taro
2020.10.18に更新

GlobalsはWindows Terminalの設定JSONのルートに書けるプロパティの大半を定義しています。それらのプロパティは以下のように#/definitions/Globals/propertiesで定義されています。

Windows TerminalのJSON Schemaを読むにあたり覚えておくと良いことを以下に上げていきます。

まず第1にpropertiesはオブジェクトです。このオブジェクトのキーはプロパティ名で値はプロパティ定義のJSON Schemaオブジェクトになります。Windows TerimnalのJSON Schema自体がJSON Schemaオブジェクトなので論理的には複雑な定義が書けるのですが、Globalspropertiesはシンプルな設定項目なので難しい箇所はほとんどありません。

// Globals/propertiesの概略を大まかに示したもの
"properties": {
    "alwaysOnTop":    { /* alwaysOnTopの定義 */ },
    "alwaysShowTabs": { /* aalwaysShowTabsの定義 */ },
    "copyOnSelect":   { /* copyOnSelect */ },
    // 他のプロパティの定義
},

properties 内のJSON Schemaオブジェクトのなかで特に大事な要素は"definitions"です。Windows Terminalの設定スキーマの"definitions"は特に丁寧に書かれており、このプロパティが何を設定するものか、その値の意味するところはなにかがしっかりと書かれています。そのため英文が少々長くなっており若干気後れするかもしれませんが、しっかり目を通すことで大半のことがわかるようになっています。

次に大事なのは"type"要素です。この"type"要素で指定された型の値が、そのプロパティの値として利用できます。プロパティとして頻出する型を以下に示します。

  • "boolean" - ブール型。有効な値は truefalse
    "alwaysOnTop": {
      "default": false,
      "description": "When set to true, the window is created on top of all other windows. If multiple windows are all \"always on top\", the most recently focused one will be the topmost",
      "type": "boolean"
    },
    
    例: L502-506から引用
  • "integer" - 整数型
    "initialCols": {
      "default": 120,
      "description": "The number of columns displayed in the window upon first load. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), this property is ignored.",
      "maximum": 999,
      "minimum": 1,
      "type": "integer"
    },
    
    例: L556-562から引用
  • "string" - 文字列型
    "defaultProfile": {
      "description": "Sets the default profile. Opens by clicking the \"+\" icon or typing the key binding assigned to \"newTab\".",
      "type": "string"
    },
    
    例: L537-540から引用
  • "array" - 配列型。要素の型は"items"要素で指定される
    "disabledProfileSources": {
      "description": "Disables all the dynamic profile generators in this list, preventing them from adding their profiles to the list of profiles on startup.",
      "items": {
        "$ref": "#/definitions/DynamicProfileSource"
      },
      "type": "array"
    },
    
    例: L541-547から引用

プロパティの中には"type"要素が存在せず、"$ref": "#/definitions/..."要素や "oneOf": [...]要素があるケースもあります。これらはいずれも右辺側で定義される複雑な型に合致する値を受け付けることを意味します。以下にそれぞれの詳細を示します。

  • "$ref": "#/definitions/..." - 複雑型。JSON Hyper-Schemaで参照される別のオブジェクト定義(=複雑型)に合致する値
    "copyFormatting": {
      "default": true,
      "description": "When set to `true`, the color and font formatting of selected text is also copied to your clipboard. When set to `false`, only plain text is copied to your clipboard. An array of specific formats can also be used. Supported array values include `html` and `rtf`. Plain text is always copied.",
      "$ref": "#/definitions/CopyFormat"
    },
    
    例: L517-521から引用
  • "oneOf": [...] - いずれかの型(=oneOf)に合致する。配列内で指定されたいずれかの型に合致する型の値
    "cursorColor": {
      "oneOf": [
        { "$ref": "#/definitions/Color" },
        {"type": "null"}
      ],
      "description": "Sets the color of the cursor. Overrides the cursor color from the color scheme. Uses hex color format: \"#rrggbb\"."
    },
    
    例: Globalsではないですが L758-764から引用

ここまでの例に登場しているのですでに気が付いている人は多いと思いますが、型のほかに設定可能な値に制限をかける以下のような要素が見られます。

  • "enum": [ ... ] - 列挙。設定可能な値を直接指定している
  • "minimum""maximum" - 最小値と最大値。"integer""number"型の最小値と最大値を指定している
  • "default" - デフォルト。そのプロパティを省略した際に使われる値を指定している

以上がGlobalsのプロパティの読み解く際に最低限覚えておくと良いことです。