~jpgleeson/spawsh

31e4a5d32ef9f068ccf11f39203f0d261537239e — jpgleeson 9 months ago 8c626a5
Update: Interactive mode now launched if no arguments passed.

Update to launch interactive mode automatically if no arguments are passed to the program. README update to match.
2 files changed, 41 insertions(+), 52 deletions(-)

M Program.cs
M README.md
M Program.cs => Program.cs +38 -49
@@ 30,71 30,60 @@ namespace spawsh
            {
                string hostArgument = args[0];

                if (hostArgument == "-i")
                if (hostArgument.Contains("gemini://"))
                {
                    inInteractive = true;
                    LineBuffer = new string[windowLineCount];

                    buildRequest(server + page);
                    LineBuffer = fetchPage();
                    linksInPage = buildLinkSet(LineBuffer);
                    hostArgument = hostArgument.Trim();
                    hostArgument = hostArgument.Substring(9);
                }
                else if (hostArgument.Contains("https://") || hostArgument.Contains("http://") || hostArgument.Contains("gopher://"))
                {
                    Console.WriteLine("Protocol not supported.");
                    validProtocol = false;
                }

                    while (inInteractive)
                    {
                        interactiveLoop();
                    }
                if (hostArgument.Contains("/"))
                {
                    int firstSlashIndex = hostArgument.IndexOf('/');
                    server = hostArgument.Remove(firstSlashIndex);
                    page = hostArgument.Substring(firstSlashIndex, hostArgument.Length - firstSlashIndex);
                }
                else
                {
                    if (hostArgument.Contains("gemini://"))
                    {
                        hostArgument = hostArgument.Trim();
                        hostArgument = hostArgument.Substring(9);
                    }
                    else if (hostArgument.Contains("https://") || hostArgument.Contains("http://") || hostArgument.Contains("gopher://"))
                    {
                        Console.WriteLine("Protocol not supported.");
                        validProtocol = false;
                    }

                    if (hostArgument.Contains("/"))
                    {
                        int firstSlashIndex = hostArgument.IndexOf('/');
                    server = hostArgument;
                }
                if (validProtocol)
                {
                    TcpClient client = new TcpClient(server, 1965);

                        server = hostArgument.Remove(firstSlashIndex);
                        page = hostArgument.Substring(firstSlashIndex, hostArgument.Length - firstSlashIndex);
                    }
                    else
                    {
                        server = hostArgument;
                    }

                    if (validProtocol)
                    using (SslStream sslStream = new SslStream(client.GetStream(), false,
                        new RemoteCertificateValidationCallback(ValidateServerCertificate), null))
                    {
                        TcpClient client = new TcpClient(server, 1965);


                        using (SslStream sslStream = new SslStream(client.GetStream(), false,
                            new RemoteCertificateValidationCallback(ValidateServerCertificate), null))
                        {
                            sslStream.AuthenticateAsClient(server);
                        sslStream.AuthenticateAsClient(server);
                        byte[] messageToSend = Encoding.UTF8.GetBytes("gemini://" + server + page + '\r' + '\n');
                        sslStream.Write(messageToSend);

                            byte[] messageToSend = Encoding.UTF8.GetBytes("gemini://" + server + page + '\r' + '\n');
                            sslStream.Write(messageToSend);
                        string responseData = ReadMessage(sslStream);

                            string responseData = ReadMessage(sslStream);
                        handleResponse(responseData);

                            handleResponse(responseData);

                        }
                        client.Close();
                    }
                    client.Close();
                }
            }
            else
            {
                buildRequest(server);
                fetchPage();
                inInteractive = true;
                LineBuffer = new string[windowLineCount];

                buildRequest(server + page);
                LineBuffer = fetchPage();
                linksInPage = buildLinkSet(LineBuffer);

                while (inInteractive)
                {
                    interactiveLoop();
                }
            }

        }

M README.md => README.md +3 -3
@@ 1,8 1,8 @@
# SPAWSH
spawsh is a command line client for gemini. It can be used as a curl-ish utility or in interactive mode.
spawsh is a command line client for gemini. It can be used as a curl-ish utility or in interactive mode. There is a current build available at https://jpgleeson.com/spawsh/spawsh-current.tar

## Usage
spawsh has two modes, interactive, and utility. Interactive can be activated by passing the flag -i at the command line.
spawsh has two modes, interactive, and utility. Interactive will launch automatically if no arguments are passed with the command.

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


@@ 10,5 10,5 @@ run  spawsh with the url requested as the first argument.
spawsh will fetch the file and display in terminal.

### Interactive
Use Enter to enter a prompt to input a new url.
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.