diff --git a/xtrn/ddfilelister/ddfilelister.cfg b/xtrn/ddfilelister/ddfilelister.cfg index 4eb288963d7b1275bb3d1bf4113f4f5a781af7e1..4decf0fe1d074720971d8d37d7e49e467b03852d 100644 --- a/xtrn/ddfilelister/ddfilelister.cfg +++ b/xtrn/ddfilelister/ddfilelister.cfg @@ -31,9 +31,19 @@ blankNFilesListedStrIfLoadableModule=true ; information for files displayUserAvatars=true -; If a file's description is unavailable, whether or not to use the -; filename in the list instead -useFilenameIfNoDescription=true +; For short descriptions (extended descriptions disabled), if a file's +; description is unavailable, whether or not to use the filename in the +; list instead +useFilenameIfShortDescriptionEmpty=true + +; How to use the filename in the extended description +; always: Always use the filename in the description +; ifDescEmpty: Only if the description is empty (also though, +; if the filename is too short to fully be shown +; in the menu, the full filename will appear in the +; description) +; never: Never use the filename in the description +filenameInExtendedDescription=ifDescEmpty ; Whether or not to display the number of files in the directory in ; the header at the top of the list diff --git a/xtrn/ddfilelister/ddfilelister.js b/xtrn/ddfilelister/ddfilelister.js index dde41cc44fc1bb4f1a0e0d641a4ea332c1b2268d..b81a9236fa5af4239fa676249196209ee834bef9 100644 --- a/xtrn/ddfilelister/ddfilelister.js +++ b/xtrn/ddfilelister/ddfilelister.js @@ -164,7 +164,10 @@ * Fix: useFilenameIfNoDescription option now used in traditional * (non-lightbar) mode. * 2025-02-25 Eric Oulashin Version 2.28a - * Long filename color fix for some edge cases + * Long filename color fix for some edge cases. + * The setting useFilenameIfNoDescription changed to + * useFilenameIfShortDescriptionEmpty. + * New setting: filenameInExtendedDescription */ "use strict"; @@ -354,9 +357,14 @@ var gTraditionalUseSyncStock = false; // file information var gDispayUserAvatars = true; -// If a file's description is unavailable, whether or not to use the -// filename instead -var gUseFilenameIfNoDescription = true; +// How to use the filename in the (extended) description +var FILENAME_IN_DESC_IF_DESC_EMPTY = 0; +var FILENAME_IN_DESC_ALWAYS = 1; +var FILENAME_IN_DESC_NEVER = 2; +var gFilenameInExtendedDesc = FILENAME_IN_DESC_IF_DESC_EMPTY; +// For short descriptions (extended descriptions disabled): If a file's description is +// unavailable, whether or not to use the filename instead +var gUseFilenameIfNoDescription_ShortDescs = true; /////////////////////////////////////////////////////////////////////////////// // Script execution code @@ -3540,11 +3548,12 @@ function createFileListMenu(pQuitKeys) } */ var desc = (typeof(gFileList[pIdx].desc) === "string" ? gFileList[pIdx].desc : ""); + var descIsEmpty = (desc == "" || /^\s+$/.test(desc)); // Remove/replace any cursor movement codes in the description, which can corrupt the display desc = removeOrReplaceSyncCursorMovementChars(desc, false); // If there is no description and the option to use the filename is enabled, then use the // filename. - if (gUseFilenameIfNoDescription && (desc == "" || /^\s+$/.test(desc))) + if (gUseFilenameIfNoDescription_ShortDescs && (desc == "" || /^\s+$/.test(desc))) desc = gFileList[pIdx].name; var fileSizeStr = file_size_str(gFileList[pIdx].size, null, FILE_SIZE_PRECISION); menuItemObj.text = format(this.fileFormatStr, @@ -4301,10 +4310,23 @@ function readConfigFile() themeFilename = js.exec_dir + settingsObj[prop]; } } - else if (propUpper == "USEFILENAMEIFNODESCRIPTION") + else if (propUpper == "USEFILENAMEIFSHORTDESCRIPTIONEMPTY") { if (typeof(settingsObj[prop]) === "boolean") - gUseFilenameIfNoDescription = settingsObj[prop]; + gUseFilenameIfNoDescription_ShortDescs = settingsObj[prop]; + } + else if (propUpper == "FILENAMEINEXTENDEDDESCRIPTION") + { + if (typeof(settingsObj[prop]) === "string") + { + var valueUpper = settingsObj[prop].toUpperCase(); + if (valueUpper == "IFDESCEMPTY") + gFilenameInExtendedDesc = FILENAME_IN_DESC_IF_DESC_EMPTY; + else if (valueUpper == "ALWAYS") + gFilenameInExtendedDesc = FILENAME_IN_DESC_ALWAYS; + else if (valueUpper == "NEVER") + gFilenameInExtendedDesc = FILENAME_IN_DESC_NEVER; + } } else if (propUpper == "DISPLAYNUMFILESINHEADER") { @@ -5344,26 +5366,28 @@ function displayFileExtDescOnMainScreen(pFileIdx, pStartScreenRow, pEndScreenRow while (fileDescArray.length > 0 && console.strlen(fileDescArray[0], P_AUTO_UTF8) == 0) fileDescArray.shift(); // If there is no description, then use the filename as the description - if (fileDescArray.length == 0 && gUseFilenameIfNoDescription) - { - fileDesc = "\x01n" + gColors.filenameInDesc + lfexpand(word_wrap(fileMetadata.name + "\r\n\x01n(No description)", maxDescLen, null, false)); - fileDescArray = fileDesc.split("\r\n"); - } - // If there is a description and the filename is too long to fit on the menu, then prepend the - // full filename (wrapped) to the the description - else if (fileDescArray.length > 0 && fileMetadata.name.length > gFileListMenu.filenameLen) - { - // See how many lines the filename takes, and use the filename color on those lines, and - // the normal attribute for the start of the description - var filenameWrapped = lfexpand(word_wrap(fileMetadata.name, maxDescLen, null, false)); - var filenameLines = filenameWrapped.split("\r\n"); - // Splitting as above can result in an extra empty last line - if (filenameLines[filenameLines.length-1].length == 0) - filenameLines.pop(); - descriptionLineAttrs[0] = "\x01n" + gColors.filenameInDesc; - descriptionLineAttrs[filenameLines.length] = "\x01n"; - fileDescArray = filenameLines.concat(fileDescArray); + if (gFilenameInExtendedDesc == FILENAME_IN_DESC_IF_DESC_EMPTY || gFilenameInExtendedDesc == FILENAME_IN_DESC_ALWAYS) + { + if (fileDescArray.length == 0) + { + fileDesc = "\x01n" + gColors.filenameInDesc + lfexpand(word_wrap(fileMetadata.name + "\r\n\x01n(No description)", maxDescLen, null, false)); + fileDescArray = fileDesc.split("\r\n"); + } + else if ((gFilenameInExtendedDesc == FILENAME_IN_DESC_IF_DESC_EMPTY && fileMetadata.name.length > gFileListMenu.filenameLen) || gFilenameInExtendedDesc == FILENAME_IN_DESC_ALWAYS) + { + // See how many lines the filename takes, and use the filename color on those lines, and + // the normal attribute for the start of the description + var filenameWrapped = lfexpand(word_wrap(fileMetadata.name, maxDescLen, null, false)); + var filenameLines = filenameWrapped.split("\r\n"); + // Splitting as above can result in an extra empty last line + if (filenameLines[filenameLines.length-1].length == 0) + filenameLines.pop(); + descriptionLineAttrs[0] = "\x01n" + gColors.filenameInDesc; + descriptionLineAttrs[filenameLines.length] = "\x01n"; + fileDescArray = filenameLines.concat(fileDescArray); + } } + // We can ignore FILENAME_IN_DESC_NEVER // Display the description on the screen console.attributes = "N"; // screenRowNum is to keep track of the row on the screen where the @@ -5632,38 +5656,57 @@ function getFileInfoLineArrayForTraditionalUI(pFileList, pIdx, pFormatInfo) var descLines; if (Boolean(user.settings & USER_EXTDESC)) // If extended descriptions + { descLines = getExtdFileDescArray(pFileList, pIdx); + // If there is no description, then use the filename as the description + if (gFilenameInExtendedDesc == FILENAME_IN_DESC_IF_DESC_EMPTY || gFilenameInExtendedDesc == FILENAME_IN_DESC_ALWAYS) + { + if (descLines.length == 0) + { + var fileDesc = "\x01n" + gColors.filenameInDesc + lfexpand(word_wrap(pFileList[pIdx].name, pFormatInfo.descLen, null, false)); + descLines = fileDesc.split("\r\n"); + // Splitting as above can result in an extra empty last line + if (descLines[descLines.length-1].length == 0) + descLines.pop(); + // Ensure the filename color is applied to all lines of the filename array + for (var i = 0; i < descLines.length; ++i) + descLines[i] = "\x01n" + gColors.filenameInDesc + descLines[i] + "\x01n"; + descLines.push("(No description)"); + } + else if ((gFilenameInExtendedDesc == FILENAME_IN_DESC_IF_DESC_EMPTY && pFileList[pIdx].name.length > gFileListMenu.filenameLen) || gFilenameInExtendedDesc == FILENAME_IN_DESC_ALWAYS) + { + // See how many lines the filename takes, and use the filename color on those lines, and + // the normal attribute for the start of the description + var filenameWrapped = lfexpand(word_wrap(pFileList[pIdx].name + "\x01n", pFormatInfo.descLen, null, false)); + var filenameLines = filenameWrapped.split("\r\n"); + // Splitting as above can result in an extra empty last line + if (filenameLines[filenameLines.length-1].length == 0) + filenameLines.pop(); + // Ensure the filename color is applied to all lines of the filename array + for (var i = 0; i < filenameLines.length; ++i) + filenameLines[i] = "\x01n" + gColors.filenameInDesc + filenameLines[i] + "\x01n"; + // Prepend the filename to the extended description + descLines = filenameLines.concat(descLines); + } + } + // We can ignore FILENAME_IN_DESC_NEVER + } else { + // gUseFilenameIfNoDescription_ShortDescs if (pFileList[pIdx].hasOwnProperty("desc") && typeof(pFileList[pIdx].desc) === "string") descLines = [ pFileList[pIdx].desc.replace(/\r$/, "").replace(/\n$/, "").replace(/\r\n$/, "") ]; - } - if (!Array.isArray(descLines)) - descLines = []; - if (descLines.length == 0) - { - // There is no description. If the option to use the filename is enabled, then use the filename. - if (gUseFilenameIfNoDescription) + else + descLines = []; + // If there is no description andthe option to use the filename is enabled, then + // use the filename for the description. + if (descLines.length == 0 && gUseFilenameIfNoDescription_ShortDescs) { var fileDesc = "\x01n" + gColors.filenameInDesc + lfexpand(word_wrap(pFileList[pIdx].name + "\r\n\x01n(No description)", pFormatInfo.descLen, null, false)); var fileDescArray = fileDesc.split("\r\n"); for (var i = 0; i < fileDescArray.length; ++i) descLines.push(fileDescArray[i]); } - else - descLines.push(""); - } - else - { - // If the filename is too long to fit on the menu, then prepend the full filename (wrapped) to - // the the description. - if (pFileList[pIdx].name.length > gFileListMenu.filenameLen) - { - var fileDescArray = lfexpand(word_wrap(pFileList[pIdx].name, pFormatInfo.descLen, null, false)).split("\r\n"); - for (var i = 0; i < fileDescArray.length; ++i) - fileDescArray[i] = "\x01n" + gColors.filenameInDesc + fileDescArray[i] + "\x01n"; - descLines = fileDescArray.concat(descLines); - } } var filename = shortenFilename(pFileList[pIdx].name, pFormatInfo.filenameLen, true); @@ -5673,6 +5716,8 @@ function getFileInfoLineArrayForTraditionalUI(pFileList, pIdx, pFormatInfo) fileInfoLines.push(format(pFormatInfo.formatStr, pIdx+1, filename, fileSizeStr.substr(0, pFormatInfo.fileSizeLen), substrWithAttrCodes(descLines[0], 0, pFormatInfo.descLen))); if (Boolean(user.settings & USER_EXTDESC)) // If extended descriptions { + // TODO: Some extended descriptions that use block characters + // aren't being displayed properly here for (var i = 1; i < descLines.length; ++i) { if (console.strlen(descLines[i]) > 0) diff --git a/xtrn/ddfilelister/readme.txt b/xtrn/ddfilelister/readme.txt index 91ed7b596dbe0b37932e6351754c8cce8a4092ca..fbf354234941a29a047e3fbf32f5c9646d9574b0 100644 --- a/xtrn/ddfilelister/readme.txt +++ b/xtrn/ddfilelister/readme.txt @@ -265,10 +265,25 @@ displayUserAvatars Whether or not to display uploader avatars in extended information for files. Valid values are true and false. -useFilenameIfNoDescription If a file's description is unavailable, - whether or not to use the filename in the - list instead. Valid values are true and - false. +useFilenameIfShortDescriptionEmpty For short descriptions (extended + descriptions disabled), if a file's + description is unavailable, use the + filename for the description instead. + Valid values are true and false. + +filenameInExtendedDescription For extended descriptions: How to use the + filename in the extended description. + This can be one of the following (and + defaults to ifDescEmpty): + always: Always use the filename in the + description + ifDescEmpty: Only if the description is + empty (also though, if the + filename is too short to + fully be shown in the menu, + the full filename will appear + in the description) + never: Never use the filename in the description displayNumFilesInHeader Whether or not to display the number of files in the directory in the header at diff --git a/xtrn/ddfilelister/revision_history.txt b/xtrn/ddfilelister/revision_history.txt index a7044ec6644b4de1b22fb06dc6b103e53b1134f4..d54e1791be2a8d0044a113ef3dbe09e2b02464e7 100644 --- a/xtrn/ddfilelister/revision_history.txt +++ b/xtrn/ddfilelister/revision_history.txt @@ -6,7 +6,10 @@ Revision History (change log) Version Date Description ------- ---- ----------- 2.28a 2025-02-25 Fix for long filename color support when used in the - description for some edge cases + description for some edge cases. + The setting useFilenameIfNoDescription changed to + useFilenameIfShortDescriptionEmpty. + New setting: filenameInExtendedDescription 2.28 2025-02-22 If extended descriptions are enabled and a filename is too long to fully fit in the menu, prepend the full filename (wrapped) to the description.