- Added Terminal.supportsTextAttributes(), supportsColor() and supportCursorMotion().

- Changed semantics for Terminal.normal(), bold(), foreground() and reset() so that they are no-ops when not supported.
- Fixed test app not to blow up on unsupported capability.
This commit is contained in:
Adam Murdoch
2012-08-10 06:00:05 +10:00
parent 0180d2f035
commit ec2eb737a6
9 changed files with 282 additions and 186 deletions

View File

@@ -12,6 +12,7 @@ import java.io.PrintStream;
public class TerminfoTerminal extends AbstractTerminal {
private final TerminalAccess.Output output;
private final PrintStream stream;
private final TerminalCapabilities capabilities = new TerminalCapabilities();
private Color foreground;
public TerminfoTerminal(TerminalAccess.Output output) {
@@ -28,7 +29,7 @@ public class TerminfoTerminal extends AbstractTerminal {
protected void doInit() {
stream.flush();
FunctionResult result = new FunctionResult();
TerminfoFunctions.initTerminal(output.ordinal(), result);
TerminfoFunctions.initTerminal(output.ordinal(), capabilities, result);
if (result.isFailed()) {
throw new NativeException(String.format("Could not open terminal for %s: %s", this, result.getMessage()));
}
@@ -45,13 +46,33 @@ public class TerminfoTerminal extends AbstractTerminal {
return terminalSize;
}
@Override
public boolean supportsColor() {
return capabilities.colors;
}
@Override
public boolean supportsCursorMotion() {
return capabilities.cursorMotion;
}
@Override
public boolean supportsTextAttributes() {
return capabilities.textAttributes;
}
@Override
public Terminal foreground(Color color) {
if (!capabilities.colors) {
return this;
}
stream.flush();
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, result.getMessage()));
throw new NativeException(String.format("Could not switch foreground color for %s: %s", this,
result.getMessage()));
}
foreground = color;
return this;
@@ -59,11 +80,16 @@ public class TerminfoTerminal extends AbstractTerminal {
@Override
public Terminal bold() {
if (!capabilities.textAttributes) {
return this;
}
stream.flush();
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, result.getMessage()));
throw new NativeException(String.format("Could not switch to bold mode for %s: %s", this,
result.getMessage()));
}
return this;
}