Skip to content

Conversation

ottok
Copy link
Contributor

@ottok ottok commented Jul 26, 2025

The Go library gohxs/readline has no commits for past 8 years. It was originally forked from chzyer/readline, which continues to be maintained, so switch back to it to ensure continued maintenance and updates.

This change necessitated adapting the output filtering mechanism due to API incompatibilities that manifested as errors:

rline/rline.go:128:16: l.Inst.Config.Output undefined (type *readline.Config has no field or method Output)

rline/rline.go:130:7: cfg.FuncFilterOutput undefined (type *readline.Config has no field or method FuncFilterOutput)

Specifically, the readline.Config no longer provides direct output fields or filter functions. To address this, implement a filterWriter to wrap the standard output stream, ensuring existing output filtering functionality is preserved.

Closes: #528

The Go library `gohxs/readline` has no commits for past 8 years. It was
originally forked from `chzyer/readline`, which continues to be
maintained, so switch back to it to ensure continued maintenance and
updates.

This change necessitated adapting the output filtering mechanism due to
API incompatibilities that manifested as errors:

    rline/rline.go:128:16: l.Inst.Config.Output undefined (type *readline.Config has no field or method Output)

    rline/rline.go:130:7: cfg.FuncFilterOutput undefined (type *readline.Config has no field or method FuncFilterOutput)

Specifically, the `readline.Config` no longer provides direct output
fields or filter functions. To address this, implement a `filterWriter`
to wrap the standard output stream, ensuring existing output filtering
functionality is preserved.

Closes: xo#528
@ottok
Copy link
Contributor Author

ottok commented Jul 26, 2025

CI failed without error messages:

  go run testcli.go &> output.log
  ls -alh output.log
  shell: /usr/bin/bash -e {0}
Error: Process completed with exit code 1.

@kenshaw
Copy link
Member

kenshaw commented Jul 26, 2025

I just tested this, it doesn't work with syntax highlighting, which basically makes this a no-go, as I personally made this project for 2 reasons: 1) to have a tool to use for all SQL databases with the xo/dbtpl project, and 2) syntax highlighting, as psql (and every other native SQL CLI I've used), doesn't support syntax highlighting.

@ottok
Copy link
Contributor Author

ottok commented Jul 26, 2025

According to chzyer/readline#116 the capability to syntax highlight was merged into Chyzer's version and that is probably also why the gohxs version seized to be maintained?

Comment on lines +154 to +161
var currentWriter io.WriteCloser
if f != nil {
// Wrap the original stdout with the filter
currentWriter = &filterWriter{writer: l.originalStdout, filter: f}
} else {
// If filter is nil, revert to the original stdout
currentWriter = l.originalStdout
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to write this this way

Suggested change
var currentWriter io.WriteCloser
if f != nil {
// Wrap the original stdout with the filter
currentWriter = &filterWriter{writer: l.originalStdout, filter: f}
} else {
// If filter is nil, revert to the original stdout
currentWriter = l.originalStdout
}
var currentWriter io.WriteCloser
// use original stdout by default
currentWriter = l.originalStdout
if f != nil {
// Wrap the original stdout with the filter
currentWriter = &filterWriter{writer: l.originalStdout, filter: f}
}

What to you think?

@ottok
Copy link
Contributor Author

ottok commented Jul 26, 2025

Thanks @ccoVeille for the suggestion, but based on Ken's comment I think we need to have confirmation on the syntax highlightning issue chzyer/readline#253 before it makes sense to polish the syntax on this change, as otherwise it won't be accepted anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using readline library from github.com/chzyer/readline
3 participants