<commit_before>import { Injectable, Provider, EventEmitter, Inject } from '@angular/core';
import { ConfigService } from './config.service';
import * as os from 'os';
let pty = require('node-pty');

export interface Process {
  pty: any,
  input: EventEmitter<string>,
  output: EventEmitter<string>,
  resize: EventEmitter<{ col: number, row: number }>,
  exit: EventEmitter<boolean>
}

@Injectable()
export class PTYService {
  shell: string;
  args: string[];
  path: string;
  processes: Process[];

  constructor(@Inject(ConfigService) private _config: ConfigService) {
    this.processes = [];
  }

  create(): Process {
    let ps: Process = {
      pty: pty.spawn(this._config.shell.shell, this._config.shell.args, {
        name: 'xterm-color',
        cols: 80,
        rows: 30,
        cwd: process.cwd() || os.homedir(),
        env: process.env
      }),
      input: new EventEmitter<string>(),
      output: new EventEmitter<string>(),
      resize: new EventEmitter<{ col: number, row: number }>(),
      exit: new EventEmitter<boolean>()
    };

    this.initializeEvents(ps);
    return ps;
  }

  initializeEvents(ps: Process): void {
    ps.pty.on('data', (data: string) => ps.output.emit(data));
    ps.pty.on('exit', (data: string) => {
      if (ps.pty) { ps.pty.kill('SIGHUP'); }
      this.processes = this.processes.filter((proc: Process) => proc !== ps);
      ps.exit.emit(true);
    });<commit_msg>fix(win32): close tab on exit<commit_after>import { Injectable, Provider, EventEmitter, Inject } from '@angular/core';
import { ConfigService } from './config.service';
import * as os from 'os';
let pty = require('node-pty');

export interface Process {
  pty: any,
  input: EventEmitter<string>,
  output: EventEmitter<string>,
  resize: EventEmitter<{ col: number, row: number }>,
  exit: EventEmitter<boolean>
}

@Injectable()
export class PTYService {
  shell: string;
  args: string[];
  path: string;
  processes: Process[];

  constructor(@Inject(ConfigService) private _config: ConfigService) {
    this.processes = [];
  }

  create(): Process {
    let ps: Process = {
      pty: pty.spawn(this._config.shell.shell, this._config.shell.args, {
        name: 'xterm-color',
        cols: 80,
        rows: 30,
        cwd: process.cwd() || os.homedir(),
        env: process.env
      }),
      input: new EventEmitter<string>(),
      output: new EventEmitter<string>(),
      resize: new EventEmitter<{ col: number, row: number }>(),
      exit: new EventEmitter<boolean>()
    };

    this.initializeEvents(ps);
    return ps;
  }

  initializeEvents(ps: Process): void {
    ps.pty.on('data', (data: string) => ps.output.emit(data));
    ps.pty.on('exit', (data: string) => {
      if (ps.pty && os.platform() !== 'win32') { ps.pty.kill('SIGHUP'); }
      this.processes = this.processes.filter((proc: Process) => proc !== ps);
      ps.exit.emit(true);
    });
{'fraction_non_alphanumeric': 0.16511547742157875, 'fraction_numerical': 0.004136504653567736, 'mean_word_length': 3.28023598820059, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '5301740', 'n_tokens_mistral': 952, 'n_tokens_neox': 963, 'n_words': 226}