From b9112c40a74ac8b193dd6f10cd3bdbec88620a6f Mon Sep 17 00:00:00 2001
From: Eric Oulashin <eric.oulashin@gmail.com>
Date: Fri, 1 Mar 2024 09:10:55 -0800
Subject: [PATCH] DDLightbarMenu: When writing an item with UTF-8 text, check
 ANSI support before moving the cursor (and this is important if the menu is
 being used in non-lightbar mode)

---
 exec/load/dd_lightbar_menu.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/exec/load/dd_lightbar_menu.js b/exec/load/dd_lightbar_menu.js
index 7ea87c1451..f8f6fd2b14 100644
--- a/exec/load/dd_lightbar_menu.js
+++ b/exec/load/dd_lightbar_menu.js
@@ -1202,7 +1202,8 @@ function DDLightbarMenu_WriteItem(pIdx, pItemLen, pHighlight, pSelected, pScreen
 	{
 		var len = this.nextDrawOnlyItemSubstr.end - this.nextDrawOnlyItemSubstr.start;
 		var shortenedText = substrWithAttrCodes(itemText, this.nextDrawOnlyItemSubstr.start, len);
-		console.gotoxy(pScreenX+this.nextDrawOnlyItemSubstr.start, pScreenY);
+		if (this.ANSISupported())
+			console.gotoxy(pScreenX+this.nextDrawOnlyItemSubstr.start, pScreenY);
 		console.print(shortenedText + "\x01n", printModeBits);
 	}
 	else
@@ -1251,7 +1252,8 @@ function DDLightbarMenu_WriteItem(pIdx, pItemLen, pHighlight, pSelected, pScreen
 				{
 					itemLen = itemColor[i].end - itemColor[i].start;
 					var textToPrint = substrWithAttrCodes(itemText, itemStartIdx, itemLen);
-					console.gotoxy(itemStartX + itemColor[i].start, itemY);
+					if (this.ANSISupported())
+						console.gotoxy(itemStartX + itemColor[i].start, itemY);
 					console.print(textToPrint, P_AUTO_UTF8); // printModeBits
 					itemStartIdx += itemLen;
 
-- 
GitLab