package com.lanyuanxiaoyao.service.command.utils;

import org.springframework.shell.table.BorderSpecification;
import org.springframework.shell.table.BorderStyle;
import org.springframework.shell.table.TableBuilder;
import org.springframework.shell.table.TableModelBuilder;

/**
 * Shell 表显示工具
 *
 * @author ZhangJiacheng
 * @date 2022-05-23
 */
public class ShellTableUtils {
    public static final String CHECK_TRUE = "√";
    public static final int TABLE_WIDTH = 500;
    public static final BorderStyle INNER_STYLE = BorderStyle.air;
    public static final int INNER_SPECIFICATION = BorderSpecification.INNER_VERTICAL;

    public static String renderTable(TableModelBuilder<?> builder) {
        return new TableBuilder(builder.build())
                .addHeaderAndVerticalsBorders(BorderStyle.oldschool)
                .build()
                .render(TABLE_WIDTH);
    }

    public static String renderInnerTable(TableModelBuilder<?> builder) {
        return new TableBuilder(builder.build())
                .paintBorder(INNER_STYLE, INNER_SPECIFICATION)
                .fromTopLeft()
                .toBottomRight()
                .build()
                .render(TABLE_WIDTH);
    }
}
