gdamore / tcell

Tcell is an alternate terminal package, similar in some ways to termbox, but better in others.
Apache License 2.0
4.57k stars 309 forks source link

imgcat support #346

Closed rigelrozanski closed 4 years ago

rigelrozanski commented 4 years ago

Okay. So iterm2 has this feature where you can send images bytes through stdout and it will be rendered as images. martinlindhe ported over the this structure to golang here: https://github.com/martinlindhe/imgcat The core of this process: https://github.com/martinlindhe/imgcat/blob/master/lib/imgcat.go#L43

My application which I've been (quite happily) building on tcell involves displaying graphs from time to time but braille-character graphs are simply not cutting it for me right now - my hope is to display graphs from images ontop of my tcell application layer.

It would be incredible to be able to extend tcell to have imgcat support either through directly building in this feature within tcell (or a fork of tcell), or alternatively building a way to exposed the or buf/out within the Screen interface such that a user like myself could extend tcell without having to fork.

@gdamore any thoughts?

If there is interest in having this feature in tcell, I'm more than willing to contribute to its development!


edit: (brainstorming)

The code can really be boiled down to:

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

func main() {
    r, err := os.Open("yourimagehere.png")
    if err != nil {
        panic(fmt.Sprintf("debug err: %v\n", err))
    }
    bz, err := ioutil.ReadAll(r)
    if err != nil {
        panic(fmt.Sprintf("debug err: %v\n", err))
    }
    fmt.Printf("\033]1337;File=;inline=1:%s\a\n", base64.StdEncoding.EncodeToString(bz))
}

So ultimately all that would need to occur is a way to send an entire string to a particular coordinate when performing the final writes as opposed to just the standard rune

rigelrozanski commented 4 years ago

nm - figured out how to do this with the kitty terminal image protocol - it's really cool and I can just overlay it over everything else!

farzadmf commented 3 years ago

@rigelrozanski do you have a sample code how to do what you mentioned?

flber commented 1 year ago

@rigelrozanski It's been a few years now, but I could definitely also use an example of how to do exactly what you're talking about! I've been trying to extend an application built on tcell to use the kitty image protocol, but I can't figure out how it should mesh with tcell.