rename justify property to align

This commit is contained in:
kepler155c@gmail.com
2019-02-27 17:15:44 -05:00
parent 5af2bb1e91
commit 177533b760
11 changed files with 78 additions and 55 deletions

View File

@@ -2,39 +2,47 @@
-- By KillaVanilla -- By KillaVanilla
-- see: http://www.computercraft.info/forums2/index.php?/topic/12450-killavanillas-various-apis/ -- see: http://www.computercraft.info/forums2/index.php?/topic/12450-killavanillas-various-apis/
Base64 = { } local Base64 = { }
local bit = _G.bit
local _brshift = bit.brshift
local _bor = bit.bor
local _blshift = bit.blshift
local _band = bit.band
local _sub = string.sub
local os = _G.os
local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
local function sixBitToBase64(input) local function sixBitToBase64(input)
return string.sub(alphabet, input+1, input+1) return _sub(alphabet, input+1, input+1)
end end
local function base64ToSixBit(input) local function base64ToSixBit(input)
for i=1, 64 do for i=1, 64 do
if input == string.sub(alphabet, i, i) then if input == _sub(alphabet, i, i) then
return i-1 return i-1
end end
end end
end end
local function octetToBase64(o1, o2, o3) local function octetToBase64(o1, o2, o3)
local i1 = sixBitToBase64(bit.brshift(bit.band(o1, 0xFC), 2)) local i1 = sixBitToBase64(_brshift(_band(o1, 0xFC), 2))
local i2 = "A" local i2
local i3 = "=" local i3 = "="
local i4 = "=" local i4 = "="
if o2 then if o2 then
i2 = sixBitToBase64(bit.bor( bit.blshift(bit.band(o1, 3), 4), bit.brshift(bit.band(o2, 0xF0), 4) )) i2 = sixBitToBase64(_bor( _blshift(_band(o1, 3), 4), _brshift(_band(o2, 0xF0), 4) ))
if not o3 then if not o3 then
i3 = sixBitToBase64(bit.blshift(bit.band(o2, 0x0F), 2)) i3 = sixBitToBase64(_blshift(_band(o2, 0x0F), 2))
else else
i3 = sixBitToBase64(bit.bor( bit.blshift(bit.band(o2, 0x0F), 2), bit.brshift(bit.band(o3, 0xC0), 6) )) i3 = sixBitToBase64(_bor( _blshift(_band(o2, 0x0F), 2), _brshift(_band(o3, 0xC0), 6) ))
end end
else else
i2 = sixBitToBase64(bit.blshift(bit.band(o1, 3), 4)) i2 = sixBitToBase64(_blshift(_band(o1, 3), 4))
end end
if o3 then if o3 then
i4 = sixBitToBase64(bit.band(o3, 0x3F)) i4 = sixBitToBase64(_band(o3, 0x3F))
end end
return i1..i2..i3..i4 return i1..i2..i3..i4
@@ -45,31 +53,31 @@ end
-- octet 3 needs characters 3/4 -- octet 3 needs characters 3/4
local function base64ToThreeOctet(s1) local function base64ToThreeOctet(s1)
local c1 = base64ToSixBit(string.sub(s1, 1, 1)) local c1 = base64ToSixBit(_sub(s1, 1, 1))
local c2 = base64ToSixBit(string.sub(s1, 2, 2)) local c2 = base64ToSixBit(_sub(s1, 2, 2))
local c3 = 0 local c3
local c4 = 0 local c4
local o1 = 0 local o1
local o2 = 0 local o2
local o3 = 0 local o3
if string.sub(s1, 3, 3) == "=" then if _sub(s1, 3, 3) == "=" then
c3 = nil c3 = nil
c4 = nil c4 = nil
elseif string.sub(s1, 4, 4) == "=" then elseif _sub(s1, 4, 4) == "=" then
c3 = base64ToSixBit(string.sub(s1, 3, 3)) c3 = base64ToSixBit(_sub(s1, 3, 3))
c4 = nil c4 = nil
else else
c3 = base64ToSixBit(string.sub(s1, 3, 3)) c3 = base64ToSixBit(_sub(s1, 3, 3))
c4 = base64ToSixBit(string.sub(s1, 4, 4)) c4 = base64ToSixBit(_sub(s1, 4, 4))
end end
o1 = bit.bor( bit.blshift(c1, 2), bit.brshift(bit.band( c2, 0x30 ), 4) ) o1 = _bor( _blshift(c1, 2), _brshift(_band( c2, 0x30 ), 4) )
if c3 then if c3 then
o2 = bit.bor( bit.blshift(bit.band(c2, 0x0F), 4), bit.brshift(bit.band( c3, 0x3C ), 2) ) o2 = _bor( _blshift(_band(c2, 0x0F), 4), _brshift(_band( c3, 0x3C ), 2) )
else else
o2 = nil o2 = nil
end end
if c4 then if c4 then
o3 = bit.bor( bit.blshift(bit.band(c3, 3), 6), c4 ) o3 = _bor( _blshift(_band(c3, 3), 6), c4 )
else else
o3 = nil o3 = nil
end end
@@ -102,12 +110,25 @@ function Base64.encode(bytes)
return output return output
end end
local function Throttle()
local ts = os.clock()
local timeout = .095
return function()
local nts = os.clock()
if nts > ts + timeout then
os.sleep(0)
ts = os.clock()
end
end
end
function Base64.decode(str) function Base64.decode(str)
local bytes = {} local bytes = {}
local blocks = {} local blocks = {}
local blockNum = 1 local blockNum = 1
local throttle = Throttle()
for i=1, #str, 4 do for i=1, #str, 4 do
blocks[blockNum] = string.sub(str, i, i+3) blocks[blockNum] = _sub(str, i, i+3)
blockNum = blockNum+1 blockNum = blockNum+1
end end
for i=1, #blocks do for i=1, #blocks do
@@ -115,9 +136,7 @@ function Base64.decode(str)
table.insert(bytes, o1) table.insert(bytes, o1)
table.insert(bytes, o2) table.insert(bytes, o2)
table.insert(bytes, o3) table.insert(bytes, o3)
if (i % 1000) == 0 then throttle()
os.sleep(0)
end
end end
-- Remove padding: -- Remove padding:
--[[ --[[

View File

@@ -221,7 +221,7 @@ local blocksTab = UI.Tab {
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = 1, y = 1,
columns = { columns = {
{ heading = 'Count', key = 'count', width = 6, justify = 'right' }, { heading = 'Count', key = 'count', width = 6, align = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
}, },
sortColumn = 'displayName', sortColumn = 'displayName',
@@ -235,8 +235,8 @@ local turtlesTab = UI.Tab {
values = pool, values = pool,
columns = { columns = {
{ heading = 'ID', key = 'id', width = 4, }, { heading = 'ID', key = 'id', width = 4, },
{ heading = ' Fuel', key = 'fuel', width = 5, justify = 'right' }, { heading = ' Fuel', key = 'fuel', width = 5, align = 'right' },
{ heading = ' Dist', key = 'distance', width = 5, justify = 'right' }, { heading = ' Dist', key = 'distance', width = 5, align = 'right' },
{ heading = 'Status', key = 'status' }, { heading = 'Status', key = 'status' },
}, },
sortColumn = 'label', sortColumn = 'label',

View File

@@ -49,7 +49,7 @@ local page = UI.Page {
grid = UI.Grid { grid = UI.Grid {
y = 2, ey = -2, y = 2, ey = -2,
columns = { columns = {
{ heading = ' Qty', key = 'count' , width = 4, justify = 'right' }, { heading = ' Qty', key = 'count' , width = 4, align = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
}, },
values = { }, values = { },

View File

@@ -40,7 +40,7 @@ local page = UI.Page {
grid = UI.Grid { grid = UI.Grid {
y = 2, ey = -2, y = 2, ey = -2,
columns = { columns = {
{ heading = ' Qty', key = 'count' , width = 4, justify = 'right' }, { heading = ' Qty', key = 'count' , width = 4, align = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = 'Min', key = 'low' , width = 4 }, { heading = 'Min', key = 'low' , width = 4 },
{ heading = 'Max', key = 'limit' , width = 4 }, { heading = 'Max', key = 'limit' , width = 4 },

View File

@@ -29,7 +29,7 @@ local networkPage = UI.Page {
y = 2, ey = -3, y = 2, ey = -3,
values = context.storage.nodes, values = context.storage.nodes,
columns = { columns = {
{ key = 'suffix', width = 4, justify = 'right' }, { key = 'suffix', width = 4, align = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = 'Type', key = 'mtype', width = 4 }, { heading = 'Type', key = 'mtype', width = 4 },
{ heading = 'Pri', key = 'priority', width = 3 }, { heading = 'Pri', key = 'priority', width = 3 },

View File

@@ -81,13 +81,14 @@ local function createPage(node)
local page = UI.Page { local page = UI.Page {
parent = monitor, parent = monitor,
backgroundColor = colors.black,
grid = UI.Grid { grid = UI.Grid {
ey = -2, ey = -3,
columns = { columns = {
{ heading = 'Qty', key = 'count', width = 5 }, { heading = 'Qty', key = 'count', width = 6, align = 'right' },
{ heading = 'Change', key = 'change', width = 5 }, { heading = '+/-', key = 'change', width = 6, align = 'right' },
{ heading = 'Rate', key = 'rate', width = 6 }, { heading = 'Name', key = 'displayName' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Rate', key = 'rate', width = 6, align = 'right' },
}, },
sortColumn = 'displayName', sortColumn = 'displayName',
headerBackgroundColor = colors.black, headerBackgroundColor = colors.black,
@@ -100,19 +101,22 @@ local function createPage(node)
prevButton = UI.Button { prevButton = UI.Button {
x = 1, width = 5, x = 1, width = 5,
event = 'previous', event = 'previous',
backgroundColor = colors.lightGray, textColor = colors.cyan,
backgroundColor = colors.black,
text = ' < ' text = ' < '
}, },
resetButton = UI.Button { resetButton = UI.Button {
x = 7, ex = -7, x = 7, ex = -7,
event = 'reset', event = 'reset',
backgroundColor = colors.lightGray, textColor = colors.cyan,
backgroundColor = colors.black,
text = 'Reset' text = 'Reset'
}, },
nextButton = UI.Button { nextButton = UI.Button {
x = -5, width = 5, x = -5, width = 5,
event = 'next', event = 'next',
backgroundColor = colors.lightGray, textColor = colors.cyan,
backgroundColor = colors.black,
text = ' > ' text = ' > '
}, },
}, },

View File

@@ -13,7 +13,7 @@ local page = UI.Page {
y = 2, ey = -4, y = 2, ey = -4,
values = context.storage.nodes, values = context.storage.nodes,
columns = { columns = {
{ key = 'suffix', width = 4, justify = 'right' }, { key = 'suffix', width = 4, align = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = 'Type', key = 'mtype', width = 4 }, { heading = 'Type', key = 'mtype', width = 4 },
{ heading = 'Pri', key = 'priority', width = 3 }, { heading = 'Pri', key = 'priority', width = 3 },

View File

@@ -100,7 +100,7 @@ local page = UI.Page {
y = 2, ey = -2, y = 2, ey = -2,
sortColumn = 'name', sortColumn = 'name',
columns = { columns = {
{ heading = 'Count', key = 'count', width = 5, justify = 'right' }, { heading = 'Count', key = 'count', width = 5, align = 'right' },
{ heading = 'Resource', key = 'displayName' }, { heading = 'Resource', key = 'displayName' },
}, },
}, },

View File

@@ -27,7 +27,7 @@ local page = UI.Page {
y = 2, y = 2,
columns = { columns = {
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = 'Count', key = 'count', width = 5, justify = 'right' }, { heading = 'Count', key = 'count', width = 5, align = 'right' },
}, },
sortColumn = 'displayName', sortColumn = 'displayName',
}, },
@@ -46,9 +46,9 @@ local page = UI.Page {
columns = { columns = {
{ heading = 'Name', key = 'name' }, { heading = 'Name', key = 'name' },
{ heading = 'Dmg', key = 'metadata', width = 3 }, { heading = 'Dmg', key = 'metadata', width = 3 },
{ heading = ' X', key = 'x', width = 3, justify = 'right' }, { heading = ' X', key = 'x', width = 3, align = 'right' },
{ heading = ' Y', key = 'y', width = 3, justify = 'right' }, { heading = ' Y', key = 'y', width = 3, align = 'right' },
{ heading = ' Z', key = 'z', width = 3, justify = 'right' }, { heading = ' Z', key = 'z', width = 3, align = 'right' },
}, },
sortColumn = 'name', sortColumn = 'name',
}, },

View File

@@ -45,9 +45,9 @@ local page = UI.Page {
y = 2, y = 2,
columns = { columns = {
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = ' X', key = 'x', width = 3, justify = 'right' }, { heading = ' X', key = 'x', width = 3, align = 'right' },
{ heading = ' Y', key = 'y', width = 3, justify = 'right' }, { heading = ' Y', key = 'y', width = 3, align = 'right' },
{ heading = ' Z', key = 'z', width = 3, justify = 'right' }, { heading = ' Z', key = 'z', width = 3, align = 'right' },
}, },
values = sensor.sense(), values = sensor.sense(),
sortColumn = 'displayName', sortColumn = 'displayName',

View File

@@ -59,9 +59,9 @@ local function createPage(node)
backgroundSelectedColor = colors.black, backgroundSelectedColor = colors.black,
unfocusedBackgroundSelectedColor = colors.gray, unfocusedBackgroundSelectedColor = colors.gray,
columns = { columns = {
{ heading = 'Stock', key = 'count', width = 6, justify = 'right' }, { heading = 'Stock', key = 'count', width = 6, align = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = ' Price', key = 'price', width = 9, justify = 'right' }, { heading = ' Price', key = 'price', width = 9, align = 'right' },
{ heading = 'Address', key = 'address', width = 12 }, { heading = 'Address', key = 'address', width = 12 },
}, },
sortColumn = 'displayName', sortColumn = 'displayName',