com.googlecode.lanterna.TextColor Java Examples

The following examples show how to use com.googlecode.lanterna.TextColor. 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: Issue249.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 {

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

        TerminalSize screenSize = screen.getTerminalSize();

        // Create panel to hold components
        Panel panel = new Panel();
        panel.setPreferredSize(screenSize);

        // 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 #2
Source File: BlinkTest.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 rawTerminal = new TestTerminalFactory(args).createTerminal();
    rawTerminal.enterPrivateMode();
    rawTerminal.clearScreen();
    rawTerminal.setForegroundColor(TextColor.ANSI.RED);
    rawTerminal.enableSGR(SGR.BLINK);
    rawTerminal.setCursorPosition(10, 10);
    rawTerminal.putCharacter('H');
    rawTerminal.putCharacter('e');
    rawTerminal.putCharacter('l');
    rawTerminal.putCharacter('l');
    rawTerminal.putCharacter('o');
    rawTerminal.putCharacter('!');
    rawTerminal.setCursorPosition(0, 0);
    rawTerminal.flush();
    try {
        Thread.sleep(5000);
    }
    catch(InterruptedException e) {}
    rawTerminal.exitPrivateMode();
}
 
Example #3
Source File: CJKScreenTest.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 {
    Screen screen = new TestTerminalFactory(args).createScreen();
    screen.startScreen();

    TextGraphics writer = new ScreenTextGraphics(screen);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(4, 2,  "Chinese (simplified):  石室诗士施氏,嗜狮,誓食十狮。");
    writer.putString(4, 3,  "                       氏时时适市视狮。");
    writer.putString(4, 5,  "Chinese (traditional): 石室詩士施氏,嗜獅,誓食十獅。 ");
    writer.putString(4, 6,  "                       氏時時適市視獅。");
    writer.putString(4, 8,  "Japanese:              祇園精舎の鐘の声、諸行無常の響あり。");
    writer.putString(4, 9,  "                       沙羅双樹の花の色、盛者必衰の理をあらはす");
    writer.putString(4, 11, "  (katakana)           ランターナ バージョンアップ!");
    writer.putString(4, 12, "  (half-width)         ランターナ バージョンアップ");
    writer.putString(4, 14, "Korean:                내 벗이 몇인가하니 수석과 송죽이라");
    writer.putString(4, 15, "                       동산에 달오르니 그 더욱 반갑도다");
    writer.putString(4, 16, "                       두어라, 이 다섯 밖에 또 더해야 무엇하리");
    screen.refresh();

    screen.readInput();
    screen.stopScreen();
}
 
Example #4
Source File: Terminal24bitColorTest.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 {
    final String string = "Hello!";
    Random random = new Random();
    Terminal terminal = new TestTerminalFactory(args).createTerminal();
    terminal.enterPrivateMode();
    terminal.clearScreen();
    TerminalSize size = terminal.getTerminalSize();

    while(true) {
        if(terminal.pollInput() != null) {
            terminal.exitPrivateMode();
            return;
        }

        terminal.setForegroundColor(new TextColor.RGB(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
        terminal.setBackgroundColor(new TextColor.RGB(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
        terminal.setCursorPosition(random.nextInt(size.getColumns() - string.length()), random.nextInt(size.getRows()));
        printString(terminal, string);

        try {
            Thread.sleep(200);
        }
        catch(InterruptedException e) {
        }
    }
}
 
Example #5
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 #6
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 #7
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 #8
Source File: SimpleTheme.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new {@link SimpleTheme} object that uses the supplied constructor arguments as the default style
 * @param foreground Color to use as the foreground unless overridden
 * @param background Color to use as the background unless overridden
 * @param styles Extra SGR styles to apply unless overridden
 */
public SimpleTheme(TextColor foreground, TextColor background, SGR... styles) {
    this.defaultDefinition = new Definition(new DefaultMutableThemeStyle(foreground, background, styles));
    this.overrideDefinitions = new HashMap<>();
    this.windowPostRenderer = null;
    this.windowDecorationRenderer = null;
}
 
Example #9
Source File: SimpleTerminalTest.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void printHelp(TextGraphics textGraphics) {
    textGraphics.setBackgroundColor(TextColor.ANSI.DEFAULT);
    textGraphics.setForegroundColor(TextColor.ANSI.DEFAULT);
    textGraphics.putString(1, 0, "Commands available:");
    textGraphics.putString(1, 1, "?            - Print this message");
    textGraphics.putString(1, 2, "m            - Toggle private mode on/off");
    textGraphics.putString(1, 3, "n            - Newline");
    textGraphics.putString(1, 4, "b            - Bell");
    textGraphics.putString(1, 5, "c            - Cycle color");
    textGraphics.putString(1, 6, "p            - Print cursor position");
    textGraphics.putString(1, 7, "<arrow keys> - Move cursor");
    textGraphics.putString(1, 8, "1-9          - Print X number of blocks at cursor");
}
 
Example #10
Source File: Issue409.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CustomBackgroundTextBox(final TextColor.ANSI color) {
    super("Custom " + color.name());
    setTheme(new DelegatingTheme(getTheme()) {
        @Override
        public ThemeDefinition getDefinition(Class<?> clazz) {
            ThemeDefinition themeDefinition = super.getDefinition(clazz);
            return new FixedBackgroundTextBoxThemeStyle(themeDefinition, color);
        }
    });
}
 
Example #11
Source File: AbstractTheme.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected AbstractTheme(WindowPostRenderer postRenderer,
                        WindowDecorationRenderer decorationRenderer) {

    this.rootNode = new ThemeTreeNode(Object.class, null);
    this.windowPostRenderer = postRenderer;
    this.windowDecorationRenderer = decorationRenderer;

    rootNode.foregroundMap.put(STYLE_NORMAL, TextColor.ANSI.WHITE);
    rootNode.backgroundMap.put(STYLE_NORMAL, TextColor.ANSI.BLACK);
}
 
Example #12
Source File: AbstractTheme.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public TextColor getForeground() {
    ThemeTreeNode node = styleNode;
    while(node != null) {
        if(node.foregroundMap.containsKey(name)) {
            return node.foregroundMap.get(name);
        }
        node = node.parent;
    }
    TextColor fallback = rootNode.foregroundMap.get(STYLE_NORMAL);
    if(fallback == null) {
        fallback = TextColor.ANSI.WHITE;
    }
    return fallback;
}
 
Example #13
Source File: AbstractTheme.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public TextColor getBackground() {
    ThemeTreeNode node = styleNode;
    while(node != null) {
        if(node.backgroundMap.containsKey(name)) {
            return node.backgroundMap.get(name);
        }
        node = node.parent;
    }
    TextColor fallback = rootNode.backgroundMap.get(STYLE_NORMAL);
    if(fallback == null) {
        fallback = TextColor.ANSI.BLACK;
    }
    return fallback;
}
 
Example #14
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 #15
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 #16
Source File: IOSafeTerminalAdapter.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setForegroundColor(TextColor color) {
    try {
        backend.setForegroundColor(color);
    }
    catch(IOException e) {
        exceptionHandler.onException(e);
    }
}
 
Example #17
Source File: IOSafeTerminalAdapter.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setBackgroundColor(TextColor color) {
    try {
        backend.setBackgroundColor(color);
    }
    catch(IOException e) {
        exceptionHandler.onException(e);
    }
}
 
Example #18
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 #19
Source File: CJKTerminalTest.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, InterruptedException {
    Terminal terminal = new TestTerminalFactory(args).createTerminal();
    terminal.enterPrivateMode();
    terminal.clearScreen();
    for(int i = 1; i < 5; i++) {
        terminal.setCursorPosition(i, i);
        printString(terminal, "あ い う え お");
    }
    int pos = 0;
    int line = 1;
    for(int i = 0; i < 50; i++) {
        if(terminal.pollInput() != null) {
            break;
        }
        terminal.setCursorPosition(0, 0);
        printString(terminal, pos + "x" + line);            
        terminal.setCursorPosition(pos++, line);
        if(pos == 10) {
            pos = 0;
            line++;
        }
        terminal.flush();
        Thread.sleep(2000);
    }
    terminal.setForegroundColor(TextColor.ANSI.WHITE);
    terminal.setBackgroundColor(TextColor.ANSI.RED);
    for(int i = 0; i < 5; i++) {
        if(terminal.pollInput() != null) {
            break;
        }
        terminal.setCursorPosition(5, i + 1);
        printString(terminal, "X");
        terminal.setCursorPosition(0, 0);
        terminal.flush();
        Thread.sleep(2000);
    }
    terminal.exitPrivateMode();
}
 
Example #20
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 #21
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 #22
Source File: LineWrappingLabelTest.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected MultiWindowTextGUI createTextGUI(Screen screen) {
    return new MultiWindowTextGUI(
            new SeparateTextGUIThread.Factory(),
            screen,
            new MyWindowManager(),
            new WindowShadowRenderer(),
            new EmptySpace(TextColor.ANSI.BLUE));
}
 
Example #23
Source File: Issue453.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public LanternaTerminalWriter(String[] args) throws IOException {
    screen = new TestTerminalFactory(args).createScreen();
    screen.startScreen();
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(),
new EmptySpace(TextColor.ANSI.BLACK));
    
    assertNotNull(new DefaultMutableThemeStyle(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK, new SGR[] {}));
    screenWriter = screen.newTextGraphics();
}
 
Example #24
Source File: NewSwingTerminalTest.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates new form NewSwingTerminalTest
 */
public NewSwingTerminalTest() {
    initComponents();

    final SwingTerminal leftTerminal = new SwingTerminal();
    final SwingTerminal rightTerminal = new SwingTerminal();
    splitPane.setLeftComponent(leftTerminal);
    splitPane.setRightComponent(rightTerminal);
    pack();

    Timer timer = new Timer(500, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            drawRandomHello(leftTerminal);
            drawRandomHello(rightTerminal);
        }

        private void drawRandomHello(IOSafeTerminal terminal) {
            TerminalSize size = terminal.getTerminalSize();
            if(size.getColumns() > 6 && size.getRows() > 1) {
                int positionX = RANDOM.nextInt(size.getColumns() - 6);
                int positionY = RANDOM.nextInt(size.getRows());

                terminal.setCursorPosition(positionX, positionY);
                terminal.setBackgroundColor(new TextColor.Indexed(RANDOM.nextInt(256)));
                terminal.setForegroundColor(new TextColor.Indexed(RANDOM.nextInt(256)));
                String hello = "Hello!";
                for(int i = 0; i < hello.length(); i++) {
                    terminal.putCharacter(hello.charAt(i));
                }
                terminal.flush();
            }
        }
    });
    timer.start();
}
 
Example #25
Source File: DefaultMutableThemeStyle.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
private DefaultMutableThemeStyle(TextColor foreground, TextColor background, EnumSet<SGR> sgrs) {
    if(foreground == null) {
        throw new IllegalArgumentException("Cannot set SimpleTheme's style foreground to null");
    }
    if(background == null) {
        throw new IllegalArgumentException("Cannot set SimpleTheme's style background to null");
    }
    this.foreground = foreground;
    this.background = background;
    this.sgrs = EnumSet.copyOf(sgrs);
}
 
Example #26
Source File: ANSITerminal.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setForegroundColor(TextColor color) throws IOException {
    writeSGRSequenceToTerminal(color.getForegroundSGRSequence());
}
 
Example #27
Source File: AWTTerminal.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setForegroundColor(TextColor color) {
    terminalImplementation.setForegroundColor(color);
}
 
Example #28
Source File: SwingTerminal.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setBackgroundColor(TextColor color) {
    terminalImplementation.setBackgroundColor(color);
}
 
Example #29
Source File: ScrollingSwingTerminal.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setForegroundColor(TextColor color) {
    swingTerminal.setForegroundColor(color);
}
 
Example #30
Source File: ScrollingSwingTerminal.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setBackgroundColor(TextColor color) {
    swingTerminal.setBackgroundColor(color);
}