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

Simplified examples. #537

Closed
lscoughlin opened this issue May 26, 2020 · 2 comments
Closed

Simplified examples. #537

lscoughlin opened this issue May 26, 2020 · 2 comments
Milestone

Comments

@lscoughlin
Copy link

Can we get some simplified examples?

Right now, Example.java is huge and somewhat difficult to follow structure.

The API is a bit quirky and highly opinionated as it is... trying to unravel what all the bits do is proving more than a little challenging.

@mattirn
Copy link
Collaborator

mattirn commented May 26, 2020

I agree in Example has remain also some outdated code. I will update it in near future.

There are other three example JLine apps: gogo, groovy-repl and graal. If you are looking something very simple to start with I will add here also a minimal JLine repl example:

import java.io.IOException;

import org.jline.reader.EndOfFileException;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.UserInterruptException;
import org.jline.reader.impl.DefaultParser;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;

public class SimpleExample {

    public static void main(String[] args) throws IOException {
        Terminal terminal = TerminalBuilder.builder().build();
        DefaultParser parser = new DefaultParser();
        LineReader reader = LineReaderBuilder.builder()
                .terminal(terminal)
                .parser(parser)
                .build();
        while (true) {
            try {
                String line = reader.readLine("prompt > ");
                System.out.println(line);
            } catch (UserInterruptException e) {
                // Ignore
            } catch (EndOfFileException e) {
                return;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

@mattirn mattirn closed this as completed in d31b678 Jun 2, 2020
@mattirn mattirn added this to the 3.15.1 milestone Jun 2, 2020
@mattirn
Copy link
Collaborator

mattirn commented Jul 11, 2020

Example.java has been split in two.
Now usage of widgets, auto suggestions, object highlight printing and other advanced console features can be found at Console.java

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

No branches or pull requests

2 participants