package com.jscape.inet.terminal.commands;

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

/**
 * NEL -- Next Line.
 * This sequence causes the active position to move to the first position on
 * the next line downward. If the active position is at the bottom margin,
 * a scroll up is performed.
 */
public class NELCommand
        implements ControlCommand {

    public static final String CANONICAL_FORM = "\033E";
    private static final NELCommand INSTANCE = new NELCommand();

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

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

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

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

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

    /**
     * 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) {
        Cursor c = terminal.getScreen().getCursor();
        c.scrollUp();
        c.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);
    }
}
