Skip to content

Commit

Permalink
fix image rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Nov 23, 2019
1 parent 001a66f commit aae0b4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
13 changes: 12 additions & 1 deletion mdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"

"github.com/MichaelMure/go-term-markdown"
"github.com/awesome-gocui/gocui"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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' {
Expand Down

0 comments on commit aae0b4d

Please sign in to comment.