Skip to content
Snippets Groups Projects
Commit 23b26a23 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Merge branch 'dd_file_lister_filename_color_in_desc_and_refactor' into 'master'

DDFileLister: New color option (filenameInDesc) for the color of the full filename when used in the description. Also, a refactor of the extended description toggle mechanism

See merge request !507
parents cc07b354 d9885f28
Branches
Tags
1 merge request!507DDFileLister: New color option (filenameInDesc) for the color of the full filename when used in the description. Also, a refactor of the extended description toggle mechanism
......@@ -156,7 +156,7 @@
* Now optionally displays the number of files in the directory in the
* header at the top of the list, configurable with the
* displayNumFilesInHeader option in the config file
* 2025-02-22 Eric Oulashin Version 2.28
* 2025-02-23 Eric Oulashin Version 2.28
* 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.
......@@ -205,7 +205,7 @@ var gAvatar = load({}, "avatar_lib.js");
// Version information
var LISTER_VERSION = "2.28";
var LISTER_DATE = "2025-02-22";
var LISTER_DATE = "2025-02-23";
///////////////////////////////////////////////////////////////////////////////
......@@ -280,7 +280,9 @@ var gColors = {
fileNormalBkgTrad: "\x01n\x01w",
listNumTrad: "\x01g\x01h",
fileAreaDescTrad: "\x01c",
fileAreaNumItemsTrad: "\x01b\x01h"
fileAreaNumItemsTrad: "\x01b\x01h",
filenameInDesc: "\x01g" // Filename when used in the description
};
......@@ -490,18 +492,7 @@ if (gUseLightbarInterface && console.term_supports(USER_ANSI))
{
currentActionVal = gFileMenuBar.getCurrentSelectedAction();
gFileMenuBar.setCurrentActionCode(currentActionVal);
if (currentActionVal == TOGGLE_EXTD_DESCS)
{
// Toggle extended descriptions
toggleExtdDescriptionsForUser_Lightbar();
drawFileListMenu = true; // Ensure the menu re-draws itself (properly)
actionRetObj = null;
}
else
{
// Handle actions (other than extended description toggle)
actionRetObj = doAction(currentActionVal, gFileList, gFileListMenu);
}
actionRetObj = doAction(currentActionVal, gFileList, gFileListMenu);
}
// Allow the delete key as a special key for sysops to delete the selected file(s). Also allow backspace
// due to some terminals returning backspace for delete.
......@@ -518,18 +509,7 @@ if (gUseLightbarInterface && console.term_supports(USER_ANSI))
{
currentActionVal = gFileMenuBar.getActionFromChar(lastUserInputUpper, false);
gFileMenuBar.setCurrentActionCode(currentActionVal, true);
if (currentActionVal == TOGGLE_EXTD_DESCS)
{
// Toggle extended descriptions
toggleExtdDescriptionsForUser_Lightbar();
drawFileListMenu = true; // Ensure the menu re-draws itself (properly)
actionRetObj = null;
}
else
{
// Handle actions (other than extended description toggle)
actionRetObj = doAction(currentActionVal, gFileList, gFileListMenu);
}
actionRetObj = doAction(currentActionVal, gFileList, gFileListMenu);
}
// If an action was done (actionRetObj is not null), then look at actionRetObj and
// do what's needed. Note that quit (for the Q key) is already handled.
......@@ -902,29 +882,24 @@ else
//gFileMenuBar.setCurrentActionCode(LAST_PAGE, !refreshWholePromptLine);
gFileMenuBar.setCurrentActionCode(LAST_PAGE, true);
}
else if (userInput == "X")
{
// Toggle extended descriptions
var userCanToggle = (Boolean(user.settings & USER_EXTDESC) ? true : userCanEnableExtendedDescriptions());
if (userCanToggle)
{
user.settings ^= USER_EXTDESC;
allFileInfoLines = [];
for (var i = 0; i < gFileList.length; ++i)
allFileInfoLines = allFileInfoLines.concat(getFileInfoLineArrayForTraditionalUI(gFileList, i, formatInfo));
topItemIndexForLastPage = allFileInfoLines.length - numLinesPerPage;
drawMenu = true;
drawDirHeaderLines = true;
}
}
else
{
drawDirHeaderLines = true;
drawMenu = true;
refreshWholePromptLine = true;
currentActionVal = gFileMenuBar.getActionFromChar(userInput, false);
//if (user.is_sysop) console.print("\x01n\r\nHere - Char:" + userInput + ":, action val: " + currentActionVal + " \x01p"); // Temporary
gFileMenuBar.setCurrentActionCode(currentActionVal, true);
actionRetObj = doAction(currentActionVal, gFileList, gFileListMenu);
// If the user toggled extended descriptions, then re-generate the array of
// filenames & descriptions
if (currentActionVal == TOGGLE_EXTD_DESCS)
{
allFileInfoLines = [];
for (var i = 0; i < gFileList.length; ++i)
allFileInfoLines = allFileInfoLines.concat(getFileInfoLineArrayForTraditionalUI(gFileList, i, formatInfo));
topItemIndexForLastPage = allFileInfoLines.length - numLinesPerPage;
}
}
}
}
......@@ -959,7 +934,7 @@ function doAction(pActionCode, pFileList, pFileListMenu)
// (for options that need one)
var useANSIInterface = gUseLightbarInterface && console.term_supports(USER_ANSI);
var fileIdx = pFileListMenu.selectedItemIdx;
if (!useANSIInterface && pActionCode != QUIT && pActionCode != HELP && pActionCode != NEXT_PAGE && pActionCode != PREV_PAGE)
if (!useANSIInterface && pActionCode != QUIT && pActionCode != HELP && pActionCode != NEXT_PAGE && pActionCode != PREV_PAGE && pActionCode != TOGGLE_EXTD_DESCS)
{
console.crlf();
console.print(getActionStr(pActionCode) + "\x01n");
......@@ -1032,34 +1007,14 @@ function doAction(pActionCode, pFileList, pFileListMenu)
if (user.is_sysop)
retObj = confirmAndRemoveFilesFromFilebase(pFileList, pFileListMenu);
break;
case TOGGLE_EXTD_DESCS: // Toggle extended descriptions
retObj = toggleExtdDescriptionsForUser(useANSIInterface);
break;
}
return retObj;
}
// Toggles the user's extended descriptions. This is a special action case for the
// lightbar interface which re-creates the lightbar menu, which will behave differently
// depending on whether the user's extended descriptions are enabled or not.
function toggleExtdDescriptionsForUser_Lightbar()
{
// Toggle extended descriptions
var userCanToggle = (Boolean(user.settings & USER_EXTDESC) ? true : userCanEnableExtendedDescriptions());
if (userCanToggle)
{
var currentSelectedItemIdx = gFileListMenu.selectedItemIdx;
user.settings ^= USER_EXTDESC;
var listPopRetObj = populateFileList(gScriptMode);
if (listPopRetObj.exitNow) // Shouldn't happen here, but just in case
exit(0);
gFileListMenu = createFileListMenu(gFileMenuBar.getAllActionKeysStr(true, true) + KEY_LEFT + KEY_RIGHT + KEY_DEL /*+ CTRL_C*/);
gFileListMenu.SetSelectedItemIdx(currentSelectedItemIdx);
// If the user has enabled extended descriptions, then write the
// current selected file's extended description on the screen
if (Boolean(user.settings & USER_EXTDESC))
displayFileExtDescOnMainScreen(gFileListMenu.selectedItemIdx);
}
}
// Returns a string representing an action code, for relevant actions (not necessarily all actions)
//
// Parameters:
......@@ -2633,6 +2588,34 @@ function confirmAndRemoveFilesFromFilebase(pFileList, pFileListMenu)
return retObj;
}
// Toggles the user's extended descriptions. This is a special action case for the
// lightbar interface which re-creates the lightbar menu, which will behave differently
// depending on whether the user's extended descriptions are enabled or not.
function toggleExtdDescriptionsForUser(pUsingLightbarInterface)
{
var retObj = getDefaultActionRetObj();
// Toggle extended descriptions
var userCanToggle = (Boolean(user.settings & USER_EXTDESC) ? true : userCanEnableExtendedDescriptions());
if (userCanToggle)
{
user.settings ^= USER_EXTDESC; // Toggle the user's extended descriptions setting
// If using the lightbar interface, then re-create the lightbar file list menu
if (pUsingLightbarInterface)
{
var currentSelectedItemIdx = gFileListMenu.selectedItemIdx;
var listPopRetObj = populateFileList(gScriptMode);
if (listPopRetObj.exitNow) // Shouldn't happen here, but just in case
exit(0);
gFileListMenu = createFileListMenu(gFileMenuBar.getAllActionKeysStr(true, true) + KEY_LEFT + KEY_RIGHT + KEY_DEL /*+ CTRL_C*/);
gFileListMenu.SetSelectedItemIdx(currentSelectedItemIdx);
retObj.reDrawMainScreenContent = true;
}
}
return retObj;
}
///////////////////////////////////////////////////////////////////////////////
// DDFileMenuBar stuff
......@@ -5354,11 +5337,11 @@ function displayFileExtDescOnMainScreen(pFileIdx, pStartScreenRow, pEndScreenRow
// filename.
var fileDescIsEmptyOrWhitespace = (fileDesc == "" || /^\s+$/.test(fileDesc));
if (gUseFilenameIfNoDescription && fileDescIsEmptyOrWhitespace)
fileDesc = lfexpand(word_wrap(fileMetadata.name + "\r\n(No description)", maxDescLen, null, false));
fileDesc = "\x01n" + gColors.filenameInDesc + lfexpand(word_wrap(fileMetadata.name + "\r\n\x01n(No description)", maxDescLen, null, false));
// 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 (!fileDescIsEmptyOrWhitespace && fileMetadata.name.length > gFileListMenu.filenameLen)
fileDesc = lfexpand(word_wrap(fileMetadata.name, maxDescLen, null, false)) + "\r\n" + fileDesc;
fileDesc = "\x01n" + gColors.filenameInDesc + lfexpand(word_wrap(fileMetadata.name, maxDescLen, null, false)) + "\r\n\x01n" + fileDesc;
// Display the description on the screen
var fileDescArray = fileDesc.split("\r\n");
console.attributes = "N";
......@@ -5640,7 +5623,7 @@ function getFileInfoLineArrayForTraditionalUI(pFileList, pIdx, pFormatInfo)
// There is no description. If the option to use the filename is enabled, then use the filename.
if (gUseFilenameIfNoDescription)
{
var fileDesc = lfexpand(word_wrap(pFileList[pIdx].name + "\r\n(No description)", pFormatInfo.descLen, null, false));
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]);
......@@ -5654,11 +5637,10 @@ function getFileInfoLineArrayForTraditionalUI(pFileList, pIdx, pFormatInfo)
// the the description.
if (pFileList[pIdx].name.length > gFileListMenu.filenameLen)
{
var filenameLines = [];
var fileDescArray = lfexpand(word_wrap(pFileList[pIdx].name, pFormatInfo.descLen, null, false)).split("\r\n");
for (var i = 0; i < fileDescArray.length; ++i)
filenameLines.push(fileDescArray[i]);
descLines = filenameLines.concat(descLines);
fileDescArray[i] = "\x01n" + gColors.filenameInDesc + fileDescArray[i] + "\x01n";
descLines = fileDescArray.concat(descLines);
}
}
......
......@@ -68,3 +68,6 @@ listNumTrad=gh
fileAreaDescTrad=c
; The number of directories/files for 'normal' colors (for moving a file)
fileAreaNumItemsTrad=bh
; Filename when used in the description
filenameInDesc=g
......@@ -372,6 +372,11 @@ fileAreaDescTrad The file library/directory description for
fileAreaNumItemsTrad The number of directories/files for
'normal' colors (for moving a file)
filenameInDesc The filename when used in the description
(for instance, if the filename is too long
to fully fit in the lightbar menu or if
the file has no description)
5. Strings used from text.dat
=============================
......
......@@ -8,6 +8,7 @@ Version Date Description
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.
New color theme option: filenameInDesc
New bottom line menu option to toggle extended
descriptions on/off
Fix: useFilenameIfNoDescription option now used in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment