java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
author František Kučera <franta-hg@frantovo.cz>
Sun, 22 Dec 2013 23:31:55 +0100
branchv_0
changeset 34 9335cf31c0f2
parent 32 5e412dbd9362
child 37 9e6f8e5d5f98
permissions -rw-r--r--
first working version

/**
 * SQL-DK
 * Copyright © 2013 František Kučera (frantovo.cz)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package info.globalcode.sql.dk.formatting;

import info.globalcode.sql.dk.ColorfulPrintWriter;

/**
 *
 * @author Ing. František Kučera (frantovo.cz)
 */
public class TabularFormatter extends AbstractFormatter {

	public static final String NAME = "tabular";
	private ColorfulPrintWriter out;

	public TabularFormatter(FormatterContext formatterContext) {
		super(formatterContext);
		out = new ColorfulPrintWriter(formatterContext.getOutputStream());
	}

	@Override
	public void writeColumnValue(Object value) {
		super.writeColumnValue(value);

		if (!isCurrentColumnFirst()) {
			out.print(ColorfulPrintWriter.TerminalColor.Green, " | ");
		}
		
		out.print(ColorfulPrintWriter.TerminalColor.Cyan, String.valueOf(value));
	}

	@Override
	public void writeEndRow() {
		super.writeEndRow();
		out.println();
		out.flush();
	}
}