|
@@ -2,142 +2,108 @@ package me.km.utils;
|
|
|
|
|
|
public class TableUtils {
|
|
public class TableUtils {
|
|
public static String getTable(int width, String color, String... args) {
|
|
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;
|
|
|
|
|
|
+ width = 9 * width - 1; // ([ ] + [│]) - [─] = 1
|
|
|
|
+ StringBuilder sb = new StringBuilder(color).append("│ ");
|
|
for(String s : args) {
|
|
for(String s : args) {
|
|
- //bonus = leftSpace > 0 ? 9 : 0;
|
|
|
|
sb.append("§r");
|
|
sb.append("§r");
|
|
sb.append(getStringWithMaxLength(s, width));
|
|
sb.append(getStringWithMaxLength(s, width));
|
|
- //leftSpace -= 9;
|
|
|
|
- sb.append(color);
|
|
|
|
- sb.append("│ ");
|
|
|
|
|
|
+ sb.append(color).append("│ ");
|
|
}
|
|
}
|
|
sb.deleteCharAt(sb.length() - 1);
|
|
sb.deleteCharAt(sb.length() - 1);
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|
|
|
|
|
|
public static String getTableMiddle(int width, int columns, String color) {
|
|
public static String getTableMiddle(int width, int columns, String color) {
|
|
- StringBuilder sb = new StringBuilder(color + "├");
|
|
|
|
|
|
+ StringBuilder sb = new StringBuilder(color).append("├");
|
|
for(int i = 0; i < columns; i++) {
|
|
for(int i = 0; i < columns; i++) {
|
|
for(int j = 0; j < width; j++) {
|
|
for(int j = 0; j < width; j++) {
|
|
sb.append("─");
|
|
sb.append("─");
|
|
}
|
|
}
|
|
sb.append("┼");
|
|
sb.append("┼");
|
|
}
|
|
}
|
|
- sb.deleteCharAt(sb.length() - 1);
|
|
|
|
- sb.append("┤");
|
|
|
|
|
|
+ sb.setCharAt(sb.length() - 1, '┤');
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|
|
|
|
|
|
public static String getTableStart(int width, int columns, String color) {
|
|
public static String getTableStart(int width, int columns, String color) {
|
|
- StringBuilder sb = new StringBuilder(color + "┌");
|
|
|
|
|
|
+ StringBuilder sb = new StringBuilder(color).append("┌");
|
|
for(int i = 0; i < columns; i++) {
|
|
for(int i = 0; i < columns; i++) {
|
|
for(int j = 0; j < width; j++) {
|
|
for(int j = 0; j < width; j++) {
|
|
sb.append("─");
|
|
sb.append("─");
|
|
}
|
|
}
|
|
sb.append("┬");
|
|
sb.append("┬");
|
|
}
|
|
}
|
|
- sb.deleteCharAt(sb.length() - 1);
|
|
|
|
- sb.append("┐");
|
|
|
|
|
|
+ sb.setCharAt(sb.length() - 1, '┐');
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|
|
|
|
|
|
public static String getTableEnd(int width, int columns, String color) {
|
|
public static String getTableEnd(int width, int columns, String color) {
|
|
- StringBuilder sb = new StringBuilder(color + "└");
|
|
|
|
|
|
+ StringBuilder sb = new StringBuilder(color).append("└");
|
|
for(int i = 0; i < columns; i++) {
|
|
for(int i = 0; i < columns; i++) {
|
|
for(int j = 0; j < width; j++) {
|
|
for(int j = 0; j < width; j++) {
|
|
sb.append("─");
|
|
sb.append("─");
|
|
}
|
|
}
|
|
sb.append("┴");
|
|
sb.append("┴");
|
|
}
|
|
}
|
|
- sb.deleteCharAt(sb.length() - 1);
|
|
|
|
- sb.append("┘");
|
|
|
|
|
|
+ sb.setCharAt(sb.length() - 1, '┘');
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static int getCharWidth(char c) {
|
|
|
|
+ switch(c) {
|
|
|
|
+ case 'f':
|
|
|
|
+ case 'k':
|
|
|
|
+ return 5;
|
|
|
|
+ case 'I':
|
|
|
|
+ case 't':
|
|
|
|
+ case ' ':
|
|
|
|
+ case '[':
|
|
|
|
+ case ']':
|
|
|
|
+ case '{':
|
|
|
|
+ case '}':
|
|
|
|
+ case '(':
|
|
|
|
+ case ')':
|
|
|
|
+ return 4;
|
|
|
|
+ case 'l':
|
|
|
|
+ return 3;
|
|
|
|
+ case ';':
|
|
|
|
+ case ',':
|
|
|
|
+ case '.':
|
|
|
|
+ case 'i':
|
|
|
|
+ return 2;
|
|
|
|
+ }
|
|
|
|
+ return 6;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static String getStringWithMaxLength(String s, int max) {
|
|
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;
|
|
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;
|
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ for(int i = 0; i < s.length(); i++) {
|
|
|
|
+ char c = s.charAt(i);
|
|
|
|
+ if(c == '§') {
|
|
|
|
+ i++;
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
- r += c;
|
|
|
|
- }
|
|
|
|
- r += "§0";
|
|
|
|
- while(sum < max) {
|
|
|
|
- if(max - sum == 1) {
|
|
|
|
- r += "ˈ";
|
|
|
|
|
|
+ int width = getCharWidth(c);
|
|
|
|
+ if(sum + width > max) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- if(max - sum >= 4) {
|
|
|
|
- r += " ";
|
|
|
|
- sum += 4;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- r += "˼";
|
|
|
|
|
|
+ sum += width;
|
|
|
|
+ sb.append(c);
|
|
|
|
+ }
|
|
|
|
+ sb.append("§0");
|
|
|
|
+ while(sum + 4 <= max) {
|
|
|
|
+ sb.append(' ');
|
|
|
|
+ sum += 4;
|
|
|
|
+ }
|
|
|
|
+ while(sum + 2 <= max) {
|
|
|
|
+ sb.append('˼');
|
|
sum += 2;
|
|
sum += 2;
|
|
}
|
|
}
|
|
- return r;
|
|
|
|
|
|
+ while(sum + 1 <= max) {
|
|
|
|
+ sb.append('ˈ');
|
|
|
|
+ sum++;
|
|
|
|
+ }
|
|
|
|
+ return sb.toString();
|
|
}
|
|
}
|
|
}
|
|
}
|