-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: kitty graphics inline (doesn't rely on kitten icat) #38 #39
Conversation
I need to heavily test this on both ghostty and Konsole, since its past midnight i will leave the reviewing & testing for the weekend. I will get to this as soon as i can. |
Sounds good! |
@MillerApps Hello again, I just got around to testing this and although it works it still has a flaw which i was expecting. It does not resize to fit the terminal dimensions, here is an example below of This was one of the reasons i chose to let SuggestionWhat i suggest instead is to implement this feature behind a experimental
Then resize the image with the following dependency ( if you find a good way to do it without any external dep that would be better, but resizing is a bit tricky) : func Scale(src image.Image, rect image.Rectangle, scale draw.Scaler) image.Image {
dst := image.NewRGBA(rect)
scale.Scale(dst, rect, src, src.Bounds(), draw.Over, nil)
return dst
} If you have any suggestions please do tell. |
@Achno In that case I agree we should add this as an experimental feature for now. I'll make the changes for that and then work on the resizing issue, in order to make this the default. |
@Achno, we could do this ( edit: we could also simply get the window size and do some easy math to get the values for |
Limiting the frame size on hard coded values is a no. Now as for the getting the window size and calculating |
If it can be done with ANSI escape codes without syscalls (which it probably can be done since you are communicating with the terminal by read/write on |
@Achno based on my understanding from the kitty docs either way it seems like |
yea i just read the docs you are right tty, err := os.OpenFile("/dev/tty", os.O_WRONLY, 0)
defer tty.Close()
buffer := make([]byte, 1024)
n, err := tty.Read(buffer) // read the response
// parsing ... Well for now use the dependency and get the image dimensions and see if it works and the images get resized correctly. |
@Achno I already have committed to trying |
@MillerApps |
@Achno I have something that I think is about what you wanted. I just pushed the changes. It does seem we still need to use Edit: No worries about the micromanaging; this is your project, so it's all good. We can always improve on my implementation as the project grows. |
Hey @MillerApps i got bad news man, the We have to scrap this implementation and go with your original implementation and forget about resizing for now. This PR will serve as a guide of how to improve the feature in the future. Now if we forget the windows thingy, it's still not 100% ready. The images appear a bit to the right (its not centered) not utilizing some columns from the left. tweeking In conclusion we cant have it replace Closing... |
@Achno, well that sucks, but it's not a total loss. I honestly never even think of Windows for these types of things. After not using Windows for almost 20 years, I forget others do, so my bad there. As for the slight shift to the right, that was intentional with the |
oh thanks for telling me.
Well i mean, we have a 90% template of how to do it, we just need to get the terminal dimensions another way, im sure we will figure that out at some point. It's just instead of replacing icat right away it needs more time.
You aren't alone lol, i completely forgot too, i haven't used windows for 6 years. i just happened to run github actions locally for building all binaries as i always do before any update and when i expected everything to be fine, windows gave me the middle finger. But i can't break gowall for anyone using it in windows for a feature |
@Achno, all fair points. What if we used |
i actually tried that yesterday to see if it works, and it actually works ( in getting I will use your original implementation and refactor the terminal parts in the We can then experiment with that branch. I will tag you when its done. |
@Achno sounds like a plan. |
@Achno, we could also use build constraints if we don't need the inline support on Windows. |
Okay https://github.com/Achno/gowall/tree/img-preview has been made along with the changes. InlineImagePreview: true
yeaaa.. i'd rather not deal with that, believe me it wont have a good end, it complicates things a lot |
fair enough, still new to Go myself. So kinda learning as I go. |
Okay i managed to find a way. if we use func getTerminalSize() (width, height int, err error) {
// Open /dev/tty for Linux & MacOS , CONOUT$ on Windows
tty, err := os.OpenFile("CONOUT$", os.O_RDWR, 0)
if err != nil {
tty, err = os.OpenFile("/dev/tty", os.O_RDWR, 0)
if err != nil {
return 0, 0, fmt.Errorf("failed to open terminal: %v", err)
}
}
defer tty.Close()
fd := int(tty.Fd())
// Switch to raw mode and ensure it gets restored
oldState, err := term.MakeRaw(fd)
if err != nil {
return 0, 0, fmt.Errorf("failed to set raw mode: %v", err)
}
defer term.Restore(fd, oldState)
// query the terminal for its dimensions via ANSI escape codes
if _, err := tty.Write([]byte("\033[18t")); err != nil {
return 0, 0, fmt.Errorf("failed to write to terminal: %v", err)
}
// Read response with a timeout
response := make([]byte, 30)
tty.SetReadDeadline(time.Now().Add(500 * time.Millisecond))
n, err := tty.Read(response)
if err != nil {
return 0, 0, fmt.Errorf("failed to read terminal response: %v", err)
}
// Parse format: ESC [ 8 ; height ; width t)
pattern := regexp.MustCompile(`\033\[8;(\d+);(\d+)t`)
matches := pattern.FindStringSubmatch(string(response[:n]))
if len(matches) == 3 {
height, _ = strconv.Atoi(matches[1])
width, _ = strconv.Atoi(matches[2])
return width, height, nil
}
return 0, 0, fmt.Errorf("unexpected terminal response: %q", string(response[:n]))
} we get : I'm going to leave it at that for the day its 1 hour before midnight now we just need to add the other code you made and boom... hopefully it works |
Adds basic inline image previews that no longer use
kitten icat
Tested and working in Ghostty. I'm on macOS, so I have not tested it in Konsole. Based on Konsole being listed as supported here, my assumption is that it should work like Ghostty.
closes #38