public setTheme()

in src/renderer/dom/DomRenderer.ts [135:202]


  public setTheme(theme: ITheme | undefined): IColorSet {
    if (theme) {
      this.colorManager.setTheme(theme);
    }

    if (!this._themeStyleElement) {
      this._themeStyleElement = document.createElement('style');
      this._terminal.screenElement.appendChild(this._themeStyleElement);
    }

    // Base CSS
    let styles =
        `${this._terminalSelector} .${ROW_CONTAINER_CLASS} {` +
        ` color: ${this.colorManager.colors.foreground.css};` +
        ` background-color: ${this.colorManager.colors.background.css};` +
        ` font-family: ${this._terminal.getOption('fontFamily')};` +
        ` font-size: ${this._terminal.getOption('fontSize')}px;` +
        `}`;
    // Text styles
    styles +=
        `${this._terminalSelector} span:not(.${BOLD_CLASS}) {` +
        ` font-weight: ${this._terminal.options.fontWeight};` +
        `}` +
        `${this._terminalSelector} span.${BOLD_CLASS} {` +
        ` font-weight: ${this._terminal.options.fontWeightBold};` +
        `}` +
        `${this._terminalSelector} span.${ITALIC_CLASS} {` +
        ` font-style: italic;` +
        `}`;
    // Cursor
    styles +=
        `${this._terminalSelector} .${ROW_CONTAINER_CLASS}:not(.${FOCUS_CLASS}) .${CURSOR_CLASS} {` +
        ` outline: 1px solid ${this.colorManager.colors.cursor.css};` +
        ` outline-offset: -1px;` +
        `}` +
        `${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${CURSOR_CLASS}.${CURSOR_STYLE_BLOCK_CLASS} {` +
        ` background-color: ${this.colorManager.colors.cursor.css};` +
        ` color: ${this.colorManager.colors.cursorAccent.css};` +
        `}` +
        `${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${CURSOR_CLASS}.${CURSOR_STYLE_BAR_CLASS} {` +
        ` box-shadow: 1px 0 0 ${this.colorManager.colors.cursor.css} inset;` +
        `}` +
        `${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${CURSOR_CLASS}.${CURSOR_STYLE_UNDERLINE_CLASS} {` +
        ` box-shadow: 0 -1px 0 ${this.colorManager.colors.cursor.css} inset;` +
        `}`;
    // Selection
    styles +=
        `${this._terminalSelector} .${SELECTION_CLASS} {` +
        ` position: absolute;` +
        ` top: 0;` +
        ` left: 0;` +
        ` z-index: 1;` +
        ` pointer-events: none;` +
        `}` +
        `${this._terminalSelector} .${SELECTION_CLASS} div {` +
        ` position: absolute;` +
        ` background-color: ${this.colorManager.colors.selection.css};` +
        `}`;
    // Colors
    this.colorManager.colors.ansi.forEach((c, i) => {
      styles +=
          `${this._terminalSelector} .${FG_CLASS_PREFIX}${i} { color: ${c.css}; }` +
          `${this._terminalSelector} .${BG_CLASS_PREFIX}${i} { background-color: ${c.css}; }`;
    });

    this._themeStyleElement.innerHTML = styles;
    return this.colorManager.colors;
  }