local liste={
	{
		p='Matrice d\'induction_13',
		nom='Laser'
	},{
		p='Matrice d\'induction_3',
		nom='QG'
	},{
		p='Matrice d\'induction_4',
		nom='Pierre'
	},{
		p='Matrice d\'induction_1',
		nom='Mekanism'
	},{
		p='Matrice d\'induction_2',
		nom='AE2'
	},{
		p='Matrice d\'induction_12',
		nom='Reacteur'
	},{
		p='Matrice d\'induction_0',
		nom='Botania'
	},{
		p='Matrice d\'induction_8',
		nom='Galacticraft'
	}
}
local ppPrincipal=peripheral.wrap('Matrice d\'induction_14')

function formatChiff(c)
	local mill=math.floor(c/1000)
	if mill==0 then
		return c
	else
		local unit=math.floor(c-(mill*1000))
		if unit<10 then
			return mill.." 00"..unit
		elseif unit<100 then
			return mill.." 0"..unit
		else
			return mill.." "..unit
		end
	end
end


local ecran=peripheral.find("monitor")
ecran.setTextScale(2)
ecran.clear()
ecran.setCursorPos(5,2)
ecran.write("Consommation")

local derPost=0
for i, d in pairs(liste) do 	
	liste[i].pp=peripheral.wrap(liste[i].p)
	print(liste[i].p)
	print(liste[i].pp)
	
	liste[i].win1=window.create(ecran,1,i+3,21,1,true)
	liste[i].win2=window.create(ecran,11,i+3,10,1,true)
	if i%2==0 then
		liste[i].win1.setBackgroundColor(colors.blue)
		liste[i].win2.setBackgroundColor(colors.blue)
	else 
		liste[i].win1.setBackgroundColor(colors.lightBlue)
		liste[i].win2.setBackgroundColor(colors.lightBlue)
	end
	liste[i].win1.clear()
	liste[i].win1.setCursorPos(2,1)
	liste[i].win1.write(liste[i].nom)
	
	derPost=i
end

ecran.setCursorPos(2,derPost+4)
ecran.write("Total")
local winTotal=window.create(ecran,11,derPost+4,10,1,true)

ecran.setCursorPos(6,derPost+6)
ecran.write("Production")
local winProduction=window.create(ecran,11,derPost+8,10,1,true)


while true do
	for i, d in pairs(liste) do			
		chiffString=formatChiff(liste[i].pp.getOutput()*4)
		chiffStringTaille=string.len(chiffString)
		liste[i].win2.clear()	
		liste[i].win2.setCursorPos(10-chiffStringTaille,1)
		liste[i].win2.write(chiffString)
	end
	
	totalString=formatChiff(ppPrincipal.getOutput())
	totalStringTaille=string.len(totalString)
	winTotal.clear()
	winTotal.setCursorPos(10-totalStringTaille,1)
	winTotal.write(totalString)
	
	totalString=formatChiff(ppPrincipal.getInput())
	totalStringTaille=string.len(totalString)
	winProduction.clear()
	winProduction.setCursorPos(10-totalStringTaille,1)
	winProduction.write(totalString)	
	
	os.sleep(5)
end