Skip to content

Commit

Permalink
Improve window borders rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 23, 2017
1 parent cd0a252 commit c78f430
Showing 1 changed file with 104 additions and 9 deletions.
113 changes: 104 additions & 9 deletions builtins/src/main/java/org/jline/builtins/Tmux.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,19 @@ protected void splitWindow(PrintStream out, PrintStream err, List<String> args)
protected synchronized void redraw() {
long[] screen = new long[size.getRows() * size.getColumns()];
// Fill
Arrays.fill(screen, 0x00000020);
Arrays.fill(screen, 0x00000020L);
int[] cursor = new int[2];
for (VirtualConsole terminal : panes) {
// Dump terminal
terminal.dump(screen, terminal.getTop(), terminal.getLeft(), size.getRows(), size.getColumns(),
terminal == active ? cursor : null);
// Draw border
drawBorder(screen, size, terminal, 0x00ff0000);
drawBorder(screen, size, terminal, 0x0L);
}
drawBorder(screen, size, active, 0x002f0000);
drawBorder(screen, size, active, 0x010080000L << 32);
// Draw status
Arrays.fill(screen, (size.getRows() - 1) * size.getColumns(), size.getRows() * size.getColumns(), 0x00f20020);
Arrays.fill(screen, (size.getRows() - 1) * size.getColumns(), size.getRows() * size.getColumns(),
0x20000080L << 32 | 0x0020L);

// Attribute mask: 0xYXFFFBBB00000000L
// X: Bit 0 - Underlined
Expand Down Expand Up @@ -485,19 +486,113 @@ private void drawBorder(long[] screen, Size size, VirtualConsole terminal, long
drawBorderChar(screen, size, x0, i, attr, '│');
drawBorderChar(screen, size, x1, i, attr, '│');
}
// TODO: fix that to have clean crosses
drawBorderChar(screen, size, terminal.getLeft() - 1, terminal.getTop() - 1, attr, '┼');
drawBorderChar(screen, size, terminal.getLeft() + terminal.getWidth(), terminal.getTop() - 1, attr, '┼');
drawBorderChar(screen, size, terminal.getLeft() - 1, terminal.getTop() + terminal.getHeight(), attr, '┼');
drawBorderChar(screen, size, terminal.getLeft() + terminal.getWidth(), terminal.getTop() + terminal.getHeight(), attr, '┼');
drawBorderChar(screen, size, terminal.getLeft() - 1, terminal.getTop() - 1, attr, '┌');
drawBorderChar(screen, size, terminal.getLeft() + terminal.getWidth(), terminal.getTop() - 1, attr, '┐');
drawBorderChar(screen, size, terminal.getLeft() - 1, terminal.getTop() + terminal.getHeight(), attr, '└');
drawBorderChar(screen, size, terminal.getLeft() + terminal.getWidth(), terminal.getTop() + terminal.getHeight(), attr, '┘');
}

private void drawBorderChar(long[] screen, Size size, int x, int y, long attr, int c) {
if (x >= 0 && x < size.getColumns() && y >= 0 && y < size.getRows() - 1) {
int oldc = (int)(screen[y * size.getColumns() + x] & 0xFFFFFFFFL);
c = addBorder(c, oldc);
screen[y * size.getColumns() + x] = attr | c;
}
}

private int addBorder(int c, int oldc) {
if (oldc == ' ') {
return c;
}
if (oldc == '┼') {
return '┼';
}
switch (c) {
case '│':
return addBorder('╷', addBorder('╵', oldc));
case '─':
return addBorder('╴', addBorder('╶', oldc));
case '┌':
return addBorder('╶', addBorder('╷', oldc));
case '┐':
return addBorder('╴', addBorder('╷', oldc));
case '└':
return addBorder('╶', addBorder('╵', oldc));
case '┘':
return addBorder('╴', addBorder('╵', oldc));
case '├':
return addBorder('╶', addBorder('│', oldc));
case '┤':
return addBorder('╴', addBorder('│', oldc));
case '┬':
return addBorder('╷', addBorder('─', oldc));
case '┴':
return addBorder('╵', addBorder('─', oldc));
case '╴':
switch (oldc) {
case '│': return '┤';
case '─': return '─';
case '┌': return '┬';
case '┐': return '┐';
case '└': return '┴';
case '┘': return '┘';
case '├': return '┼';
case '┤': return '┤';
case '┬': return '┬';
case '┴': return '┴';
default:
throw new IllegalArgumentException();
}
case '╵':
switch (oldc) {
case '│': return '│';
case '─': return '┴';
case '┌': return '├';
case '┐': return '┤';
case '└': return '└';
case '┘': return '┘';
case '├': return '├';
case '┤': return '┤';
case '┬': return '┼';
case '┴': return '┴';
default:
throw new IllegalArgumentException();
}
case '╶':
switch (oldc) {
case '│': return '├';
case '─': return '─';
case '┌': return '┌';
case '┐': return '┬';
case '└': return '└';
case '┘': return '┴';
case '├': return '├';
case '┤': return '┼';
case '┬': return '┬';
case '┴': return '┴';
default:
throw new IllegalArgumentException();
}
case '╷':
switch (oldc) {
case '│': return '│';
case '─': return '┬';
case '┌': return '┌';
case '┐': return '┐';
case '└': return '├';
case '┘': return '┤';
case '├': return '├';
case '┤': return '┤';
case '┬': return '┬';
case '┴': return '┼';
default:
throw new IllegalArgumentException();
}
default:
throw new IllegalArgumentException();
}
}

private String getNewPaneName() {
return String.format("tmux%02d", paneId.incrementAndGet());
}
Expand Down

0 comments on commit c78f430

Please sign in to comment.