Skip to content
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

Pretty print output #68

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/jid/jid.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ func main() {
var help bool
var version bool
var mono bool
var pretty bool
qs := "."

flag.BoolVar(&qm, "q", false, "Output query mode")
flag.BoolVar(&help, "h", false, "print a help")
flag.BoolVar(&help, "help", false, "print a help")
flag.BoolVar(&version, "version", false, "print the version and exit")
flag.BoolVar(&mono, "M", false, "monochrome output mode")
flag.BoolVar(&pretty, "p", false, "pretty print json result")
flag.Parse()

if help {
Expand All @@ -44,6 +46,7 @@ func main() {
ea := &jid.EngineAttribute{
DefaultQuery: qs,
Monochrome: mono,
PrettyResult: pretty,
}

e, err := jid.NewEngine(content, ea)
Expand Down
18 changes: 14 additions & 4 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ type Engine struct {
candidateidx int
contentOffset int
queryConfirm bool
prettyResult bool
}

type EngineAttribute struct {
DefaultQuery string
Monochrome bool
PrettyResult bool
}

func NewEngine(s io.Reader, ea *EngineAttribute) (EngineInterface, error) {
Expand All @@ -58,6 +60,7 @@ func NewEngine(s io.Reader, ea *EngineAttribute) (EngineInterface, error) {
candidateidx: 0,
contentOffset: 0,
queryConfirm: false,
prettyResult: ea.PrettyResult,
}
e.queryCursorIdx = e.query.Length()
return e, nil
Expand Down Expand Up @@ -158,11 +161,18 @@ func (e *Engine) Run() EngineResultInterface {
e.escapeCandidateMode()
case termbox.KeyEnter:
if !e.candidatemode {
cc, _, _, err := e.manager.Get(e.query, true)
var cc string
var err error
if e.prettyResult {
cc, _, _, err = e.manager.GetPretty(e.query, true)
}else{
cc, _, _, err = e.manager.Get(e.query, true)
}

return &EngineResult{
content: cc,
qs: e.query.StringGet(),
err: err,
content: cc,
qs: e.query.StringGet(),
err: err,
}
}
e.confirmCandidate()
Expand Down