Advertisement
PaymentOption

limtRead for os.reboot()

Jul 22nd, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. function limitRead( nLength, cReplaceChar )
  2.     term.setCursorBlink( true )
  3.    
  4.     nLength = nLength or -1 -- -1 is unlimited
  5.     sReturnString = ""
  6.    
  7.     xPos, yPos = term.getCursorPos()
  8.    
  9.     while true do
  10.         event, char = os.pullEvent()
  11.        
  12.         if nLength ~= -1 and string.len( sReturnString ) >= nLength then term.setCursorBlink( false ); return sReturnString end -- Length check
  13.        
  14.         if event == "char" then sReturnString = sReturnString .. char
  15.         elseif event == "key" and char == 28 then term.setCursorBlink( false ); return sReturnString -- Enter
  16.         elseif event == "key" and char == 14 then -- Backspace
  17.             term.setCursorPos( xPos, yPos )
  18.             term.write( string.rep( " ", string.len( sReturnString ) ) )
  19.             sReturnString = string.sub( sReturnString, 1, string.len( sReturnString )-1 )
  20.             term.setCursorPos( xPos, yPos )
  21.            
  22.             if not cReplaceChar then term.write( sReturnString )
  23.             else term.write( string.rep( cReplaceChar, string.len( sReturnString ) ) ) end
  24.         end
  25.        
  26.         term.setCursorPos( xPos, yPos )
  27.         term.write( string.rep( " ", string.len( sReturnString ) ) )
  28.         term.setCursorPos( xPos, yPos )
  29.         if not cReplaceChar then term.write( sReturnString )
  30.         else term.write( string.rep( cReplaceChar, string.len( sReturnString ) ) ) end
  31.     end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement