From a2465f3b82f1fd463af5ff1bf4d84df47eb163fb Mon Sep 17 00:00:00 2001 From: Jack Gleeson Date: Mon, 22 Nov 2021 17:21:39 -0800 Subject: [PATCH] Highlight currently selected link --- Program.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index e59822b..c3432ee 100644 --- a/Program.cs +++ b/Program.cs @@ -510,7 +510,19 @@ namespace spawsh string outString = DisplayBuffer[i].Replace("#", string.Empty); Console.WriteLine(outString); Console.ForegroundColor = originalColour; - } else { + } else if (DisplayBuffer[i].Length > 3 && DisplayBuffer[i].Substring(0, 2) == "{l") { + string linkMetadata = DisplayBuffer[i].Split("}")[0]; + string numberMetadata = linkMetadata.Replace("{l", string.Empty); + int thisLinkIndex = int.Parse(numberMetadata); + + var originalColour = Console.ForegroundColor; + string outString = DisplayBuffer[i].Replace(linkMetadata + "}", string.Empty); + if (selectedLinkIndex == thisLinkIndex) { + Console.ForegroundColor = ConsoleColor.Blue; + } + Console.WriteLine(outString); + Console.ForegroundColor = originalColour; + }else { Console.WriteLine(DisplayBuffer[i]); } } @@ -522,6 +534,7 @@ namespace spawsh static void buildDisplayBuffer() { string[] tempBuffer = new string[1024]; int currentPointer = 0; + int currentLink = 0; foreach (string singleLine in LineBuffer) { if (singleLine.Length < Console.WindowWidth) @@ -536,13 +549,14 @@ namespace spawsh //then singleLine = singleLine.Replace(toRemove, ""); string linkAndDescription = singleLine.Substring(3); if (linkAndDescription.Contains('\t')) { - tempBuffer[currentPointer] = linkAndDescription.Split('\t')[1]; + tempBuffer[currentPointer] = "{l" + currentLink + "}" + linkAndDescription.Split('\t')[1]; } else { toRemove = linkAndDescription.Split(' ')[0]; linkAndDescription = linkAndDescription.Replace(toRemove, ""); - tempBuffer[currentPointer] = linkAndDescription; + tempBuffer[currentPointer] = "{l" + currentLink + "}" + linkAndDescription; } currentPointer++; + currentLink++; } else { tempBuffer[currentPointer] = singleLine; currentPointer++; -- 2.45.2