X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTTerminalWidget.java;h=acd1cc2761b94acec9a31b62e054ac0931990e9f;hb=c950b791c6c4f94ab8a1777e709ecb259de7ab4f;hp=6c8b9894a016c70797e123c96a35911bb864914e;hpb=83787cfb2eb1501a328f8c5f2416c2532e3fef1c;p=fanfix.git diff --git a/src/jexer/TTerminalWidget.java b/src/jexer/TTerminalWidget.java index 6c8b989..acd1cc2 100644 --- a/src/jexer/TTerminalWidget.java +++ b/src/jexer/TTerminalWidget.java @@ -49,6 +49,7 @@ import jexer.backend.MultiScreen; import jexer.backend.SwingTerminal; import jexer.bits.Cell; import jexer.bits.CellAttributes; +import jexer.event.TCommandEvent; import jexer.event.TKeypressEvent; import jexer.event.TMenuEvent; import jexer.event.TMouseEvent; @@ -57,13 +58,14 @@ import jexer.menu.TMenu; import jexer.tterminal.DisplayLine; import jexer.tterminal.DisplayListener; import jexer.tterminal.ECMA48; +import static jexer.TCommand.*; import static jexer.TKeypress.*; /** * TTerminalWidget exposes a ECMA-48 / ANSI X3.64 style terminal in a widget. */ public class TTerminalWidget extends TScrollableWidget - implements DisplayListener { + implements DisplayListener, EditMenuUser { /** * Translated strings. @@ -198,7 +200,7 @@ public class TTerminalWidget extends TScrollableWidget * @param x column relative to parent * @param y row relative to parent * @param command the command line to execute - * @param closeAction action to perform when the shell sxits + * @param closeAction action to perform when the shell exits */ public TTerminalWidget(final TWidget parent, final int x, final int y, final String [] command, final TAction closeAction) { @@ -215,7 +217,7 @@ public class TTerminalWidget extends TScrollableWidget * @param width width of widget * @param height height of widget * @param command the command line to execute - * @param closeAction action to perform when the shell sxits + * @param closeAction action to perform when the shell exits */ public TTerminalWidget(final TWidget parent, final int x, final int y, final int width, final int height, final String [] command, @@ -251,12 +253,24 @@ public class TTerminalWidget extends TScrollableWidget fullCommand[5] = stringArrayToString(command); } else { // Default: behave like Linux - fullCommand = new String[5]; - fullCommand[0] = "script"; - fullCommand[1] = "-fqe"; - fullCommand[2] = "/dev/null"; - fullCommand[3] = "-c"; - fullCommand[4] = stringArrayToString(command); + if (System.getProperty("jexer.TTerminal.setsid", + "true").equals("false") + ) { + fullCommand = new String[5]; + fullCommand[0] = "script"; + fullCommand[1] = "-fqe"; + fullCommand[2] = "/dev/null"; + fullCommand[3] = "-c"; + fullCommand[4] = stringArrayToString(command); + } else { + fullCommand = new String[6]; + fullCommand[0] = "setsid"; + fullCommand[1] = "script"; + fullCommand[2] = "-fqe"; + fullCommand[3] = "/dev/null"; + fullCommand[4] = "-c"; + fullCommand[5] = stringArrayToString(command); + } } spawnShell(fullCommand); } @@ -278,7 +292,7 @@ public class TTerminalWidget extends TScrollableWidget * @param parent parent widget * @param x column relative to parent * @param y row relative to parent - * @param closeAction action to perform when the shell sxits + * @param closeAction action to perform when the shell exits */ public TTerminalWidget(final TWidget parent, final int x, final int y, final TAction closeAction) { @@ -294,7 +308,7 @@ public class TTerminalWidget extends TScrollableWidget * @param y row relative to parent * @param width width of widget * @param height height of widget - * @param closeAction action to perform when the shell sxits + * @param closeAction action to perform when the shell exits */ public TTerminalWidget(final TWidget parent, final int x, final int y, final int width, final int height, final TAction closeAction) { @@ -320,6 +334,7 @@ public class TTerminalWidget extends TScrollableWidget // GNU differ on the '-f' vs '-F' flags, we need two different // commands. Lovely. String cmdShellGNU = "script -fqe /dev/null"; + String cmdShellGNUSetsid = "setsid script -fqe /dev/null"; String cmdShellBSD = "script -q -F /dev/null"; // ptypipe is another solution that permits dynamic window resizing. @@ -337,7 +352,13 @@ public class TTerminalWidget extends TScrollableWidget } else if (System.getProperty("os.name").startsWith("Mac")) { spawnShell(cmdShellBSD.split("\\s+")); } else if (System.getProperty("os.name").startsWith("Linux")) { - spawnShell(cmdShellGNU.split("\\s+")); + if (System.getProperty("jexer.TTerminal.setsid", + "true").equals("false") + ) { + spawnShell(cmdShellGNU.split("\\s+")); + } else { + spawnShell(cmdShellGNUSetsid.split("\\s+")); + } } else { // When all else fails, assume GNU. spawnShell(cmdShellGNU.split("\\s+")); @@ -525,6 +546,32 @@ public class TTerminalWidget extends TScrollableWidget super.onMouseMotion(mouse); } + /** + * Handle posted command events. + * + * @param command command event + */ + @Override + public void onCommand(final TCommandEvent command) { + if (emulator == null) { + return; + } + + if (command.equals(cmPaste)) { + // Paste text from clipboard. + String text = getClipboard().pasteText(); + if (text != null) { + for (int i = 0; i < text.length(); ) { + int ch = text.codePointAt(i); + emulator.addUserEvent(new TKeypressEvent(false, 0, ch, + false, false, false)); + i += Character.charCount(ch); + } + } + return; + } + } + // ------------------------------------------------------------------------ // TScrollableWidget ------------------------------------------------------ // ------------------------------------------------------------------------ @@ -882,10 +929,7 @@ public class TTerminalWidget extends TScrollableWidget } }); } - if (getApplication() != null) { - getApplication().postEvent(new TMenuEvent( - TMenu.MID_REPAINT)); - } + app.doRepaint(); } } @@ -1161,4 +1205,44 @@ public class TTerminalWidget extends TScrollableWidget return 24; } + // ------------------------------------------------------------------------ + // EditMenuUser ----------------------------------------------------------- + // ------------------------------------------------------------------------ + + /** + * Check if the cut menu item should be enabled. + * + * @return true if the cut menu item should be enabled + */ + public boolean isEditMenuCut() { + return false; + } + + /** + * Check if the copy menu item should be enabled. + * + * @return true if the copy menu item should be enabled + */ + public boolean isEditMenuCopy() { + return false; + } + + /** + * Check if the paste menu item should be enabled. + * + * @return true if the paste menu item should be enabled + */ + public boolean isEditMenuPaste() { + return true; + } + + /** + * Check if the clear menu item should be enabled. + * + * @return true if the clear menu item should be enabled + */ + public boolean isEditMenuClear() { + return false; + } + }