[Swift-commit] r5829 - in trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi: . tui
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Thu Jul 12 16:03:37 CDT 2012
Author: hategan
Date: 2012-07-12 16:03:37 -0500 (Thu, 12 Jul 2012)
New Revision: 5829
Modified:
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSI.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/CharacterMap.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Graph.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/HLine.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VHCrossing.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VLine.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VScrollbar.java
Log:
ability to use unicode (if tui.use.unicode property set to true); support for more terminals using alternate size query method
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -98,6 +98,7 @@
}
}
catch (Exception e) {
+ logger.error("Could not run display", e);
e.printStackTrace();
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSI.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSI.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSI.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -54,6 +54,10 @@
public static final int GCH_HASH = 97;
public static final int GCH_BULLET = 96;
+ public static final int GCH_ARROW_UP = 94;
+ public static final int GCH_ARROW_DOWN = 95;
+ public static final int GCH_ARROW_LEFT = 60;
+ public static final int GCH_ARROW_RIGHT = 62;
public static String moveTo(int x, int y) {
return AESC + y + ';' + x + 'H';
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -26,6 +26,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;
@@ -43,15 +44,29 @@
private ScreenBuffer buf;
private boolean doubleBuffered;
private int lock;
- private boolean done;
+ private boolean done, unicode;
private Terminal terminal;
private boolean redraw;
+ private UnicodeDrawingScheme uds;
public ANSIContext(OutputStream os, InputStream is) {
- this.os = new OutputStreamWriter(os);
+ try {
+ this.os = new OutputStreamWriter(os, "UTF8");
+ }
+ catch (UnsupportedEncodingException e) {
+ logger.warn("UTF8 not supported here");
+ this.os = new OutputStreamWriter(os);
+ }
this.is = is;
doubleBuffered = true;
+ unicode = "true".equals(System.getProperty("tui.use.unicode"));
+ if (unicode) {
+ uds = new UnicodeDrawingScheme.RoundedLight();
+ }
+ else {
+ uds = new UnicodeDrawingScheme.ASCII();
+ }
}
public void moveTo(int x, int y) throws IOException {
@@ -117,15 +132,6 @@
}
}
- public void lineArt(boolean enabled) throws IOException {
- if (doubleBuffered) {
- buf.lineArt(enabled);
- }
- else {
- os.write(ANSI.lineArt(enabled));
- }
- }
-
public void printReply() throws IOException {
try {
Thread.sleep(100);
@@ -140,6 +146,7 @@
}
public boolean init() {
+ logger.info("Initializing terminal");
terminal = Terminal.setupTerminal();
try {
terminal.initializeTerminal();
@@ -156,8 +163,16 @@
}
return terminal.isANSISupported();
}
+
+ private boolean querySizeWorks = true, alternate = false;
public int[] querySize() throws IOException {
+ if (!querySizeWorks) {
+ return null;
+ }
+ if (alternate) {
+ return new int[] {terminal.getTerminalWidth(), terminal.getTerminalHeight() };
+ }
os.write(ANSI.AESC + "18t");
os.flush();
try {
@@ -177,9 +192,16 @@
int[] sz = new int[2];
sz[0] = ((Integer) nums.get(1)).intValue();
sz[1] = ((Integer) nums.get(0)).intValue();
+ logger.info("Terminal size is " + sz[0] + "x" + sz[1]);
return sz;
}
- catch (UnsupportedOperationException e) {
+ catch (Exception e) {
+ logger.info("Could not query terminal size", e);
+ if (terminal.getTerminalWidth() != 0) {
+ alternate = true;
+ return new int[] {terminal.getTerminalWidth(), terminal.getTerminalHeight() };
+ }
+ querySizeWorks = false;
return null;
}
}
@@ -427,8 +449,10 @@
}
public void putChar(char c) throws IOException {
- if (c < 32 || c >= 240) {
- c = '.';
+ if (!unicode) {
+ if (c < 32 || c >= 240) {
+ c = '.';
+ }
}
if (doubleBuffered) {
buf.write(c);
@@ -439,8 +463,10 @@
}
public void putChar(int c) throws IOException {
- if (c < 32 || c >= 240) {
- c = '.';
+ if (!unicode) {
+ if (c < 32 || c >= 240) {
+ c = '.';
+ }
}
if (doubleBuffered) {
buf.write(c);
@@ -461,51 +487,69 @@
}
public void frame(int x, int y, int width, int height) throws IOException {
- lineArt(true);
moveTo(x, y);
- putChar(ANSI.GCH_UL_CORNER);
+ lineArt(ANSI.GCH_UL_CORNER);
for (int i = 0; i < width - 2; i++) {
- putChar(ANSI.GCH_H_LINE);
+ lineArt(ANSI.GCH_H_LINE);
}
- putChar(ANSI.GCH_UR_CORNER);
+ lineArt(ANSI.GCH_UR_CORNER);
for (int i = 0; i < height - 2; i++) {
moveTo(x, y + i + 1);
- putChar(ANSI.GCH_V_LINE);
+ lineArt(ANSI.GCH_V_LINE);
moveTo(x + width - 1, y + i + 1);
- putChar(ANSI.GCH_V_LINE);
+ lineArt(ANSI.GCH_V_LINE);
}
moveTo(x, y + height - 1);
- putChar(ANSI.GCH_LL_CORNER);
+ lineArt(ANSI.GCH_LL_CORNER);
for (int i = 0; i < width - 2; i++) {
- putChar(ANSI.GCH_H_LINE);
+ lineArt(ANSI.GCH_H_LINE);
}
- putChar(ANSI.GCH_LR_CORNER);
- lineArt(false);
+ lineArt(ANSI.GCH_LR_CORNER);
}
public void filledFrame(int x, int y, int width, int height)
throws IOException {
- lineArt(true);
moveTo(x, y);
- putChar(ANSI.GCH_UL_CORNER);
+ lineArt(ANSI.GCH_UL_CORNER);
for (int i = 0; i < width - 2; i++) {
- putChar(ANSI.GCH_H_LINE);
+ lineArt(ANSI.GCH_H_LINE);
}
- putChar(ANSI.GCH_UR_CORNER);
+ lineArt(ANSI.GCH_UR_CORNER);
for (int i = 0; i < height - 2; i++) {
moveTo(x, y + i + 1);
- putChar(ANSI.GCH_V_LINE);
+ lineArt(ANSI.GCH_V_LINE);
spaces(width - 2);
- putChar(ANSI.GCH_V_LINE);
+ lineArt(ANSI.GCH_V_LINE);
}
moveTo(x, y + height - 1);
- putChar(ANSI.GCH_LL_CORNER);
+ lineArt(ANSI.GCH_LL_CORNER);
for (int i = 0; i < width - 2; i++) {
- putChar(ANSI.GCH_H_LINE);
+ lineArt(ANSI.GCH_H_LINE);
}
- putChar(ANSI.GCH_LR_CORNER);
- lineArt(false);
+ lineArt(ANSI.GCH_LR_CORNER);
}
+
+ public void lineArt(int code) throws IOException {
+ if (unicode) {
+ putChar(uds.getChar(code));
+ }
+ else {
+ lineArt(true);
+ putChar(uds.getChar(code));
+ lineArt(false);
+ }
+ }
+
+ public void lineArt(boolean enabled) throws IOException {
+ if (!unicode) {
+ if (doubleBuffered) {
+ buf.lineArt(enabled);
+ }
+ else {
+ os.write(ANSI.lineArt(enabled));
+ }
+ }
+ }
public void filledRect(int x, int y, int width, int height)
throws IOException {
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/CharacterMap.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/CharacterMap.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/CharacterMap.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -30,12 +30,10 @@
protected void draw(ANSIContext context) throws IOException {
for (int i = 0; i < 16; i++) {
context.moveTo(sx, sy + i);
- context.lineArt(true);
for (int j = 0; j < 16; j++) {
- context.putChar((char) (i*16 + j));
+ context.lineArt((char) (i*16 + j));
context.putChar(' ');
}
- context.lineArt(false);
}
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Graph.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Graph.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Graph.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -54,51 +54,49 @@
int last = Integer.MIN_VALUE;
i = data.iterator();
int j = sx + 1;
- context.lineArt(true);
while (i.hasNext()) {
Double d = (Double) i.next();
double v = (d.doubleValue() - min) / (max - min) * (height - 3);
int c = (int) v;
if (last == Integer.MIN_VALUE || last == c) {
context.moveTo(j, sy + height - c - 2);
- context.putChar(ANSI.GCH_H_LINE);
+ context.lineArt(ANSI.GCH_H_LINE);
}
else if (last > c) {
for (int k = c; k <= last; k ++) {
context.moveTo(j, sy + height - k - 2);
if (k == last) {
- context.putChar(ANSI.GCH_UR_CORNER);
+ context.lineArt(ANSI.GCH_UR_CORNER);
}
else {
- context.putChar(ANSI.GCH_V_LINE);
+ context.lineArt(ANSI.GCH_V_LINE);
}
}
context.moveTo(j, sy + height - c - 2);
- context.putChar(ANSI.GCH_LL_CORNER);
+ context.lineArt(ANSI.GCH_LL_CORNER);
}
else {
for (int k = last; k < c; k ++) {
context.moveTo(j, sy + height - k - 2);
if (k == last) {
- context.putChar(ANSI.GCH_LR_CORNER);
+ context.lineArt(ANSI.GCH_LR_CORNER);
}
else {
- context.putChar(ANSI.GCH_V_LINE);
+ context.lineArt(ANSI.GCH_V_LINE);
}
}
context.moveTo(j, sy + height - c - 2);
- context.putChar(ANSI.GCH_UL_CORNER);
+ context.lineArt(ANSI.GCH_UL_CORNER);
}
last = c;
j++;
}
context.moveTo(sx, sy + 1);
- context.putChar(ANSI.GCH_CROSS);
+ context.lineArt(ANSI.GCH_CROSS);
context.text(String.valueOf(max));
context.moveTo(sx, sy + height - 2);
- context.putChar(ANSI.GCH_CROSS);
+ context.lineArt(ANSI.GCH_CROSS);
context.text(String.valueOf(min));
- context.lineArt(false);
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/HLine.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/HLine.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/HLine.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -44,20 +44,18 @@
try {
context.bgColor(bgColor);
context.fgColor(fgColor);
- context.lineArt(true);
context.moveTo(sx, sy);
for (int i = 0; i < width; i++) {
- context.putChar(ANSI.GCH_H_LINE);
+ context.lineArt(ANSI.GCH_H_LINE);
}
if (leftEndCap) {
context.moveTo(sx - 1, sy);
- context.putChar(ANSI.GCH_ML_CORNER);
+ context.lineArt(ANSI.GCH_ML_CORNER);
}
if (rightEndCap) {
context.moveTo(sx + width, sy);
- context.putChar(ANSI.GCH_MR_CORNER);
+ context.lineArt(ANSI.GCH_MR_CORNER);
}
- context.lineArt(false);
}
finally {
context.unlock();
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -39,9 +39,13 @@
public boolean init() throws IOException {
if (!context.init()) {
+ logger.info("Terminal does not support ANSI escape sequences!");
return false;
}
int[] size = context.querySize();
+ if (size == null) {
+ size = new int[] {80, 25};
+ }
setSize(size[0], size[1]);
context.setScreen(this);
context.clear();
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VHCrossing.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VHCrossing.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VHCrossing.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -27,9 +27,7 @@
protected void draw(ANSIContext context) throws IOException {
context.bgColor(bgColor);
context.fgColor(fgColor);
- context.lineArt(true);
context.moveTo(sx, sy);
- context.putChar(ANSI.GCH_CROSS);
- context.lineArt(false);
+ context.lineArt(ANSI.GCH_CROSS);
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VLine.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VLine.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VLine.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -42,19 +42,17 @@
protected void draw(ANSIContext context) throws IOException {
context.bgColor(bgColor);
context.fgColor(fgColor);
- context.lineArt(true);
for (int i = 0; i < height; i++) {
context.moveTo(sx, sy + i);
- context.putChar(ANSI.GCH_V_LINE);
+ context.lineArt(ANSI.GCH_V_LINE);
}
if (topEndCap) {
context.moveTo(sx, sy - 1);
- context.putChar(ANSI.GCH_UM_CORNER);
+ context.lineArt(ANSI.GCH_UM_CORNER);
}
if (bottomEndCap) {
context.moveTo(sx, sy + height);
- context.putChar(ANSI.GCH_LM_CORNER);
+ context.lineArt(ANSI.GCH_LM_CORNER);
}
- context.lineArt(false);
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VScrollbar.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VScrollbar.java 2012-07-12 17:50:22 UTC (rev 5828)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/VScrollbar.java 2012-07-12 21:03:37 UTC (rev 5829)
@@ -37,10 +37,13 @@
protected void draw(ANSIContext context) throws IOException {
context.bgColor(bgColor);
context.fgColor(fgColor);
- context.lineArt(true);
- for (int i = 0; i < height; i++) {
+ context.moveTo(sx, sy);
+ context.lineArt(ANSI.GCH_ARROW_UP);
+ context.moveTo(sx, sy + height - 1);
+ context.lineArt(ANSI.GCH_ARROW_DOWN);
+ for (int i = 1; i < height - 1; i++) {
context.moveTo(sx, sy + i);
- context.putChar(backgroundChar);
+ context.lineArt(backgroundChar);
}
int pos = 0;
if (total > 1) {
@@ -50,15 +53,14 @@
if (current < 0) {
current = 0;
}
- pos = (height - 1) * current / (total - 1);
+ pos = (height - 3) * current / (total - 1);
}
if (invertThumbColor) {
context.bgColor(fgColor);
context.fgColor(bgColor);
}
- context.moveTo(sx, sy + pos);
- context.putChar(thumbChar);
- context.lineArt(false);
+ context.moveTo(sx, sy + pos + 1);
+ context.lineArt(thumbChar);
}
public int getCurrent() {
More information about the Swift-commit
mailing list