<commit_before>{$, View} = require 'atom-space-pen-views'
file_sys  = require 'fs'
mkdirp    = require 'mkdirp'

module.exports =
class TerminalView extends View
  @content: ->
    @div class: 'learn-synced-fs-status inline-block icon-terminal'

  constructor: (state, fs) ->
    super

    @fs = fs
    @ws = fs.ws

    # Default text
    @text(" Learn")
    @element.style.color = '#d92626'

    @handleEvents()

  deleteDirectoryRecursive: (path) ->
    self = this
    files = []
    sep = /^win/.test(process.platform) ? '\\' : '/'

    if file_sys.existsSync(path)
      files = file_sys.readdirSync(path)
      files.forEach (file, index) ->
        curPath = path + sep + file
        if file_sys.lstatSync(curPath).isDirectory()
          self.deleteDirectoryRecursive(curPath)
        else
          file_sys.unlinkSync(curPath)

      file_sys.rmdirSync(path)

  handleEvents: ->
    sep = /^win/.test(process.platform) ? '\\' : '/'

    @ws.onopen = (e) =>
      @element.style.color = '#73c990'
    @ws.onmessage = (e) =>
      try
        console.log(e.data)
        event = JSON.parse(e.data)
        switch event.event
          when 'remote_create'
            console.log('Created: ' + event.location + sep + event.file)
            if event.directory
              mkdirp.sync(atom.getUserWorkingDirPath() + sep + event.location + sep + event.file)
            else
              mkdirp.sync(atom.getUserWorkingDirPath() + sep + event.location)
              file_sys.openSync(atom.getUserWorkingDirPath() + sep + event.location + sep + event.file, 'a')

              @ws.send JSON.stringify({
                action: 'request_content',
                location: event.location,
                file: event.file
              })
          when 'content_response'
            content = new Buffer(event.content, 'base64').toString()
            file_sys.writeFileSync atom.getUserWorkingDirPath() + sep + event.location + sep + event.file, content
          when 'remote_delete'
            if event.directory
              this.deleteDirectoryRecursive atom.getUserWorkingDirPath() + sep + event.location + sep + event.file
            else
              delPath = atom.getUserWorkingDirPath() + sep + event.location + sep + event.file
              if file_sys.existsSync(delPath)
                file_sys.unlinkSync(delPath)
          when 'remote_move_from'
            console.log('move_from')
          when 'remote_move_to'
            console.log('move_to')
          when 'remote_modify'
            if !event.directory
              mkdirp.sync(atom.getUserWorkingDirPath() + sep + event.location)
              file_sys.openSync(atom.getUserWorkingDirPath() + sep + event.location + sep + event.file, 'a')

              @ws.send JSON.stringify({
                action: 'request_content',
                location: event.location,
                file: event.file
              })
          when 'remote_open'
            console.log('Opened: ' + event.location + sep + event.file)

            if event.location == ''
              atom.workspace.open(event.file)
            else
              atom.workspace.open(event.location + sep + event.file)

      catch err
        console.log(err)
      console.log("SyncedFS debug: " + e)
    @ws.onclose = =>
      @element.style.color = '#d92626'
<commit_msg>Roll that back a bit<commit_after>{$, View} = require 'atom-space-pen-views'
file_sys  = require 'fs'
mkdirp    = require 'mkdirp'

module.exports =
class TerminalView extends View
  @content: ->
    @div class: 'learn-synced-fs-status inline-block icon-terminal'

  constructor: (state, fs) ->
    super

    @fs = fs
    @ws = fs.ws

    # Default text
    @text(" Learn")
    @element.style.color = '#d92626'

    @handleEvents()

  deleteDirectoryRecursive: (path) ->
    self = this
    files = []
    sep = /^win/.test(process.platform) ? '\\' : '/'

    if file_sys.existsSync(path)
      files = file_sys.readdirSync(path)
      files.forEach (file, index) ->
        curPath = path + sep + file
        if file_sys.lstatSync(curPath).isDirectory()
          self.deleteDirectoryRecursive(curPath)
        else
          file_sys.unlinkSync(curPath)

      file_sys.rmdirSync(path)

  handleEvents: ->
    @ws.onopen = (e) =>
      @element.style.color = '#73c990'
    @ws.onmessage = (e) =>
      try
        console.log(e.data)
        event = JSON.parse(e.data)
        switch event.event
          when 'remote_create'
            console.log('Created: ' + event.location + '/' + event.file)
            if event.directory
              mkdirp.sync(atom.getUserWorkingDirPath() + '/' + event.location + '/' + event.file)
            else
              mkdirp.sync(atom.getUserWorkingDirPath() + '/' + event.location)
              file_sys.openSync(atom.getUserWorkingDirPath() + '/' + event.location + '/' + event.file, 'a')

              @ws.send JSON.stringify({
                action: 'request_content',
                location: event.location,
                file: event.file
              })
          when 'content_response'
            content = new Buffer(event.content, 'base64').toString()
            file_sys.writeFileSync atom.getUserWorkingDirPath() + '/' + event.location + '/' + event.file, content
          when 'remote_delete'
            if event.directory
              this.deleteDirectoryRecursive atom.getUserWorkingDirPath() + '/' + event.location + '/' + event.file
            else
              delPath = atom.getUserWorkingDirPath() + '/' + event.location + '/' + event.file
              if file_sys.existsSync(delPath)
                file_sys.unlinkSync(delPath)
          when 'remote_move_from'
            console.log('move_from')
          when 'remote_move_to'
            console.log('move_to')
          when 'remote_modify'
            if !event.directory
              mkdirp.sync(atom.getUserWorkingDirPath() + '/' + event.location)
              file_sys.openSync(atom.getUserWorkingDirPath() + '/' + event.location + '/' + event.file, 'a')

              @ws.send JSON.stringify({
                action: 'request_content',
                location: event.location,
                file: event.file
              })
          when 'remote_open'
            console.log('Opened: ' + event.location + '/' + event.file)

            if event.location == ''
              atom.workspace.open(event.file)
            else
              atom.workspace.open(event.location + '/' + event.file)

      catch err
        console.log(err)
      console.log("SyncedFS debug: " + e)
    @ws.onclose = =>
      @element.style.color = '#d92626'

{'fraction_non_alphanumeric': 0.1252074219339267, 'fraction_numerical': 0.005128978729823503, 'mean_word_length': 1.9194187582562747, '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': '5255819', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1936, 'n_words': 361}