From aae0b4d9999dc973bc6a13e3f2402544ed08833f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 24 Nov 2019 00:25:47 +0100 Subject: [PATCH] fix image rendering --- go.mod | 2 +- go.sum | 2 ++ mdr.go | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index fff66e8..e5b68d9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/MichaelMure/mdr go 1.12 require ( - github.com/MichaelMure/go-term-markdown v0.0.0-20191123220412-7c8717fe60b9 + github.com/MichaelMure/go-term-markdown v0.0.0-20191123232303-eda6491f3738 github.com/alecthomas/chroma v0.6.6 // indirect github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 // indirect github.com/awesome-gocui/gocui v0.6.0 diff --git a/go.sum b/go.sum index c95b57b..9fc092e 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0= github.com/MichaelMure/go-term-markdown v0.0.0-20191123220412-7c8717fe60b9 h1:P0rAeOsd1ceUMx52JSyh/sXTzOPz0I9La34rJKrAA7k= github.com/MichaelMure/go-term-markdown v0.0.0-20191123220412-7c8717fe60b9/go.mod h1:BwI1DYmYkEcaD98TuJN5y3CupnQ4Qjvv4x3g2Qh0yXk= +github.com/MichaelMure/go-term-markdown v0.0.0-20191123232303-eda6491f3738 h1:aI1p3Hzj7imnDxRLKHnINezqqt0pxrMkICdmWGEvDaE= +github.com/MichaelMure/go-term-markdown v0.0.0-20191123232303-eda6491f3738/go.mod h1:BwI1DYmYkEcaD98TuJN5y3CupnQ4Qjvv4x3g2Qh0yXk= github.com/MichaelMure/go-term-text v0.2.1 h1:6axyQDcdH8haB+TuxnhXzkvIO+JrQL1sZtGB1vC62zs= github.com/MichaelMure/go-term-text v0.2.1/go.mod h1:vgMpuXPXAhBYN8buVKg8XrLVQ5xp6JYRRZs8bnmPa0I= github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= diff --git a/mdr.go b/mdr.go index f676f5d..bfffaf0 100644 --- a/mdr.go +++ b/mdr.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "path" "github.com/MichaelMure/go-term-markdown" "github.com/awesome-gocui/gocui" @@ -31,6 +32,10 @@ func main() { if err != nil { exitError(errors.Wrap(err, "error while reading file")) } + err = os.Chdir(path.Dir(os.Args[1])) + if err != nil { + exitError(err) + } content = data default: @@ -152,7 +157,13 @@ func (ui *ui) layout(g *gocui.Gui) error { func (ui *ui) render(g *gocui.Gui) []byte { maxX, _ := g.Size() - rendered := markdown.Render(ui.raw, maxX-1-padding, padding) + + opts := []markdown.Options{ + // needed when going through gocui + markdown.WithImageDithering(markdown.DitheringWithBlocks), + } + + rendered := markdown.Render(ui.raw, maxX-1-padding, padding, opts...) ui.lines = 0 for _, b := range rendered { if b == '\n' {