Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local windows = {}
- local clipboard = ""
- local oldSize = term.getSize
- local oldClear = term.clear
- term.forceCursorPos = term.setCursorPos
- oldClearLine = term.clearLine
- term.paste = function()
- return os.queueEvent( "char", clipboard )
- end
- term.clear = function()
- local x,y = term.getCursorPos()
- oldClear()
- statusBar()
- term.setCursorPos(x,y)
- end
- term.copy = function( text )
- clipboard = text
- end
- term.getClipboard = function()
- return clipboard
- end
- term.getWindows = function()
- return windows
- end
- term.getSize = function()
- local x,y = oldSize()
- return x,y-2
- end
- read = function( _sReplaceChar, _tHistory )
- term.setCursorBlink( true )
- local cStart = 0
- local cEnd = 0
- local sLine = ""
- local nHistoryPos = nil
- local nPos = 0
- if _sReplaceChar then
- _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
- end
- local w, h = term.getSize()
- local sx, sy = term.getCursorPos()
- local function redraw( _sCustomReplaceChar )
- local nScroll = 0
- if sx + nPos >= w then
- nScroll = (sx + nPos) - w
- end
- term.setCursorPos( sx, sy )
- local sReplace = _sCustomReplaceChar or _sReplaceChar
- if sReplace then
- sText = string.rep(sReplace, string.len(sLine) - nScroll)
- else
- sText = string.sub( sLine, nScroll + 1 )
- end
- if cStart ~= 0 and cEnd ~= 0 then
- local sText1 = string.sub( sText, 1, cStart-1 )
- local sHigh = string.sub( sText, cStart, cEnd )
- local sText2 = string.sub( sText, cEnd+1, #sText )
- if sText1 then
- write( sText1 )
- end
- term.setBackgroundColour( colors.blue )
- if sHigh then
- write( sHigh )
- end
- term.setBackgroundColour( colors.black )
- if sText2 then
- write( sText2 )
- end
- else
- write( sText )
- end
- term.setCursorPos( sx + nPos - nScroll, sy )
- end
- local dragTimer = false
- while true do
- local sEvent, param, key, p2 = os.pullEvent()
- if sEvent == "char" then
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
- nPos = nPos + 1
- redraw()
- elseif sEvent == "mouse_drag" then
- local p1 = key
- local cPos = p1-sx+1
- print( "Mouse dragged (left) " ..p1.. ":" ..p2.. " (" ..p1.. ")")
- if cPos > 0 then
- if dragTimer == false then
- dragTimer = os.startTimer(0.9)
- cStart = cPos
- os.reboot()
- end
- cEnd = cPos
- end
- elseif sEvent == "timer" then
- if param == dragTimer then
- dragTimer = false
- end
- elseif sEvent == "key" then
- if param == keys.enter then
- -- Enter
- break
- elseif param == keys.left then
- -- Left
- if nPos > 0 then
- nPos = nPos - 1
- redraw()
- end
- elseif param == keys.right then
- -- Right
- if nPos < string.len(sLine) then
- nPos = nPos + 1
- redraw()
- end
- elseif param == keys.up or param == keys.down then
- -- Up or down
- if _tHistory then
- redraw(" ");
- if param == keys.up then
- -- Up
- if nHistoryPos == nil then
- if #_tHistory > 0 then
- nHistoryPos = #_tHistory
- end
- elseif nHistoryPos > 1 then
- nHistoryPos = nHistoryPos - 1
- end
- else
- -- Down
- if nHistoryPos == #_tHistory then
- nHistoryPos = nil
- elseif nHistoryPos ~= nil then
- nHistoryPos = nHistoryPos + 1
- end
- end
- if nHistoryPos then
- sLine = _tHistory[nHistoryPos]
- nPos = string.len( sLine )
- else
- sLine = ""
- nPos = 0
- end
- redraw()
- end
- elseif param == keys.backspace then
- -- Backspace
- if nPos > 0 then
- redraw(" ");
- sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
- nPos = nPos - 1
- redraw()
- end
- elseif param == keys.home then
- -- Home
- nPos = 0
- redraw()
- elseif param == keys.delete then
- if nPos < string.len(sLine) then
- redraw(" ");
- sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
- redraw()
- end
- elseif param == keys["end"] then
- -- End
- nPos = string.len(sLine)
- redraw()
- end
- end
- end
- term.setCursorBlink( false )
- term.setCursorPos( w + 1, sy )
- print()
- return sLine
- end
- function statusBar()
- term.setBackgroundColour( colors.black )
- local x,y = oldSize()
- local function cPrint( txt ) --Version 2.0 of cPrint
- local function printC( text )
- x2,y2 = term.getCursorPos()
- term.forceCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- write(text.. "\n")
- end
- if type(txt) == "string" then
- printC( txt )
- elseif type(txt) == "table" then
- for i=1,#txt do
- printC( txt[i] )
- end
- end
- end
- term.forceCursorPos(5,y-1)
- write( string.rep( "_", x-8 ) )
- term.forceCursorPos(4,y)
- term.clearLine()
- write("/")
- term.forceCursorPos( x-3, y )
- write("\\")
- if #windows ~= 0 then
- cPrint( string.rep( "o", #windows-1 ).. "o" )
- end
- end
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement