diff --git a/src/main/java/net/rubygrapefruit/platform/internal/TerminfoTerminal.java b/src/main/java/net/rubygrapefruit/platform/internal/TerminfoTerminal.java index 916a78a..38b7f04 100755 --- a/src/main/java/net/rubygrapefruit/platform/internal/TerminfoTerminal.java +++ b/src/main/java/net/rubygrapefruit/platform/internal/TerminfoTerminal.java @@ -18,6 +18,10 @@ public class TerminfoTerminal extends AbstractTerminal { @Override public String toString() { + return String.format("Curses terminal on %s", getOutputDisplay()); + } + + private String getOutputDisplay() { return output.toString().toLowerCase(); } @@ -26,7 +30,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.initTerminal(output.ordinal(), capabilities, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not open terminal for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not open terminal for %s: %s", getOutputDisplay(), result.getMessage())); } } @@ -35,7 +39,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); PosixTerminalFunctions.getTerminalSize(output.ordinal(), terminalSize, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not get terminal size for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not get terminal size for %s: %s", getOutputDisplay(), result.getMessage())); } return terminalSize; } @@ -60,7 +64,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.foreground(color.ordinal(), result); if (result.isFailed()) { - throw new NativeException(String.format("Could not switch foreground color for %s: %s", this, + throw new NativeException(String.format("Could not switch foreground color for %s: %s", getOutputDisplay(), result.getMessage())); } foreground = color; @@ -75,7 +79,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.bold(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not switch to bold mode for %s: %s", this, + throw new NativeException(String.format("Could not switch to bold mode for %s: %s", getOutputDisplay(), result.getMessage())); } return this; @@ -93,7 +97,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.reset(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not reset terminal for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not reset terminal for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -102,7 +106,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.down(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor down for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor down for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -111,7 +115,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.up(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor up for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor up for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -120,7 +124,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.left(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor left for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor left for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -129,7 +133,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.right(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor right for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor right for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -138,7 +142,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.startLine(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor to start of line for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor to start of line for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -147,7 +151,7 @@ public class TerminfoTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); TerminfoFunctions.clearToEndOfLine(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not clear to end of line for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not clear to end of line for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } diff --git a/src/main/java/net/rubygrapefruit/platform/internal/WindowsTerminal.java b/src/main/java/net/rubygrapefruit/platform/internal/WindowsTerminal.java index 52cbd90..d223616 100755 --- a/src/main/java/net/rubygrapefruit/platform/internal/WindowsTerminal.java +++ b/src/main/java/net/rubygrapefruit/platform/internal/WindowsTerminal.java @@ -15,6 +15,10 @@ public class WindowsTerminal extends AbstractTerminal { @Override public String toString() { + return String.format("Windows console on %s", getOutputDisplay()); + } + + private String getOutputDisplay() { return output.toString().toLowerCase(); } @@ -23,7 +27,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.initConsole(output.ordinal(), result); if (result.isFailed()) { - throw new NativeException(String.format("Could not open console for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not open console for %s: %s", getOutputDisplay(), result.getMessage())); } } @@ -44,7 +48,7 @@ public class WindowsTerminal extends AbstractTerminal { MutableTerminalSize size = new MutableTerminalSize(); WindowsConsoleFunctions.getConsoleSize(output.ordinal(), size, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not determine console size for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not determine console size for %s: %s", getOutputDisplay(), result.getMessage())); } return size; } @@ -53,7 +57,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.bold(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not switch console to bold mode for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not switch console to bold mode for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -62,7 +66,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.foreground(color.ordinal(), result); if (result.isFailed()) { - throw new NativeException(String.format("Could not change console foreground color for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not change console foreground color for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -71,7 +75,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.normal(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not switch console to normal mode for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not switch console to normal mode for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -80,7 +84,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.reset(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not reset console for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not reset console for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -89,7 +93,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.down(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor down for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor down for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -98,7 +102,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.up(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor up for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor up for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -107,7 +111,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.left(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor left for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor left for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -116,7 +120,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.right(count, result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor right for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor right for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -125,7 +129,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.startLine(result); if (result.isFailed()) { - throw new NativeException(String.format("Could not move cursor to start of line for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could not move cursor to start of line for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } @@ -134,7 +138,7 @@ public class WindowsTerminal extends AbstractTerminal { FunctionResult result = new FunctionResult(); WindowsConsoleFunctions.clearToEndOfLine(result); if (result.isFailed()) { - throw new NativeException(String.format("Could clear to end of line for %s: %s", this, result.getMessage())); + throw new NativeException(String.format("Could clear to end of line for %s: %s", getOutputDisplay(), result.getMessage())); } return this; } diff --git a/src/main/java/net/rubygrapefruit/platform/internal/WrapperTerminal.java b/src/main/java/net/rubygrapefruit/platform/internal/WrapperTerminal.java index 96f372d..b2dd4b2 100644 --- a/src/main/java/net/rubygrapefruit/platform/internal/WrapperTerminal.java +++ b/src/main/java/net/rubygrapefruit/platform/internal/WrapperTerminal.java @@ -26,26 +26,26 @@ public class WrapperTerminal extends AbstractTerminal { } @Override + public String toString() { + return terminal.toString(); + } + public TerminalSize getTerminalSize() throws NativeException { return terminal.getTerminalSize(); } - @Override public boolean supportsColor() { return terminal.supportsColor(); } - @Override public boolean supportsCursorMotion() { return terminal.supportsCursorMotion(); } - @Override public boolean supportsTextAttributes() { return terminal.supportsTextAttributes(); } - @Override public Terminal normal() throws NativeException { stream.flush(); synchronized (lock) { @@ -54,7 +54,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal bold() throws NativeException { stream.flush(); synchronized (lock) { @@ -63,7 +62,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal reset() throws NativeException { stream.flush(); synchronized (lock) { @@ -72,7 +70,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal foreground(Color color) throws NativeException { stream.flush(); synchronized (lock) { @@ -81,7 +78,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal cursorLeft(int count) throws NativeException { stream.flush(); synchronized (lock) { @@ -90,7 +86,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal cursorRight(int count) throws NativeException { stream.flush(); synchronized (lock) { @@ -99,7 +94,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal cursorUp(int count) throws NativeException { stream.flush(); synchronized (lock) { @@ -108,7 +102,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal cursorDown(int count) throws NativeException { stream.flush(); synchronized (lock) { @@ -117,7 +110,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal cursorStartOfLine() throws NativeException { stream.flush(); synchronized (lock) { @@ -126,7 +118,6 @@ public class WrapperTerminal extends AbstractTerminal { return this; } - @Override public Terminal clearToEndOfLine() throws NativeException { stream.flush(); synchronized (lock) {