@Override
 protected void init() {
   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()));
   }
 }
 public Terminal reset() {
   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()));
   }
   return this;
 }
 public Terminal clearToEndOfLine() throws NativeException {
   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()));
   }
   return this;
 }
 public Terminal cursorRight(int count) {
   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()));
   }
   return this;
 }
 public Terminal cursorStartOfLine() throws NativeException {
   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()));
   }
   return this;
 }
  public Terminal bold() {
    if (!capabilities.textAttributes) {
      return this;
    }

    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()));
    }
    return this;
  }
  public Terminal foreground(Color color) {
    if (!capabilities.colors) {
      return this;
    }

    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()));
    }
    foreground = color;
    return this;
  }