~jpgleeson/spawsh

2a2e9b46aa674ecbdce9535423c41ac38f8b8da0 — Jack Gleeson 7 months ago a67d995
Working on a more curses like interface
2 files changed, 46 insertions(+), 7 deletions(-)

M Program.cs
M spawsh.csproj
M Program.cs => Program.cs +45 -6
@@ 18,6 18,8 @@ namespace spawsh
        static string currentPage;
        static X509Store certStore;
        static X509CertificateCollection collection;
        static int windowLineCount;
        static int currentOffset;

        static void Main(string[] args)
        {


@@ 27,7 29,8 @@ namespace spawsh
            string page = "/";
            bool validProtocol = true;

            int windowLineCount = Console.WindowHeight;            
            windowLineCount = Console.WindowHeight;     
            currentOffset = 0;       

            if (args.Length > 0)
            {


@@ 115,13 118,15 @@ namespace spawsh

        public static void interactiveLoop()
        {
            Console.Clear();
            Console.Write("\x1b[2J");
            Console.Write("\x1b[3J");
            Console.Write("\x1b[H");

            for (int i = 0; i < Console.WindowWidth - LineBuffer[0].Length; i++)
            {
                Console.Write(" ");    
            }
            Console.WriteLine(LineBuffer[0]);
            //Console.WriteLine(LineBuffer[0]);

            for (int i = 0; i < Console.WindowWidth; i++)
            {


@@ 129,21 134,23 @@ namespace spawsh
            }
            Console.Write('\n');

            displayWindow(currentOffset);

            for (int i = 1; i < LineBuffer.Length; i++)
            {
                if (LineBuffer[i] != null)
                {
                    if (LineBuffer[i].Length < Console.WindowWidth)
                    {
                        Console.WriteLine(LineBuffer[i]);
                        //Console.WriteLine(LineBuffer[i]);
                    }
                    else if (LineBuffer[i].Substring(0, 2) == "=>")
                    {
                        Console.WriteLine(LineBuffer[i]);
                        //Console.WriteLine(LineBuffer[i]);
                    }
                    else
                    {
                        lineWrapString(LineBuffer[i]);
                        //lineWrapString(LineBuffer[i]);
                    }
                }
            }


@@ 180,6 187,8 @@ namespace spawsh

                    string[] fetchedPage = fetchPage();

                    currentOffset = 0;

                    LineBuffer = fetchedPage;
                    
                    if (LineBuffer[0] == "No such host is known." || LineBuffer[0] == "Resource temporarily unavailable")


@@ 210,6 219,22 @@ namespace spawsh
                    selectedLinkIndex--;
                }
            }
            else if (keyRead.Key == ConsoleKey.DownArrow)
            {
                currentOffset++;
                if (currentOffset > (windowLineCount - currentOffset))
                {
                    currentOffset = windowLineCount - (currentOffset + 1);
                }
            }
            else if (keyRead.Key == ConsoleKey.UpArrow)
            {
                currentOffset--;
                if (currentOffset < 0)
                {
                    currentOffset = 0;
                }
            }

            if (selectedLinkIndex < 0)
            {


@@ 481,6 506,20 @@ namespace spawsh
            return responseLines;
        }

        static void displayWindow(int currentOffset)
        {
            for (int i = currentOffset; i < currentOffset + windowLineCount; i++)
            {
                if (i < LineBuffer.Length)
                {
                    if (LineBuffer[i] != null)
                    {
                        Console.WriteLine(LineBuffer[i]);
                    }
                }
            }
        }

        static void lineWrapString(string input)
        {


M spawsh.csproj => spawsh.csproj +1 -1
@@ 2,7 2,7 @@

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp5.0</TargetFramework>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>