<commit_before>﻿/*global $, emojify: true, escapeHTML:true, nw, autosize, twemoji */
var fs = nw.require('fs');
var async = nw.require('async');
/* var; TODO: use it */ escapeHTML = nw.require('lodash.escape');
var iconv = nw.require('iconv-lite');

/* var; TODO: use it */ emojify = () => {
   if( twemoji ) twemoji.parse( $('body')[0] );
};

var errorCLI = errHTML => $('.purposeMain').html([
   '<div class="alert alert-danger" role="alert">',
   errHTML, '</div>'
].join(''));

var convertFileToText = (filePath, fileDone) => async.waterfall([
   callback => fs.readFile(filePath, callback),
   (fileBuf, callback) => callback(null,
      iconv.decode(fileBuf, 'cp866')
   )
], fileDone);

$(() => {
   var paramsCLI = nw.App.argv;

   var msgFilePath = paramsCLI.find( param => param.startsWith('--file=') );
   if( typeof msgFilePath === 'undefined') return errorCLI(
      'Filename has not been given.'
   );
   msgFilePath = msgFilePath.slice( '--file='.length );

   var lineNum = paramsCLI.find( param => param.startsWith('--line=') );
   if( typeof lineNum === 'undefined') return errorCLI(
      'Line number has not been given.'
   );
   lineNum = lineNum.slice( '--line='.length );

   convertFileToText(msgFilePath, (err, fileText) => {
      if( err ) return errorCLI(`Error reading «${msgFilePath}».`);

      nw.Window.get().maximize();

      $('.purposeMain').html(`<textarea>${fileText}</textarea>`);
      autosize($('.purposeMain textarea'));
      $('textarea').focus();<commit_msg>actually write edited messages<commit_after>﻿/*global $, emojify: true, escapeHTML:true, nw, autosize, twemoji */
var fs = nw.require('fs');
var os = nw.require('os');
var async = nw.require('async');
/* var; TODO: use it */ escapeHTML = nw.require('lodash.escape');
var iconv = nw.require('iconv-lite');

/* var; TODO: use it */ emojify = () => {
   if( twemoji ) twemoji.parse( $('body')[0] );
};

var errorCLI = errHTML => $('.purposeMain').html([
   '<div class="alert alert-danger" role="alert">',
   errHTML, '</div>'
].join(''));

var convertFileToText = (filePath, fileDone) => async.waterfall([
   callback => fs.readFile(filePath, callback),
   (fileBuf, callback) => callback(null,
      iconv.decode(fileBuf, 'cp866')
   )
], fileDone);

var convertTextareaToFile = ($textarea, filePath, fileDone) => fs.writeFile(
   filePath,
   iconv.encode( $textarea.val().replace(/\n/g, os.EOL), 'cp866' ),
   fileDone
);

$(() => {
   var paramsCLI = nw.App.argv;

   var msgFilePath = paramsCLI.find( param => param.startsWith('--file=') );
   if( typeof msgFilePath === 'undefined') return errorCLI(
      'Filename has not been given.'
   );
   msgFilePath = msgFilePath.slice( '--file='.length );

   var lineNum = paramsCLI.find( param => param.startsWith('--line=') );
   if( typeof lineNum === 'undefined') return errorCLI(
      'Line number has not been given.'
   );
   lineNum = lineNum.slice( '--line='.length );

   convertFileToText(msgFilePath, (err, fileText) => {
      if( err ) return errorCLI(`Error reading «${msgFilePath}».`);

      nw.Window.get().maximize();

      $('.purposeMain').html(`<textarea>${fileText}</textarea>`);
      autosize($('.purposeMain textarea'));
      $('.purposeMain textarea').focus();

      nw.Window.get().on('close', function(){
         var thisWin = this;
         thisWin.hide(); // imitate closing, prevent futher `close` events
         convertTextareaToFile(
            $('.purposeMain textarea'),
            msgFilePath,
            ( /* err */ ) => thisWin.close(true) // ignore `err`, force close
         );
      });
{'fraction_non_alphanumeric': 0.19677150013915948, 'fraction_numerical': 0.0030615084887280824, 'mean_word_length': 3.5037593984962405, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '1936792', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1186, 'n_words': 268}