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

Inline Previews #38

Open
MillerApps opened this issue Feb 21, 2025 · 4 comments
Open

Inline Previews #38

MillerApps opened this issue Feb 21, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@MillerApps
Copy link
Contributor

It seems the inline image previews rely solely on Kitty being installed for Ghostty and Konsole. However, I think it is best to use the built-in support for the Kitty image protocol, at least in the case of Ghostty. A basic implementation would be something like:

package utils

import (
	"encoding/base64"
	"fmt"
	"io"
	"os"
)

// SendKittyImg sends a file as a Kitty protocol inline image without any extra output.
// The escape sequence is formatted per the spec: begins with ESC _ G, parameters terminated with a semicolon,
// then the base64 data, and finally terminated with ESC \.
func SendKittyImg(filePath string) error {
	// Open the file.
	f, err := os.Open(filePath)
	if err != nil {
		return err
	}
	defer f.Close()

	// Begin the inline image sequence
	fmt.Printf("\x1b_Gf=100,a=T;")
	
	// Base64-encode the file contents directly to stdout.
	encoder := base64.NewEncoder(base64.StdEncoding, os.Stdout)
	if _, err := io.Copy(encoder, f); err != nil {
		return err
	}
	encoder.Close()

	// Terminate the escape sequence
	fmt.Printf("\x1b\\\n")
	return nil
}
func IsGhosttyTerminalRunning() bool {

	terminal := os.Getenv("TERM")

    if strings.Contains(terminal, "ghostty") {
        return true
    }

	return false
}

The issue I ran into is this only works on gowall -w something breaks when modifying an image then trying to the same code does nothing, unlike with kitten icat. I'd be willing to work on this when I have time unless you already know what I am missing.

@Achno
Copy link
Owner

Achno commented Feb 21, 2025

Hello @MillerApps ,

By all means, if you're interested in working on it, go for it, it would be great because i'm also not that keen on relying on kitten icat for other terminals.

Right now i'm focused on fixing bugs , polishing and refactoring gowall as you can see from the latest commits so i can't really invest much time for this enhancement. After refactoring i have to plan to add the main big features for the next release too.

@Achno Achno added the enhancement New feature or request label Feb 21, 2025
@MillerApps
Copy link
Contributor Author

@Achno I'll take it on and see if I can figure it out. No idea on a timeline but I have a starting point.

@Achno
Copy link
Owner

Achno commented Feb 21, 2025

@MillerApps

No worries and above all no pressure :)

@MillerApps
Copy link
Contributor Author

@Achno Definitely a good way to learn something new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants