ethernalsteve

Openfetch 1.2

Jan 17th, 2021 (edited)
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.35 KB | None | 0 0
  1. -- openfetch 1.2 | by ethernalsteve & Bs0Dd
  2.  
  3. local component = require("component")
  4. local computer = require("computer")
  5. local fs = require("filesystem")
  6. local term = require("term")
  7. local gpu = component.gpu
  8.  
  9. local logos = {
  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.  
  65. local w, h = gpu.maxResolution()
  66. local devs = component.computer.getDeviceInfo()
  67. local gpuInfoStr
  68.  
  69. local function getGPUTier()
  70.     local dp = gpu.maxDepth()
  71.     if dp == 8 then
  72.         return 3
  73.     elseif dp == 4 then
  74.         return 2
  75.     else
  76.         return 1
  77.     end
  78. end
  79.  
  80. local function getModel(desc)
  81.     local name
  82.     for _, dev in pairs(devs) do
  83.         if dev.description == desc then
  84.             name = dev.product
  85.             break
  86.         end
  87.     end
  88.     return name
  89. end
  90.  
  91. local function getOS()
  92.     if fs.exists("/lib/core") then
  93.         return "OpenOS"
  94.     elseif fs.exists("/root") then
  95.         return "Plan9k"
  96.     end
  97. end
  98.  
  99. local function getParsedUptime()
  100.     local seconds, minutes, hours = math.floor(computer.uptime()), 0, 0
  101.     local time = ""
  102.     if seconds >= 60 then
  103.         minutes = math.floor(seconds / 60)
  104.         seconds = seconds % 60
  105.     end
  106.     if minutes >= 60 then
  107.         hours = math.floor(minutes / 60)
  108.         minutes = minutes % 60
  109.     end
  110.     if getGPUTier() == 1 then
  111.         time = time .. string.format("%02d:%02d:%02d", hours, minutes, seconds)
  112.     else
  113.         if hours == 1 then time = hours .. " hour, "
  114.         elseif hours >= 2 then time = hours .. " hours, "
  115.         end
  116.         if minutes == 1 then time = time .. minutes .. " min, "
  117.         elseif minutes >= 2 then time = time .. minutes .. " mins, "
  118.         end
  119.         time = time .. seconds .. " sec"
  120.     end
  121.     return time
  122. end
  123.  
  124. local logo = logos[getGPUTier()]
  125. local function addCharacteristics()
  126.     local cpu, apu = getModel("CPU"), getModel("APU")
  127.     gpuInfoStr = 8
  128.  
  129.     logo[2] = logo[2] .. "|OS:|" .. getOS()
  130.     logo[3] = logo[3] .. "|Uptime:|" .. getParsedUptime()
  131.     logo[4] = logo[4] .. "|Architecture:|" .. _VERSION
  132.     logo[5] = logo[5] .. "|Resolution:|" .. math.floor(w) .. "x" .. math.floor(h)
  133.     logo[6] = logo[6] .. "|Terminal:|" .. getModel("Text buffer")
  134.     if cpu ~= nil then logo[7] = logo[7] .. "|CPU:|" .. cpu
  135.     elseif apu ~= nil then logo[7] = logo[7] .. "|APU:|" .. apu end
  136.     for _, dev in pairs(devs) do
  137.         if dev.description == "Graphics controller" then
  138.             logo[gpuInfoStr] = logo[gpuInfoStr] .. "|GPU:|" .. dev.product
  139.             gpuInfoStr = gpuInfoStr + 1
  140.         end
  141.     end
  142.     logo[gpuInfoStr] = logo[gpuInfoStr] .. "|Memory:|" .. math.floor(computer.totalMemory() / 1024 - computer.freeMemory() / 1024) .. " KB / " .. math.floor(computer.totalMemory() / 1024) .. " KB"
  143. end
  144.  
  145. local function drawPalette()
  146.     local palette = {{0x000000, 0x333333}, {0xCC0000, 0xFF0000}, {0x00CC00, 0x00FF00}, {0xCCCC00, 0xFFFF00},
  147.         {0x0000CC, 0x0000FF}, {0xCC00CC, 0xFF00FF}, {0x00CCCC, 0x00FFFF}, {0xCCCCCC, 0xFFFFFF}}
  148.     local cur = #logo[1] + 2
  149.     for _, color in pairs(palette) do
  150.         gpu.setForeground(color[1])
  151.         gpu.set(cur, gpuInfoStr + 2, "███")
  152.         gpu.setForeground(color[2])
  153.         gpu.set(cur, gpuInfoStr + 3, "███")
  154.         cur = cur + 3
  155.     end
  156. end
  157.  
  158. gpu.setResolution(w, h)
  159. addCharacteristics()
  160. gpu.fill(1, 1, w, h, " ")
  161. term.setCursor(1, #logo + 2 > 14 and #logo + 2 or 14)
  162.  
  163. for i = 1, #logo do
  164.     local logoLine, tmp, f = {}, {}, false
  165.     logo[i]:gsub(".", function(c) table.insert(logoLine, c) end)
  166.     for ii = 1, #logoLine do
  167.         if f then
  168.             if string.match(logoLine[ii], "|") then
  169.                 f = false
  170.             else
  171.                 if string.match(logoLine[ii], ":") then
  172.                     gpu.setForeground(0xffffff)
  173.                 elseif getOS() == "OpenOS" then
  174.                     gpu.setForeground(0x30ff80)
  175.                 elseif getOS() == "Plan9k" then
  176.                     gpu.setForeground(0xff0000)
  177.                 end
  178.                 gpu.set(ii, i, logoLine[ii])
  179.             end
  180.         else
  181.             if logoLine[ii] == "%" then
  182.                 if getOS() == "OpenOS" then
  183.                     gpu.setForeground(0x228822)
  184.                 elseif getOS() == "Plan9k" then
  185.                     gpu.setForeground(0xff0000)
  186.                 end
  187.                 gpu.set(ii, i, logoLine[ii])
  188.             elseif logoLine[ii] == "/" then
  189.                 gpu.setForeground(0xfffafa)
  190.                 gpu.set(ii, i, logoLine[ii])
  191.             elseif logoLine[ii] == "#" then
  192.                 gpu.setForeground(0x585858)
  193.                 gpu.set(ii, i, logoLine[ii])
  194.             elseif logoLine[ii] == "(" then
  195.                 gpu.setForeground(0xc0c0c0)
  196.                 gpu.set(ii, i, logoLine[ii])
  197.             elseif string.match(logoLine[ii], "|") then
  198.                 f = true
  199.             else
  200.                 gpu.setForeground(0xffffff)
  201.                 gpu.set(ii, i, logoLine[ii])
  202.             end
  203.         end
  204.     end
  205. end
  206.  
  207. drawPalette()
Add Comment
Please, Sign In to add comment