package com.jscape.inet.terminal.commands;

import com.jscape.inet.terminal.Terminal;

/**
 * RI -- Reverse Index.
 * Move the active position to the same horizontal position on the preceding
 * line. If the active position is at the top margin, a scroll down is performed.
 */
public class RICommand
        implements ControlCommand {

    public static final String CANONICAL_FORM = "\033M";
    private static final RICommand INSTANCE = new RICommand();

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

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

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

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

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

    /**
     * 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().scrollDown();
    }

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

    /**
     * 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);
    }

}
