-
Notifications
You must be signed in to change notification settings - Fork 189
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(image): basic iTerm image protocol support #196
base: master
Are you sure you want to change the base?
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-0a12aed65d12 main.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
=============================================
![Image](./alice.jpg) 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. |
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
TestImageDisplay
in glamour_test.go .I'm happy to integrate any modification from the maintainers into my code.