Skip to content

Commit

Permalink
Display raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
yunabe committed May 27, 2018
1 parent 6fb07fe commit 1df8ecd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cmd/lgo-internal/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"log"
Expand All @@ -16,8 +17,8 @@ import (
"github.com/golang/glog"
"github.com/yunabe/lgo/cmd/lgo-internal/liner"
"github.com/yunabe/lgo/cmd/runner"
"github.com/yunabe/lgo/core"
"github.com/yunabe/lgo/converter"
"github.com/yunabe/lgo/core"
scaffold "github.com/yunabe/lgo/jupyter/gojupyterscaffold"
)

Expand Down Expand Up @@ -99,6 +100,19 @@ func (d jupyterDisplayer) display(data *scaffold.DisplayData, id *string) {
d(data, update)
}

func (d jupyterDisplayer) Raw(contentType string, v interface{}, id *string) error {
_, err := json.Marshal(v)
if err != nil {
return err
}
d.display(&scaffold.DisplayData{
Data: map[string]interface{}{
contentType: v,
},
}, id)
return nil
}

func (d jupyterDisplayer) displayString(contentType, content string, id *string) {
d.display(&scaffold.DisplayData{
Data: map[string]interface{}{
Expand Down Expand Up @@ -250,7 +264,7 @@ func (*handlers) HandleGoFmt(req *scaffold.GoFmtRequest) (*scaffold.GoFmtReply,
}
return &scaffold.GoFmtReply{
Status: "ok",
Code: formatted,
Code: formatted,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type DataDisplayer interface {
GIF(b []byte, id *string)
PDF(b []byte, id *string)
Text(s string, id *string)
Raw(contentType string, v interface{}, id *string) error
}

type resultCounter struct {
Expand Down

0 comments on commit 1df8ecd

Please sign in to comment.