From 50bac9585723f461856b320056c141a2b870b8ea Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 11 Sep 2017 21:01:35 -0600 Subject: [PATCH] * Fix ANSI description display during upload * Major improvements to upload: Allow user to properly edit descriptions even if provided by .diz/system/etc. --- core/multi_line_edit_text_view.js | 28 +++++++++++++----- core/string_util.js | 4 +++ mods/upload.js | 48 ++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/core/multi_line_edit_text_view.js b/core/multi_line_edit_text_view.js index 9d46e8a1..55e84080 100644 --- a/core/multi_line_edit_text_view.js +++ b/core/multi_line_edit_text_view.js @@ -1068,9 +1068,9 @@ MultiLineEditTextView.prototype.setFocus = function(focused) { MultiLineEditTextView.super_.prototype.setFocus.call(this, focused); }; -MultiLineEditTextView.prototype.setText = function(text) { +MultiLineEditTextView.prototype.setText = function(text, options = { scrollMode : 'default' } ) { this.textLines = [ ]; - this.addText(text); + this.addText(text, options); /*this.insertRawText(text); if(this.isEditMode()) { @@ -1085,13 +1085,27 @@ MultiLineEditTextView.prototype.setAnsi = function(ansi, options = { prepped : f return this.setAnsiWithOptions(ansi, options, cb); }; -MultiLineEditTextView.prototype.addText = function(text) { +MultiLineEditTextView.prototype.addText = function(text, options = { scrollMode : 'default' }) { this.insertRawText(text); - if(this.isEditMode() || this.autoScroll) { - this.cursorEndOfDocument(); - } else { - this.cursorStartOfDocument(); + switch(options.scrollMode) { + case 'default' : + if(this.isEditMode() || this.autoScroll) { + this.cursorEndOfDocument(); + } else { + this.cursorStartOfDocument(); + } + break; + + case 'top' : + case 'start' : + this.cursorStartOfDocument(); + break; + + case 'end' : + case 'bottom' : + this.cursorEndOfDocument(); + break; } }; diff --git a/core/string_util.js b/core/string_util.js index 08987058..238aeeee 100644 --- a/core/string_util.js +++ b/core/string_util.js @@ -623,6 +623,10 @@ function isFormattedLine(line) { } function isAnsi(input) { + if(!input || 0 === input.length) { + return false; + } + // // * ANSI found - limited, just colors // * Full ANSI art diff --git a/mods/upload.js b/mods/upload.js index 5c5fd5b2..30c84c48 100644 --- a/mods/upload.js +++ b/mods/upload.js @@ -15,6 +15,7 @@ const pathWithTerminatingSeparator = require('../core/file_util.js').pathWithTe const Log = require('../core/logger.js').log; const Errors = require('../core/enig_error.js').Errors; const FileEntry = require('../core/file_entry.js'); +const isAnsi = require('../core/string_util.js').isAnsi; // deps const async = require('async'); @@ -421,9 +422,8 @@ exports.getModule = class UploadModule extends MenuModule { return nextEntry(err); } - // if the file entry did *not* have a desc, take the user desc - if(!this.fileEntryHasDetectedDesc(newEntry)) { - newEntry.desc = newValues.shortDesc.trim(); + if(!newEntry.descIsAnsi) { + newEntry.desc = _.trimEnd(newValues.shortDesc); } if(newValues.estYear.length > 0) { @@ -659,14 +659,16 @@ exports.getModule = class UploadModule extends MenuModule { displayFileDetailsPageForUploadEntry(fileEntry, cb) { const self = this; - async.series( + async.waterfall( [ function prepArtAndViewController(callback) { return self.prepViewControllerWithArt( 'fileDetails', FormIds.fileDetails, { clearScreen : true, trailingLF : false }, - callback + err => { + return callback(err); + } ); }, function populateViews(callback) { @@ -679,18 +681,32 @@ exports.getModule = class UploadModule extends MenuModule { tagsView.setText( Array.from(fileEntry.hashTags).join(',') ); // :TODO: optional 'hashTagsSep' like file list/browse yearView.setText(fileEntry.meta.est_release_year || ''); - if(self.fileEntryHasDetectedDesc(fileEntry)) { - descView.setPropertyValue('mode', 'preview'); - descView.setText(fileEntry.desc); - descView.acceptsFocus = false; - self.viewControllers.fileDetails.switchFocus(MciViewIds.fileDetails.tags); - } else { - descView.setPropertyValue('mode', 'edit'); - descView.setText(getDescFromFileName(fileEntry.fileName)); // try to come up with something good as a default - descView.acceptsFocus = true; - self.viewControllers.fileDetails.switchFocus(MciViewIds.fileDetails.desc); - } + if(isAnsi(fileEntry.desc)) { + fileEntry.descIsAnsi = true; + return descView.setAnsi( + fileEntry.desc, + { + prepped : false, + forceLineTerm : true, + }, + () => { + return callback(null, descView, 'preview', MciViewIds.fileDetails.tags); + } + ); + } else { + const hasDesc = self.fileEntryHasDetectedDesc(fileEntry); + descView.setText( + hasDesc ? fileEntry.desc : getDescFromFileName(fileEntry.fileName), + { scrollMode : 'top' } // override scroll mode; we want to be @ top + ); + return callback(null, descView, 'edit', hasDesc ? MciViewIds.fileDetails.tags : MciViewIds.fileDetails.desc); + } + }, + function finalizeViews(descView, descViewMode, focusId, callback) { + descView.setPropertyValue('mode', descViewMode); + descView.acceptsFocus = 'preview' === descViewMode ? false : true; + self.viewControllers.fileDetails.switchFocus(focusId); return callback(null); } ],