Search code examples
jqueryhtmltextcommand-lineposition

HTML/jQuery - Make TextArea Behaviour like Command Line


I am trying to make a textarea look and behave like a command line, but I have one problem now..

Each time the user writes a command and presses 'Enter', I don't want the user to be able to write on lines above, but he can copy the content written before.

So the challenge is, how to limitate the lines where user can write?

Thanks alot in advance!


Solution

  • What if we disable going back up?

    Like:

    HTML

    <textarea id="command-line"></textarea>
    

    Jquery

    $('#command-line').keydown(function(e){
        if(e.keyCode === 38){
            return false;
        }
    });
    

    JSFiddle: http://jsfiddle.net/RE9hk/4/

    EDIT: flaw is the mouse which can be used to set the cursor, or have turned that off (in cmd (windows) it's not possible to use the mouse)