<commit_before>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  Application
} from 'phosphide/lib/core/application';

import {
  JupyterServices
} from '../services/plugin';

import {
  WidgetTracker
} from '../widgettracker';

import {
  TerminalWidget
} from './index';


/**
 * The default terminal extension.
 */
export
const terminalExtension = {
  id: 'jupyter.extensions.terminal',
  requires: [JupyterServices],
  activate: activateTerminal
};

/**
 * The class name for all main area landscape tab icons.
 */
const LANDSCAPE_ICON_CLASS = 'jp-MainAreaLandscapeIcon';

/**
 * The class name for the terminal icon in the default theme.
 */
const TERMINAL_ICON_CLASS = 'jp-ImageTerminal';


function activateTerminal(app: Application, services: JupyterServices): void {

  let newTerminalId = 'terminal:create-new';
  let increaseTerminalFontSize = 'terminal:increase-font';
  let decreaseTerminalFontSize = 'terminal:decrease-font';
  let toggleTerminalTheme = 'terminal:toggle-theme';
  let closeAllTerminals = 'terminal:close-all-terminals';
  let tracker = new WidgetTracker<TerminalWidget>();
  let options = {
    background: 'black',
    color: 'white',
    fontSize: 14
  };
  
  app.commands.add([
    {
      id: newTerminalId,
      handler: () => {
        let term = new TerminalWidget(options);
        term.title.closable = true;
        term.title.icon = `${LANDSCAPE_ICON_CLASS} ${TERMINAL_ICON_CLASS}`;
        app.shell.addToMainArea(term);
        tracker.addWidget(term);
        services.terminalManager.createNew().then(session => {
          term.session = session;
        });
      }
    },
    {
      id: increaseTerminalFontSize,
      handler: increaseFont
    },
    {
      id: decreaseTerminalFontSize,
      handler: decreaseFont
    },
    {
      id: toggleTerminalTheme,
      handler: toggleTheme
    },
    {
      id: closeAllTerminals,
      handler: closeAllTerms
    }
  ]);
  app.palette.add([
    {
      command: newTerminalId,
      category: 'Terminal',
      text: 'New Terminal',
      caption: 'Start a new terminal session'
    },
    {
      command: increaseTerminalFontSize,
      category: 'Terminal',
      text: 'Increase Terminal Font Size',
    },
    {
      command: decreaseTerminalFontSize,
      category: 'Terminal',
      text: 'Decrease Terminal Font Size',
    },
    {
      command: toggleTerminalTheme,
      category: 'Terminal',
      text: 'Toggle Terminal Theme',
      caption: 'Switch Terminal Background and Font Colors'
    },
    {
      command: closeAllTerminals,
      category: 'Terminal',
      text: 'Close All Terminals'
    }
  ]);

  function increaseFont(): void {
    if (!tracker.isDisposed) {
      let widgets = tracker.widgets;
      if (options.fontSize < 72) {
        options.fontSize++;
      }
      for (let i = 0; i < widgets.length; i++) {
        widgets[i].fontSize = options.fontSize;
      }
    }
  }

  function decreaseFont(): void {
    if (!tracker.isDisposed) {
      let widgets = tracker.widgets;
      if (options.fontSize > 9) {
        options.fontSize--;
      }
      for (let i = 0; i < widgets.length; i++) {
        widgets[i].fontSize = options.fontSize;
      }
    }
  }

  function toggleTheme(): void {
    if (!tracker.isDisposed) {
      let widgets = tracker.widgets;
      if (options.background === 'black') {
        options.background = 'white';
        options.color = 'black';
      }
      else {
        options.background = 'black';
        options.color = 'white';
      }
      for (let i = 0; i < widgets.length; i++) {
          widgets[i].background = options.background;
          widgets[i].color = options.color;
      }
    }
  }

  function closeAllTerms(): void {
    if (!tracker.isDisposed) {
      let widgets = tracker.widgets;
      for (let i = 0; i < widgets.length; i++) {
        widgets[i].dispose();
      }
    }
  }
}
<commit_msg>Fixed some logic<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  Application
} from 'phosphide/lib/core/application';

import {
  JupyterServices
} from '../services/plugin';

import {
  WidgetTracker
} from '../widgettracker';

import {
  TerminalWidget
} from './index';


/**
 * The default terminal extension.
 */
export
const terminalExtension = {
  id: 'jupyter.extensions.terminal',
  requires: [JupyterServices],
  activate: activateTerminal
};

/**
 * The class name for all main area landscape tab icons.
 */
const LANDSCAPE_ICON_CLASS = 'jp-MainAreaLandscapeIcon';

/**
 * The class name for the terminal icon in the default theme.
 */
const TERMINAL_ICON_CLASS = 'jp-ImageTerminal';


function activateTerminal(app: Application, services: JupyterServices): void {

  let newTerminalId = 'terminal:create-new';
  let increaseTerminalFontSize = 'terminal:increase-font';
  let decreaseTerminalFontSize = 'terminal:decrease-font';
  let toggleTerminalTheme = 'terminal:toggle-theme';
  let closeAllTerminals = 'terminal:close-all-terminals';
  let tracker = new WidgetTracker<TerminalWidget>();
  let options = {
    background: 'black',
    color: 'white',
    fontSize: 14
  };

  app.commands.add([
    {
      id: newTerminalId,
      handler: () => {
        let term = new TerminalWidget(options);
        term.title.closable = true;
        term.title.icon = `${LANDSCAPE_ICON_CLASS} ${TERMINAL_ICON_CLASS}`;
        app.shell.addToMainArea(term);
        tracker.addWidget(term);
        services.terminalManager.createNew().then(session => {
          term.session = session;
        });
      }
    },
    {
      id: increaseTerminalFontSize,
      handler: increaseFont
    },
    {
      id: decreaseTerminalFontSize,
      handler: decreaseFont
    },
    {
      id: toggleTerminalTheme,
      handler: toggleTheme
    },
    {
      id: closeAllTerminals,
      handler: closeAllTerms
    }
  ]);
  app.palette.add([
    {
      command: newTerminalId,
      category: 'Terminal',
      text: 'New Terminal',
      caption: 'Start a new terminal session'
    },
    {
      command: increaseTerminalFontSize,
      category: 'Terminal',
      text: 'Increase Terminal Font Size',
    },
    {
      command: decreaseTerminalFontSize,
      category: 'Terminal',
      text: 'Decrease Terminal Font Size',
    },
    {
      command: toggleTerminalTheme,
      category: 'Terminal',
      text: 'Toggle Terminal Theme',
      caption: 'Switch Terminal Background and Font Colors'
    },
    {
      command: closeAllTerminals,
      category: 'Terminal',
      text: 'Close All Terminals'
    }
  ]);

  function increaseFont(): void {
    if (!tracker.isDisposed && options.fontSize < 72) {
      let widgets = tracker.widgets;
      options.fontSize++;
      for (let i = 0; i < widgets.length; i++) {
        widgets[i].fontSize = options.fontSize;
      }
    }
  }

  function decreaseFont(): void {
    if (!tracker.isDisposed && options.fontSize > 9) {
      let widgets = tracker.widgets;
      options.fontSize--;
      for (let i = 0; i < widgets.length; i++) {
        widgets[i].fontSize = options.fontSize;
      }
    }
  }

  function toggleTheme(): void {
    if (!tracker.isDisposed) {
      let widgets = tracker.widgets;
      if (options.background === 'black') {
        options.background = 'white';
        options.color = 'black';
      }
      else {
        options.background = 'black';
        options.color = 'white';
      }
      for (let i = 0; i < widgets.length; i++) {
          widgets[i].background = options.background;
          widgets[i].color = options.color;
      }
    }
  }

  function closeAllTerms(): void {
    if (!tracker.isDisposed) {
      let widgets = tracker.widgets;
      for (let i = 0; i < widgets.length; i++) {
        widgets[i].dispose();
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.12390725959711137, 'fraction_numerical': 0.002280501710376283, 'mean_word_length': 2.5225345827755468, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1742585', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2402, 'n_words': 564}