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

import {
  Kernel, KernelMessage, Session, nbformat
} from '@jupyterlab/services';

import {
  map, toArray
} from 'phosphor/lib/algorithm/iteration';

import {
  Message
} from 'phosphor/lib/core/messaging';

import {
  clearSignalData, defineSignal, ISignal
} from 'phosphor/lib/core/signaling';

import {
  Panel, PanelLayout
} from 'phosphor/lib/ui/panel';

import {
  Widget
} from 'phosphor/lib/ui/widget';

import {
  IEditorMimeTypeService, CodeEditor
} from '../codeeditor';

import {
  BaseCellWidget, CodeCellWidget, RawCellWidget,
  CodeCellModel, RawCellModel
} from '../notebook/cells';

import {
  IRenderMime
} from '../rendermime';

import {
  ForeignHandler
} from './foreign';

import {
  ConsoleHistory, IConsoleHistory
} from './history';

import {
  IObservableVector, ObservableVector
} from '../common/observablevector';

/**
 * The class name added to console widgets.
 */
const CONSOLE_CLASS = 'jp-Console';

/**
 * The class name added to the console banner.
 */
const BANNER_CLASS = 'jp-Console-banner';

/**
 * The class name of a cell whose input originated from a foreign session.
 */
const FOREIGN_CELL_CLASS = 'jp-Console-foreignCell';

/**
 * The class name of the active prompt
 */
const PROMPT_CLASS = 'jp-Console-prompt';

/**
 * The class name of the panel that holds cell content.
 */
const CONTENT_CLASS = 'jp-Console-content';

/**
 * The class name of the panel that holds prompts.
 */
const INPUT_CLASS = 'jp-Console-input';

/**
 * The timeout in ms for execution requests to the kernel.
 */
const EXECUTION_TIMEOUT = 250;


/**
 * A widget containing a Jupyter console.
 *
 * #### Notes
 * The Console class is intended to be used within a ConsolePanel
 * instance. Under most circumstances, it is not instantiated by user code.
 */
export
class Console extends Widget {
  /**
   * Construct a console widget.
   */
  constructor(options: Console.IOptions) {
    super();
    this.addClass(CONSOLE_CLASS);

    // Create the panels that hold the content and input.
    let layout = this.layout = new PanelLayout();
    this._cells = new ObservableVector<BaseCellWidget>();
    this._content = new Panel();
    this._input = new Panel();
    let factory = this.contentFactory = options.contentFactory;
    this.rendermime = options.rendermime;
    this.session = options.session;
    this._mimeTypeService = options.mimeTypeService;

    // Add top-level CSS classes.
    this._content.addClass(CONTENT_CLASS);
    this._input.addClass(INPUT_CLASS);

    // Insert the content and input panes into the widget.
    layout.addWidget(this._content);
    layout.addWidget(this._input);

    // Create the banner.
    let model = new RawCellModel();
    model.value.text = '...';
    let banner = factory.createBanner({
      model,
      contentFactory: factory.rawContentFactory
    }, this);
    banner.addClass(BANNER_CLASS);
    banner.readOnly = true;
    this._content.addWidget(banner);

    // Set the banner text and the mimetype.
    this._initialize();

    // Set up the foreign iopub handler.
    this._foreignHandler = factory.createForeignHandler({
      kernel: this.session.kernel,
      parent: this,
      cellFactory: () => this._createForeignCell(),
    });

    this._history = factory.createConsoleHistory({
      kernel: this.session.kernel
    });

    this.session.kernelChanged.connect(this._onKernelChanged, this);
  }

  /**
   * A signal emitted when the console finished executing its prompt.
   */
  readonly executed: ISignal<this, Date>;

  /**
   * A signal emitted when a new prompt is created.
   */
  readonly promptCreated: ISignal<this, CodeCellWidget>;

  /**
   * The content factory used by the console.
   */
  readonly contentFactory: Console.IContentFactory;

  /**
   * The rendermime instance used by the console.
   */
  readonly rendermime: IRenderMime;

  /**
   * The session used by the console.
   */
  readonly session: Session.ISession;

  /**
   * The list of content cells in the console.
   *
   * #### Notes
   * This list does not include the banner or the prompt for a console.
   */
  get cells(): IObservableVector<BaseCellWidget> {
    return this._cells;<commit_msg>Expose the banner widget of the console<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  Kernel, KernelMessage, Session, nbformat
} from '@jupyterlab/services';

import {
  map, toArray
} from 'phosphor/lib/algorithm/iteration';

import {
  Message
} from 'phosphor/lib/core/messaging';

import {
  clearSignalData, defineSignal, ISignal
} from 'phosphor/lib/core/signaling';

import {
  Panel, PanelLayout
} from 'phosphor/lib/ui/panel';

import {
  Widget
} from 'phosphor/lib/ui/widget';

import {
  IEditorMimeTypeService, CodeEditor
} from '../codeeditor';

import {
  BaseCellWidget, CodeCellWidget, RawCellWidget,
  CodeCellModel, RawCellModel
} from '../notebook/cells';

import {
  IRenderMime
} from '../rendermime';

import {
  ForeignHandler
} from './foreign';

import {
  ConsoleHistory, IConsoleHistory
} from './history';

import {
  IObservableVector, ObservableVector
} from '../common/observablevector';

/**
 * The class name added to console widgets.
 */
const CONSOLE_CLASS = 'jp-Console';

/**
 * The class name added to the console banner.
 */
const BANNER_CLASS = 'jp-Console-banner';

/**
 * The class name of a cell whose input originated from a foreign session.
 */
const FOREIGN_CELL_CLASS = 'jp-Console-foreignCell';

/**
 * The class name of the active prompt
 */
const PROMPT_CLASS = 'jp-Console-prompt';

/**
 * The class name of the panel that holds cell content.
 */
const CONTENT_CLASS = 'jp-Console-content';

/**
 * The class name of the panel that holds prompts.
 */
const INPUT_CLASS = 'jp-Console-input';

/**
 * The timeout in ms for execution requests to the kernel.
 */
const EXECUTION_TIMEOUT = 250;


/**
 * A widget containing a Jupyter console.
 *
 * #### Notes
 * The Console class is intended to be used within a ConsolePanel
 * instance. Under most circumstances, it is not instantiated by user code.
 */
export
class Console extends Widget {
  /**
   * Construct a console widget.
   */
  constructor(options: Console.IOptions) {
    super();
    this.addClass(CONSOLE_CLASS);

    // Create the panels that hold the content and input.
    let layout = this.layout = new PanelLayout();
    this._cells = new ObservableVector<BaseCellWidget>();
    this._content = new Panel();
    this._input = new Panel();
    let factory = this.contentFactory = options.contentFactory;
    this.rendermime = options.rendermime;
    this.session = options.session;
    this._mimeTypeService = options.mimeTypeService;

    // Add top-level CSS classes.
    this._content.addClass(CONTENT_CLASS);
    this._input.addClass(INPUT_CLASS);

    // Insert the content and input panes into the widget.
    layout.addWidget(this._content);
    layout.addWidget(this._input);

    // Create the banner.
    let model = new RawCellModel();
    model.value.text = '...';
    let banner = this.banner = factory.createBanner({
      model,
      contentFactory: factory.rawContentFactory
    }, this);
    banner.addClass(BANNER_CLASS);
    banner.readOnly = true;
    this._content.addWidget(banner);

    // Set the banner text and the mimetype.
    this._initialize();

    // Set up the foreign iopub handler.
    this._foreignHandler = factory.createForeignHandler({
      kernel: this.session.kernel,
      parent: this,
      cellFactory: () => this._createForeignCell(),
    });

    this._history = factory.createConsoleHistory({
      kernel: this.session.kernel
    });

    this.session.kernelChanged.connect(this._onKernelChanged, this);
  }

  /**
   * A signal emitted when the console finished executing its prompt.
   */
  readonly executed: ISignal<this, Date>;

  /**
   * A signal emitted when a new prompt is created.
   */
  readonly promptCreated: ISignal<this, CodeCellWidget>;

  /**
   * The content factory used by the console.
   */
  readonly contentFactory: Console.IContentFactory;

  /**
   * The rendermime instance used by the console.
   */
  readonly rendermime: IRenderMime;

  /**
   * The session used by the console.
   */
  readonly session: Session.ISession;

  /**
   * The console banner widget.
   */
  readonly banner: RawCellWidget;

  /**
   * The list of content cells in the console.
   *
   * #### Notes
   * This list does not include the banner or the prompt for a console.
   */
  get cells(): IObservableVector<BaseCellWidget> {
    return this._cells;
{'fraction_non_alphanumeric': 0.11182622687047465, 'fraction_numerical': 0.0006895759108148489, 'mean_word_length': 3.2698724239450443, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3703988', 'n_tokens_mistral': 2652, 'n_tokens_neox': 2536, 'n_words': 781}