Java Code Examples for com.googlecode.lanterna.graphics.TextGraphics#setBackgroundColor()
The following examples show how to use
com.googlecode.lanterna.graphics.TextGraphics#setBackgroundColor() .
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: VirtualScreenTest.java From lanterna with GNU Lesser General Public License v3.0 | 5 votes |
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 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: 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 8
Source File: ScreenTriangleTest.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 useFilled = false; boolean slow = false; boolean rotating = false; boolean square = false; for(String arg : args) { if(arg.equals("--ansi-colors")) { useAnsiColors = true; } if(arg.equals("--filled")) { useFilled = true; } if(arg.equals("--slow")) { slow = true; } if(arg.equals("--rotating")) { rotating = true; } if(arg.equals("--square")) { square = true; } } Screen screen = new TestTerminalFactory(args).createScreen(); screen.startScreen(); TextGraphics graphics = new ScreenTextGraphics(screen); if(square) { graphics = new DoublePrintingTextGraphics(graphics); } Random random = new Random(); TextColor color = null; double rad = 0.0; while(true) { KeyStroke keyStroke = screen.pollInput(); if(keyStroke != null && (keyStroke.getKeyType() == KeyType.Escape || keyStroke.getKeyType() == KeyType.EOF)) { break; } screen.doResizeIfNecessary(); TerminalSize size = graphics.getSize(); if(useAnsiColors) { if(color == null || !rotating) { color = TextColor.ANSI.values()[random.nextInt(TextColor.ANSI.values().length)]; } } else { if(color == null || !rotating) { //Draw a rectangle in random indexed color color = new TextColor.Indexed(random.nextInt(256)); } } TerminalPosition p1; TerminalPosition p2; TerminalPosition p3; if(rotating) { screen.clear(); double triangleSize = 15.0; int x0 = (size.getColumns() / 2) + (int) (Math.cos(rad) * triangleSize); int y0 = (size.getRows() / 2) + (int) (Math.sin(rad) * triangleSize); int x1 = (size.getColumns() / 2) + (int) (Math.cos(rad + oneThirdOf2PI) * triangleSize); int y1 = (size.getRows() / 2) + (int) (Math.sin(rad + oneThirdOf2PI) * triangleSize); int x2 = (size.getColumns() / 2) + (int) (Math.cos(rad + twoThirdsOf2PI) * triangleSize); int y2 = (size.getRows() / 2) + (int) (Math.sin(rad + twoThirdsOf2PI) * triangleSize); p1 = new TerminalPosition(x0, y0); p2 = new TerminalPosition(x1, y1); p3 = new TerminalPosition(x2, y2); rad += Math.PI / 90.0; } else { p1 = new TerminalPosition(random.nextInt(size.getColumns()), random.nextInt(size.getRows())); p2 = new TerminalPosition(random.nextInt(size.getColumns()), random.nextInt(size.getRows())); p3 = new TerminalPosition(random.nextInt(size.getColumns()), random.nextInt(size.getRows())); } graphics.setBackgroundColor(color); if(useFilled) { graphics.fillTriangle(p1, p2, p3, ' '); } else { graphics.drawTriangle(p1, p2, p3, ' '); } screen.refresh(Screen.RefreshType.DELTA); if(slow) { Thread.sleep(500); } } 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: DrawImageTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
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 13
Source File: ScreenRectangleTest.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 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 14
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 15
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 16
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(); }