Skip to content

Conversation

ShaunLawrie
Copy link

@ShaunLawrie ShaunLawrie commented Nov 12, 2024

fixes #1678

Some discussion in #1671
And more discussion on https://bsky.app/profile/shaunlawrie.com/post/3lao4uw5eos2m

  • I have read the Contribution Guidelines
  • I have commented on the issue above and discussed the intended changes
  • A maintainer has signed off on the changes and the issue was assigned to me
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors
  • The documentation was modified to reflect the changes OR no documentation changes are required.

Changes

Add a first cut of sixel for @patriksvensson to play with.

This is modified source from mine and @trackd's sixel tinkering in https://github.com/trackd/Sixel and PwshSpectreConsole, it's all MIT so free to consume.


Please upvote 👍 this pull request if you are interested in it.

@ShaunLawrie
Copy link
Author

I've left the SPECTRE_CONSOLE_DEBUG env var in there because I found it easier to visualize the dimensions of the sixel data and how they lined up to character cells positioning. When you set that it will render a canvas checkerboard overtop of the sixel data.
image

I used cursor-right control codes to simulate transparent pixels in the canvas which breaks the snapshot tests for canvas rendering. Using those characters could be only under sixel rendering circumstances but I'm not sure how @patriksvensson wanted to reorganize this so they're still broken atm.

@patriksvensson
Copy link
Contributor

I'll take a look at this asap

@phil-scott-78
Copy link
Contributor

I think there might be opportunities for some interesting use cases for the Sixel output independent of ImageSharp. Might be cool if the parsing and building of the ansi was part of Spectre.Console itself with the code to convert an ImageSharp frame being the only code with dependencies on ImageSharp.

@patriksvensson
Copy link
Contributor

@phil-scott-78 Yes, that was my initial idea as well, but quickly realized that it's a pretty daunting task without a library behind it. Open to refactor it out later, and make it available without the ImageSharp library, but for now I think it's ok.

@github-actions github-actions bot added the ⭐ top pull request Top pull request. label Nov 14, 2024
@ShaunLawrie
Copy link
Author

FYI I noticed an issue using this approach in layouts. Because the Sixel data is drawn before the top left of the canvas when it draws the Sixel it can extend below the bottom of the window and scroll the layout which breaks the rendering if the image is taller than the available space in the layout.

I tried shifting the sixel to render after the Canvas so that if the whole canvas can't fit inside a layout it would never output the sixel data but it's pretty janky ShaunLawrie#1

@JustArion
Copy link

Could such a feature allow us to add "previews" to our SelectionPrompts?

eg. From the site's example

// Ask for the user's favorite fruit
var fruit = AnsiConsole.Prompt(
    new SelectionPrompt<string>()
        .Title("What's your [green]favorite fruit[/]?")
        .PageSize(10)
        .MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
        .AddChoices(new[] {
            "Apple", "Apricot", "Avocado", 
            "Banana", "Blackcurrant", "Blueberry",
            "Cherry", "Cloudberry", "Cocunut",
        }));

// Echo the fruit back to the terminal
AnsiConsole.WriteLine($"I agree. {fruit} is tasty!");

Can we expect to be able to preview each fruit as a sixel image in the future?

@romero126
Copy link

Wouldn't it be better to leverage some sort of framebuffer in between and then render it after it gets drawn?
If so maybe use https://github.com/romero126/PSConsoleGL instead? (Its my repo but aligns pretty good here)

@patriksvensson
Copy link
Contributor

@romero126 Great idea but we don't take any dependencies for this library except ones that we control directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ top pull request Top pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Sixel Support
5 participants