<commit_before>class WebTermView extends KDView

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

    @appStorage = new AppStorage 'WebTerm', '1.0'
    @appStorage.fetchStorage =>
      @appStorage.setValue 'font', 'ubuntu-mono' if not @appStorage.getValue('font')?
      @appStorage.setValue 'fontSize', 14 if not @appStorage.getValue('fontSize')?
      @appStorage.setValue 'theme', 'green-on-black' if not @appStorage.getValue('theme')?
      @appStorage.setValue 'visualBell', false if not @appStorage.getValue('visualBell')?
      @updateSettings()

    super

  viewAppended: ->
    @container = new KDView
      cssClass : "console ubuntu-mono black-on-white"
      bind     : "scroll"
    @container.on "scroll", =>
      @container.$().scrollLeft 0
    @addSubView @container

    @sessionBox = new KDView
      cssClass: "kddialogview"
      position:
        top: 10
        left: 10
    @sessionBox.hide()
    @addSubView @sessionBox

    label = new KDLabelView
      title: "Select session:"
    @sessionBox.addSubView label

    @sessionList = new KDListView
      itemClass: WebTermSessionItem
    @sessionBox.addSubView @sessionList

    label = new KDLabelView
      title: "Create session with name:"
    @sessionBox.addSubView label

    sessionNameInput = new KDInputView
      label: label
      defaultValue: (new Date).format "yyyy-mm-dd HH:MM:ss"
    @sessionBox.addSubView sessionNameInput

    createSessionButton = new KDButtonView
      title: "Create"
      callback: =>
        @sessionBox.hide()
        @terminal.createSession sessionNameInput.getValue()
        @setKeyView()
    @sessionBox.addSubView createSessionButton

    @terminal = new WebTerm.Terminal @container.$()

    @advancedSettings = new KDButtonViewWithMenu
      style         : 'editor-advanced-settings-menu'
      icon          : yes
      iconOnly      : yes
      iconClass     : "cog"
      type          : "contextmenu"
      delegate      : @
      itemClass     : WebtermSettingsView
      click         : (pubInst, event)-> @contextMenu event
      menu          : @getAdvancedSettingsMenuItems.bind @
    @addSubView @advancedSettings
    @updateSettings()

    @terminal.sessionEndedCallback = (sessions) =>
      @emit "WebTerm.terminated"
      return

      @server.getSessions (sessions) =>
        keys = Object.keys sessions
        keys.sort (a, b) ->
          if sessions[a] < sessions[b]
            -1
          else if sessions[a] > sessions[b]
            1
          else
            0
        @sessionList.empty()
        for key in keys
          @sessionList.addItem
            id: parseInt(key)
            name: sessions[key]
            mainView: this
        @sessionBox.show()
    @terminal.setTitleCallback = (title) =>
      #@tabPane.setTitle title

    @terminal.flushedCallback = =>
      @emit 'WebTerm.flushed'

    @listenWindowResize()

    @focused = true

    @on "ReceivedClickElsewhere", =>
      @focused = false
      @terminal.setFocused false
      @getSingleton('windowController').removeLayer @

    $(window).bind "blur", =>
      @terminal.setFocused false

    $(window).bind "focus", =>
      @terminal.setFocused @focused

    $(document).on "paste", (event) =>
      if @focused
        @terminal.server.input event.originalEvent.clipboardData.getData("text/plain")
        @setKeyView()

    @bindEvent 'contextmenu'

    KD.singletons.kiteController.run
      kiteName : 'os',
      method   : 'webterm.createSession',
      vmName   : @getOption('delegate').getOption('vmName')
      withArgs :
        remote : @terminal.clientInterface
        name   : "none"
        sizeX  : @terminal.sizeX
        sizeY  : @terminal.sizeY
    , (err, remote) =>
      if err
        log err
      else
        @terminal.server = remote
        remote.setSize @terminal.sizeX, @terminal.sizeY # might have changed in the meantime
        @setKeyView()
        @emit "WebTermConnected", remote

  destroy: ->
    super
    @terminal.server?.close()

  updateSettings: ->
    @container.unsetClass font.value for font in __webtermSettings.fonts
    @container.unsetClass theme.value for theme in __webtermSettings.themes
    @container.setClass @appStorage.getValue('font')
    @container.setClass @appStorage.getValue('theme')
    @container.$().css
      fontSize: @appStorage.getValue('fontSize') + 'px'
    @terminal.updateSize true
    @terminal.scrollToBottom(no)<commit_msg>fix for webterm error. We don't create any error popup not to be annoying. User can handle the error.<commit_after>class WebTermView extends KDView

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

    @appStorage = new AppStorage 'WebTerm', '1.0'
    @appStorage.fetchStorage =>
      @appStorage.setValue 'font', 'ubuntu-mono' if not @appStorage.getValue('font')?
      @appStorage.setValue 'fontSize', 14 if not @appStorage.getValue('fontSize')?
      @appStorage.setValue 'theme', 'green-on-black' if not @appStorage.getValue('theme')?
      @appStorage.setValue 'visualBell', false if not @appStorage.getValue('visualBell')?
      @updateSettings()

    super

  viewAppended: ->
    @container = new KDView
      cssClass : "console ubuntu-mono black-on-white"
      bind     : "scroll"
    @container.on "scroll", =>
      @container.$().scrollLeft 0
    @addSubView @container

    @sessionBox = new KDView
      cssClass: "kddialogview"
      position:
        top: 10
        left: 10
    @sessionBox.hide()
    @addSubView @sessionBox

    label = new KDLabelView
      title: "Select session:"
    @sessionBox.addSubView label

    @sessionList = new KDListView
      itemClass: WebTermSessionItem
    @sessionBox.addSubView @sessionList

    label = new KDLabelView
      title: "Create session with name:"
    @sessionBox.addSubView label

    sessionNameInput = new KDInputView
      label: label
      defaultValue: (new Date).format "yyyy-mm-dd HH:MM:ss"
    @sessionBox.addSubView sessionNameInput

    createSessionButton = new KDButtonView
      title: "Create"
      callback: =>
        @sessionBox.hide()
        @terminal.createSession sessionNameInput.getValue()
        @setKeyView()
    @sessionBox.addSubView createSessionButton

    @terminal = new WebTerm.Terminal @container.$()

    @advancedSettings = new KDButtonViewWithMenu
      style         : 'editor-advanced-settings-menu'
      icon          : yes
      iconOnly      : yes
      iconClass     : "cog"
      type          : "contextmenu"
      delegate      : @
      itemClass     : WebtermSettingsView
      click         : (pubInst, event)-> @contextMenu event
      menu          : @getAdvancedSettingsMenuItems.bind @
    @addSubView @advancedSettings
    @updateSettings()

    @terminal.sessionEndedCallback = (sessions) =>
      @emit "WebTerm.terminated"
      return

      @server.getSessions (sessions) =>
        keys = Object.keys sessions
        keys.sort (a, b) ->
          if sessions[a] < sessions[b]
            -1
          else if sessions[a] > sessions[b]
            1
          else
            0
        @sessionList.empty()
        for key in keys
          @sessionList.addItem
            id: parseInt(key)
            name: sessions[key]
            mainView: this
        @sessionBox.show()
    @terminal.setTitleCallback = (title) =>
      #@tabPane.setTitle title

    @terminal.flushedCallback = =>
      @emit 'WebTerm.flushed'

    @listenWindowResize()

    @focused = true

    @on "ReceivedClickElsewhere", =>
      @focused = false
      @terminal.setFocused false
      @getSingleton('windowController').removeLayer @

    $(window).bind "blur", =>
      @terminal.setFocused false

    $(window).bind "focus", =>
      @terminal.setFocused @focused

    $(document).on "paste", (event) =>
      if @focused
        @terminal.server.input event.originalEvent.clipboardData.getData("text/plain")
        @setKeyView()

    @bindEvent 'contextmenu'

    KD.singletons.kiteController.run
      kiteName : 'os',
      method   : 'webterm.createSession',
      vmName   : @getOption('delegate').getOption('vmName')
      withArgs :
        remote : @terminal.clientInterface
        name   : "none"
        sizeX  : @terminal.sizeX
        sizeY  : @terminal.sizeY
    , (err, remote) =>
      if err
        # We don't create any error popup not to be annoying. User can handle the error.
        error err
      else
        @terminal.server = remote
        remote.setSize @terminal.sizeX, @terminal.sizeY # might have changed in the meantime
        @setKeyView()
        @emit "WebTermConnected", remote

  destroy: ->
    super
    @terminal.server?.close()

  updateSettings: ->
    @container.unsetClass font.value for font in __webtermSettings.fonts
    @container.unsetClass theme.value for theme in __webtermSettings.themes
    @container.setClass @appStorage.getValue('font')
    @container.setClass @appStorage.getValue('theme')
    @container.$().css
      fontSize: @appStorage.getValue('fontSize') + 'px'
    @terminal.updateSize true
    @terminal.scrollToBottom(no)
{'fraction_non_alphanumeric': 0.10858725761772853, 'fraction_numerical': 0.002659279778393352, 'mean_word_length': 2.4903325599381283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '5010231', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2570, 'n_words': 600}