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

Dumb terminal when piping input to console app disallows ANSI formatting #299

Closed
bdw429s opened this issue Aug 7, 2018 · 2 comments
Closed
Milestone

Comments

@bdw429s
Copy link
Contributor

bdw429s commented Aug 7, 2018

When I pipe input to CommandBox like so:

echo myCommand | box.exe

Then the JLine uses a dumb terminal which prevents the commands from using any ANSI formatting, even though I may be running inside of a terminal that is fully capable of 256 colors, etc. It is correct that JLIne uses a dumb terminal in this situation?

@gnodet
Copy link
Member

gnodet commented Aug 7, 2018

No, I think the problem comes from the fact that JLine does not support having 2 different terminal types for the input and the output. In your case, the input is not a real terminal, but the output is.
The actual problem is located at:
https://github.com/jline/jline3/blob/master/terminal/src/main/java/org/jline/utils/AttributedCharSequence.java#L46-L48

@mattirn
Copy link
Collaborator

mattirn commented Nov 7, 2020

JLine TerminalBuilder will create dumb-color terminal when redirecting input, the output stream is connected to terminal and the enviroment variable TERM is set. Does not work an EXEC based terminals -you need to have JNA or Jansi lib in your classpath.

@mattirn mattirn mentioned this issue Dec 11, 2020
ldziedziul added a commit to hazelcast/hazelcast that referenced this issue Jun 20, 2023
…ut/output (#24855)

Allow for a dumb terminal as a fallback if no system terminal detected
in the hz-cli input or output.

Fixes: https://hazelcast.atlassian.net/browse/HZ-2610

Also see:
- jline/jline3#291 (comment)
- jline/jline3#299

Testing:
- build local docker image using script
(https://hazelcast.slack.com/archives/C01MH9KF1QT/p1657111661829299):
`DOCKER_TAG=test ./build-docker-image.sh`
- run the container: `docker run -it --rm --name hz-test hazelcast:test`
- start container shell: `docker exec -it hz-test sh`
- exec hz-cli with piped input: `echo exit\n | hz-cli sql`

Before:
```
$ docker exec -it hz-test sh
/opt/hazelcast $ echo exit\n | hz-cli sql
10:45:18.310 [ WARN] [o.jline] Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
Connected to Hazelcast 5.3.0 at [172.17.0.2]:5701 (+0 more)
Type 'help' for instructions
sql> Exiting from SQL console
```


After: no jline warning
```
$ docker exec -it hz-test sh
/opt/hazelcast $ echo exit\n | hz-cli sql
Connected to Hazelcast 5.4.0 at [172.17.0.3]:5701 (+0 more)
Type 'help' for instructions
sql> Exiting from SQL console
```


Breaking changes (list specific methods/types/messages):
* API
* client protocol format
* serialized form
* snapshot format

Checklist:
- [x] Labels (`Team:`, `Type:`, `Source:`, `Module:`) and Milestone set
- [x] Label `Add to Release Notes` or `Not Release Notes content` set
- [x] Request reviewers if possible
- [x] Send backports/forwardports if fix needs to be applied to
past/future releases
- [x] New public APIs have `@Nonnull/@Nullable` annotations
- [x] New public APIs have `@since` tags in Javadoc
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

No branches or pull requests

3 participants