123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package me.km.utils;
- public class TableUtils
- {
- public static String getTable(int width, String color, String... args)
- {
- //int leftSpace = (9 * width - 6 - 10 * args.length) % args.length;
- width = 9 * width - 1;
-
- StringBuilder sb = new StringBuilder(color + "│ ");
- //int bonus;
- for(String s : args)
- {
- //bonus = leftSpace > 0 ? 9 : 0;
- sb.append("§r");
- sb.append(getStringWithMaxLength(s, width));
- //leftSpace -= 9;
- sb.append(color);
- sb.append("│ ");
- }
- sb.deleteCharAt(sb.length() - 1);
- return sb.toString();
- }
-
- public static String getTableMiddle(int width, int columns, String color)
- {
- StringBuilder sb = new StringBuilder(color + "├");
- for(int i = 0; i < columns; i++)
- {
- for(int j = 0; j < width; j++)
- {
- sb.append("─");
- }
- sb.append("┼");
- }
- sb.deleteCharAt(sb.length() - 1);
- sb.append("┤");
- return sb.toString();
- }
-
- public static String getTableStart(int width, int columns, String color)
- {
- StringBuilder sb = new StringBuilder(color + "┌");
- for(int i = 0; i < columns; i++)
- {
- for(int j = 0; j < width; j++)
- {
- sb.append("─");
- }
- sb.append("┬");
- }
- sb.deleteCharAt(sb.length() - 1);
- sb.append("┐");
- return sb.toString();
- }
-
- public static String getTableEnd(int width, int columns, String color)
- {
- StringBuilder sb = new StringBuilder(color + "└");
- for(int i = 0; i < columns; i++)
- {
- for(int j = 0; j < width; j++)
- {
- sb.append("─");
- }
- sb.append("┴");
- }
- sb.deleteCharAt(sb.length() - 1);
- sb.append("┘");
- return sb.toString();
- }
-
- private static String getStringWithMaxLength(String s, int max)
- {
- // 9 Pixel: └,─,┬
- // 8 Pixel:
- // 7 Pixel:
- // 6 Pixel: normal, │
- // 5 Pixel: f, k
- // 4 Pixel: I, t
- // 3 Pixel: l
- // 2 Pixel: is
- int sum = 0;
- String r = "";
- int should;
- boolean onColor = false;
- for(char c : s.toCharArray())
- {
- switch(c)
- {
- case 'f':
- case 'k':
- should = 5;
- break;
- case 'I':
- case 't':
- case ' ':
- should = 4;
- break;
- case 'l':
- should = 3;
- break;
- case 'i':
- should = 2;
- break;
- case '§':
- should = 0;
- onColor = true;
- break;
- default:
- should = 6;
- }
- if(!onColor || should == 0)
- {
- sum += should;
- }
- else
- {
- onColor = false;
- }
- //System.out.println(sum + " " + max);
- if(sum > max)
- {
- sum -= should;
- r += "§0";
- while(sum < max)
- {
- if(max - sum == 1)
- {
- r += "ˈ";
- break;
- }
- if(max - sum >= 4)
- {
- r += " ";
- sum += 4;
- continue;
- }
- r += "˼";
- sum += 2;
- }
- return r;
- }
- else if(sum == max)
- {
- r += c;
- return r;
- }
- r += c;
- }
- r += "§0";
- while(sum < max)
- {
- if(max - sum == 1)
- {
- r += "ˈ";
- break;
- }
- if(max - sum >= 4)
- {
- r += " ";
- sum += 4;
- continue;
- }
- r += "˼";
- sum += 2;
- }
- return r;
- }
- }
|