Java Code Examples for com.googlecode.lanterna.graphics.TextGraphics#setForegroundColor()
The following examples show how to use
com.googlecode.lanterna.graphics.TextGraphics#setForegroundColor() .
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: InternationalCharactersTest.java From lanterna with GNU Lesser General Public License v3.0 | 6 votes |
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 2
Source File: CJKScreenTest.java From lanterna with GNU Lesser General Public License v3.0 | 6 votes |
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 3
Source File: VirtualScreen.java From lanterna with GNU Lesser General Public License v3.0 | 5 votes |
@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 4
Source File: FullScreenTextGUITest.java From lanterna with GNU Lesser General Public License v3.0 | 5 votes |
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 5
Source File: ExtendedTerminalTests.java From lanterna with GNU Lesser General Public License v3.0 | 5 votes |
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 6
Source File: SimpleTerminalTest.java From lanterna with GNU Lesser General Public License v3.0 | 5 votes |
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 7
Source File: TerminalTextGraphicsTest.java From lanterna with GNU Lesser General Public License v3.0 | 5 votes |
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 8
Source File: TerminalColorTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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(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.enableModifiers(SGR.BOLD); writer.putString(13, 4, "Hello World"); writer.setForegroundColor(TextColor.ANSI.WHITE); writer.setBackgroundColor(TextColor.ANSI.BLACK); writer.putString(14, 5, "Hello World"); writer.setForegroundColor(TextColor.ANSI.DEFAULT); writer.setBackgroundColor(TextColor.ANSI.DEFAULT); writer.putString(15, 6, "Hello World"); writer.setForegroundColor(TextColor.ANSI.DEFAULT); writer.setBackgroundColor(TextColor.ANSI.DEFAULT); writer.disableModifiers(SGR.BOLD); 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); writer.setForegroundColor(TextColor.ANSI.DEFAULT); writer.setBackgroundColor(TextColor.ANSI.RED); writer.fill(' '); screen.refresh(); try { Thread.sleep(5000); } catch(InterruptedException ignored) { } screen.stopScreen(); }
Example 9
Source File: SimpleScreenTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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 10
Source File: TextGraphicsWriterTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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 11
Source File: ScreenClearTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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 12
Source File: ScreenResizeTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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 13
Source File: ScreenTabTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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 14
Source File: ScreenLineTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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 15
Source File: SGRTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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(); }