package com.jscape.inet.terminal.commands;

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

/**
 * Erase to End of Line.
 * Erase all characters from the active position to the end of the current line.
 * The active position is not changed.
 */
public class EELCommand
        implements ControlCommand {

    public static final String CANONICAL_FORM = "\033K";
    private static final EELCommand INSTANCE = new EELCommand();

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

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

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

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

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

    /**
     * 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) {
        Screen s = terminal.getScreen();
        s.eraseLine(s.getCursor().column(), s.getMaxCol());
    }

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

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