From: Kevin Lamonte Date: Sat, 21 Mar 2015 02:06:59 +0000 (-0400) Subject: merge X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=e7083f0b935964ca5a04835187397ff117941044;hp=-c;p=fanfix.git merge --- e7083f0b935964ca5a04835187397ff117941044 diff --combined README.md index 570a017,ce70771..746b168 --- a/README.md +++ b/README.md @@@ -20,9 -20,8 +20,9 @@@ Two backends are available * Java AWT UI. This backend can be selected by setting jexer.AWT=true. This is the default backend on Windows platforms. - AWT is VERY experimental, please consider filing bugs when you - encounter them. + AWT is experimental, please consider filing bugs when you encounter + them. The default window size for AWT is 132x40, which is set in + jexer.session.AWTSession. A demo application showing the existing UI controls is available via 'java -jar jexer.jar' or 'java -Djexer.AWT=true -jar jexer.jar' . @@@ -87,13 -86,11 +87,14 @@@ ambiguous. This section describes suc --------------- - TTerminalWindow will hang on input from the remote if the - TApplication is exited before closing the TTerminalWindow. This - is due to a Java limitation/interaction between blocking reads - (necessary to get UTF8 translation correct) and file streams. + TApplication is exited before the TTerminalWindow's process has + closed on its own. This is due to a Java limitation/interaction + between blocking reads (which is necessary to get UTF8 translation + correct) and file streams. + - See jexer.tterminal.ECMA48 for more specifics of terminal + emulation limitations. + Roadmap ------- @@@ -102,15 -99,22 +103,22 @@@ Many tasks remain before calling this v 0.0.2: + - Making TMenu keyboard accelerators active/inactive - AWT: - Blinking cursor + - Handle kbTab (disable focus traversal BS) + - Block cursor - - Fix mouse artifacts - ECMA48Backend running on socket - TTreeView - TDirectoryList - TFileOpen - Decide on naming convention: getText, getValue, getLabel: one or all of them? + - Refactor: + - TKeypress: + - getCh() --> getChar() + - getAlt/getCtrl/getShift --> isAltDown / isCtrlDown / isShiftDown + - Other boolean getters --> isSomething 0.0.3: @@@ -120,7 -124,6 +128,6 @@@ - Bugs - TSubMenu keyboard mnemonic not working - - Making TMenu keyboard accelerators active/inactive - TDirectoryList cannot be navigated only with keyboard - TTreeView cannot be navigated only with keyboard - RangeViolation after dragging scrollbar up/down diff --combined src/jexer/TTerminalWindow.java index 336c3ff,90a95ae..010cc49 --- a/src/jexer/TTerminalWindow.java +++ b/src/jexer/TTerminalWindow.java @@@ -36,7 -36,6 +36,7 @@@ import java.io.OutputStream import java.io.UnsupportedEncodingException; import java.util.LinkedList; import java.util.List; +import java.util.Map; import jexer.bits.Cell; import jexer.bits.CellAttributes; @@@ -80,9 -79,6 +80,9 @@@ public class TTerminalWindow extends TW super(application, "Terminal", x, y, 80 + 2, 24 + 2, flags); + // Assume XTERM + ECMA48.DeviceType deviceType = ECMA48.DeviceType.XTERM; + try { String [] cmdShellWindows = { "cmd.exe" @@@ -95,21 -91,19 +95,21 @@@ "script", "-fqe", "/dev/null" }; // Spawn a shell and pass its I/O to the other constructor. + ProcessBuilder pb; if (System.getProperty("os.name").startsWith("Windows")) { pb = new ProcessBuilder(cmdShellWindows); } else { pb = new ProcessBuilder(cmdShell); } - // shell = Runtime.getRuntime().exec(cmdShell); - - // TODO: add LANG, TERM, LINES, and COLUMNS + Map env = pb.environment(); + env.put("TERM", ECMA48.deviceTypeTerm(deviceType)); + env.put("LANG", ECMA48.deviceTypeLang(deviceType, "en")); + env.put("COLUMNS", "80"); + env.put("LINES", "24"); pb.redirectErrorStream(true); shell = pb.start(); - emulator = new ECMA48(ECMA48.DeviceType.XTERM, - shell.getInputStream(), + emulator = new ECMA48(deviceType, shell.getInputStream(), shell.getOutputStream()); } catch (IOException e) { e.printStackTrace(); @@@ -167,13 -161,18 +167,13 @@@ List display = emulator.getDisplayBuffer(); // Put together the visible rows - // System.err.printf("----------------------------\n"); - // System.err.printf("vScroller.value %d\n", vScroller.getValue()); int visibleHeight = getHeight() - 2; - // System.err.printf("visibleHeight %d\n", visibleHeight); int visibleBottom = scrollback.size() + display.size() + vScroller.getValue(); - // System.err.printf("visibleBottom %d\n", visibleBottom); assert (visibleBottom >= 0); List preceedingBlankLines = new LinkedList(); int visibleTop = visibleBottom - visibleHeight; - // System.err.printf("visibleTop %d\n", visibleTop); if (visibleTop < 0) { for (int i = visibleTop; i < 0; i++) { preceedingBlankLines.add(emulator.getBlankDisplayLine()); @@@ -185,13 -184,16 +185,13 @@@ List displayLines = new LinkedList(); displayLines.addAll(scrollback); displayLines.addAll(display); - // System.err.printf("displayLines.size %d\n", displayLines.size()); List visibleLines = new LinkedList(); visibleLines.addAll(preceedingBlankLines); visibleLines.addAll(displayLines.subList(visibleTop, visibleBottom)); - // System.err.printf("visibleLines.size %d\n", visibleLines.size()); visibleHeight -= visibleLines.size(); - // System.err.printf("visibleHeight %d\n", visibleHeight); assert (visibleHeight >= 0); // Now draw the emulator screen @@@ -242,7 -244,12 +242,12 @@@ * Handle window close. */ @Override public void onClose() { - emulator.close(); + if (shell != null) { + shell.destroy(); + shell = null; + } else { + emulator.close(); + } } /** @@@ -273,6 -280,7 +278,6 @@@ setTitle(emulator.getScreenTitle()); } } - setMaximumWindowWidth(emulator.getWidth() + 2); // Check to see if the shell has died. if (!emulator.isReading() && (shell != null)) { @@@ -352,31 -360,6 +357,31 @@@ } // synchronized (emulator) } + /** + * Check if a mouse press/release/motion event coordinate is over the + * emulator. + * + * @param mouse a mouse-based event + * @return whether or not the mouse is on the emulator + */ + private final boolean mouseOnEmulator(final TMouseEvent mouse) { + + synchronized (emulator) { + if (!emulator.isReading()) { + return false; + } + } + + if ((mouse.getAbsoluteX() >= getAbsoluteX() + 1) + && (mouse.getAbsoluteX() < getAbsoluteX() + getWidth() - 1) + && (mouse.getAbsoluteY() >= getAbsoluteY() + 1) + && (mouse.getAbsoluteY() < getAbsoluteY() + getHeight() - 1) + ) { + return true; + } + return false; + } + /** * Handle keystrokes. * @@@ -433,11 -416,6 +438,11 @@@ */ @Override public void onMouseDown(final TMouseEvent mouse) { + if (inWindowMove || inWindowResize) { + // TWindow needs to deal with this. + super.onMouseDown(mouse); + return; + } if (mouse.getMouseWheelUp()) { vScroller.decrement(); @@@ -447,72 -425,9 +452,72 @@@ vScroller.increment(); return; } + if (mouseOnEmulator(mouse)) { + synchronized (emulator) { + mouse.setX(mouse.getX() - 1); + mouse.setY(mouse.getY() - 1); + emulator.mouse(mouse); + readEmulatorState(); + return; + } + } - // Pass to children + // Emulator didn't consume it, pass it on super.onMouseDown(mouse); } + /** + * Handle mouse release events. + * + * @param mouse mouse button release event + */ + @Override + public void onMouseUp(final TMouseEvent mouse) { + if (inWindowMove || inWindowResize) { + // TWindow needs to deal with this. + super.onMouseUp(mouse); + return; + } + + if (mouseOnEmulator(mouse)) { + synchronized (emulator) { + mouse.setX(mouse.getX() - 1); + mouse.setY(mouse.getY() - 1); + emulator.mouse(mouse); + readEmulatorState(); + return; + } + } + + // Emulator didn't consume it, pass it on + super.onMouseUp(mouse); + } + + /** + * Handle mouse motion events. + * + * @param mouse mouse motion event + */ + @Override + public void onMouseMotion(final TMouseEvent mouse) { + if (inWindowMove || inWindowResize) { + // TWindow needs to deal with this. + super.onMouseMotion(mouse); + return; + } + + if (mouseOnEmulator(mouse)) { + synchronized (emulator) { + mouse.setX(mouse.getX() - 1); + mouse.setY(mouse.getY() - 1); + emulator.mouse(mouse); + readEmulatorState(); + return; + } + } + + // Emulator didn't consume it, pass it on + super.onMouseMotion(mouse); + } + }