feat(image): basic iTerm image protocol support#196
feat(image): basic iTerm image protocol support#196panda2134 wants to merge 1 commit intocharmbracelet:masterfrom
Conversation
This commit implements the functions in issue charmbracelet#175. Currently, only the iTerm image protocol is supported. Some code from muesli/reflow is copied manually patched, so wrapping and indentation will not interfere with the iTerm escape sequence (which is not quite the same as the ANSI sequences) This functionality is only enabled if you pass `WithImageDisplay()` when creating a new TermRenderer. I have verified that it works under WezTerm. If the terminal is not supported, it will automatically switch to the old rendering mode of images as fallback. For more details, please see `TestImageDisplay` in glamour_test.go .
|
This shall close #175 if merged. |
|
Hey. I've been testing this with WezTerm, even going as far as setting Unfortunately, it doesn't display the expected result but rather just the file name. go.mod require github.com/charmbracelet/glamour v0.6.0
replace github.com/charmbracelet/glamour => github.com/panda2134/glamour v0.0.0-20221019190525-0a12aed65d12main.go package main
import (
"fmt"
"os"
"github.com/charmbracelet/glamour"
)
// TODO: Add proper syslogging
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
fileName := os.Args[1:]
file, err := os.ReadFile(fileName[0])
check(err)
os.Setenv("TERM_PROGRAM", "iterm.app")
r, _ := glamour.NewTermRenderer(
glamour.WithStandardStyle("dark"),
glamour.WithImageDisplay(),
)
// TODO: Find a way to add padding (<br/>) between bullet points
out, _ := r.Render(string(file))
fmt.Print(out)
}test.md Alice(1) -- A modern manpage viewer alternative
=============================================
I previously checked that WezTerm's iTerm2 image support works through the imgcat tool by olivere (which it does). |
Hi! Please look at |
Thanks for looking into it. |
I figured it out finally. You need to set the BaseURL in glamour like this: After correctly setting the BaseURL (ending with "/") you'll see the image rendered. I probably forgot to mention this requirement, sorry for that. |
Looks like we figured it out at the exact same time. Hehe. |
|
if the repo owner is still interested in this pr, I'll be happy to fix those conflicts. |
|
are there any updates for this? is kitty support in the roadmap? |
This commit implements the function requested in issue #175.
Currently, only the iTerm image protocol is supported. Some code from muesli/reflow is copied & manually patched, so wrapping and indentation will not interfere with the iTerm escape sequence (which is not quite the same as the ANSI sequences)
This functionality is only enabled if you pass
WithImageDisplay()when creating a new TermRenderer. You also need to specify the BaseURL withWithBaseURL(path), where path ends with a slash.I have verified that it works under WezTerm. If the terminal is not supported, it will automatically switch to the old rendering mode of images as fallback.
For more details, please see
TestImageDisplayin glamour_test.go .I'm happy to integrate any modification from the maintainers into my code.