1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Multiple fixes and feature fixes for lua side of CC

In no particular order:
bios.lua - added missing test for ensure turtle folder exists.
paintutils.lua - added drawLineHorizontal() to reduce most (not all) cases of running multiple writes on same horizontal line that can be solved with one write.
textutils.lua - Added exception to complete function - will not complete if provided with LuaKeyword - solves do->dofile problem and removes other LuaKeyword related ones in advance.
edit.lua - Changed logic in handling the paste event - if paste event is received when menu is open it automatically closed said menu and lets it paste - resolves ctrl+ctrl+v annoyance. Added Jump to Menu functions - allows for fast jump to needed line - must for bigger files and a nice feature to have.
set.lua - Switched set to use pagedPrint - this will ensure that even if there are more settings than lines on screen the set command will show you all of them.
startup.lua - Added autocompletition for turtle programs go, turn, equip, unequip and command program exec.
lua.lua - Changed return function to print returned stuff correctly -
will print all returned variables even if there are any nils in there.
This commit is contained in:
Wojbie 2017-06-13 00:13:06 +02:00
parent 0f982e6199
commit 76a3562d58
7 changed files with 130 additions and 55 deletions

View File

@ -747,7 +747,7 @@ for n,sFile in ipairs( tApis ) do
end
end
if turtle then
if turtle and fs.isDir( "rom/apis/turtle" ) then
-- Load turtle APIs
local tApis = fs.list( "rom/apis/turtle" )
for n,sFile in ipairs( tApis ) do

View File

@ -4,6 +4,11 @@ local function drawPixelInternal( xPos, yPos )
term.write(" ")
end
local function drawLineHorizontal( xPos, yPos , nLen )
term.setCursorPos( xPos, yPos )
term.write(string.rep( " ", nLen ))
end
local tColourLookup = {}
for n=1,16 do
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
@ -77,6 +82,11 @@ function drawLine( startX, startY, endX, endY, nColour )
local xDiff = maxX - minX
local yDiff = maxY - minY
if minY == maxY then
drawLineHorizontal( minX, minY , xDiff + 1 )
return
end
if xDiff > math.abs(yDiff) then
local y = minY
@ -133,10 +143,8 @@ function drawBox( startX, startY, endX, endY, nColour )
maxY = startY
end
for x=minX,maxX do
drawPixelInternal( x, minY )
drawPixelInternal( x, maxY )
end
drawLineHorizontal( minX, minY , maxX - minX + 1 )
drawLineHorizontal( minX, maxY , maxX - minX + 1 )
if (maxY - minY) >= 2 then
for y=(minY+1),(maxY-1) do
@ -177,10 +185,8 @@ function drawFilledBox( startX, startY, endX, endY, nColour )
maxY = startY
end
for x=minX,maxX do
for y=minY,maxY do
drawPixelInternal( x, y )
end
for y=minY,maxY do
drawLineHorizontal( minX, y , maxX - minX + 1 )
end
end

View File

@ -338,6 +338,7 @@ end
local tEmpty = {}
function complete( sSearchText, tSearchTable )
if g_tLuaKeywords[sSearchText] then return tEmpty end
local nStart = 1
local nDot = string.find( sSearchText, ".", nStart, true )
local tTable = tSearchTable or _ENV

View File

@ -59,6 +59,7 @@ end
if peripheral.find( "printer" ) then
table.insert( tMenuItems, "Print" )
end
table.insert( tMenuItems, "Jump" )
table.insert( tMenuItems, "Exit" )
local sStatus = "Press Ctrl to access menu"
@ -282,6 +283,47 @@ local function redrawMenu()
term.setCursorPos( x - scrollX, y - scrollY )
end
local function setCursor( newX, newY )
local oldX, oldY = x, y
x, y = newX, newY
local screenX = x - scrollX
local screenY = y - scrollY
local bRedraw = false
if screenX < 1 then
scrollX = x - 1
screenX = 1
bRedraw = true
elseif screenX > w then
scrollX = x - w
screenX = w
bRedraw = true
end
if screenY < 1 then
scrollY = y - 1
screenY = 1
bRedraw = true
elseif screenY > h-1 then
scrollY = y - (h-1)
screenY = h-1
bRedraw = true
end
recomplete()
if bRedraw then
redrawText()
elseif y ~= oldY then
redrawLine( oldY )
redrawLine( y )
else
redrawLine( y )
end
term.setCursorPos( screenX, screenY )
redrawMenu()
end
local tMenuFuncs = {
Save = function()
if bReadOnly then
@ -395,7 +437,26 @@ local tMenuFuncs = {
sStatus="Error saving to "..sTempPath
end
redrawMenu()
end
end,
Jump = function()
term.setCursorPos( 1, h )
term.clearLine()
term.setTextColour( highlightColour )
term.write( "Line : " )
term.setTextColour( textColour )
local nLine = tonumber(read())
if type(nLine) == "number" then
nLine = math.min(math.max( 1, nLine ), #tLines )
setCursor( 1, nLine )
sStatus="Jumped to line "..nLine
redrawMenu()
redrawText()
else
sStatus="Invalid line number"
redrawMenu()
redrawText()
end
end,
}
local function doMenuItem( _n )
@ -407,47 +468,6 @@ local function doMenuItem( _n )
redrawMenu()
end
local function setCursor( newX, newY )
local oldX, oldY = x, y
x, y = newX, newY
local screenX = x - scrollX
local screenY = y - scrollY
local bRedraw = false
if screenX < 1 then
scrollX = x - 1
screenX = 1
bRedraw = true
elseif screenX > w then
scrollX = x - w
screenX = w
bRedraw = true
end
if screenY < 1 then
scrollY = y - 1
screenY = 1
bRedraw = true
elseif screenY > h-1 then
scrollY = y - (h-1)
screenY = h-1
bRedraw = true
end
recomplete()
if bRedraw then
redrawText()
elseif y ~= oldY then
redrawLine( oldY )
redrawLine( y )
else
redrawLine( y )
end
term.setCursorPos( screenX, screenY )
redrawMenu()
end
-- Actual program functionality begins
load(sPath)
@ -709,7 +729,13 @@ while bRunning do
end
elseif sEvent == "paste" then
if not bMenu and not bReadOnly then
if not bReadOnly then
-- Close menu if open
if bMenu then
bMenu = false
term.setCursorBlink( true )
redrawMenu()
end
-- Input text
local sLine = tLines[y]
tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)

View File

@ -64,10 +64,10 @@ while bRunning do
end
if func then
local tResults = { pcall( func ) }
local tResults = table.pack( pcall( func ) )
if tResults[1] then
local n = 1
while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
while n < tResults.n or (n <= nForcePrint) do
local value = tResults[ n + 1 ]
if type( value ) == "table" then
local metatable = getmetatable( value )

View File

@ -2,9 +2,12 @@
local tArgs = { ... }
if #tArgs == 0 then
-- "set"
local x,y = term.getCursorPos()
local tSettings = {}
for n,sName in ipairs( settings.getNames() ) do
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
tSettings[n] = textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName))
end
textutils.pagedPrint(table.concat(tSettings,"\n"),y-3)
elseif #tArgs == 1 then
-- "set foo"

View File

@ -195,6 +195,45 @@ shell.setCompletionFunction( "rom/programs/fun/advanced/paint.lua", completeFile
shell.setCompletionFunction( "rom/programs/http/pastebin.lua", completePastebin )
shell.setCompletionFunction( "rom/programs/rednet/chat.lua", completeChat )
if turtle then
local tGoOptions = { "left", "right", "forward", "back", "down", "up" }
local function completeGo( shell, nIndex, sText )
if nIndex == 1 then
return completeMultipleChoice(sText,tGoOptions)
end
end
local tTurnOptions = { "left", "right" }
local function completeTurn( shell, nIndex, sText )
if nIndex == 1 then
return completeMultipleChoice( sText, tTurnOptions )
end
end
local tEquipOptions = { "left", "right" }
local function completeEquip( shell, nIndex, sText )
if nIndex == 2 then
return completeMultipleChoice( sText, tEquipOptions )
end
end
local function completeUnequip( shell, nIndex, sText )
if nIndex == 1 then
return completeMultipleChoice( sText, tEquipOptions )
end
end
shell.setCompletionFunction( "rom/programs/turtle/go.lua", completeGo )
shell.setCompletionFunction( "rom/programs/turtle/turn.lua", completeTurn )
shell.setCompletionFunction( "rom/programs/turtle/equip.lua", completeEquip )
shell.setCompletionFunction( "rom/programs/turtle/unequip.lua", completeUnequip )
end
if commands then
local function completExec( shell, nIndex, sText )
if nIndex == 1 then
return completeMultipleChoice( sText, commands.list() )
end
end
shell.setCompletionFunction( "rom/programs/command/exec.lua", completExec )
end
-- Run autorun files
if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
local tFiles = fs.list( "/rom/autorun" )