m = peripheral.wrap('bottom')
t = peripheral.wrap('left')

warning_on = false
sleep_delay = 0.3

function toggle_warning()
    if warning_on then
        t.clear()
    else
        t.clear()
        t.setTextScale(5)
        t.setCursorPos(1,1)
        t.setTextColor(colors.green)
        t.write('Standby')
    end
    warning_on = not warning_on
end

lm = {}
f = io.open('loading_messages', 'r')
for line in f:lines() do
    table.insert (lm, line);
end
current_lines = {}

offset = 6
lines = 11

function update_loading()
    table.insert(current_lines,lm[math.random(#lm)])
    if #current_lines > lines then
        table.remove(current_lines, 1)
    end
    
    for i=1,lines do
        if current_lines[i] then
            m.setCursorPos(1,i+offset)
            m.clearLine()
            m.write(current_lines[i]..'...')
        end
    end
end

m.setTextScale(1.8)
m.clear()
w,h = m.getSize()
s = '-'

m.setCursorPos(1,1)
m.write(s:rep(w))
m.setCursorPos(1,2)
m.write(' Reality jump was a success ...')
m.setCursorPos(1,3)
m.write(' Checking cargo chests ...')
m.setCursorPos(1,4)
m.write(' Detecting slight orientation corruption ...')
m.setCursorPos(1,5)
m.write(' Standing by for now ...')
m.setCursorPos(1,6)
m.write(s:rep(w))

toggle_warning()

while false do
    toggle_warning()
    update_loading()
    os.sleep(sleep_delay)
end
