<commit_before>class TerminalModal extends KDModalView

  constructor: (options={}, data)->

    options.cssClass  = KD.utils.curry "terminal", options.cssClass

    if options.machine?.getName? and not options.title
      options.title = "Terminal on #{options.machine.getName()}"

    super options, data

    {machine, command} = @getOptions()

    @webterm           = new WebTermView
      delegate         : this
      cssClass         : "webterm"
      machine          : machine
      advancedSettings : no

    @webterm.on "WebTermEvent", (data)=>
      @emit "terminal.event", data

    @webterm.once "WebTermConnected", (remote)=>

      @emit "terminal.connected", remote

      @on "terminal.input", (command)=>
        remote.input command
        @webterm.getDomElement().click()

      @run command  if command?

    @webterm.on "WebTerm.terminated", =>
      @emit "terminal.terminated"

    @on "click", => @setCss 'zIndex', 10000 + KD.utils.uniqueId()

  viewAppended: ->

    @addSubView @webterm
    @webterm.connectToTerminal()
    @setCss 'zIndex', 10000 + KD.utils.uniqueId()

  run: (command)->
<commit_msg>TerminalModal: simplfy the usage of WebTermView, destroy the modal when terminal session ends<commit_after>class TerminalModal extends KDModalView

  constructor: (options={}, data)->

    options.cssClass  = KD.utils.curry "terminal", options.cssClass

    if options.machine?.getName? and not options.title
      options.title = "Terminal on #{options.machine.getName()}"

    super options, data

    {machine, command, readOnly} = @getOptions()

    @webterm = new WebTermView {
      delegate: this, machine, readOnly
    }

    @webterm.on "WebTermEvent", (data)=>
      @emit "terminal.event", data

    @webterm.once "WebTermConnected", (remote)=>

      @emit "terminal.connected", remote

      @on "terminal.input", (command)=>
        remote.input command
        @webterm.getDomElement().click()

      @run command  if command?

    @webterm.on "WebTerm.terminated", =>
      @emit "terminal.terminated"
      @destroy()

    @on "click", => @setCss 'zIndex', 10000 + KD.utils.uniqueId()

  viewAppended: ->

    @addSubView @webterm
    @webterm.connectToTerminal()
    @setCss 'zIndex', 10000 + KD.utils.uniqueId()

  run: (command)->

{'fraction_non_alphanumeric': 0.13272010512483573, 'fraction_numerical': 0.008760402978537012, 'mean_word_length': 2.9790940766550524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7041408', 'n_tokens_mistral': 749, 'n_tokens_neox': 676, 'n_words': 168}