~jpgleeson/spawsh

de4273f0304e0a6f25e3e3009f481a943b87714d — jpgleeson a month ago 169110e
Better search & redirect handling.

Detangled some of the spaghetti stuff to use less direct references. Now search works correctly. Also took the chance to handle all redirects the same as I don't keep a permanent record of them anyway.
2 files changed, 23 insertions(+), 23 deletions(-)

M Program.cs
M README.md
M Program.cs => Program.cs +16 -19
@@ 155,7 155,10 @@ namespace spawsh
                if (newInput.Length != 0)
                {
                    buildRequest(newInput);
                    LineBuffer = fetchPage();

                    string[] fetchedPage = fetchPage();

                    LineBuffer = fetchedPage;

                    linksInPage = buildLinkSet(LineBuffer);



@@ 188,6 191,7 @@ namespace spawsh
        {
            TcpClient client = new TcpClient();
            string responseData = "";
            string[] fetchedOutput = new string[1024];

            try
            {


@@ 196,6 200,7 @@ namespace spawsh
            catch (SocketException error)
            {
                responseData = error.Message;
                fetchedOutput[0] = error.Message;
            }

            if (client != null && client.Connected)


@@ 210,7 215,7 @@ namespace spawsh

                    responseData = ReadMessage(sslStream);

                    handleResponse(responseData);
                    fetchedOutput = handleResponse(responseData);

                }
            }


@@ 218,7 223,7 @@ namespace spawsh
            
            client.Close();

            return responseData.Split('\n');
            return fetchedOutput;
        }

        static bool buildRequest(string inputString)


@@ 329,7 334,7 @@ namespace spawsh
            return messageData.ToString();
        }

        static void handleResponse(string responseData)
        static string[] handleResponse(string responseData)
        {
            string[] responseLines = responseData.Split('\n');
            string responseBody = "";


@@ 354,7 359,7 @@ namespace spawsh
            {
                Console.WriteLine(responseBody);
            }
            else if (responseCode == "31")
            else if (responseCode[0] == '3')
            {
                string redirectAddress = responseHeader.Split(' ')[1];



@@ 362,18 367,13 @@ namespace spawsh
                {
                    Console.WriteLine("Redirect to {0}. Fetching.", redirectAddress);

                    LineBuffer = fetchPage();
                    responseLines = fetchPage();

                    linksInPage = buildLinkSet(LineBuffer);
                    linksInPage = buildLinkSet(responseLines);
                }

                selectedLinkIndex = -1;
            }
            else if (responseCode[0] == '3')
            {
                Console.WriteLine("Redirect to {0}", responseHeader.Split(' ')[1]);
                Console.WriteLine("Try again at new url above.");
            }
            else if (responseCode == "50")
            {
                Console.WriteLine("Permanent Failure");


@@ 390,18 390,15 @@ namespace spawsh

                page += "?" + searchParams;

                Console.WriteLine(page);
                Console.ReadKey();

                buildRequest(server + page);
                Console.WriteLine("Searching for {0}", searchParams);

                LineBuffer = fetchPage();
                linksInPage = buildLinkSet(LineBuffer);
                responseLines = fetchPage();
                linksInPage = buildLinkSet(responseLines);
                selectedLinkIndex = -1;

                Console.ReadKey();
            }

            return responseLines;
        }

    }

M README.md => README.md +7 -4
@@ 2,10 2,13 @@
spawsh is a command line client for gemini. It can be used as a curl-ish utility or in interactive mode.

## Usage
run  spawsh with the url requested as the first argument. Do not prepend the url with gemini://.
e.g. ./spawsh.exe gemini.circumlunar.space/docs/
spawsh has two modes, interactive, and utility. Interactive can be activated by passing the flag -i at the command line.

### Utility
run  spawsh with the url requested as the first argument.

spawsh will fetch the file and display in terminal.

Run spawsh with -i as the flag to enter interactive mode. Use right and left arrows to cycle through the links on the page and press enter to go to that link.
If no link is selected, press enter, then type in the new url, and enter again, and the new page will be fetched.
\ No newline at end of file
### Interactive
Use right and left arrows to cycle through the links on the page and press enter to go to that link.
Alternatively, press enter to input a url.