Java Code Examples for com.googlecode.lanterna.TextColor#ANSI

The following examples show how to use com.googlecode.lanterna.TextColor#ANSI . 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: 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 2
Source File: Terminal4bitColorTest.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 rawTerminal = new TestTerminalFactory(args).createTerminal();
    if (rawTerminal instanceof SwingTerminalFrame) {
        SwingTerminalFrame extendedTerminal = (SwingTerminalFrame) rawTerminal;
        extendedTerminal.setSize(1500, 600);
    }
    rawTerminal.enterPrivateMode();
    rawTerminal.clearScreen();

    for (TextColor.ANSI fg : TextColor.ANSI.values()) {
        rawTerminal.resetColorAndSGR();
        char[] charArray = fg.name().toCharArray();
        for (int i = 0; i < 14; i++) {
            char c = i < charArray.length ? charArray[i] : ' ';
            rawTerminal.putCharacter(c);
        }
        rawTerminal.putCharacter(' ');
        rawTerminal.setForegroundColor(fg);
        for (TextColor.ANSI bg : TextColor.ANSI.values()) {
            rawTerminal.setBackgroundColor(bg);
            rawTerminal.putCharacter(' ');
            rawTerminal.putCharacter('x');
            rawTerminal.putCharacter('Y');
            rawTerminal.putCharacter('z');
            rawTerminal.putCharacter(' ');
        }
        rawTerminal.putCharacter('\n');
    }

    rawTerminal.flush();
    try {
        while(rawTerminal.pollInput() == null) {
            Thread.sleep(1);
        }
    }
    catch(InterruptedException e) {}
    rawTerminal.exitPrivateMode();
}
 
Example 3
Source File: TerminalEmulatorPalette.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Returns the AWT color from this palette given an ANSI color and two hints for if we are looking for a background
 * color and if we want to use the bright version.
 * @param color Which ANSI color we want to extract
 * @param isForeground Is this color we extract going to be used as a background color?
 * @param useBrightTones If true, we should return the bright version of the color
 * @return AWT color extracted from this palette for the input parameters
 */
public Color get(TextColor.ANSI color, boolean isForeground, boolean useBrightTones) {
    if(useBrightTones) {
        switch(color) {
            case BLACK:
            case BLACK_BRIGHT:
                return brightBlack;
            case BLUE:
            case BLUE_BRIGHT:
                return brightBlue;
            case CYAN:
            case CYAN_BRIGHT:
                return brightCyan;
            case DEFAULT:
                return isForeground ? defaultBrightColor : defaultBackgroundColor;
            case GREEN:
            case GREEN_BRIGHT:
                return brightGreen;
            case MAGENTA:
            case MAGENTA_BRIGHT:
                return brightMagenta;
            case RED:
            case RED_BRIGHT:
                return brightRed;
            case WHITE:
            case WHITE_BRIGHT:
                return brightWhite;
            case YELLOW:
            case YELLOW_BRIGHT:
                return brightYellow;
        }
    }
    else {
        switch(color) {
            case BLACK:
                return normalBlack;
            case BLACK_BRIGHT:
                return brightBlack;
            case BLUE:
                return normalBlue;
            case BLUE_BRIGHT:
                return brightBlue;
            case CYAN:
                return normalCyan;
            case CYAN_BRIGHT:
                return brightCyan;
            case DEFAULT:
                return isForeground ? defaultColor : defaultBackgroundColor;
            case GREEN:
                return normalGreen;
            case GREEN_BRIGHT:
                return brightGreen;
            case MAGENTA:
                return normalMagenta;
            case MAGENTA_BRIGHT:
                return brightMagenta;
            case RED:
                return normalRed;
            case RED_BRIGHT:
                return brightRed;
            case WHITE:
                return normalWhite;
            case WHITE_BRIGHT:
                return brightWhite;
            case YELLOW:
                return normalYellow;
            case YELLOW_BRIGHT:
                return brightYellow;
        }
    }
    throw new IllegalArgumentException("Unknown text color " + color);
}
 
Example 4
Source File: ThemeTest.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void runCustomTheme(final WindowBasedTextGUI textGUI) {
    final BasicWindow customThemeCreator = new BasicWindow("Custom Theme");
    customThemeCreator.setHints(Collections.singletonList(Window.Hint.CENTERED));

    Panel mainPanel = new Panel();
    mainPanel.addComponent(new Label("Choose colors:"));

    Panel colorTable = new Panel(new GridLayout(2));
    colorTable.addComponent(new Label("Base foreground:"));
    final ComboBox<TextColor.ANSI> baseForeground = new ComboBox<>(TextColor.ANSI.values());
    colorTable.addComponent(baseForeground);
    colorTable.addComponent(new Label("Base background:"));
    final ComboBox<TextColor.ANSI> baseBackground = new ComboBox<>(TextColor.ANSI.values());
    baseBackground.setSelectedIndex(7);
    colorTable.addComponent(baseBackground);
    colorTable.addComponent(new Label("Editable foreground:"));
    final ComboBox<TextColor.ANSI> editableForeground = new ComboBox<>(TextColor.ANSI.values());
    editableForeground.setSelectedIndex(7);
    colorTable.addComponent(editableForeground);
    colorTable.addComponent(new Label("Editable background:"));
    final ComboBox<TextColor.ANSI> editableBackground = new ComboBox<>(TextColor.ANSI.values());
    editableBackground.setSelectedIndex(4);
    colorTable.addComponent(editableBackground);
    colorTable.addComponent(new Label("Selected foreground:"));
    final ComboBox<TextColor.ANSI> selectedForeground = new ComboBox<>(TextColor.ANSI.values());
    selectedForeground.setSelectedIndex(7);
    colorTable.addComponent(selectedForeground);
    colorTable.addComponent(new Label("Selected background:"));
    final ComboBox<TextColor.ANSI> selectedBackground = new ComboBox<>(TextColor.ANSI.values());
    selectedBackground.setSelectedIndex(4);
    colorTable.addComponent(selectedBackground);
    colorTable.addComponent(new Label("GUI background:"));
    final ComboBox<TextColor.ANSI> guiBackground = new ComboBox<>(TextColor.ANSI.values());
    guiBackground.setSelectedIndex(4);
    colorTable.addComponent(guiBackground);
    final CheckBox activeIsBoxCheck = new CheckBox("Active content is bold").setChecked(true);

    mainPanel.addComponent(new EmptySpace());
    mainPanel.addComponent(colorTable);
    mainPanel.addComponent(activeIsBoxCheck);
    mainPanel.addComponent(new EmptySpace());

    Button okButton = new Button(LocalizedString.OK.toString(), () -> {
        SimpleTheme theme = SimpleTheme.makeTheme(
                activeIsBoxCheck.isChecked(),
                baseForeground.getSelectedItem(),
                baseBackground.getSelectedItem(),
                editableForeground.getSelectedItem(),
                editableBackground.getSelectedItem(),
                selectedForeground.getSelectedItem(),
                selectedBackground.getSelectedItem(),
                guiBackground.getSelectedItem());
        textGUI.setTheme(theme);
        customThemeCreator.close();
    });
    Button cancelButton = new Button(LocalizedString.Cancel.toString(), customThemeCreator::close);
    mainPanel.addComponent(Panels.horizontal(
            okButton,
            cancelButton
    ).setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.End)));

    customThemeCreator.setComponent(mainPanel);
    okButton.takeFocus();
    textGUI.addWindowAndWait(customThemeCreator);
}
 
Example 5
Source File: Issue409.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
public FixedBackgroundTextBoxThemeStyle(ThemeDefinition definition, TextColor.ANSI color) {
    super(definition);
    this.color = color;
}
 
Example 6
Source File: TerminalEmulatorColorConfiguration.java    From lanterna with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Given a TextColor and a hint as to if the color is to be used as foreground or not and if we currently have
 * bold text enabled or not, it returns the closest AWT color that matches this.
 * @param color What text color to convert
 * @param isForeground Is the color intended to be used as foreground color
 * @param inBoldContext Is the color intended to be used for on a character this is bold
 * @return The AWT color that represents this text color
 * @deprecated This adds a runtime dependency to the java.desktop module which isn't declared in the module
 * descriptor of lanterna. If you want to call this method, make sure to add it to your module.
 */
@Deprecated
public Color toAWTColor(TextColor color, boolean isForeground, boolean inBoldContext) {
    if(color instanceof TextColor.ANSI) {
        return colorPalette.get((TextColor.ANSI)color, isForeground, inBoldContext && useBrightColorsOnBold);
    }
    return color.toColor();
}