private boolean handleControl ( Char c ) { if ( c instanceof Control ) { if ( c . equals ( Control . DELETE ) ) { if ( after . length ( ) > 0 ) { after = after . substring ( 1 ) ; } } else if ( c . equals ( Control . LEFT ) ) { if ( before . length ( ) > 0 ) { after = "" + before . charAt ( before . length ( ) - 1 ) + after ; before = before . substring ( 0 , before . length ( ) - 1 ) ; } } else if ( c . equals ( Control . HOME ) ) { after = before + after ; before = "" ; } else if ( c . equals ( Control . CTRL_LEFT ) ) { int cut = cutWordBefore ( ) ; if ( cut > 0 ) { after = before . substring ( cut ) + after ; before = before . substring ( 0 , cut ) ; } else { after = before + after ; before = "" ; } } else if ( c . equals ( Control . RIGHT ) ) { if ( after . length ( ) > 0 ) { before = before + after . charAt ( 0 ) ; after = after . substring ( 1 ) ; } } else if ( c . equals ( Control . END ) ) { before = before + after ; after = "" ; } else if ( c . equals ( Control . CTRL_RIGHT ) ) { int cut = cutWordAfter ( ) ; if ( cut > 0 ) { before = before + after . substring ( 0 , cut ) ; after = after . substring ( cut ) ; } else { before = before + after ; after = "" ; } } else if ( c . equals ( ALT_W ) ) { // delete word before the cursor. int cut = cutWordBefore ( ) ; if ( cut > 0 ) { before = before . substring ( 0 , cut ) ; } else { before = "" ; } } else if ( c . equals ( ALT_D ) ) { // delete word after the cursor. int cut = cutWordAfter ( ) ; if ( cut > 0 ) { after = after . substring ( cut ) ; } else { after = "" ; } } else if ( c . equals ( ALT_K ) ) { // delete everything after the cursor. after = "" ; } else if ( c . equals ( ALT_U ) ) { // delete everything before the cursor. before = "" ; } else { printAbove ( "Invalid control: " + c . asString ( ) ) ; return true ; } printInputLine ( ) ; return true ; } return false ; }
Handle control sequence chars .