CCCPaste

ArcTerm API

-- ArcTerm API

-- This is a collection of functions for CC:Tweaked's turtules and terminals screens

local ArcUtilities	=	require("ArcUtilities")


-- EXTERNAL FUNCTIONS

local function Reset()
	term.clear()
	term.setCursorPos(1,1)
end

local function Write(pnX,pnY,psText)
	term.setCursorPos(pnX,pnY)
	write(psText)
end

local function ResetLines(ptabnLines)
	local nX	=	nil
	local nY	=	nil
	nX,nY = term.getSize()
	for i=1,#ptabnLines,1 do
		Write(1,ptabnLines[i],ArcUtilities.Complete(""," ",nX,"R",false))
	end
	term.setCursorPos(1,ptabnLines[1])
end

local function WriteYesNo(pnX,pnY,pbYesNo)
	term.setCursorPos(pnX,pnY)
	if pbYesNo then write("YES  ")
	else write("NO   ") end
end

local function Read(pnX,pnY)
	local sReturn
	term.setCursorPos(pnX,pnY)
	sReturn = read()
	return sReturn
end

local function ReadYesNo(pnX,pnY)
	local sEvent
	local nKey
	local sKey
	local bHold
	Write(pnX,pnY,"(y/n)")
	sEvent,nKey,bHold = os.pullEvent("key")
	sKey = keys.getName(nKey)
	if sKey == "y" then
		Write(pnX,pnY,"YES  ")
		return true
	else
		Write(pnX,pnY,"NO   ")
		return false
	end
end

local function ReadKey()
	local nKey		=	0
	local bHold		=	false
	local sKey		=	""
	sEvent,nKey,bHold = os.pullEvent("key")
	sKey = keys.getName(nKey)
	return sKey
end


-- RETURN

return
{
	Reset		=	Reset,
	Write		=	Write,
	ResetLines	=	ResetLines,	
	WriteYesNo	=	WriteYesNo,
	Read		=	Read,
	ReadYesNo	=	ReadYesNo,
	ReadKey		=	ReadKey
}