de.vandermeer.asciitable.AsciiTable Java Examples

The following examples show how to use de.vandermeer.asciitable.AsciiTable. 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: AT_06a_Grids.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("rc 11", "rc 12");
	at.addRule();
	at.addRow("rc 21", "rc 22");
	at.addRule();
	at.getContext().setWidth(13);

	System.out.println(at.render());

	at.getContext().setGrid(A7_Grids.minusBarPlusEquals());
	System.out.println(at.render());

	at.getContext().setGrid(A8_Grids.lineDoubleBlocks());
	System.out.println(at.render());

	at.getContext().setGrid(U8_Grids.borderDoubleLight());
	System.out.println(at.render());

	at.getContext().setGrid(U8_Grids.borderDouble());
	System.out.println(at.render());
	// end::example[]
}
 
Example #2
Source File: AT_07c_LongestLine.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("0", "1", "22", "333", "4444");
	at.addRule();
	CWC_LongestLine cwc = new CWC_LongestLine();

	at.getRenderer().setCWC(cwc);
	System.out.println(at.render());

	cwc.add(4, 0);
	System.out.println(at.render());

	cwc.add(6, 0).add(0, 0).add(0, 0).add(0, 2);
	System.out.println(at.render());

	at.addRow("0", "1", "22", "333<br>55555", "4444");
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #3
Source File: SDLogger.java    From spring-data-generator with MIT License 6 votes vote down vote up
private static void printGenericTable(String title, List<String> messages) {
    AsciiTable table = new AsciiTable();
    table.addRule();
    table.addRow(null, title + ": " + messages.size()).getCells().get(1).getContext().setTextAlignment(TextAlignment.CENTER);
    table.addRule();

    int count = 1;
    for (String mess : messages) {
        table.addRow("#" + count, mess).getCells().get(0).getContext().setTextAlignment(TextAlignment.CENTER);
        table.addRule();
        count ++;
    }

    table.getContext().setGrid(A7_Grids.minusBarPlusEquals());
    table.getRenderer().setCWC(new CWC_LongestWordMin(new int[]{5, 101}));
    table.renderAsCollection().forEach(SDLogger::info);
}
 
Example #4
Source File: AT_00e_AddColumn_HasTextCluster.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectHasTextCluster implements HasTextCluster{
		@Override
		public Collection<String> getTextAsCollection() {
			ArrayList<String> text = new ArrayList<>();
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			return text;
		}
	}

	at.addRule();
	at.addRow(new ObjectHasTextCluster());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #5
Source File: AT_04a_Padding_Table.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("row 1 col 1", "row 1 col 2");
	at.addRule();
	at.addRow("row 2 col 1", "row 2 col 2");
	at.addRule();

	at.setPaddingTopChar('v');
	at.setPaddingBottomChar('^');
	at.setPaddingLeftChar('>');
	at.setPaddingRightChar('<');
	at.setTextAlignment(TextAlignment.CENTER);
	at.setPadding(1);
	System.out.println(at.render(33));
	// end::example[]
}
 
Example #6
Source File: AT_00h_AddColumn_RendersToCluster.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectRendersToCluster implements RendersToCluster{
		@Override
		public Collection<String> renderAsCollection() {
			ArrayList<String> text = new ArrayList<>();
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			text.add(new LoremIpsum().getWords(10));
			return text;
		}
	}

	at.addRule();
	at.addRow(new ObjectRendersToCluster());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #7
Source File: AT_06d_NewGrid.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	TA_Grid myGrid = TA_Grid.create("grid using UTF-8 light border characters")
			.addCharacterMap(TA_GridConfig.RULESET_NORMAL, ' ', '#', '&', '#', '#', '%', '%', '+', '+', '+', '#', '%')
	;

	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("rc 11", "rc 12");
	at.addRule();
	at.addRow("rc 21", "rc 22");
	at.addRule();
	at.getContext().setWidth(13);

	at.getContext().setGrid(myGrid);
	System.out.println(at.render());
	// end::example[]
}
 
Example #8
Source File: AT_04b_Padding_Row.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("row 1 col 1", "row 1 col 2");
	at.addRule();
	AT_Row row = at.addRow("row 2 col 1", "row 2 col 2");
	at.addRule();

	row.setPaddingTopChar('v');
	row.setPaddingBottomChar('^');
	row.setPaddingLeftChar('>');
	row.setPaddingRightChar('<');
	row.setTextAlignment(TextAlignment.CENTER);
	row.setPadding(1);
	System.out.println(at.render(33));
	// end::example[]
}
 
Example #9
Source File: AT_00i_AddColumn_RendersToClusterWidth.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectRendersToClusterWidth implements RendersToClusterWidth{
		@Override
		public Collection<String> renderAsCollection(int width) {
			return ClusterElementTransformer.create().transform(
					Text_To_FormattedText.justified(new LoremIpsum().getWords(30), width),
					StrBuilder_To_String.create(),
					ArrayListStrategy.create()
			);
		}
	}

	at.addRule();
	at.addRow(new ObjectRendersToClusterWidth());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #10
Source File: AT_05_MarginBehavior.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("row 1 col 1", "row 1 col 2");
	at.addRule();
	at.addRow("row 2 col 1", "row 2 col 2");
	at.addRule();

	at.getContext().setFrameTopChar('v');
	at.getContext().setFrameBottomChar('^');
	at.getContext().setFrameLeftChar('>');
	at.getContext().setFrameRightChar('<');

	at.getContext().setFrameTopMargin(1);
	at.getContext().setFrameBottomMargin(2);
	at.getContext().setFrameLeftMargin(3);
	at.getContext().setFrameRightMargin(4);

	System.out.println(at.render(39));
	// end::example[]
}
 
Example #11
Source File: AT_00d_AddColumn_HasText.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectHasText implements HasText{
		@Override
		public String getText() {
			return new LoremIpsum().getWords(10);
		}
	}

	at.addRule();
	at.addRow(new ObjectHasText());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #12
Source File: AT_00g_AddColumn_DoesRenderToWidth.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectDoesRenderToWidth implements DoesRenderToWidth{
		@Override
		public String render(int width) {
			return new StrBuilder().appendWithSeparators(Text_To_FormattedText.left(new LoremIpsum().getWords(10), width), "\n").toString();
		}
	}

	at.addRule();
	at.addRow(new ObjectDoesRenderToWidth());
	at.addRule();
	System.out.println(at.render(30));
	// end::example[]
}
 
Example #13
Source File: AT_06b_GridRuleStyle.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("rc 11", "rc 12");
	at.addLightRule();
	at.addRow("rc 21", "rc 22");
	at.addStrongRule();
	at.addRow("rc 31", "rc 32");
	at.addHeavyRule();
	at.getContext().setWidth(13);

	at.getContext().setGrid(A8_Grids.lineDoubleBlocks());
	System.out.println(at.render());
	// end::example[]
}
 
Example #14
Source File: AT_08a_TargetTranslator_Latex.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	String text = "A sentence with some normal text, not specific to LaTeX. " +
		"Now for some characters that require conversion: # % &. " +
		"And some more: © § ¤. " +
		"And even more: È É Ê Ë. " +
		"And some arrows as well: ← ↑ → ↓ ↔"
	;

	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow(text, text).getCells().get(1).getContext().setTargetTranslator(new Text2Latex());
	at.addRule();
	at.setTextAlignment(TextAlignment.LEFT);

	System.out.println(at.render());
	// end::example[]
}
 
Example #15
Source File: AT_07f_LongestWordMin.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("first", "information");
	at.addRule();
	at.addRow("second", "info");
	at.addRule();

	at.getRenderer().setCWC(new CWC_LongestWordMin(9));
	System.out.println(at.render());

	at.getRenderer().setCWC(new CWC_LongestWordMin(new int[]{-1,30}));
	System.out.println(at.render());
	// end::example[]
}
 
Example #16
Source File: AT_03_AlignmentOptions.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	String text = new LoremIpsum().getWords(19);
	AT_Row row;
	at.addRule();
	row = at.addRow(text, text, text);
	row.getCells().get(0).getContext().setTextAlignment(TextAlignment.JUSTIFIED_LEFT);
	row.getCells().get(1).getContext().setTextAlignment(TextAlignment.JUSTIFIED);
	row.getCells().get(2).getContext().setTextAlignment(TextAlignment.JUSTIFIED_RIGHT);
	at.addRule();
	row = at.addRow(text, text, text);
	row.getCells().get(0).getContext().setTextAlignment(TextAlignment.LEFT);
	row.getCells().get(1).getContext().setTextAlignment(TextAlignment.CENTER);
	row.getCells().get(2).getContext().setTextAlignment(TextAlignment.RIGHT);
	at.addRule();
	System.out.println(at.render(79));
	// end::example[]
}
 
Example #17
Source File: AT_07d_LongestWord.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	AT_Row row1 = at.addRow("first", "information");
	at.addRule();
	AT_Row row2 = at.addRow("second", "info");
	at.addRule();

	at.getRenderer().setCWC(new CWC_LongestWord());
	System.out.println(at.render());

	at.setPaddingLeftRight(1);
	System.out.println(at.render());

	at.setPaddingLeftRight(0);
	row1.getCells().get(0).getContext().setPaddingLeftRight(2);
	row1.getCells().get(1).getContext().setPaddingLeftRight(3);
	row2.getCells().get(0).getContext().setPaddingLeftRight(3);
	row2.getCells().get(1).getContext().setPaddingLeftRight(4);
	System.out.println(at.render());
	// end::example[]
}
 
Example #18
Source File: AT_00f_AddColumn_DoesRender.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	class ObjectDoesRender implements DoesRender{
		@Override
		public String render() {
			return new LoremIpsum().getWords(10);
		}
	}

	at.addRule();
	at.addRow(new ObjectDoesRender());
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #19
Source File: AT_02_ColSpan.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow(null, null, null, null, "span all 5 columns");
	at.addRule();
	at.addRow(null, null, null, "span 4 columns", "just 1 column");
	at.addRule();
	at.addRow(null, null, "span 3 columns", null, "span 2 columns");
	at.addRule();
	at.addRow(null, "span 2 columns", null, null, "span 3 columns");
	at.addRule();
	at.addRow("just 1 column", null, null, null, "span 4 columns");
	at.addRule();
	at.addRow("just 1 column", "just 1 column", "just 1 column", "just 1 column", "just 1 column");
	at.addRule();
	System.out.println(at.render(71));
	// end::example[]
}
 
Example #20
Source File: AT_00b_WidthBehavior.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("row 1 col 1", "row 1 col 2");
	at.addRule();
	at.addRow("row 2 col 1", "row 2 col 2");
	at.addRule();

	at.getContext().setWidth(50);
	System.out.println(at.render());

	at.getContext().setWidth(40);
	System.out.println(at.render());

	at.getContext().setWidth(30);
	System.out.println(at.render());

	// end::example[]
}
 
Example #21
Source File: AT_07e_LongestWordMax.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("first", "information");
	at.addRule();
	at.addRow("second", "info");
	at.addRule();

	at.getRenderer().setCWC(new CWC_LongestWordMax(8));
	System.out.println(at.render());

	at.getRenderer().setCWC(new CWC_LongestWordMax(new int[]{4,-1}));
	System.out.println(at.render());
	// end::example[]
}
 
Example #22
Source File: AT_09b_ConditionalLinebreak.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
	public void showOutput(){
		// tag::example[]
		String text = "line 1<br>" +
			"line 2<br/>" +
			"line three \n still line three"
		;
//		String text = new LoremIpsum().getParagraphs(1) + "\r\n\n<br><br><br>" + new LoremIpsum().getParagraphs(1);

		AsciiTable at = new AsciiTable();
		at.addRule();
		at.addRow(text);
		at.addRule();
		at.setTextAlignment(TextAlignment.LEFT);
		System.out.println(at.render(50));
		// end::example[]
	}
 
Example #23
Source File: AT_07b_Width_Fixed.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("col1", "col2", "col3");
	at.addRule();

	at.getRenderer().setCWC(new CWC_FixedWidth().add(10).add(20).add(30));
	System.out.println(at.render());

	at.getRenderer().setCWC(new CWC_FixedWidth().add(5).add(10).add(15));
	System.out.println(at.render());

	at.getRenderer().setCWC(new CWC_FixedWidth().add(3).add(5).add(7));
	System.out.println(at.render());
	// end::example[]
}
 
Example #24
Source File: AT_08b_TargetTranslator_HTML.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	String text = "A sentence with some normal text, not specific to HTML. " +
			"Now for some characters that require conversion: # % & < >. " +
			"And some more: © § ¤. " +
			"And even more: Ē ē Ĕ ĕ Ė ė Ę ę Ě ě. " +
			"And some arrows as well: ← ↑ → ↓ ↔ ↕"
	;

	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow(text, text).getCells().get(1).getContext().setTargetTranslator(new Text2Html());
	at.addRule();
	at.setTextAlignment(TextAlignment.LEFT);

	System.out.println(at.render());
	// end::example[]
}
 
Example #25
Source File: AT_04c_Padding_Cell.java    From asciitable with Apache License 2.0 6 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("row 1 col 1", "row 1 col 2");
	at.addRule();
	AT_Cell cell = at.addRow("row 2 col 1", "row 2 col 2").getCells().get(1);
	at.addRule();

	cell.getContext().setPaddingTopChar('v');
	cell.getContext().setPaddingBottomChar('^');
	cell.getContext().setPaddingLeftChar('>');
	cell.getContext().setPaddingRightChar('<');
	cell.getContext().setTextAlignment(TextAlignment.CENTER);
	cell.getContext().setPadding(1);
	System.out.println(at.render(33));
	// end::example[]
}
 
Example #26
Source File: AT_09c_ListWithLinebreaks.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("column with a list using conditional line breaks", " * list item one<br> * list item two<br> * list item three");
	at.addRule();
	at.setTextAlignment(TextAlignment.LEFT);
	at.getRenderer().setCWC(new CWC_FixedWidth().add(20).add(25));
	System.out.println(at.render(50));
	// end::example[]
}
 
Example #27
Source File: AT_03c_AlignmentCell.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	String text = new LoremIpsum().getWords(9);
	at.addRule();
	at.addRow(text, text, text);
	at.addRule();
	AT_Row row = at.addRow(text, text, text);
	at.addRule();
	row.getCells().get(2).getContext().setTextAlignment(TextAlignment.RIGHT);
	System.out.println(at.render(76));
	// end::example[]
}
 
Example #28
Source File: AT_01d_3Columns.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("first row (col1)", "some information (col2)", "more info (col3)");
	at.addRule();
	at.addRow("second row (col1)", "some information (col2)", "more info (col3)");
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #29
Source File: AT_00c_AddColumn_ST.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	ST st = new ST(new LoremIpsum().getWords(10));
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow(st);
	at.addRule();
	System.out.println(at.render());
	// end::example[]
}
 
Example #30
Source File: AT_01b_1Column.java    From asciitable with Apache License 2.0 5 votes vote down vote up
@Override
public void showOutput(){
	// tag::example[]
	AsciiTable at = new AsciiTable();
	at.addRule();
	at.addRow("Table Heading");
	at.addRule();
	at.addRow("first row (col1)");
	at.addRule();
	at.addRow("second row (col1)");
	at.addRule();
	System.out.println(at.render(30));
	// end::example[]
}