com.googlecode.lanterna.terminal.Terminal Java Examples

The following examples show how to use com.googlecode.lanterna.terminal.Terminal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrawRectangle.java    From lanterna with GNU Lesser General Public License v3.0 7 votes vote down vote up
public static void main(String[] args) throws IOException {
	Terminal terminal = new DefaultTerminalFactory().createTerminal();
	Screen screen = new TerminalScreen(terminal);

	TextGraphics tGraphics = screen.newTextGraphics();

	screen.startScreen();
	screen.clear();

	tGraphics.drawRectangle(
		new TerminalPosition(3,3), new TerminalSize(10,10), '*');
	screen.refresh();

	screen.readInput();
	screen.stopScreen();
}
 
Example #2
Source File: SessionStatePrinter.java    From bt with Apache License 2.0 6 votes vote down vote up
public SessionStatePrinter() {
    try {
        Terminal terminal = new DefaultTerminalFactory(System.out, System.in,
                StandardCharsets.UTF_8).createTerminal();
        terminal.setCursorVisible(false);

        screen = new TerminalScreen(terminal);
        graphics = screen.newTextGraphics();
        screen.startScreen();
        clearScreen();

        started = System.currentTimeMillis();

        this.torrent = Optional.empty();
        printTorrentInfo();
    } catch (IOException e) {
        throw new RuntimeException("Failed to create terminal", e);
    }
}
 
Example #3
Source File: FancyChooser.java    From apdu4j with MIT License 6 votes vote down vote up
private FancyChooser(Terminal terminal, Screen screen, CardTerminals monitorObject, List<CardTerminal> terminals) {
    if (monitorObject != null)
        monitor = new MonitorThread(monitorObject);
    else monitor = null;
    this.terminal = terminal;
    this.screen = screen;
    gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
    this.initialList = terminals;
    // Create UI elements
    mainWindow = new BasicWindow(" apdu4j ");
    mainWindow.setCloseWindowWithEscape(true);
    mainWindow.setHints(Arrays.asList(Window.Hint.FIT_TERMINAL_WINDOW, Window.Hint.CENTERED));

    mainPanel = new Panel();
    mainPanel.setLayoutManager(new BorderLayout());
    mainPanel.setLayoutManager(new LinearLayout(Direction.VERTICAL));
    mainActions = new ActionListBox();
    mainActions.setLayoutData(BorderLayout.Location.CENTER);
    mainPanel.addComponent(mainActions);
    mainPanel.addComponent(new EmptySpace(new TerminalSize(0, 1)));
    quitButton = new Button("Cancel and quit", () -> mainWindow.close());
    quitButton.setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.End));
    mainPanel.addComponent(quitButton);
    //mainPanel.setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.End));
    mainWindow.setComponent(mainPanel);
}
 
Example #4
Source File: Issue358.java    From lanterna with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();
    MultiWindowTextGUI textGUI = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));

    String title = "Issue358";

    int nbColumns = 5;
    final Window window = new BasicWindow(title);

    final GridLayout layoutManager = new GridLayout(nbColumns);
    layoutManager.setVerticalSpacing(0);
    layoutManager.setHorizontalSpacing(1);
    final Panel contentPanel = new Panel(layoutManager);
    contentPanel.addComponent(
            new EmptySpace(TextColor.ANSI.CYAN).setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.CENTER, GridLayout.Alignment.CENTER, false, false,3, 1)));
    window.setComponent(contentPanel);
    textGUI.addWindowAndWait(window);
}
 
Example #5
Source File: Issue312.java    From lanterna with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    TextGraphics textGraphics = terminal.newTextGraphics();
    int row = 0;
    while(true) {
        KeyStroke keyStroke = terminal.pollInput();
        if (keyStroke == null) {
            terminal.setCursorPosition(0, 0);
            textGraphics.putString(0, terminal.getCursorPosition().getRow(), " > ");
            terminal.flush();
            keyStroke = terminal.readInput();
            row = 1;
            terminal.clearScreen();
        }
        if (keyStroke.getKeyType() == KeyType.Escape || keyStroke.getKeyType() == KeyType.EOF) {
            break;
        }
        textGraphics.putString(0, row++, "Read KeyStroke: " + keyStroke + "\n");
        terminal.flush();
    }
    terminal.close();
}
 
Example #6
Source File: Issue392.java    From lanterna with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    DefaultTerminalFactory terminalFactory = new DefaultTerminalFactory();
    Terminal terminal = terminalFactory.createTerminal();
    TerminalScreen screen = new TerminalScreen(terminal);
    screen.startScreen();
    textGUI = new MultiWindowTextGUI(screen);
    setExceptionHandler();
    BasicWindow window = new BasicWindow();

    Button button = new Button("test");
    button.addListener(b -> {
        setExceptionHandler();
        throw new RuntimeException("This should be caught in the uncaght exception handler!");
    });
    window.setComponent(button);

    textGUI.addWindowAndWait(window);
    screen.stopScreen();
}
 
Example #7
Source File: Issue334.java    From lanterna with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    // Create panel to hold components
    Panel panel = new Panel();
    panel.setLayoutManager(new GridLayout(1));
    panel.addComponent(new Label(""));

    // Create gui and start gui
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));

    // Create window to hold the panel
    final BasicWindow window = new BasicWindow();
    window.setComponent(Panels.vertical(panel));
    window.setCloseWindowWithEscape(true);

    gui.addWindowAndWait(window);
    screen.stopScreen();
    terminal.close();
}
 
Example #8
Source File: TerminalScreen.java    From lanterna with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void useScrollHint() throws IOException {
    if (scrollHint == null) { return; }

    try {
        if (scrollHint == ScrollHint.INVALID) { return; }
        Terminal term = getTerminal();
        if (term instanceof Scrollable) {
            // just try and see if it cares:
            scrollHint.applyTo( (Scrollable)term );
            // if that didn't throw, then update front buffer:
            scrollHint.applyTo( getFrontBuffer() );
        }
    }
    catch (UnsupportedOperationException uoe) { /* ignore */ }
    finally { scrollHint = null; }
}
 
Example #9
Source File: OutputString.java    From lanterna with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
	Terminal terminal = new DefaultTerminalFactory().createTerminal();
	Screen screen = new TerminalScreen(terminal);

	String s = "Hello World!";
	TextGraphics tGraphics = screen.newTextGraphics();

	screen.startScreen();
	screen.clear();

	tGraphics.putString(10, 10, s);
	screen.refresh();

	screen.readInput();
	screen.stopScreen();
}
 
Example #10
Source File: TerminalTta3Orchestrator.java    From pen-test-automation with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    // Setup terminal and screen layers
    TerminalSize size = new TerminalSize(80,50);  // unsure how to do this.
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    /// ???.setPreferredSize(new TerminalSize(20, 5))

    try {
        screen.startScreen();
        TerminalTta3Orchestrator terminalTta3Orchestrator = new TerminalTta3Orchestrator(screen);
        terminalTta3Orchestrator.start();
    } finally {
        screen.stopScreen();
        terminal.close();
    }
}
 
Example #11
Source File: OutputChar.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
	Terminal terminal = new DefaultTerminalFactory().createTerminal();
	Screen screen = new TerminalScreen(terminal);

	screen.startScreen();
	screen.clear();

	screen.setCharacter(10, 10, new TextCharacter('*'));
	screen.refresh();

	screen.readInput();
	screen.stopScreen();
}
 
Example #12
Source File: Issue460.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    final BasicWindow window1 = new BasicWindow();
    Panel contentPanel = new Panel(new GridLayout(1));
    contentPanel.addComponent(new Label("VERTICAL"), GridLayout.createLayoutData(
            GridLayout.Alignment.CENTER,
            GridLayout.Alignment.CENTER,
            true,
            true,
            1,
            4
    ));
    contentPanel.addComponent(new Button("Close", new Runnable() {
        @Override
        public void run() {
            window1.close();
        }
    }), GridLayout.createHorizontallyFilledLayoutData(2));
    window1.setComponent(contentPanel);

    // Create gui and start gui
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen);
    gui.addWindowAndWait(window1);
    screen.stopScreen();
}
 
Example #13
Source File: Issue221.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {

        // Setup terminal and screen layers
        Terminal terminal = new DefaultTerminalFactory().createTerminal();
        Screen screen = new TerminalScreen(terminal);
        screen.startScreen();

        // Create panel to hold components
        Panel panel = new Panel();
        panel.setLayoutManager(new GridLayout(2));

        panel.addComponent(new Label("The List"));
        RadioBoxList<String> box = new RadioBoxList<>();
        box.addItem("Item 1");
        box.addItem("Item 2");
        box.addItem("Item 3");
        box.addListener((selected, previous) -> System.out.println("Selected Index: " + selected + ", previous: " + previous));

        panel.addComponent(box);

        // Create window to hold the panel
        BasicWindow window = new BasicWindow();
        window.setComponent(panel);

        // Create gui and start gui
        MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
        gui.addWindowAndWait(window);
    }
 
Example #14
Source File: Issue150.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String... args) throws IOException {
    Terminal term = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(term);
    WindowManager windowManager = new DefaultWindowManager();
    Component background = new EmptySpace(TextColor.ANSI.DEFAULT);
    final WindowBasedTextGUI gui = new MultiWindowTextGUI(screen, windowManager, background);
    screen.startScreen();
    gui.addWindowAndWait(new BasicWindow("Issue150") {{
        setComponent(createUi());
    }});
    screen.stopScreen();
}
 
Example #15
Source File: Issue313.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    BasicWindow window = new BasicWindow();
    window.setTitle("Hello World");

    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
    gui.addWindowAndWait(window);
}
 
Example #16
Source File: Issue254.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    // Now resize the window to the smallest possible size allowed by the window manager
    // Then quickly make it bigger by grabbing the bottom right corner
}
 
Example #17
Source File: Issue216.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    // Create panel to hold components
    Panel panel = new Panel();
    panel.setLayoutManager(new GridLayout(2));

    panel.addComponent(new Label("Forename"));
    panel.addComponent(new TextBox());

    panel.addComponent(new Label("Surname"));
    panel.addComponent(new TextBox());

    panel.addComponent(new Label("Table"));
    final Table<String> table = new Table<>("Test");
    final TableModel<String> tableModel = table.getTableModel();
    tableModel.addRow("hi");
    panel.addComponent(table);

    panel.addComponent(new EmptySpace(new TerminalSize(0,0))); // Empty space underneath labels
    panel.addComponent(new Button("Submit", () -> {
        tableModel.addRow("haiiii");
        //table.invalidate();
    }));

    // Create window to hold the panel
    BasicWindow window = new BasicWindow();
    window.setComponent(panel);

    // Create gui and start gui
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
    gui.addWindowAndWait(window);
}
 
Example #18
Source File: Issue446.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    DefaultTerminalFactory terminalFactory = new DefaultTerminalFactory();
    Terminal terminal = terminalFactory.createTerminal();
    TerminalScreen screen = new TerminalScreen(terminal);
    screen.startScreen();
    WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen);
    textGUI.addWindowAndWait(buildWindow());
}
 
Example #19
Source File: Issue78.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal t = new TestTerminalFactory(args).createTerminal();
    t.enterPrivateMode();
    TerminalScreen s = new TerminalScreen(t);
    s.startScreen();
    try {
        Thread.sleep(1000);
    }
    catch(InterruptedException e) {}
    s.stopScreen();
    t.exitPrivateMode();
}
 
Example #20
Source File: Issue261.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    // Create panel to hold components
    Panel panel = new Panel();
    panel.setLayoutManager(new GridLayout(2));

    panel.addComponent(new Label("Forename"));
    panel.addComponent(new TextBox());

    panel.addComponent(new Label("Surname"));
    panel.addComponent(new TextBox());

    panel.addComponent(new EmptySpace(new TerminalSize(0,0))); // Empty space underneath labels
    panel.addComponent(new Button("Submit"));

    // Create gui and start gui
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));

    // Create window to hold the panel
    BasicWindow window = new BasicWindow();
    window.setFixedSize(new TerminalSize(500, 700));
    window.setComponent(panel);

    gui.addWindowAndWait(window);
}
 
Example #21
Source File: Issue212.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    final Table<String> table = new Table<>("Column 1", "Column 2",
            "Column 3");
    table.getTableModel().addRow("1", "2", "3");
    table.getTableModel().addRow("1", "2", "3");
    table.getTableModel().addRow("1", "2", "3");
    table.getTableModel().addRow("1", "2", "3");
    table.getTableModel().addRow("1", "2", "3");
    table.setSelectAction(() -> {
        List<String> data = table.getTableModel().getRow(
                table.getSelectedRow());
        for (String aData : data) {
            System.out.println(aData);
        }
    });

    Window win = new BasicWindow();
    win.setComponent(table);

    DefaultTerminalFactory factory = new DefaultTerminalFactory();
    Terminal terminal = factory.createTerminal();

    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    // Create gui and start gui
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen,
            new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
    gui.addWindowAndWait(win);

    screen.stopScreen();
}
 
Example #22
Source File: Issue155.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String... args) throws IOException {
    Terminal term = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(term);
    WindowManager windowManager = new DefaultWindowManager();
    Component background = new EmptySpace(TextColor.ANSI.DEFAULT);
    final WindowBasedTextGUI gui = new MultiWindowTextGUI(screen, windowManager, background);
    screen.startScreen();
    gui.addWindowAndWait(new BasicWindow("Issue155") {{
        setComponent(createUi(gui, this));
    }});
    screen.stopScreen();
}
 
Example #23
Source File: Issue374.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();

    final BasicWindow window = new BasicWindow("FocusTraversalTest");
    window.setHints(Collections.singletonList(Window.Hint.FULL_SCREEN));
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen);

    Panel mainPanel = new Panel(new LinearLayout());
    window.setComponent(mainPanel);

    Button disabledInBorder1 = new Button("disabledB1");
    disabledInBorder1.setEnabled(false);
    mainPanel.addComponent(disabledInBorder1.withBorder(Borders.singleLine("border")));

    Button first = new Button("enabled");
    mainPanel.addComponent(first);

    Button disabled = new Button("disabled");
    disabled.setEnabled(false);
    mainPanel.addComponent(disabled);

    Button disabledInBorder2 = new Button("disabledB2");
    disabledInBorder2.setEnabled(false);
    mainPanel.addComponent(disabledInBorder2.withBorder(Borders.singleLine("border")));

    Button anotherFocusable = new Button("focusable");
    mainPanel.addComponent(anotherFocusable);

    mainPanel.addComponent(new Button("Button"));

    first.takeFocus();
    gui.addWindowAndWait(window);
}
 
Example #24
Source File: DefaultVirtualTerminalTest.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testVirtualTerminalListener() {
    final AtomicInteger flushCounter = new AtomicInteger(0);
    final AtomicInteger bellCounter = new AtomicInteger(0);
    final AtomicInteger resizeCounter = new AtomicInteger(0);
    final AtomicInteger closeCounter = new AtomicInteger(0);

    VirtualTerminalListener listener = new VirtualTerminalListener() {
        @Override
        public void onFlush() {
            flushCounter.incrementAndGet();
        }

        @Override
        public void onBell() {
            bellCounter.incrementAndGet();
        }

        @Override
        public void onResized(Terminal terminal, TerminalSize newSize) {
            resizeCounter.incrementAndGet();
        }

        @Override
        public void onClose() {
            closeCounter.incrementAndGet();
        }
    };

    virtualTerminal.flush();
    virtualTerminal.bell();
    virtualTerminal.setTerminalSize(new TerminalSize(40, 10));
    assertEquals(0, flushCounter.get());
    assertEquals(0, bellCounter.get());
    assertEquals(0, resizeCounter.get());
    assertEquals(0, closeCounter.get());

    virtualTerminal.addVirtualTerminalListener(listener);
    virtualTerminal.flush();
    virtualTerminal.bell();
    virtualTerminal.setTerminalSize(new TerminalSize(80, 20));
    assertEquals(1, flushCounter.get());
    assertEquals(1, bellCounter.get());
    assertEquals(1, resizeCounter.get());
    assertEquals(0, closeCounter.get());

    virtualTerminal.close();
    assertEquals(1, closeCounter.get());

    virtualTerminal.removeVirtualTerminalListener(listener);
    virtualTerminal.flush();
    virtualTerminal.bell();
    virtualTerminal.setTerminalSize(new TerminalSize(40, 10));
    virtualTerminal.close();
    assertEquals(1, flushCounter.get());
    assertEquals(1, bellCounter.get());
    assertEquals(1, resizeCounter.get());
    assertEquals(1, closeCounter.get());
}
 
Example #25
Source File: FancyChooser.java    From apdu4j with MIT License 4 votes vote down vote up
public static FancyChooser forTerminals(CardTerminals terminals) throws IOException, CardException {
    List<CardTerminal> terminalList = terminals.list();
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    return new FancyChooser(terminal, screen, terminals, terminalList);
}
 
Example #26
Source File: FancyChooser.java    From apdu4j with MIT License 4 votes vote down vote up
public static FancyChooser forTerminals(List<CardTerminal> terminals) throws IOException {
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    return new FancyChooser(terminal, screen, null, terminals);
}
 
Example #27
Source File: SimpleScreenTest.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Terminal terminal = new TestTerminalFactory(args).createTerminal();
    Screen screen = new TerminalScreen(terminal);
    screen.startScreen();
    screen.refresh();

    TextGraphics textGraphics = screen.newTextGraphics();

    int foregroundCycle = 1;
    int backgroundCycle = 0;

    mainLoop:
    while(true) {
        KeyStroke keyStroke = screen.readInput();
        switch(keyStroke.getKeyType()) {
            case EOF:
            case Escape:
                break mainLoop;

            case ArrowUp:
                screen.setCursorPosition(screen.getCursorPosition().withRelativeRow(-1));
                break;

            case ArrowDown:
                screen.setCursorPosition(screen.getCursorPosition().withRelativeRow(1));
                break;

            case ArrowLeft:
                screen.setCursorPosition(screen.getCursorPosition().withRelativeColumn(-1));
                break;

            case ArrowRight:
                screen.setCursorPosition(screen.getCursorPosition().withRelativeColumn(1));
                break;

            case Character:
                if(keyStroke.isCtrlDown()) {
                    switch(keyStroke.getCharacter()) {
                        case 'k':
                            screen.setCharacter(screen.getCursorPosition(), new TextCharacter('桜', COLORS_TO_CYCLE[foregroundCycle], COLORS_TO_CYCLE[backgroundCycle]));
                            screen.setCursorPosition(screen.getCursorPosition().withRelativeColumn(2));
                            break;

                        case 'f':
                            foregroundCycle++;
                            if(foregroundCycle >= COLORS_TO_CYCLE.length) {
                                foregroundCycle = 0;
                            }
                            break;

                        case 'b':
                            backgroundCycle++;
                            if(backgroundCycle >= COLORS_TO_CYCLE.length) {
                                backgroundCycle = 0;
                            }
                            break;
                    }
                    if(COLORS_TO_CYCLE[foregroundCycle] != TextColor.ANSI.BLACK) {
                        textGraphics.setBackgroundColor(TextColor.ANSI.BLACK);
                    }
                    else {
                        textGraphics.setBackgroundColor(TextColor.ANSI.WHITE);
                    }
                    textGraphics.setForegroundColor(COLORS_TO_CYCLE[foregroundCycle]);
                    textGraphics.putString(0, screen.getTerminalSize().getRows() - 2, "Foreground color");

                    if(COLORS_TO_CYCLE[backgroundCycle] != TextColor.ANSI.BLACK) {
                        textGraphics.setBackgroundColor(TextColor.ANSI.BLACK);
                    }
                    else {
                        textGraphics.setBackgroundColor(TextColor.ANSI.WHITE);
                    }
                    textGraphics.setForegroundColor(COLORS_TO_CYCLE[backgroundCycle]);
                    textGraphics.putString(0, screen.getTerminalSize().getRows() - 1, "Background color");
                }
                else {
                    screen.setCharacter(screen.getCursorPosition(), new TextCharacter(keyStroke.getCharacter(), COLORS_TO_CYCLE[foregroundCycle], COLORS_TO_CYCLE[backgroundCycle]));
                    screen.setCursorPosition(screen.getCursorPosition().withRelativeColumn(1));
                    break;
                }
            default:
        }

        screen.refresh();
    }

    screen.stopScreen();
}
 
Example #28
Source File: TerminalScreen.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onResized(Terminal terminal, TerminalSize newSize) {
    addResizeRequest(newSize);
}
 
Example #29
Source File: TerminalScreen.java    From lanterna with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Creates a new Screen on top of a supplied terminal, will query the terminal for its size. The screen is initially
 * blank. The default character used for unused space (the newly initialized state of the screen and new areas after
 * expanding the terminal size) will be a blank space in 'default' ANSI front- and background color.
 * <p>
 * Before you can display the content of this buffered screen to the real underlying terminal, you must call the
 * {@code startScreen()} method. This will ask the terminal to enter private mode (which is required for Screens to
 * work properly). Similarly, when you are done, you should call {@code stopScreen()} which will exit private mode.
 *
 * @param terminal Terminal object to create the DefaultScreen on top of.
 * @param defaultCharacter What character to use for the initial state of the screen and expanded areas
 * @throws java.io.IOException If there was an underlying I/O error when querying the size of the terminal
 */
public TerminalScreen(Terminal terminal, TextCharacter defaultCharacter) throws IOException {
    super(terminal.getTerminalSize(), defaultCharacter);
    this.terminal = terminal;
    this.terminal.addResizeListener(new TerminalScreenResizeListener());
    this.isStarted = false;
    this.fullRedrawHint = true;
}
 
Example #30
Source File: TerminalScreen.java    From lanterna with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new Screen on top of a supplied terminal, will query the terminal for its size. The screen is initially
 * blank. The default character used for unused space (the newly initialized state of the screen and new areas after
 * expanding the terminal size) will be a blank space in 'default' ANSI front- and background color.
 * <p>
 * Before you can display the content of this buffered screen to the real underlying terminal, you must call the
 * {@code startScreen()} method. This will ask the terminal to enter private mode (which is required for Screens to
 * work properly). Similarly, when you are done, you should call {@code stopScreen()} which will exit private mode.
 *
 * @param terminal Terminal object to create the DefaultScreen on top of
 * @throws java.io.IOException If there was an underlying I/O error when querying the size of the terminal
 */
public TerminalScreen(Terminal terminal) throws IOException {
    this(terminal, DEFAULT_CHARACTER);
}