package com.jscape.inet.terminal.commands;

import com.jscape.inet.terminal.Screen.Cursor;
import com.jscape.inet.terminal.Terminal;

/**
 * CPR -- Cursor Position Report.
 * The CPR sequence reports the active position by means of the parameters.
 * This sequence has two parameter values, the first specifying the line and
 * the second specifying the column.
 * The default condition with no parameters present,
 * or parameters of 0, is equivalent to a cursor at home position.
 * The numbering of lines depends on the state of the Origin Mode (DECOM).
 * This control sequence is solicited by a device status
 * report (DSR) sent from the host.
 */
public class CPRCommand
        implements ControlCommand {

    public static final String CANONICAL_FORM = "\033[R";
    private static final CPRCommand INSTANCE = new CPRCommand();

    //----------------------------------------------------------------------------

    /**
     * Returns one and only one instance of this type.
     *
     * @return one and only one instance of this type.
     */
    public static final CPRCommand getInstance() {
        return INSTANCE;
    }

    //----------------------------------------------------------------------------

    /**
     * Private constructor to prevent uncontrolled creation.
     */
    private CPRCommand() {
    }

    //----------------------------------------------------------------------------

    /**
     * Executes command giving parameters and <code>Terminal</code> object.
     *
     * @param params   array of <code>int</code> command parametrs.
     * @param terminal target <code>Terminal</code> object.
     */
    public void execute(int[] params, Terminal terminal) {
    }

    //----------------------------------------------------------------------------

    /**
     * Sends command to remote host.
     *
     * @param params   command parameters.
     * @param terminal target <code>Terminal</code> object to send command.
     */
    public void send(int[] params, Terminal terminal) {
        Cursor c = terminal.getScreen().getCursor();
        StringBuffer b =
                new StringBuffer("\033[").append(c.row()).append(';').append(
                        c.column()).append(
                        'R');
        terminal.send(b.toString());
    }
}
