com.googlecode.lanterna.graphics.TextGraphics Java Examples

The following examples show how to use com.googlecode.lanterna.graphics.TextGraphics. 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: 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 #3
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 #4
Source File: InternationalCharactersTest.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,  "Armenian:   Ճանաչել զիմաստութիւն եւ զխրատ, իմանալ զբանս հանճարոյ");
    writer.putString(4, 3,  "Greek:      μὴ μου τοὺς κύκλους τάραττε");
    writer.putString(4, 4,  "Hebrew:     סְבָאלְבָּרְד הוא ארכיפלג הנמצא באוקיינוס הארקטי");
    writer.putString(4, 5,  "Icelandic:  þungur hnífur   þessi hnífur á að vera þungur");
    writer.putString(4, 6,  "Persian:    آنان که محیط فضل و آداب شدند  در جمع کمال شمع اصحاب شدند");
    writer.putString(4, 7,  "Russian:    Запорізькі козаки турецькому султану!");
    writer.putString(4, 8,  "Swedish:    Flygande bäckasiner söka hwila på mjuka tuvor");
    writer.putString(4, 9,  "Thai:       เสียงฦๅเสียงเล่าอ้าง    อันใด พี่เอย");
    screen.refresh();
    screen.readInput();
    screen.stopScreen();
}
 
Example #5
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 #6
Source File: TerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TextGraphics putString(int column, int row, String string) {
    try {
        enterAtomic();
        return super.putString(column, row, string);
    }
    finally {
        leaveAtomic();
    }
}
 
Example #7
Source File: FullScreenTextGUITest.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
private TextImage createBackground() {
    BasicTextImage image = new BasicTextImage(80, 25);
    TextGraphics graphics = image.newTextGraphics();
    graphics.setForegroundColor(TextColor.ANSI.WHITE);
    graphics.setBackgroundColor(TextColor.ANSI.BLUE);
    graphics.fill(' ');

    graphics.enableModifiers(SGR.BOLD);

    graphics.putString(7, 0, "Reminds you of some BIOS, doesn't it?");
    graphics.setCharacter(0, 1, Symbols.DOUBLE_LINE_TOP_LEFT_CORNER);
    graphics.drawLine(1, 1, 78, 1, Symbols.DOUBLE_LINE_HORIZONTAL);
    graphics.setCharacter(79, 1, Symbols.DOUBLE_LINE_TOP_RIGHT_CORNER);
    graphics.drawLine(79, 2, 79, 23, Symbols.DOUBLE_LINE_VERTICAL);
    graphics.setCharacter(79, 24, Symbols.DOUBLE_LINE_BOTTOM_RIGHT_CORNER);
    graphics.drawLine(1, 24, 78, 24, Symbols.DOUBLE_LINE_HORIZONTAL);
    graphics.setCharacter(0, 24, Symbols.DOUBLE_LINE_BOTTOM_LEFT_CORNER);
    graphics.drawLine(0, 2, 0, 23, Symbols.DOUBLE_LINE_VERTICAL);

    graphics.setCharacter(0, 17, Symbols.DOUBLE_LINE_T_SINGLE_RIGHT);
    graphics.drawLine(1, 17, 78, 17, Symbols.SINGLE_LINE_HORIZONTAL);
    graphics.setCharacter(79, 17, Symbols.DOUBLE_LINE_T_SINGLE_LEFT);
    graphics.setCharacter(40, 17, Symbols.SINGLE_LINE_T_UP);
    graphics.drawLine(40, 2, 40, 16, Symbols.SINGLE_LINE_VERTICAL);
    graphics.setCharacter(40, 1, Symbols.DOUBLE_LINE_T_SINGLE_DOWN);

    graphics.setCharacter(0, 20, Symbols.DOUBLE_LINE_T_SINGLE_RIGHT);
    graphics.drawLine(1, 20, 78, 20, Symbols.SINGLE_LINE_HORIZONTAL);
    graphics.setCharacter(79, 20, Symbols.DOUBLE_LINE_T_SINGLE_LEFT);
    
    graphics.putString(2, 18, "Esc : Quit");
    graphics.putString(42, 18, Symbols.ARROW_UP + " " + Symbols.ARROW_DOWN + " " + Symbols.ARROW_RIGHT + " " + 
            Symbols.ARROW_LEFT + "   : Select Item");
    graphics.putString(2, 19, "F10 : Save & Exit Setup");
    return image;
}
 
Example #8
Source File: VirtualScreenTest.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
public VirtualScreenTest(String[] args) throws InterruptedException, IOException {
    Screen screen = new TestTerminalFactory(args).createScreen();
    screen = new VirtualScreen(screen);
    screen.startScreen();

    TextGraphics textGraphics = screen.newTextGraphics();
    textGraphics.setBackgroundColor(TextColor.ANSI.GREEN);
    textGraphics.fillTriangle(new TerminalPosition(40, 0), new TerminalPosition(25,19), new TerminalPosition(65, 19), ' ');
    textGraphics.setBackgroundColor(TextColor.ANSI.RED);
    textGraphics.drawRectangle(TerminalPosition.TOP_LEFT_CORNER, screen.getTerminalSize(), ' ');
    screen.refresh();

    while(true) {
        KeyStroke keyStroke = screen.pollInput();
        if(keyStroke != null) {
            if(keyStroke.getKeyType() == KeyType.Escape) {
                break;
            }
        }
        else if(screen.doResizeIfNecessary() != null) {
            screen.refresh();
        }
        else {
            Thread.sleep(1);
        }
    }
    screen.stopScreen();
}
 
Example #9
Source File: VirtualTerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public TextGraphics setCharacter(int columnIndex, int rowIndex, TextCharacter textCharacter) {
    TerminalSize size = getSize();
    if(columnIndex < 0 || columnIndex >= size.getColumns() ||
            rowIndex < 0 || rowIndex >= size.getRows()) {
        return this;
    }
    synchronized(virtualTerminal) {
        virtualTerminal.setCursorPosition(new TerminalPosition(columnIndex, rowIndex));
        virtualTerminal.putCharacter(textCharacter);
    }
    return this;
}
 
Example #10
Source File: IOSafeTerminalAdapter.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public TextGraphics newTextGraphics() {
    try {
        return backend.newTextGraphics();
    }
    catch(IOException e) {
        exceptionHandler.onException(e);
    }
    return null;
}
 
Example #11
Source File: TerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TextGraphics drawRectangle(TerminalPosition topLeft, TerminalSize size, char character) {
    try {
        enterAtomic();
        super.drawRectangle(topLeft, size, character);
        return this;
    }
    finally {
        leaveAtomic();
    }
}
 
Example #12
Source File: TerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TextGraphics fillRectangle(TerminalPosition topLeft, TerminalSize size, char character) {
    try {
        enterAtomic();
        super.fillRectangle(topLeft, size, character);
        return this;
    }
    finally {
        leaveAtomic();
    }
}
 
Example #13
Source File: TerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TextGraphics drawTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, char character) {
    try {
        enterAtomic();
        super.drawTriangle(p1, p2, p3, character);
        return this;
    }
    finally {
        leaveAtomic();
    }
}
 
Example #14
Source File: TerminalTextGraphicsTest.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();
    TextGraphics textGraphics = terminal.newTextGraphics();
    if((args.length > 0 && args[0].equals("--square")) ||
            (args.length > 1 && args[1].equals("--square"))) {
        textGraphics = new DoublePrintingTextGraphics(textGraphics);
    }
    textGraphics.setForegroundColor(TextColor.ANSI.BLUE);
    textGraphics.putString(3, 3, "Hello World!");
    textGraphics.setForegroundColor(TextColor.ANSI.CYAN);
    TerminalPosition lineStart = new TerminalPosition(3 + "Hello World!".length(), 3);
    textGraphics.drawLine(lineStart, lineStart.withRelativeColumn(2).withRelativeRow(6), Symbols.BLOCK_SOLID);
    textGraphics.setForegroundColor(TextColor.ANSI.RED);
    textGraphics.drawRectangle(lineStart.withRelativeColumn(2).withRelativeRow(6), new TerminalSize(5, 3), Symbols.BULLET);
    textGraphics.setForegroundColor(TextColor.ANSI.MAGENTA);
    TerminalPosition triangleStart = lineStart.withRelativeColumn(7).withRelativeRow(9);
    textGraphics.drawTriangle(
            triangleStart,
            triangleStart.withColumn(0).withRelativeRow(-1),
            triangleStart.withColumn(5).withRelativeRow(3),
            Symbols.SPADES);
    textGraphics.setForegroundColor(TextColor.ANSI.YELLOW);
    textGraphics.fillRectangle(new TerminalPosition(30, 1), new TerminalSize(8, 5), Symbols.DIAMOND);
    textGraphics.setForegroundColor(TextColor.ANSI.GREEN);
    triangleStart = new TerminalPosition(30, 6);
    textGraphics.fillTriangle(
            triangleStart,
            triangleStart.withRelativeRow(5).withRelativeColumn(-2),
            triangleStart.withRelativeRow(5).withRelativeColumn(4),
            Symbols.CLUB);

    terminal.resetColorAndSGR();
    terminal.flush();

    Thread.sleep(4000);

    if(terminal instanceof Window) {
        ((Window)terminal).dispose();
    }
}
 
Example #15
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 #16
Source File: ExtendedTerminalTests.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 {
    ExtendedTerminal extendedTerminal = new UnixTerminal();
    extendedTerminal.clearScreen();
    TextGraphics textGraphics = extendedTerminal.newTextGraphics();
    textGraphics.setForegroundColor(TextColor.ANSI.CYAN);
    textGraphics.putString(4, 4, "Please wait four seconds and the terminal will be resized", SGR.BLINK);
    extendedTerminal.flush();
    Thread.sleep(4 * 1000);
    extendedTerminal.setTerminalSize(80, 40);
    extendedTerminal.clearScreen();
    textGraphics.putString(4, 4, "There, did anything happen? Will set a title in 3 seconds...");
    extendedTerminal.flush();
    Thread.sleep(3 * 1000);
    extendedTerminal.setTitle("ExtendedTerminalTests");
    extendedTerminal.clearScreen();
    textGraphics.putString(4, 4, "Check the title, did it change?");
    textGraphics.setForegroundColor(TextColor.ANSI.RED);
    textGraphics.putString(0, textGraphics.getSize().getRows() - 1, "Will terminate in 3 seconds...", SGR.BLINK);
    extendedTerminal.setCursorPosition(0, 0);
    extendedTerminal.flush();
    Thread.sleep(3 * 1000);
    extendedTerminal.clearScreen();
    extendedTerminal.resetColorAndSGR();
    extendedTerminal.flush();

    //Drain the input queue (could hold the size reply)
    //noinspection StatementWithEmptyBody
    while(extendedTerminal.pollInput() != null);
}
 
Example #17
Source File: VirtualScreen.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void drawFrame(
        TextGraphics graphics,
        TerminalSize realSize,
        TerminalSize virtualSize,
        TerminalPosition virtualScrollPosition) {

    if(realSize.getColumns() == 1 || realSize.getRows() <= 2) {
        return;
    }
    TerminalSize viewportSize = getViewportSize(realSize, virtualSize);

    graphics.setForegroundColor(TextColor.ANSI.WHITE);
    graphics.setBackgroundColor(TextColor.ANSI.BLACK);
    graphics.fill(' ');
    graphics.putString(0, graphics.getSize().getRows() - 1, "Terminal too small, use ALT+arrows to scroll");

    int horizontalSize = (int)(((double)(viewportSize.getColumns()) / (double)virtualSize.getColumns()) * (viewportSize.getColumns()));
    int scrollable = viewportSize.getColumns() - horizontalSize - 1;
    int horizontalPosition = (int)((double)scrollable * ((double)virtualScrollPosition.getColumn() / (double)(virtualSize.getColumns() - viewportSize.getColumns())));
    graphics.drawLine(
            new TerminalPosition(horizontalPosition, graphics.getSize().getRows() - 2),
            new TerminalPosition(horizontalPosition + horizontalSize, graphics.getSize().getRows() - 2),
            Symbols.BLOCK_MIDDLE);

    int verticalSize = (int)(((double)(viewportSize.getRows()) / (double)virtualSize.getRows()) * (viewportSize.getRows()));
    scrollable = viewportSize.getRows() - verticalSize - 1;
    int verticalPosition = (int)((double)scrollable * ((double)virtualScrollPosition.getRow() / (double)(virtualSize.getRows() - viewportSize.getRows())));
    graphics.drawLine(
            new TerminalPosition(graphics.getSize().getColumns() - 1, verticalPosition),
            new TerminalPosition(graphics.getSize().getColumns() - 1, verticalPosition + verticalSize),
            Symbols.BLOCK_MIDDLE);
}
 
Example #18
Source File: AbstractScreen.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public TextGraphics newTextGraphics() {
    return new ScreenTextGraphics(this) {
        @Override
        public TextGraphics drawImage(TerminalPosition topLeft, TextImage image, TerminalPosition sourceImageTopLeft, TerminalSize sourceImageSize) {
            backBuffer.copyFrom(image, sourceImageTopLeft.getRow(), sourceImageSize.getRows(), sourceImageTopLeft.getColumn(), sourceImageSize.getColumns(), topLeft.getRow(), topLeft.getColumn());
            return this;
        }
    };
}
 
Example #19
Source File: TerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TextGraphics setCharacter(TerminalPosition position, TextCharacter textCharacter) {
    try {
        if(manageCallStackSize.get() > 0) {
            if(lastCharacter == null || !lastCharacter.equals(textCharacter)) {
                applyGraphicState(textCharacter);
                lastCharacter = textCharacter;
            }
            if(lastPosition == null || !lastPosition.equals(position)) {
                terminal.setCursorPosition(position.getColumn(), position.getRow());
                lastPosition = position;
            }
        }
        else {
            terminal.setCursorPosition(position.getColumn(), position.getRow());
            applyGraphicState(textCharacter);
        }
        terminal.putCharacter(textCharacter.getCharacter());
        if(manageCallStackSize.get() > 0) {
            lastPosition = position.withRelativeColumn(1);
        }
        writeHistory.put(position, textCharacter);
    }
    catch(IOException e) {
        throw new RuntimeException(e);
    }
    return this;
}
 
Example #20
Source File: TerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TextGraphics drawLine(TerminalPosition fromPoint, TerminalPosition toPoint, char character) {
    try {
        enterAtomic();
        super.drawLine(fromPoint, toPoint, character);
        return this;
    }
    finally {
        leaveAtomic();
    }
}
 
Example #21
Source File: TerminalTextGraphics.java    From lanterna with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TextGraphics fillTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, char character) {
    try {
        enterAtomic();
        super.fillTriangle(p1, p2, p3, character);
        return this;
    }
    finally {
        leaveAtomic();
    }
}
 
Example #22
Source File: ScreenResizeTest.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void putStrings(String topTitle) throws IOException {
    TextGraphics writer = new ScreenTextGraphics(screen);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.fill(' ');

    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(0, 0, topTitle);
    writer.putString(10, 1, "Hello World");

    writer.setForegroundColor(TextColor.ANSI.BLACK);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(11, 2, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.WHITE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(12, 3, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLACK);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(13, 4, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.WHITE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(14, 5, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(15, 6, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(16, 7, "Hello World");

    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(10, 10, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(11, 11, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(12, 12, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.MAGENTA);
    writer.putString(13, 13, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(14, 14, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(15, 15, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(16, 16, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.MAGENTA);
    writer.putString(17, 17, "Hello World");

    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(10, 20, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(11, 21, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(12, 22, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.MAGENTA);
    writer.putString(13, 23, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(14, 24, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(15, 25, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(16, 26, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.CYAN);
    writer.setBackgroundColor(TextColor.ANSI.BLUE);
    writer.putString(17, 27, "Hello World", SGR.BOLD);
    screen.refresh();
}
 
Example #23
Source File: ScreenLineTest.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, InterruptedException {
    boolean useAnsiColors = false;
    boolean slow = false;
    boolean circle = false;
    for(String arg: args) {
        if(arg.equals("--ansi-colors")) {
            useAnsiColors = true;
        }
        if(arg.equals("--slow")) {
            slow = true;
        }
        if(arg.equals("--circle")) {
            circle = true;
        }
    }
    Screen screen = new TestTerminalFactory(args).createScreen();
    screen.startScreen();

    TextGraphics textGraphics = new ScreenTextGraphics(screen);
    Random random = new Random();
    while(true) {
        KeyStroke keyStroke = screen.pollInput();
        if(keyStroke != null &&
                (keyStroke.getKeyType() == KeyType.Escape || keyStroke.getKeyType() == KeyType.EOF)) {
            break;
        }
        screen.doResizeIfNecessary();
        TerminalSize size = textGraphics.getSize();
        TextColor color;
        if(useAnsiColors) {
            color = TextColor.ANSI.values()[random.nextInt(TextColor.ANSI.values().length)];
        }
        else {
            //Draw a rectangle in random indexed color
            color = new TextColor.Indexed(random.nextInt(256));
        }

        TerminalPosition p1;
        TerminalPosition p2;
        if(circle) {
            p1 = new TerminalPosition(size.getColumns() / 2, size.getRows() / 2);
            if(CIRCLE_LAST_POSITION == null) {
                CIRCLE_LAST_POSITION = new TerminalPosition(0, 0);
            }
            else if(CIRCLE_LAST_POSITION.getRow() == 0) {
                if(CIRCLE_LAST_POSITION.getColumn() < size.getColumns() - 1) {
                    CIRCLE_LAST_POSITION = CIRCLE_LAST_POSITION.withRelativeColumn(1);
                }
                else {
                    CIRCLE_LAST_POSITION = CIRCLE_LAST_POSITION.withRelativeRow(1);
                }
            }
            else if(CIRCLE_LAST_POSITION.getRow() < size.getRows() - 1) {
                if(CIRCLE_LAST_POSITION.getColumn() == 0) {
                    CIRCLE_LAST_POSITION = CIRCLE_LAST_POSITION.withRelativeRow(-1);
                }
                else {
                    CIRCLE_LAST_POSITION = CIRCLE_LAST_POSITION.withRelativeRow(1);
                }
            }
            else {
                if(CIRCLE_LAST_POSITION.getColumn() > 0) {
                    CIRCLE_LAST_POSITION = CIRCLE_LAST_POSITION.withRelativeColumn(-1);
                }
                else {
                    CIRCLE_LAST_POSITION = CIRCLE_LAST_POSITION.withRelativeRow(-1);
                }
            }
            p2 = CIRCLE_LAST_POSITION;
        }
        else {
            p1 = new TerminalPosition(random.nextInt(size.getColumns()), random.nextInt(size.getRows()));
            p2 = new TerminalPosition(random.nextInt(size.getColumns()), random.nextInt(size.getRows()));
        }
        textGraphics.setBackgroundColor(color);
        textGraphics.drawLine(p1, p2, ' ');
        textGraphics.setBackgroundColor(TextColor.ANSI.BLACK);
        textGraphics.setForegroundColor(TextColor.ANSI.WHITE);
        textGraphics.putString(4, size.getRows() - 1, "P1 " + p1 + " -> P2 " + p2);
        screen.refresh(Screen.RefreshType.DELTA);
        if(slow) {
            Thread.sleep(500);
        }
    }
    screen.stopScreen();
}
 
Example #24
Source File: ScreenRectangleTest.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, InterruptedException {
    boolean useAnsiColors = false;
    boolean useFilled = false;
    boolean slow = false;
    for(String arg: args) {
        if(arg.equals("--ansi-colors")) {
            useAnsiColors = true;
        }
        if(arg.equals("--filled")) {
            useFilled = true;
        }
        if(arg.equals("--slow")) {
            slow = true;
        }
    }
    Screen screen = new TestTerminalFactory(args).createScreen();
    screen.startScreen();

    TextGraphics textGraphics = new ScreenTextGraphics(screen);
    Random random = new Random();

    long startTime = System.currentTimeMillis();
    while(System.currentTimeMillis() - startTime < 1000 * 20) {
        KeyStroke keyStroke = screen.pollInput();
        if(keyStroke != null &&
                (keyStroke.getKeyType() == KeyType.Escape || keyStroke.getKeyType() == KeyType.EOF)) {
            break;
        }
        screen.doResizeIfNecessary();
        TerminalSize size = textGraphics.getSize();
        TextColor color;
        if(useAnsiColors) {
            color = TextColor.ANSI.values()[random.nextInt(TextColor.ANSI.values().length)];
        }
        else {
            //Draw a rectangle in random indexed color
            color = new TextColor.Indexed(random.nextInt(256));
        }

        TerminalPosition topLeft = new TerminalPosition(random.nextInt(size.getColumns()), random.nextInt(size.getRows()));
        TerminalSize rectangleSize = new TerminalSize(random.nextInt(size.getColumns() - topLeft.getColumn()), random.nextInt(size.getRows() - topLeft.getRow()));

        textGraphics.setBackgroundColor(color);
        if(useFilled) {
            textGraphics.fillRectangle(topLeft, rectangleSize, ' ');
        }
        else {
            textGraphics.drawRectangle(topLeft, rectangleSize, ' ');
        }
        screen.refresh(Screen.RefreshType.DELTA);
        if(slow) {
            Thread.sleep(500);
        }
    }
    screen.stopScreen();
}
 
Example #25
Source File: ScreenTabTest.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void putStrings(String topTitle) throws IOException {
    TextGraphics writer = new ScreenTextGraphics(screen);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.fill(' ');

    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(0, 0, topTitle, SGR.BLINK);
    writer.setTabBehaviour(TabBehaviour.CONVERT_TO_ONE_SPACE);
    writer.putString(10, 1, "TabBehaviour.CONVERT_TO_ONE_SPACE:    |\t|\t|\t|\t|");
    writer.setTabBehaviour(TabBehaviour.CONVERT_TO_TWO_SPACES);
    writer.putString(10, 2, "TabBehaviour.CONVERT_TO_TWO_SPACES:   |\t|\t|\t|\t|");
    writer.setTabBehaviour(TabBehaviour.CONVERT_TO_THREE_SPACES);
    writer.putString(10, 3, "TabBehaviour.CONVERT_TO_THREE_SPACES: |\t|\t|\t|\t|");
    writer.setTabBehaviour(TabBehaviour.CONVERT_TO_FOUR_SPACES);
    writer.putString(10, 4, "TabBehaviour.CONVERT_TO_FOUR_SPACES:  |\t|\t|\t|\t|");
    writer.setTabBehaviour(TabBehaviour.CONVERT_TO_EIGHT_SPACES);
    writer.putString(10, 5, "TabBehaviour.CONVERT_TO_EIGHT_SPACES: |\t|\t|\t|\t|");
    writer.setTabBehaviour(TabBehaviour.ALIGN_TO_COLUMN_4);
    writer.putString(10, 6, "TabBehaviour.ALIGN_TO_COLUMN_4:       |\t|\t|\t|\t|");
    writer.setTabBehaviour(TabBehaviour.ALIGN_TO_COLUMN_8);
    writer.putString(10, 7, "TabBehaviour.ALIGN_TO_COLUMN_8:       |\t|\t|\t|\t|");
    writer.putString(10, 9, "Default behaviour is: " + screen.getTabBehaviour());
    writer.putString(10, 10, "Testing Screen's tab replacement:");
    writer.putString(10, 11, "XXXXXXXXXXXXXXXX");
    screen.setCharacter(12, 11, new TextCharacter('\t'));
    screen.setTabBehaviour(TabBehaviour.CONVERT_TO_ONE_SPACE);
    screen.setCharacter(20, 11, new TextCharacter('\t'));
    screen.refresh();

    //Verify
    if(' ' != screen.getBackCharacter(new TerminalPosition(20, 11)).getCharacter()) {
        throw new IllegalStateException("Expected tab to be replaced with space");
    }
    if('X' != screen.getBackCharacter(new TerminalPosition(21, 11)).getCharacter()) {
        throw new IllegalStateException("Expected X in back buffer");
    }
    if(' ' != screen.getFrontCharacter(new TerminalPosition(20, 11)).getCharacter()) {
        throw new IllegalStateException("Expected tab to be replaced with space");
    }
    if('X' != screen.getFrontCharacter(new TerminalPosition(21, 11)).getCharacter()) {
        throw new IllegalStateException("Expected X in front buffer");
    }
}
 
Example #26
Source File: DrawImageTest.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 {
    //Setup a standard Screen
    Screen screen = new TestTerminalFactory(args).createScreen();
    screen.startScreen();
    screen.setCursorPosition(null);

    //Create an 'image' that we fill with recognizable characters
    TextImage image = new BasicTextImage(5, 5);
    TextCharacter imageCharacter = new TextCharacter('X');
    TextGraphics textGraphics = image.newTextGraphics();
    textGraphics.drawRectangle(
            TerminalPosition.TOP_LEFT_CORNER,
            new TerminalSize(5, 5),
            imageCharacter.withBackgroundColor(TextColor.ANSI.RED));
    textGraphics.drawRectangle(
            TerminalPosition.OFFSET_1x1,
            new TerminalSize(3, 3),
            imageCharacter.withBackgroundColor(TextColor.ANSI.MAGENTA));
    textGraphics.setCharacter(2, 2,
            imageCharacter.withBackgroundColor(TextColor.ANSI.CYAN));

    TextGraphics screenGraphics = screen.newTextGraphics();
    screenGraphics.setBackgroundColor(TextColor.Indexed.fromRGB(50, 50, 50));
    screenGraphics.fill(' ');
    screenGraphics.drawImage(TerminalPosition.OFFSET_1x1, image);
    screenGraphics.drawImage(new TerminalPosition(8, 1), image, TerminalPosition.TOP_LEFT_CORNER, image.getSize().withRelativeColumns(-4));
    screenGraphics.drawImage(new TerminalPosition(10, 1), image, TerminalPosition.TOP_LEFT_CORNER, image.getSize().withRelativeColumns(-3));
    screenGraphics.drawImage(new TerminalPosition(13, 1), image, TerminalPosition.TOP_LEFT_CORNER, image.getSize().withRelativeColumns(-2));
    screenGraphics.drawImage(new TerminalPosition(17, 1), image, TerminalPosition.TOP_LEFT_CORNER, image.getSize().withRelativeColumns(-1));
    screenGraphics.drawImage(new TerminalPosition(22, 1), image);
    screenGraphics.drawImage(new TerminalPosition(28, 1), image, new TerminalPosition(1, 0), image.getSize());
    screenGraphics.drawImage(new TerminalPosition(33, 1), image, new TerminalPosition(2, 0), image.getSize());
    screenGraphics.drawImage(new TerminalPosition(37, 1), image, new TerminalPosition(3, 0), image.getSize());
    screenGraphics.drawImage(new TerminalPosition(40, 1), image, new TerminalPosition(4, 0), image.getSize());

    //Try to draw bigger than the image size, this should ignore the extra size
    screenGraphics.drawImage(new TerminalPosition(1, 7), image, TerminalPosition.TOP_LEFT_CORNER, image.getSize().withRelativeColumns(10));

    //0 size should draw nothing
    screenGraphics.drawImage(new TerminalPosition(8, 7), image, TerminalPosition.TOP_LEFT_CORNER, TerminalSize.ZERO);

    //Drawing with a negative source image offset will move the target position
    screenGraphics.drawImage(new TerminalPosition(8, 7), image, new TerminalPosition(-2, -2), image.getSize());

    screen.refresh();
    screen.readInput();
    screen.stopScreen();
}
 
Example #27
Source File: ScreenClearTest.java    From lanterna with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void drawText(Screen screen) {
    TextGraphics writer = new ScreenTextGraphics(screen);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(10, 1, "Hello World");

    writer.setForegroundColor(TextColor.ANSI.BLACK);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(11, 2, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.WHITE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(12, 3, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLACK);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(13, 4, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.WHITE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(14, 5, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(15, 6, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.DEFAULT);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(16, 7, "Hello World");

    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(10, 10, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(11, 11, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(12, 12, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.MAGENTA);
    writer.putString(13, 13, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(14, 14, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(15, 15, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(16, 16, "Hello World");
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.MAGENTA);
    writer.putString(17, 17, "Hello World");

    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(10, 20, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(11, 21, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(12, 22, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.BLUE);
    writer.setBackgroundColor(TextColor.ANSI.MAGENTA);
    writer.putString(13, 23, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.DEFAULT);
    writer.putString(14, 24, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.WHITE);
    writer.putString(15, 25, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.GREEN);
    writer.setBackgroundColor(TextColor.ANSI.BLACK);
    writer.putString(16, 26, "Hello World", SGR.BOLD);
    writer.setForegroundColor(TextColor.ANSI.CYAN);
    writer.setBackgroundColor(TextColor.ANSI.BLUE);
    writer.putString(17, 27, "Hello World", SGR.BOLD);
}
 
Example #28
Source File: TextGraphicsWriterTest.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 {
    Screen screen = new TestTerminalFactory(args).createScreen();
    screen.startScreen();

    TextGraphics writer = new ScreenTextGraphics(screen);
    writer.setForegroundColor(TextColor.ANSI.WHITE);
    writer.setBackgroundColor(TextColor.ANSI.BLUE);
    writer.fill(' ');
    TextGraphicsWriter tw = new TextGraphicsWriter(writer);

    String loremIpsum =
            "  Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod" +
            " tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim" +
            " veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid" +
            " ex ea commodi consequat. Quis aute iure reprehenderit in voluptate" +
            " velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" +
            " obcaecat cupiditat non proident, sunt in culpa qui officia deserunt" +
            " mollit anim id est laborum.\n";
    // change all blanks behind full-stops or commas to underlined tabs:
    loremIpsum = loremIpsum.replaceAll("([.,]) ", "$1\033[4m\t\033[24m");
    // each occurrence of "dolor" gets its own background:
    loremIpsum = loremIpsum.replaceAll("(dolor)", "\033[45m$1\033[49m");
    // each 'o' is turned yellow.
    loremIpsum = loremIpsum.replaceAll("([o])", "\033[1;33m$1\033[22;39m");

    tw.putString("\033[m");
    tw.setWrapBehaviour(WrapBehaviour.SINGLE_LINE);
    writer.setTabBehaviour(TabBehaviour.ALIGN_TO_COLUMN_4);
    tw.putString("\n"+tw.getWrapBehaviour()+":\n");
    tw.putString(loremIpsum);

    tw.setWrapBehaviour(WrapBehaviour.CLIP);
    tw.putString("\n"+tw.getWrapBehaviour()+":\n");
    tw.putString(loremIpsum);

    tw.setWrapBehaviour(WrapBehaviour.CHAR);
    tw.putString("\n"+tw.getWrapBehaviour()+":\n");
    tw.putString(loremIpsum);

    tw.setWrapBehaviour(WrapBehaviour.WORD);
    tw.putString("\n"+tw.getWrapBehaviour()+":\n");
    tw.putString(loremIpsum);

    tw.setWrapBehaviour(WrapBehaviour.CLIP);
    writer.setTabBehaviour(TabBehaviour.IGNORE);
    tw.putString("\n"+tw.getWrapBehaviour()+" + TabBehaviour.IGNORE:\n");
    tw.putString(loremIpsum);

    tw.putString("\033[m");
    tw.setStyleable(false);
    tw.putString(tw.getWrapBehaviour()+" + Styleable turned off, so esc-sequences are visible:\n");
    tw.putString(loremIpsum);

    screen.refresh();
    screen.readInput();
    screen.stopScreen();
}
 
Example #29
Source File: SGRTest.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 rawTerminal = new TestTerminalFactory(args).createTerminal();
    rawTerminal.enterPrivateMode();
    rawTerminal.clearScreen();
    
    String string = "Hello!";
    
    TextGraphics textGraphics = rawTerminal.newTextGraphics();
    textGraphics.setForegroundColor(TextColor.ANSI.RED);
    textGraphics.enableModifiers(SGR.BLINK);
    textGraphics.putString(10, 2, string);
    textGraphics.disableModifiers(SGR.BLINK);
    textGraphics.enableModifiers(SGR.BOLD);
    textGraphics.putString(10, 4, string);
    textGraphics.disableModifiers(SGR.BOLD);
    textGraphics.enableModifiers(SGR.BORDERED);
    textGraphics.putString(10, 6, string);
    textGraphics.disableModifiers(SGR.BORDERED);
    textGraphics.enableModifiers(SGR.CIRCLED);
    textGraphics.putString(10, 8, string);
    textGraphics.disableModifiers(SGR.CIRCLED);
    textGraphics.enableModifiers(SGR.CROSSED_OUT);
    textGraphics.putString(10, 10, string);
    textGraphics.disableModifiers(SGR.CROSSED_OUT);
    textGraphics.enableModifiers(SGR.UNDERLINE);
    textGraphics.putString(10, 12, string);
    textGraphics.disableModifiers(SGR.UNDERLINE);
    textGraphics.enableModifiers(SGR.FRAKTUR);
    textGraphics.putString(10, 14, string);
    textGraphics.disableModifiers(SGR.FRAKTUR);
    textGraphics.enableModifiers(SGR.REVERSE);
    textGraphics.putString(10, 16, string);
    textGraphics.disableModifiers(SGR.REVERSE);
    rawTerminal.setCursorPosition(0, 0);
    textGraphics.setForegroundColor(TextColor.ANSI.RED_BRIGHT);
    textGraphics.putString(10, 18, string);
    rawTerminal.flush();
    try {
        while(rawTerminal.pollInput() == null) {
            Thread.sleep(1);
        }
    }
    catch(InterruptedException e) {}
    rawTerminal.exitPrivateMode();
}
 
Example #30
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();
}