/*
 * Trident - A Multithreaded Server Alternative
 * Copyright 2016 The TridentSDK Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.tridentsdk.server.command;

import org.fusesource.jansi.AnsiConsole;

import java.io.PrintStream;

/**
 * A few custom overrides of PrintStream in order to produce
 * the command-line-esque effect.
 */
public class TridentPrintStream extends PrintStream {
    public TridentPrintStream() {
        super(AnsiConsole.out);
    }

    @Override
    public void println(String line) {
        synchronized (this) {
            super.print("\r" + line);
            super.println();
            super.print("$ ");
            super.flush();
        }
    }

    @Override
    public void println(Object x) {
        synchronized (this) {
            super.print("\r" + x.toString());
            super.println();
            super.print("$ ");
            super.flush();
        }
    }
    
    @Override
    public void println() {
        this.println("");
    }

    @Override
    public void println(boolean x) {
        synchronized (this) {
            this.print(x);
            this.println();
        }
    }

    @Override
    public void println(char x) {
        synchronized (this) {
            this.print(x);
            this.println();
        }
    }

    @Override
    public void println(int x) {
        synchronized (this) {
            this.print(x);
            this.println();
        }
    }

    @Override
    public void println(long x) {
        synchronized (this) {
            this.print(x);
            this.println();
        }
    }

    @Override
    public void println(float x) {
        synchronized (this) {
            this.print(x);
            this.println();
        }
    }

    @Override
    public void println(double x) {
        synchronized (this) {
            this.print(x);
            this.println();
        }
    }

    @Override
    public void println(char x[]) {
        synchronized (this) {
            this.print(x);
            this.println();
        }
    }
}
@@ -719,17 +719,84 @@
 Ansi
-Console;%0A
+;%0Aimport org.fusesource.jansi.AnsiConsole;%0A%0Aimport javax.annotation.Nonnull;
 %0Aimp
@@ -1158,20 +1158,41 @@
 r.print(
-%22%5Cr%22
+Ansi.ansi().cursorLeft(2)
  + line)
@@ -1359,1156 +1359,698 @@
     
-synchronized (this) %7B%0A            super.print(%22%5Cr%22 + x.toString());%0A            super.println();%0A            super.print(%22$ %22);%0A            super.flush();%0A        %7D%0A    %7D%0A    %0A    @Override%0A    public void println() %7B%0A        this.println(%22%22);%0A    %7D%0A%0A    @Override%0A    public void println(boolean x) %7B%0A        synchronized (this) %7B%0A            this.print(x);%0A            this.println();%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void println(char x) %7B%0A        synchronized (this) %7B%0A            this.print(x);%0A            this.println();%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void println(int x) %7B%0A        synchronized (this) %7B%0A            this.print(x);%0A            this.println();%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void println(long x) %7B%0A        synchronized (this) %7B%0A            this.print(x);%0A            this.println();%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void println(float x) %7B%0A        synchronized (this) %7B%0A            this.print(x);%0A            this.println();%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void println(double x) %7B%0A        synchronized (this) %7B%0A            this.print(x);%0A            this.println();%0A        %7D
+this.println(x.toString());%0A    %7D%0A    %0A    @Override%0A    public void println() %7B%0A        this.println(%22%22);%0A    %7D%0A%0A    @Override%0A    public void println(boolean x) %7B%0A        this.println(x ? %22true%22 : %22false%22);%0A    %7D%0A%0A    @Override%0A    public void println(char x) %7B%0A        this.println(String.valueOf(x));%0A    %7D%0A%0A    @Override%0A    public void println(int x) %7B%0A        this.println(String.valueOf(x));%0A    %7D%0A%0A    @Override%0A    public void println(long x) %7B%0A        this.println(String.valueOf(x));%0A    %7D%0A%0A    @Override%0A    public void println(float x) %7B%0A        this.println(String.valueOf(x));%0A    %7D%0A%0A    @Override%0A    public void println(double x) %7B%0A        this.println(String.valueOf(x));
 %0A   
@@ -2087,24 +2087,33 @@
 oid println(
+@Nonnull 
 char x%5B%5D) %7B%0A
@@ -2124,94 +2124,36 @@
     
-synchronized (this) %7B%0A            this.print(x);%0A            this.println();%0A        %7D
+this.println(new String(x));
 %0A   

Use ANSI escape instead of \r