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

TerminalBuilder.system(false).dumb(true) does not give a DumbTerminal. Is this working as intended? #979

Closed
dattasid opened this issue May 10, 2024 · 3 comments
Milestone

Comments

@dattasid
Copy link
Contributor

Jline version 3.26.1
JDK : 11.0.23

Java code:

import org.jline.terminal.Terminal;                                                  
import org.jline.terminal.TerminalBuilder;                                           
                                                                                     
public class jt {                                                                    
  public static void main(String[] args) throws Exception                            
    {                                                                                
      TerminalBuilder builder = TerminalBuilder.builder()                            
        .type("dumb")                                                                
        .dumb(true)                                                                  
        .system(false)                                                               
        .streams(System.in, System.out);                                             
      System.out.println(builder.build());                                           
    }                                                                                
}

Execute:

$ java -cp ./jline3-jline-parent-3.26.1/jline/target/jline-3.26.1.jar:. --add-opens java.base/java.io=ALL-UNNAMED jt
org.jline.terminal.impl.PosixPtyTerminal@4b1c1ea0

Note: I will get a DumbTerminal if I set system(true), but then I get occasional terminal codes in the output.

@gnodet
Copy link
Member

gnodet commented May 13, 2024

The dumb, jna, jansi, jni, exec and ffm methods on the TerminalBuilder are meant to enable/disable a given provider, not force its usage. If you want to force the use of a given provider, you can use builder.provider("jni") for example.
The dumb provider can only create a system terminal, so if you specify system(false), the dumb provider won't be used.

The ansi sequences appearing with a dumb terminal should be fixed, so do not hesitate to raise issues for those.

What's your use case exactly ? You usually don't really always want a dumb terminal...

@dattasid
Copy link
Contributor Author

My CLI can be used in interactive mode or be fed a file cli < in > out .

When I see that System.console() == null, I assume that the cli is reading from a file. So I try to use a dumb terminal. This is because when I started using JLine 3, other terminals would print console codes in the output file.

I also had to set terminal.setSize(10000,10000) so that even dumb terminal does not output control codes when reaching the end of the supposed screen. Now that dumb terminal is always a system terminal, it is now ignoring the size I set. I am seeing console codes in the output file.

Is there a terminal which knows if we are reading from and/or writing to a file, and disables all control characters ?

PS: As a separate issue, I see that JLine behaves badly when size is set to (0,0). This is possible if stty is set up badly and returns lines 0 columns 0. JLine should assume sane values (maybe 24,80) when it sees invalid values like (0,0) . I think the code is ExecPty.getSize(), but I havent tested a fix.

I also see some issues with JLine on serial port like ttyS0 , Do you have a system where you can test ttyS0 ?

@gnodet
Copy link
Member

gnodet commented May 16, 2024

My CLI can be used in interactive mode or be fed a file cli < in > out .

When I see that System.console() == null, I assume that the cli is reading from a file. So I try to use a dumb terminal. This is because when I started using JLine 3, other terminals would print console codes in the output file.

The TerminalBuilder is supposed to handle that. It will create a real terminal if the input stream is connected to the terminal and if either the output or error stream is connected. On output, you can force the selection by configuring

public TerminalBuilder systemOutput(SystemOutput systemOutput) {

I also had to set terminal.setSize(10000,10000) so that even dumb terminal does not output control codes when reaching the end of the supposed screen. Now that dumb terminal is always a system terminal, it is now ignoring the size I set. I am seeing console codes in the output file.

Is there a terminal which knows if we are reading from and/or writing to a file, and disables all control characters ?

The dumb terminal is supposed to. Anything else is a bug.

PS: As a separate issue, I see that JLine behaves badly when size is set to (0,0). This is possible if stty is set up badly and returns lines 0 columns 0. JLine should assume sane values (maybe 24,80) when it sees invalid values like (0,0) . I think the code is ExecPty.getSize(), but I havent tested a fix.

Ok, that may need a fix too.

I also see some issues with JLine on serial port like ttyS0 , Do you have a system where you can test ttyS0 ?

Not sure how I could do that...

@gnodet gnodet closed this as completed in 49b0aa8 May 21, 2024
@gnodet gnodet added this to the 3.26.2 milestone Jun 4, 2024
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

2 participants