Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to output raw string content (e.g. sixel) directly via Application.Driver #3763

Open
tznind opened this issue Sep 28, 2024 · 0 comments
Labels
enhancement v2 For discussions, issues, etc... relavant for v2
Milestone

Comments

@tznind
Copy link
Collaborator

tznind commented Sep 28, 2024

Is your feature request related to a problem? Please describe.
In looking at #3734 I have been able to generate the correct encoded data. However I need a way to reliably and efficiently output it to the console.

Sixels can be output using Console.Write. Initially I added this as a bespoke thing in Driver i.e. part of the draw step after everything else was drawn. I only implemented it in NetDriver because that one was already using Console.Write so seemed easiest.

I added this to end of NetDriver.UpdateScreen

// Works with no flicker because it is the last thing in the draw step 
// (but code is suboptimal in terms of design and maintainability)
foreach (var s in Application.Sixel)
{
    if (!string.IsNullOrWhiteSpace (s.SixelData))
    {
        SetCursorPosition (s.ScreenPosition.X, s.ScreenPosition.Y);
        Console.Write (s.SixelData);
    }
}

But I think that was a mistake, instead I should try to 'work with' the driver rather than 'against it'.

Describe the solution you'd like
Rather than teaching Driver about sixel we should make it a view concern only, i.e. it should be possible to do something like the following:

    void SixelViewOnDrawContent (object sender, DrawEventArgs e)
    {
        if (!string.IsNullOrWhiteSpace (_encodedSixelData))
        {
            // Does not work
            Application.Driver?.Move (_screenLocationForSixel.X, _screenLocationForSixel.Y);
            Application.Driver?.AddStr (_encodedSixelData);

            // Works in NetDriver but results in screen flicker when moving mouse but vanish instantly
            // Console.SetCursorPosition (_screenLocationForSixel.X, _screenLocationForSixel.Y);
            // Console.Write (_encodedSixelData);
        }
    }

The above code using Console.Write works but flickers as it fights with the Driver to render.

Sixel data is just string of text but does not work with Application.Driver.AddString, presumably because it is expecting to advance cursor etc and/or turn to Rune. What we want is just to output directly to the console stream at render time.

flicker-console-writeline

Maybe we can add a method like

Application.Driver.AddRaw(_encodedSixelData)

Describe alternatives you've considered
Would love to hear any ideas

@tznind tznind added enhancement v2 For discussions, issues, etc... relavant for v2 labels Sep 28, 2024
@tznind tznind changed the title Ability to output raw content data (e.g. sixel) directly via Application.Driver Ability to output raw string content (e.g. sixel) directly via Application.Driver Sep 28, 2024
@tig tig added this to the V2 Release milestone Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement v2 For discussions, issues, etc... relavant for v2
Projects
Status: No status
Development

No branches or pull requests

2 participants