package com.jscape.inet.terminal.commands;

import com.jscape.inet.terminal.Terminal;

/**
 * Move cursor to the left margin on the current line.
 */
public class CRCommand
        implements ControlCommand {

    public static final String CANONICAL_FORM = "\015";
    private static final CRCommand INSTANCE = new CRCommand();

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

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

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

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

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

    /**
     * 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) {
        terminal.getScreen().getCursor().moveHome();
    }

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

    /**
     * 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) {
        terminal.send(CANONICAL_FORM);
    }
}
