Skip to content

Commit

Permalink
Command colors: reformatting name table, step II
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Dec 20, 2020
1 parent 12dc013 commit 89d4ec4
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions builtins/src/main/java/org/jline/builtins/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,10 @@ public static void colors(Terminal terminal, PrintStream out, String[] argv) thr
if (opt.isSet("help")) {
throw new Options.HelpException(opt.usage());
}
int columns = terminal.getWidth() > 131 ? 6 : 5;
int columns = terminal.getWidth() > 122 ? 6 : 5;
if (opt.isSet("small")) {
columns = columns + 2;
}
if (opt.isSet("columns")) {
columns = opt.getNumber("columns");
}
Expand Down Expand Up @@ -1184,17 +1187,25 @@ public void printColors(boolean name, boolean small, int columns) throws IOExcep
String line = reader.readLine();
int col = 0;
Integer idx = 0;
int colWidth = 22;
int colWidth = 21;
int lb = 1;
while (line != null) {
line = line.trim();
if (!line.isEmpty() && !line.startsWith("#")) {
String fg = foreground(idx);
AttributedStyle ss = new StyleResolver(this::getStyle).resolve("." + fg + line, null);
asb.style(ss);
if (columns > 3) {
colWidth = idx > 15 && idx < 232 ? 22 : (idx % 2 == 0 || columns != 6 ? 16 : 17);
lb = idx > 15 && idx < 232 ? 1 : -1;
if (small) {
colWidth = 15;
lb = 1;
} else if (columns > 4) {
if (idx > 15 && idx < 232) {
colWidth = columns != 6 || col == 1 || col == 2 || col == 3 ? 21 : 20;
lb = 1;
} else {
colWidth = columns != 6 || idx % 2 == 0 || col == 7 ? 15 : 16;
lb = -1;
}
}
asb.append(String.valueOf(idx)).append(addPadding(colWidth - idx.toString().length(), line));
col++;
Expand All @@ -1204,21 +1215,20 @@ public void printColors(boolean name, boolean small, int columns) throws IOExcep
asb.style(AttributedStyle.DEFAULT);
asb.append('\n');
}
}
if (idx == 16) {
if (small) {
break;
} else if (col != 0) {
if (idx == 16) {
if (small) {
break;
} else if (col != 0) {
col = 0;
asb.style(AttributedStyle.DEFAULT);
asb.append('\n');
}
} else if (idx == 232 && col != 0) {
col = 0;
asb.style(AttributedStyle.DEFAULT);
asb.append('\n');
}
}
if (idx == 232 && col != 0) {
col = 0;
asb.style(AttributedStyle.DEFAULT);
asb.append('\n');
}
line = reader.readLine();
}
reader.close();
Expand Down

0 comments on commit 89d4ec4

Please sign in to comment.