<commit_before>import keypress from 'keypress';
import Cursor from 'kittik-cursor';
import Print from 'kittik-animation-print';
import Slide from './Slide';

/**
 * Implements Presentation class.
 * Responsible for switching slide and running the presentation.
 *
 * @since 1.0.0
 * @version 1.0.0
 */
export default class Deck {
  /**
   * Creates presentation instance with slides.
   *
   * @param {Array<Array<Object>>} slides
   */
  constructor(slides) {
    this._cursor = Cursor.create().resetTTY().hideCursor();
    this._currentSlideIndex = 0;
    this._slides = slides.map(slide => Slide.create(slide));

    keypress(process.stdin);
    process.stdin.setRawMode(true);
    process.stdin.setEncoding('utf8');

    process.stdin.on('keypress', this._onKeyPress.bind(this));
  }

  /**
   * Run the presentation.
   *
   * @returns {Presentation}
   */
  run() {
    this.renderSlide();
    return this;
  }

  /**
   * Renders specified slide.
   *
   * @param {Number} [index] Slide index in presentation
   * @returns {Presentation}
   */
  renderSlide(index = this._currentSlideIndex) {
    if (!this._slides[index]) return this;

    this._cursor.resetTTY().hideCursor();
    this._slides[index].render(this._cursor);

    return this;
  }

  /**
   * Renders the next slide.
   *
   * @returns {Presentation}
   */
  nextSlide() {
    if (this._currentSlideIndex + 1 > this._slides.length - 1) return this;

    this.renderSlide(++this._currentSlideIndex);
    return this;
  }

  /**
   * Renders the previous slide.
   *
   * @returns {Presentation}
   */
  prevSlide() {
    if (this._currentSlideIndex - 1 < 0) return this;

    this.renderSlide(--this._currentSlideIndex);
    return this;
  }

  /**
   * Closes the presentation and returns to terminal.
   */
  exit() {
    this._cursor.resetTTY().showCursor();
    setTimeout(process.exit, 500);
  }

  /**
   * Triggers when user is pressing the key.
   *
   * @param {String} ch
   * @param {Object} key
   * @private
   */
  _onKeyPress(ch, key) {
    if (key.name == 'left') this.prevSlide();
    if (key.name == 'right') this.nextSlide();
    if (key.ctrl && key.name == 'c') this.exit();

    return this;
  }

  /**
   * Wrapper around `new Presentation()`.
   *
   * @param {*} args
   * @returns {Presentation}
   */
  static create(...args) {
    return new this(...args);
  }
}
<commit_msg>refactor(deck): Change Deck API for accepting declaration not the slides<commit_after>import keypress from 'keypress';
import Cursor from 'kittik-cursor';
import Print from 'kittik-animation-print';
import Slide from './Slide';

/**
 * Implements Presentation class.
 * Responsible for switching slide and running the presentation.
 *
 * @since 1.0.0
 * @version 1.0.0
 */
export default class Deck {
  /**
   * Creates presentation instance with slides.
   *
   * @param {Array<Array<Object>>} declaration
   */
  constructor(declaration) {
    this._cursor = Cursor.create().resetTTY().hideCursor();
    this._currentSlideIndex = 0;
    this._slides = declaration.slides.map(slide => Slide.create(slide));

    keypress(process.stdin);
    process.stdin.setRawMode(true);
    process.stdin.setEncoding('utf8');

    process.stdin.on('keypress', this._onKeyPress.bind(this));
  }

  /**
   * Run the presentation.
   *
   * @returns {Presentation}
   */
  run() {
    this.renderSlide();
    return this;
  }

  /**
   * Renders specified slide.
   *
   * @param {Number} [index] Slide index in presentation
   * @returns {Presentation}
   */
  renderSlide(index = this._currentSlideIndex) {
    if (!this._slides[index]) return this;

    this._cursor.resetTTY().hideCursor();
    this._slides[index].render(this._cursor);

    return this;
  }

  /**
   * Renders the next slide.
   *
   * @returns {Presentation}
   */
  nextSlide() {
    if (this._currentSlideIndex + 1 > this._slides.length - 1) return this;

    this.renderSlide(++this._currentSlideIndex);
    return this;
  }

  /**
   * Renders the previous slide.
   *
   * @returns {Presentation}
   */
  prevSlide() {
    if (this._currentSlideIndex - 1 < 0) return this;

    this.renderSlide(--this._currentSlideIndex);
    return this;
  }

  /**
   * Closes the presentation and returns to terminal.
   */
  exit() {
    this._cursor.resetTTY().showCursor();
    setTimeout(process.exit, 500);
  }

  /**
   * Triggers when user is pressing the key.
   *
   * @param {String} ch
   * @param {Object} key
   * @private
   */
  _onKeyPress(ch, key) {
    if (key.name == 'left') this.prevSlide();
    if (key.name == 'right') this.nextSlide();
    if (key.ctrl && key.name == 'c') this.exit();

    return this;
  }

  /**
   * Wrapper around `new Presentation()`.
   *
   * @param {*} args
   * @returns {Presentation}
   */
  static create(...args) {
    return new this(...args);
  }
}

{'fraction_non_alphanumeric': 0.15158417891903087, 'fraction_numerical': 0.006212466349140609, 'mean_word_length': 2.836378077839555, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1912118', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1607, 'n_words': 359}