git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
#18 move to event-driven main loop
[fanfix.git]
/
src
/
jexer
/
backend
/
ECMA48Terminal.java
diff --git
a/src/jexer/backend/ECMA48Terminal.java
b/src/jexer/backend/ECMA48Terminal.java
index 13704151df3037585b4d4d0f442593444a880834..ea99a0b79eeaf7adb24fe8c2e7a7f01b4c99f45c 100644
(file)
--- a/
src/jexer/backend/ECMA48Terminal.java
+++ b/
src/jexer/backend/ECMA48Terminal.java
@@
-40,7
+40,6
@@
import java.io.PrintWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import java.util.LinkedList;
import java.util.List;
import java.util.LinkedList;
@@
-195,6
+194,16
@@
public final class ECMA48Terminal extends LogicalScreen
*/
private Object listener;
*/
private Object listener;
+ /**
+ * Set listener to a different Object.
+ *
+ * @param listener the new listening object that run() wakes up on new
+ * input
+ */
+ public void setListener(final Object listener) {
+ this.listener = listener;
+ }
+
/**
* Get the output writer.
*
/**
* Get the output writer.
*
@@
-342,6
+351,11
@@
public final class ECMA48Terminal extends LogicalScreen
this.output.printf("%s%s", mouse(true), xtermMetaSendsEscape(true));
this.output.flush();
this.output.printf("%s%s", mouse(true), xtermMetaSendsEscape(true));
this.output.flush();
+ // Query the screen size
+ sessionInfo.queryWindowSize();
+ setDimensions(sessionInfo.getWindowWidth(),
+ sessionInfo.getWindowHeight());
+
// Hang onto the window size
windowResize = new TResizeEvent(TResizeEvent.Type.SCREEN,
sessionInfo.getWindowWidth(), sessionInfo.getWindowHeight());
// Hang onto the window size
windowResize = new TResizeEvent(TResizeEvent.Type.SCREEN,
sessionInfo.getWindowWidth(), sessionInfo.getWindowHeight());
@@
-350,6
+364,8
@@
public final class ECMA48Terminal extends LogicalScreen
if (System.getProperty("jexer.ECMA48.rgbColor") != null) {
if (System.getProperty("jexer.ECMA48.rgbColor").equals("true")) {
doRgbColor = true;
if (System.getProperty("jexer.ECMA48.rgbColor") != null) {
if (System.getProperty("jexer.ECMA48.rgbColor").equals("true")) {
doRgbColor = true;
+ } else {
+ doRgbColor = false;
}
}
}
}
@@
-358,10
+374,6
@@
public final class ECMA48Terminal extends LogicalScreen
readerThread = new Thread(this);
readerThread.start();
readerThread = new Thread(this);
readerThread.start();
- // Query the screen size
- setDimensions(sessionInfo.getWindowWidth(),
- sessionInfo.getWindowHeight());
-
// Clear the screen
this.output.write(clearAll());
this.output.flush();
// Clear the screen
this.output.write(clearAll());
this.output.flush();
@@
-429,6
+441,11
@@
public final class ECMA48Terminal extends LogicalScreen
this.output.printf("%s%s", mouse(true), xtermMetaSendsEscape(true));
this.output.flush();
this.output.printf("%s%s", mouse(true), xtermMetaSendsEscape(true));
this.output.flush();
+ // Query the screen size
+ sessionInfo.queryWindowSize();
+ setDimensions(sessionInfo.getWindowWidth(),
+ sessionInfo.getWindowHeight());
+
// Hang onto the window size
windowResize = new TResizeEvent(TResizeEvent.Type.SCREEN,
sessionInfo.getWindowWidth(), sessionInfo.getWindowHeight());
// Hang onto the window size
windowResize = new TResizeEvent(TResizeEvent.Type.SCREEN,
sessionInfo.getWindowWidth(), sessionInfo.getWindowHeight());
@@
-437,6
+454,8
@@
public final class ECMA48Terminal extends LogicalScreen
if (System.getProperty("jexer.ECMA48.rgbColor") != null) {
if (System.getProperty("jexer.ECMA48.rgbColor").equals("true")) {
doRgbColor = true;
if (System.getProperty("jexer.ECMA48.rgbColor") != null) {
if (System.getProperty("jexer.ECMA48.rgbColor").equals("true")) {
doRgbColor = true;
+ } else {
+ doRgbColor = false;
}
}
}
}
@@
-445,10
+464,6
@@
public final class ECMA48Terminal extends LogicalScreen
readerThread = new Thread(this);
readerThread.start();
readerThread = new Thread(this);
readerThread.start();
- // Query the screen size
- setDimensions(sessionInfo.getWindowWidth(),
- sessionInfo.getWindowHeight());
-
// Clear the screen
this.output.write(clearAll());
this.output.flush();
// Clear the screen
this.output.write(clearAll());
this.output.flush();
@@
-696,11
+711,6
@@
public final class ECMA48Terminal extends LogicalScreen
* physical screen
*/
private String flushString() {
* physical screen
*/
private String flushString() {
- if (!dirty) {
- assert (!reallyCleared);
- return "";
- }
-
CellAttributes attr = null;
StringBuilder sb = new StringBuilder();
CellAttributes attr = null;
StringBuilder sb = new StringBuilder();
@@
-713,7
+723,6
@@
public final class ECMA48Terminal extends LogicalScreen
flushLine(y, sb, attr);
}
flushLine(y, sb, attr);
}
- dirty = false;
reallyCleared = false;
String result = sb.toString();
reallyCleared = false;
String result = sb.toString();
@@
-730,6
+739,8
@@
public final class ECMA48Terminal extends LogicalScreen
public void flushPhysical() {
String result = flushString();
if ((cursorVisible)
public void flushPhysical() {
String result = flushString();
if ((cursorVisible)
+ && (cursorY >= 0)
+ && (cursorX >= 0)
&& (cursorY <= height - 1)
&& (cursorX <= width - 1)
) {
&& (cursorY <= height - 1)
&& (cursorX <= width - 1)
) {
@@
-1088,10
+1099,10
@@
public final class ECMA48Terminal extends LogicalScreen
* @param queue list to append new events to
*/
private void getIdleEvents(final List<TInputEvent> queue) {
* @param queue list to append new events to
*/
private void getIdleEvents(final List<TInputEvent> queue) {
-
Date now = new Date
();
+
long nowTime = System.currentTimeMillis
();
// Check for new window size
// Check for new window size
- long windowSizeDelay = now
.getTime()
- windowSizeTime;
+ long windowSizeDelay = now
Time
- windowSizeTime;
if (windowSizeDelay > 1000) {
sessionInfo.queryWindowSize();
int newWidth = sessionInfo.getWindowWidth();
if (windowSizeDelay > 1000) {
sessionInfo.queryWindowSize();
int newWidth = sessionInfo.getWindowWidth();
@@
-1105,12
+1116,12
@@
public final class ECMA48Terminal extends LogicalScreen
newWidth, newHeight);
queue.add(event);
}
newWidth, newHeight);
queue.add(event);
}
- windowSizeTime = now
.getTime()
;
+ windowSizeTime = now
Time
;
}
// ESCDELAY type timeout
if (state == ParseState.ESCAPE) {
}
// ESCDELAY type timeout
if (state == ParseState.ESCAPE) {
- long escDelay = now
.getTime()
- escapeTime;
+ long escDelay = now
Time
- escapeTime;
if (escDelay > 100) {
// After 0.1 seconds, assume a true escape character
queue.add(controlChar((char)0x1B, false));
if (escDelay > 100) {
// After 0.1 seconds, assume a true escape character
queue.add(controlChar((char)0x1B, false));
@@
-1174,9
+1185,9
@@
public final class ECMA48Terminal extends LogicalScreen
private void processChar(final List<TInputEvent> events, final char ch) {
// ESCDELAY type timeout
private void processChar(final List<TInputEvent> events, final char ch) {
// ESCDELAY type timeout
-
Date now = new Date
();
+
long nowTime = System.currentTimeMillis
();
if (state == ParseState.ESCAPE) {
if (state == ParseState.ESCAPE) {
- long escDelay = now
.getTime()
- escapeTime;
+ long escDelay = now
Time
- escapeTime;
if (escDelay > 250) {
// After 0.25 seconds, assume a true escape character
events.add(controlChar((char)0x1B, false));
if (escDelay > 250) {
// After 0.25 seconds, assume a true escape character
events.add(controlChar((char)0x1B, false));
@@
-1196,7
+1207,7
@@
public final class ECMA48Terminal extends LogicalScreen
if (ch == 0x1B) {
state = ParseState.ESCAPE;
if (ch == 0x1B) {
state = ParseState.ESCAPE;
- escapeTime = now
.getTime()
;
+ escapeTime = now
Time
;
return;
}
return;
}
@@
-1882,8
+1893,10
@@
public final class ECMA48Terminal extends LogicalScreen
synchronized (eventQueue) {
eventQueue.addAll(events);
}
synchronized (eventQueue) {
eventQueue.addAll(events);
}
- synchronized (listener) {
- listener.notifyAll();
+ if (listener != null) {
+ synchronized (listener) {
+ listener.notifyAll();
+ }
}
events.clear();
}
}
events.clear();
}
@@
-1895,8
+1908,10
@@
public final class ECMA48Terminal extends LogicalScreen
eventQueue.addAll(events);
}
events.clear();
eventQueue.addAll(events);
}
events.clear();
- synchronized (listener) {
- listener.notifyAll();
+ if (listener != null) {
+ synchronized (listener) {
+ listener.notifyAll();
+ }
}
}
}
}