Fix Util.getVersion

This commit is contained in:
Kan18 2022-12-28 20:05:16 +04:00
parent 5f153721ea
commit 2597724dab
5 changed files with 20 additions and 17 deletions

View File

@ -51,7 +51,7 @@ local config = {
} }
Config.load('Overview', config) Config.load('Overview', config)
local extSupport = Util.getVersion() >= 1.76 local extSupport = Util.supportsExtChars()
local applications = { } local applications = { }
local buttons = { } local buttons = { }

View File

@ -26,12 +26,12 @@ return UI.Tab {
x = 2, y = 5, ex = -2, ey = -2, x = 2, y = 5, ex = -2, ey = -2,
values = { values = {
{ name = '', value = '' }, { name = '', value = '' },
{ name = 'CC version', value = Util.getVersion() }, { name = 'CC version', value = ("%d.%d"):format(Util.getVersion()) },
{ name = 'Lua version', value = _VERSION }, { name = 'Lua version', value = _VERSION },
{ name = 'MC version', value = Util.getMinecraftVersion() }, { name = 'MC version', value = Util.getMinecraftVersion() },
{ name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) }, { name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) },
{ name = 'Computer ID', value = tostring(os.getComputerID()) }, { name = 'Computer ID', value = tostring(os.getComputerID()) },
{ name = 'Day', value = tostring(os.day()) }, { name = 'Day', value = tostring(os.day()) },
}, },
disableHeader = true, disableHeader = true,
inactive = true, inactive = true,

View File

@ -14,7 +14,7 @@ local parentTerm = _G.device.terminal
local w,h = parentTerm.getSize() local w,h = parentTerm.getSize()
local overviewId local overviewId
local tabsDirty = false local tabsDirty = false
local closeInd = Util.getVersion() >= 1.76 and '\215' or '*' local closeInd = Util.supportsExtChars() and '\215' or '*'
local multishell = { } local multishell = { }
_ENV.multishell = multishell _ENV.multishell = multishell

View File

@ -44,7 +44,7 @@ function UI:init()
tertiary = colors.gray, tertiary = colors.gray,
} }
} }
self.extChars = Util.getVersion() >= 1.76 self.extChars = Util.supportsExtChars()
local function keyFunction(event, code, held) local function keyFunction(event, code, held)
local ie = Input:translate(event, code, held) local ie = Input:translate(event, code, held)

View File

@ -170,16 +170,19 @@ function Util.print(pattern, ...)
end end
function Util.getVersion() function Util.getVersion()
local version local versionString = _G._HOST or _G._CC_VERSION
local versionMajor, versionMinor = versionString:match("(%d+)%.(%d+)")
-- ex.: 1.89 would return 1, 89
return versionMajor, versionMinor
end
if _G._CC_VERSION then function Util.compareVersion(major, minor)
version = tonumber(_G._CC_VERSION:match('[%d]+%.?[%d][%d]')) local currentMajor, currentMinor = Util.getVersion()
end return currentMajor > major or currentMajor == major and currentMinor >= minor
if not version and _G._HOST then end
version = tonumber(_G._HOST:match('[%d]+%.?[%d][%d]'))
end
return version or 1.7 function Util.supportsExtChars()
return Util.compareVersion(1, 76)
end end
function Util.getMinecraftVersion() function Util.getMinecraftVersion()