A quick whack at the problem. Solving off-by-one errors is an exercise left to the reader.
function renderBar(current, max, label)
local cursorX, cursorY = term.getCursorPos()
local x, y = term.getSize()
local center = math.floor(x / 2)
local transition = max * x / current
local textStart = center - math.floor(#label / 2)
local textStop = textStart + #label
local before, after = textStart - 1, x - textStop
local beforeStart, afterStart = math.floor(before / 2) - math.floor(string.len(tostring(current)) / 2), math.floor(after / 2) - math.floor(string.len(tostring(after)) / 2)
local barString = string.rep(" ", beforeStart)..tostring(current)
barString = barString..string.rep(" ", textStart - #barString)..label
barString = barString..string.rep(" ", afterStart - #barString)..tostring(max)
barString = barString..string .rep(" ", x - #barString)
local first, second = string.sub(barString, math.min(1, transition - 1), transition - 1), string.sub(barString, transition)
term.setCursorPos(1, cursorY)
term.setTextColor(colors.black)
term.setBackgroundColor(colors.green)
term.write(first)
term.setBackgroundColor(colors.red)
term.write(second)
end