Advertisement
VlaD00m

Openfetch

Jan 17th, 2021 (edited)
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.96 KB | None | 0 0
  1. -- openfetch 1.4 | by ethernalsteve & Bs0Dd
  2.  
  3. local component = require("component")
  4. local computer = require("computer")
  5. local fs = require("filesystem")
  6. local gpu = component.gpu
  7.  
  8. local logos = {
  9.     {
  10.         "  %%%%(///////(%%%    ",
  11.         " %%   (///%%%/(%%%%%  ",
  12.         " %%   (///%%%/(%%%%%  ",
  13.         " %%   (///////(%%%%%  ",
  14.         " %%%%%%%%%%%%%%%%%%%  ",
  15.         " %%%%%%%%%%%%%%%%%%%  ",
  16.         " %%               %%  ",
  17.         " %%               %%  ",
  18.         " %%%%%%%%%%%%%%%%%%%  ",
  19.         "  %%%%%%%%%%%%%%%%%   "
  20.     },
  21.     {
  22.         "  %%%%%(///////////////(%%%%      ",
  23.         " %%%###(//////%%%%%%///(%%%%%%%   ",
  24.         " %%%###(//////%%%%%%///(%%%%%%%   ",
  25.         " %%%###(//////%%%%%%///(%%%%%%%   ",
  26.         " %%%###(//////%%%%%%///(%%%%%%%   ",
  27.         " %%%###(///////////////(%%%%%%%   ",
  28.         " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   ",
  29.         " %%%((((((((((((((((((((((((%%%   ",
  30.         " %%%((((((((((((((((((((((((%%%   ",
  31.         " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   ",
  32.         " %%%                        %%%   ",
  33.         " %%%////////////////////////%%%   ",
  34.         " %%%                        %%%   ",
  35.         " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   ",
  36.         "  %%%%%%%%%%%%%%%%%%%%%%%%%%%%    "
  37.     },
  38.     {
  39.         "  %%%%%%%%%%(///////////////////////(%%%%%%%      ",
  40.         " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%    ",
  41.         " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%%   ",
  42.         " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%%   ",
  43.         " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%%   ",
  44.         " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%%   ",
  45.         " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%%   ",
  46.         " %%%%%%#####(///////////////////////(%%%%%%%%%%   ",
  47.         " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   ",
  48.         " %%%%%%((((((((((((((((((((((((((((((((((%%%%%%   ",
  49.         " %%%%%%((((((((((((((((((((((((((((((((((%%%%%%   ",
  50.         " %%%%%%((((((((((((((((((((((((((((((((((%%%%%%   ",
  51.         " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   ",
  52.         " %%%%%%                                  %%%%%%   ",
  53.         " %%%%%%                                  %%%%%%   ",
  54.         " %%%%%%                                  %%%%%%   ",
  55.         " %%%%%%//////////////////////////////////%%%%%%   ",
  56.         " %%%%%%                                  %%%%%%   ",
  57.         " %%%%%%                                  %%%%%%   ",
  58.         " %%%%%%                                  %%%%%%   ",
  59.         " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   ",
  60.         "  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    "
  61.     }
  62. }
  63.  
  64. local w, h = gpu.maxResolution()
  65. local devs = component.computer.getDeviceInfo()
  66. local gpuInfoStr
  67.  
  68. local function getGPUTier()
  69.     local dp = gpu.maxDepth()
  70.     if dp == 8 then
  71.         return 3
  72.     elseif dp == 4 then
  73.         return 2
  74.     else
  75.         return 1
  76.     end
  77. end
  78.  
  79. local function getModel(desc)
  80.     local name
  81.     for _, dev in pairs(devs) do
  82.         if dev.description == desc then
  83.             name = dev.product
  84.             break
  85.         end
  86.     end
  87.     return name
  88. end
  89.  
  90. local function getOS()
  91.     if fs.exists("OS.lua") then
  92.         return "MineOS"
  93.     elseif fs.exists("/lib/core") then
  94.         return "OpenOS"
  95.     elseif fs.exists("/root") then
  96.         return "Plan9k"
  97.     end
  98. end
  99.  
  100. local function getParsedUptime()
  101.     local seconds, minutes, hours = math.floor(computer.uptime()), 0, 0
  102.     local time = ""
  103.     if seconds >= 60 then
  104.         minutes = math.floor(seconds / 60)
  105.         seconds = seconds % 60
  106.     end
  107.     if minutes >= 60 then
  108.         hours = math.floor(minutes / 60)
  109.         minutes = minutes % 60
  110.     end
  111.     if getGPUTier() == 1 then
  112.         time = time .. string.format("%02d:%02d:%02d", hours, minutes, seconds)
  113.     else
  114.         if hours == 1 then time = hours .. " hour, "
  115.         elseif hours >= 2 then time = hours .. " hours, "
  116.         end
  117.         if minutes == 1 then time = time .. minutes .. " min, "
  118.         elseif minutes >= 2 then time = time .. minutes .. " mins, "
  119.         end
  120.         time = time .. seconds .. " sec"
  121.     end
  122.     return time
  123. end
  124.  
  125. local logo = logos[getGPUTier()]
  126. local function addCharacteristics()
  127.     local cpu, apu = getModel("CPU"), getModel("APU")
  128.     gpuInfoStr = 8
  129.  
  130.     logo[2] = logo[2] .. "|OS:|" .. getOS()
  131.     logo[3] = logo[3] .. "|Uptime:|" .. getParsedUptime()
  132.     logo[4] = logo[4] .. "|Architecture:|" .. _VERSION
  133.     logo[5] = logo[5] .. "|Resolution:|" .. math.floor(w) .. "x" .. math.floor(h)
  134.     logo[6] = logo[6] .. "|Terminal:|" .. getModel("Text buffer")
  135.     if cpu ~= nil then logo[7] = logo[7] .. "|CPU:|" .. cpu:sub(0,11) .. ' (' .. cpu:match('%d') .. ' Tier)'
  136.     elseif apu ~= nil then logo[7] = logo[7] .. "|APU:|" .. apu:sub(0,11) .. ' (' .. apu:match('%d') .. ' Tier)' end
  137.     for _, dev in pairs(devs) do
  138.         if dev.description == "Graphics controller" then
  139.             logo[gpuInfoStr] = logo[gpuInfoStr] .. "|GPU:|" .. dev.product .. ' (' .. dev.product:match('%d') .. ' Tier)'
  140.             gpuInfoStr = gpuInfoStr + 1
  141.         end
  142.     end
  143.     logo[gpuInfoStr] = logo[gpuInfoStr] .. "|Memory:|" .. math.floor(computer.totalMemory() / 1024 - computer.freeMemory() / 1024) .. " KB / " .. math.floor(computer.totalMemory() / 1024) .. " KB"
  144. end
  145.  
  146. local function drawPalette()
  147.     local palette = {{0x000000, 0x333333}, {0xCC0000, 0xFF0000}, {0x00CC00, 0x00FF00}, {0xCCCC00, 0xFFFF00},
  148.         {0x0000CC, 0x0000FF}, {0xCC00CC, 0xFF00FF}, {0x00CCCC, 0x00FFFF}, {0xCCCCCC, 0xFFFFFF}}
  149.     local cur = #logo[1] + 2
  150.     for _, color in pairs(palette) do
  151.         gpu.setForeground(color[1])
  152.         gpu.set(cur, gpuInfoStr + 2, "███")
  153.         gpu.setForeground(color[2])
  154.         gpu.set(cur, gpuInfoStr + 3, "███")
  155.         cur = cur + 3
  156.     end
  157. end
  158.  
  159. gpu.setResolution(w, h)
  160. addCharacteristics()
  161. gpu.setBackground(0x000000)
  162. gpu.fill(1, 1, w, h, " ")
  163.  
  164. for i = 1, #logo do
  165.     local logoLine, tmp, f = {}, {}, false
  166.     logo[i]:gsub(".", function(c) table.insert(logoLine, c) end)
  167.     for ii = 1, #logoLine do
  168.         if f then
  169.             if string.match(logoLine[ii], "|") then
  170.                 f = false
  171.             else
  172.                 if string.match(logoLine[ii], ":") then
  173.                     gpu.setForeground(0xffffff)
  174.                 elseif getOS() == "MineOS" then
  175.                     gpu.setForeground(0x32e3de)
  176.                 elseif getOS() == "OpenOS" then
  177.                     gpu.setForeground(0x30ff80)
  178.                 elseif getOS() == "Plan9k" then
  179.                     gpu.setForeground(0xff0000)
  180.                 end
  181.                 gpu.set(ii, i, logoLine[ii])
  182.             end
  183.         else
  184.             if logoLine[ii] == "%" then
  185.                 if getOS() == "MineOS" then
  186.                     gpu.setForeground(0x35ffff)
  187.                 elseif getOS() == "OpenOS" then
  188.                     gpu.setForeground(0x228822)
  189.                 elseif getOS() == "Plan9k" then
  190.                     gpu.setForeground(0xff0000)
  191.                 end
  192.                 gpu.set(ii, i, logoLine[ii])
  193.             elseif logoLine[ii] == "/" then
  194.                 gpu.setForeground(0xfffafa)
  195.                 gpu.set(ii, i, logoLine[ii])
  196.             elseif logoLine[ii] == "#" then
  197.                 gpu.setForeground(0x585858)
  198.                 gpu.set(ii, i, logoLine[ii])
  199.             elseif logoLine[ii] == "(" then
  200.                 gpu.setForeground(0xc0c0c0)
  201.                 gpu.set(ii, i, logoLine[ii])
  202.             elseif string.match(logoLine[ii], "|") then
  203.                 f = true
  204.             else
  205.                 gpu.setForeground(0xffffff)
  206.                 gpu.set(ii, i, logoLine[ii])
  207.             end
  208.         end
  209.     end
  210. end
  211.  
  212. drawPalette()
  213.  
  214. if getOS() == "MineOS" then
  215.   gpu.set(1, #logo + 2 > 14 and #logo + 2 or 14, 'Press any key to exit.')
  216.   local evtype
  217.   while evtype ~= 'key_down' do
  218.     evtype = computer.pullSignal()
  219.   end
  220. else require("term").setCursor(1, #logo + 2 > 14 and #logo + 2 or 14) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement