<commit_before>grammarMap = require './grammars'
{View, BufferedProcess} = require 'atom'

# Runs a portion of a script through an interpreter and displays it line by line
module.exports =
class ScriptView extends View
  @bufferedProcess: null

  @content: ->
    # Display layout and outlets
    @div class: 'tool-panel panel panel-bottom padding script', outlet: 'script', tabindex: -1, =>
      @div class: 'panel-heading padded heading', outlet: 'heading'
      @div class: 'panel-body padded output', outlet: 'output'

  initialize: (serializeState) ->
    # Bind commands
    atom.workspaceView.command "script:run", => @show()
    atom.workspaceView.command "script:close-view", => @close()
    atom.workspaceView.command "script:kill-process", => @stop()

  serialize: ->

  destroy: ->
    # Stop the running process (if necessary) and dismiss window
    @stop()
    @detach()

  show: ->
    # Display window and load message

    # First run, create view
    if not @hasParent()
      atom.workspaceView.prependToBottom(this)

    @heading.text("Loading...")
    # Close any existing process and start a new one
    @stop()
    @output.empty()

    @start()

  close: ->
    # Dismiss window and stop any running process
    if @hasParent()
      @destroy()

  start: ->
    # Get current editor
    editor = atom.workspace.getActiveEditor()
    if editor? then @setup(editor) else @destroy()

  getlang: (editor) ->
    grammar = editor.getGrammar()
    lang = grammar.name
    return lang

  setup: (editor) ->
    # Get language
    lang = @getlang(editor)<commit_msg>check before drawing view. refactored start, show, and close<commit_after>grammarMap = require './grammars'
{View, BufferedProcess} = require 'atom'

# Runs a portion of a script through an interpreter and displays it line by line
module.exports =
class ScriptView extends View
  @bufferedProcess: null

  @content: ->
    # Display layout and outlets
    @div class: 'tool-panel panel panel-bottom padding script', outlet: 'script', tabindex: -1, =>
      @div class: 'panel-heading padded heading', outlet: 'heading'
      @div class: 'panel-body padded output', outlet: 'output'

  initialize: (serializeState) ->
    # Bind commands
    atom.workspaceView.command "script:run", => @start()
    atom.workspaceView.command "script:close-view", => @close()
    atom.workspaceView.command "script:kill-process", => @stop()

  serialize: ->

  start: ->
    # Get current editor
    editor = atom.workspace.getActiveEditor()
    if editor? then @show(editor) else @close()

  show: (editor) ->
    # Display window and load message

    # First run, create view
    if not @hasParent()
      atom.workspaceView.prependToBottom(this)

    @heading.text("Loading...")
    # Close any existing process and start a new one
    @stop()
    # Get script view ready
    @output.empty()
    @setup(editor)

  close: ->
    # Stop any running process and dismiss window
    @stop()
    if @hasParent() then @detach()

  getlang: (editor) ->
    grammar = editor.getGrammar()
    lang = grammar.name
    return lang

  setup: (editor) ->
    # Get language
    lang = @getlang(editor)
{'fraction_non_alphanumeric': 0.12202852614896989, 'fraction_numerical': 0.0006339144215530904, 'mean_word_length': 3.2248995983935744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '2188791', 'n_tokens_mistral': 960, 'n_tokens_neox': 919, 'n_words': 300}