0 votes
by (150 points)

How to write to a specific position in Console.GetOutputStream() in a Rebex File Server SSH session without clearing the console?

Hello everyone,

I am working on a C# console application and would like to write to a specific position in the console using Console.GetOutputStream(), but without calling Console.Clear() each time.

I know that in traditional console applications, we can use Console.SetCursorPosition(x, y), but when working with Console.GetOutputStream(), I am not sure how to achieve this.

Is there a way to move the write position in the output stream without clearing everything?
Can I update only certain parts of the console output efficiently?
Any help or insights would be greatly appreciated!

Thanks in advance!

Applies to: File Server

1 Answer

0 votes
by (74.0k points)
selected by
 
Best answer

Unfortunately, SSH Server Console is very simple and it does not support direct cursor positioning. We will consider to add support for it in the future.

In the meantime, you can use standard cursor positioning characters:

0x0D - CR = move to line start
0x0B - VT = move one line down
0x0A - LF = move to line start and one line down
0x08 - BS = move one char left
0x0C - FF = move screen content to history and move cursor to the top-left corner

It can look like this:

if (e.Command == "test")
{
    e.Action = (args, console) =>
    {
        var output = console.GetOutputStream();
        switch (e.RawArguments.ToLowerInvariant())
        {
            case "bs":
                output.Write("Moving left...");
                output.Write("\x08");
                break;
            case "cr":
                output.Write("Moving to line start...");
                output.Write("\x0D");
                break;
            case "lf":
                output.Write("Moving to line start and one down...");
                output.Write("\x0A");
                break;
            case "vt":
                output.Write("Moving one line down...");
                output.Write("\x0B");
                break;
            case "ff":
                output.Write("Moving to top-left corner...");
                output.Write("\x0C");
                break;
            default:
                output.Write("Invalid arguments.\n");
                return -1;
        }
        output.Write("DONE\n");
        return 0;
    };
}
...