[
  { "type"  : "label",
    "read"  : "(label) => {
      var view;
      function showLabel() {
        label.text = '<b>%1</b>'.arg((view.keyMode == Wind.LocalMode) ? qsTr('Local Mode') : qsTr('Remote Mode'));
        label.visible = true;
      }
      function update(activeView) {
        if (view != activeView) {
          if (view) view.keyModeChanged.disconnect(showLabel);
          if (view = activeView) showLabel(); else label.visible = false;
          if (view) view.keyModeChanged.connect(showLabel);
        }
      }
      terminal.viewActivated.connect(update);
      update(terminal.view());
    }",
    "write" : "(label) => {
        view.keyMode = (view.keyMode == Wind.LocalMode) ? Wind.RemoteMode : Wind.LocalMode);
    }"
  },
  { "type"  : "button",
    "read"  : "(button) => {
      var view;
      function pad(count) {
        var spaces = '  ';
        return count + spaces.substring(0, spaces.length - String(count).length);
      }
      function showButton() {
        button.text = 'Ln %1 Ch %2'.arg(pad(view.caretLine + 1)).arg(pad(view.caretLineOffset));
        button.visible = true;
      }
      function update(activeView) {
        if (view != activeView) {
          if (view) view.caretPositionChanged.disconnect(showButton);
          if (view = activeView) showButton(); else button.visible = false;
          if (view) view.caretPositionChanged.connect(showButton);
        }
      }
      terminal.viewActivated.connect(update);
      update(terminal.view());
    }"
  },
  { "type"  : "button",
    "read"  : "(button) => {
      var view;
      function showButton() {
        button.text = view.scheme();
        button.visible = true;
      }
      function update(activeView) {
        if (view != activeView) {
          if (view) view.schemeChanged.disconnect(showButton);
          if (view = activeView) showButton(); else button.visible = false;
          if (view) view.schemeChanged.connect(showButton);
        }
      }
      terminal.viewActivated.connect(update);
      update(terminal.view());
    }"
  },
  { "type"  : "label",
    "read"  : "(label) => {
      window.setInterval(() => {
        var date = new Date();
        label.text = date.toLocaleString();
      }, 2000);
    }"
  },
  { "type"  : "label",
    "read"  : "(label) => {
      label.text = '<a href=\"https://www.github.com/kingtoolbox/windterm\" style=\"text-decoration:none;\">WindTerm</a>';
    }"
  }
]
