Advertisement
JackMacWindows

screenfetch.lua

Sep 14th, 2019
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.58 KB | None | 0 0
  1. if os.pullEvent ~= nil then
  2.  
  3.     local ccart = [[------------------------
  4. |                      |
  5. | -------------------- |
  6. | | \                | |
  7. | | / __             | |
  8. | |                  | |
  9. | |                  | |
  10. | |                  | |
  11. | |                  | |
  12. | |                  | |
  13. | |                  | |
  14. | -------------------- |
  15. |                      |
  16. |                  [=] |
  17. |                      |
  18. ------------------------]]
  19.  
  20.     local ccart_fg = [[ffffffffffffffffffffffff
  21. f7777777777777777777777f
  22. f7ffffffffffffffffffff7f
  23. f7ff0fffffffffffffffff7f
  24. f7ff0f00ffffffffffffff7f
  25. f7ffffffffffffffffffff7f
  26. f7ffffffffffffffffffff7f
  27. f7ffffffffffffffffffff7f
  28. f8ffffffffffffffffffff8f
  29. f8ffffffffffffffffffff8f
  30. f8ffffffffffffffffffff8f
  31. f8ffffffffffffffffffff8f
  32. f8888888888888888888888f
  33. f888888888888888888fff8f
  34. f8888888888888888888888f
  35. ffffffffffffffffffffffff]]
  36.  
  37.     local ccart_bg = [[ffffffffffffffffffffffff
  38. f7777777777777777777777f
  39. f7ffffffffffffffffffff7f
  40. f7ffffffffffffffffffff7f
  41. f7ffffffffffffffffffff7f
  42. f7ffffffffffffffffffff7f
  43. f7ffffffffffffffffffff7f
  44. f7ffffffffffffffffffff7f
  45. f8ffffffffffffffffffff8f
  46. f8ffffffffffffffffffff8f
  47. f8ffffffffffffffffffff8f
  48. f8ffffffffffffffffffff8f
  49. f8888888888888888888888f
  50. f888888888888888888fff8f
  51. f8888888888888888888888f
  52. ffffffffffffffffffffffff]]
  53.  
  54.     local ccart_adv_fg = [[ffffffffffffffffffffffff
  55. f4444444444444444444444f
  56. f4ffffffffffffffffffff4f
  57. f4ff0fffffffffffffffff4f
  58. f4ff0f00ffffffffffffff4f
  59. f4ffffffffffffffffffff4f
  60. f4ffffffffffffffffffff4f
  61. f4ffffffffffffffffffff4f
  62. f4ffffffffffffffffffff4f
  63. f4ffffffffffffffffffff4f
  64. f4ffffffffffffffffffff4f
  65. f4ffffffffffffffffffff4f
  66. f4444444444444444444444f
  67. f444444444444444444ddd4f
  68. f4444444444444444444444f
  69. ffffffffffffffffffffffff]]
  70.  
  71.     local ccart_adv_bg = [[ffffffffffffffffffffffff
  72. f4444444444444444444444f
  73. f4ffffffffffffffffffff4f
  74. f4ffffffffffffffffffff4f
  75. f4ffffffffffffffffffff4f
  76. f4ffffffffffffffffffff4f
  77. f4ffffffffffffffffffff4f
  78. f4ffffffffffffffffffff4f
  79. f4ffffffffffffffffffff4f
  80. f4ffffffffffffffffffff4f
  81. f4ffffffffffffffffffff4f
  82. f4ffffffffffffffffffff4f
  83. f4444444444444444444444f
  84. f444444444444444444ddd4f
  85. f4444444444444444444444f
  86. ffffffffffffffffffffffff]]
  87.  
  88.     local function fg(l) if term.isColor() then return string.rep("4", l) else return string.rep("8", l) end end
  89.     local function text(title, str) return {title .. str, fg(string.len(title)) .. string.rep("0", string.len(str)), string.rep("f", string.len(title .. str))} end
  90.  
  91.     local function time(n)
  92.         local h = math.floor(n / 3600)
  93.         local m = math.floor(n / 60) % 60
  94.         local s = n % 60
  95.         local retval = s .. "s"
  96.         if m > 0 or h > 0 then retval = m .. "m " .. retval end
  97.         if h > 0 then retval = h .. "h " .. retval end
  98.         return retval
  99.     end
  100.  
  101.     local function ext(retval)
  102.         if http ~= nil then table.insert(retval, text("    ", "HTTP enabled"))
  103.         if http.websocket ~= nil then table.insert(retval, text("    ", "CC: Tweaked")) end end
  104.         if mounter ~= nil then table.insert(retval, text("    ", "CraftOS-PC")) end
  105.         if term.setGraphicsMode ~= nil then table.insert(retval, text("    ", "CraftOS-PC GFX")) end
  106.         if term.screenshot ~= nil then table.insert(retval, text("    ", "CraftOS-PC 2")) end
  107.         if ccemux ~= nil then table.insert(retval, text("    ", "CCEmuX")) end
  108.         if fs.exists(".mbs") or fs.exists("rom/.mbs") then table.insert(retval, text("    ", "MBS")) end
  109.         if type(kernel) == "table" then table.insert(retval, text("    ", "CCKernel2")) end
  110.         return retval
  111.     end
  112.  
  113.     local function getRuntime()
  114.         if os.about ~= nil then return string.sub(os.about(), 1, string.find(os.about(), "\n"))
  115.         elseif ccemux ~= nil then return ccemux.getVersion()
  116.         elseif _MC_VERSION ~= nil then return _MC_VERSION
  117.         else return "Unknown" end
  118.     end
  119.  
  120.     local sysinfo = {
  121.         text(os.getComputerLabel() or "Untitled Computer", ""),
  122.         text("Type: ", commands ~= nil and "Command Computer" or term.isColor() and "Advanced Computer" or "Standard Computer"),
  123.         text("OS: ", os.version()),
  124.         text("Runtime: ", getRuntime()),
  125.         text("Lua: ", _VERSION),
  126.         text("Host: ", _HOST),
  127.         text("Uptime: ", time(os.clock())),
  128.         text("Extensions: ", "")
  129.     }
  130.     ext(sysinfo)
  131.  
  132.     print("")
  133.     for i = 1, string.len(ccart), 25 do
  134.         term.blit(string.sub(ccart, i, i+23), string.sub(term.isColor() and ccart_adv_fg or ccart_fg, i, i+23), string.sub(term.isColor() and ccart_adv_bg or ccart_bg, i, i+23))
  135.         write("  ")
  136.         if sysinfo[((i-1)/25)+1] ~= nil then term.blit(table.unpack(sysinfo[((i-1)/25)+1])) end
  137.         print("")
  138.     end
  139.     print("")
  140.     if term.screenshot ~= nil then term.screenshot() end
  141.     sleep(0.25)
  142.  
  143. elseif require("filesystem") ~= nil then
  144.  
  145.     -- TODO: Find better art
  146.     local ccart = [[------------------------
  147. |                      |
  148. | -------------------- |
  149. | | \                | |
  150. | | / __             | |
  151. | |                  | |
  152. | |                  | |
  153. | |                  | |
  154. | |                  | |
  155. | |                  | |
  156. | |                  | |
  157. | -------------------- |
  158. |                      |
  159. |                  [=] |
  160. |                      |
  161. ------------------------]]
  162.  
  163.     local ccart_fg = [[ffffffffffffffffffffffff
  164. f0000000000000000000000f
  165. f0ffffffffffffffffffff0f
  166. f0ff0fffffffffffffffff0f
  167. f0ff0f00ffffffffffffff0f
  168. f0ffffffffffffffffffff0f
  169. f0ffffffffffffffffffff0f
  170. f0ffffffffffffffffffff0f
  171. f0ffffffffffffffffffff0f
  172. f0ffffffffffffffffffff0f
  173. f0ffffffffffffffffffff0f
  174. f0ffffffffffffffffffff0f
  175. f0000000000000000000000f
  176. f000000000000000000fff0f
  177. f0000000000000000000000f
  178. ffffffffffffffffffffffff]]
  179.  
  180.     local ccart_bg = [[ffffffffffffffffffffffff
  181. f0000000000000000000000f
  182. f0ffffffffffffffffffff0f
  183. f0ffffffffffffffffffff0f
  184. f0ffffffffffffffffffff0f
  185. f0ffffffffffffffffffff0f
  186. f0ffffffffffffffffffff0f
  187. f0ffffffffffffffffffff0f
  188. f0ffffffffffffffffffff0f
  189. f0ffffffffffffffffffff0f
  190. f0ffffffffffffffffffff0f
  191. f0ffffffffffffffffffff0f
  192. f0000000000000000000000f
  193. f000000000000000000fff0f
  194. f0000000000000000000000f
  195. ffffffffffffffffffffffff]]
  196.  
  197.     local ccart_adv_fg = [[ffffffffffffffffffffffff
  198. f4444444444444444444444f
  199. f4ffffffffffffffffffff4f
  200. f4ff0fffffffffffffffff4f
  201. f4ff0f00ffffffffffffff4f
  202. f4ffffffffffffffffffff4f
  203. f4ffffffffffffffffffff4f
  204. f4ffffffffffffffffffff4f
  205. f4ffffffffffffffffffff4f
  206. f4ffffffffffffffffffff4f
  207. f4ffffffffffffffffffff4f
  208. f4ffffffffffffffffffff4f
  209. f4444444444444444444444f
  210. f444444444444444444ddd4f
  211. f4444444444444444444444f
  212. ffffffffffffffffffffffff]]
  213.  
  214.     local ccart_adv_bg = [[ffffffffffffffffffffffff
  215. f4444444444444444444444f
  216. f4ffffffffffffffffffff4f
  217. f4ffffffffffffffffffff4f
  218. f4ffffffffffffffffffff4f
  219. f4ffffffffffffffffffff4f
  220. f4ffffffffffffffffffff4f
  221. f4ffffffffffffffffffff4f
  222. f4ffffffffffffffffffff4f
  223. f4ffffffffffffffffffff4f
  224. f4ffffffffffffffffffff4f
  225. f4ffffffffffffffffffff4f
  226. f4444444444444444444444f
  227. f444444444444444444ddd4f
  228. f4444444444444444444444f
  229. ffffffffffffffffffffffff]]
  230.  
  231.     local component = require("component")
  232.     local computer = require("computer")
  233.     local term = require("term")
  234.     local gpu = term.gpu()
  235.  
  236.     local function fg(l) if gpu.getDepth() > 1 then return string.rep("4", l) else return string.rep("0", l) end end
  237.     local function text(title, str) return {title .. str, fg(string.len(title)) .. string.rep("0", string.len(str)), string.rep("f", string.len(title .. str))} end
  238.  
  239.     local function time(n)
  240.         local h = math.floor(n / 3600)
  241.         local m = math.floor(n / 60) % 60
  242.         local s = n % 60
  243.         local retval = s .. "s"
  244.         if m > 0 or h > 0 then retval = m .. "m " .. retval end
  245.         if h > 0 then retval = h .. "h " .. retval end
  246.         return retval
  247.     end
  248.  
  249.     local function mem(bytes)
  250.         if bytes > 1048576 then return string.gsub(string.sub((math.floor((bytes / 1048576) * 1000) / 1000) .. "", 1, 4), "%.$", "") .. " MB"
  251.         elseif bytes > 1024 then return string.gsub(string.sub((math.floor((bytes / 1024) * 1000) / 1000) .. "", 1, 4), "%.$", "") .. " kB"
  252.         else return bytes .. " B" end
  253.     end
  254.  
  255.     local function ext(retval)
  256.         for address, type in component.list() do table.insert(retval, text("    " .. type .. " ", address)) end
  257.         return retval
  258.     end
  259.  
  260.     local tier = "Unknown"
  261.     for k,v in pairs(component.computer.getDeviceInfo()) do if v.class == "processor" then tier = string.match(v.product, "FlexiArch (%d+) Processor") end end
  262.  
  263.     local sysinfo = {
  264.         text("OpenComputers", ""),
  265.         text("Tier: ", tier),
  266.         text("OS: ", _OSVERSION),
  267.         text("Lua: ", _VERSION),
  268.         text("RAM: ", mem(computer.totalMemory() - computer.freeMemory()) .. " / " .. mem(computer.totalMemory())),
  269.         text("Uptime: ", time(computer.uptime())),
  270.         text("Components: ", "")
  271.     }
  272.     ext(sysinfo)
  273.  
  274.     local ccColors = {
  275.         ["0"] = 0xFFFFFF,
  276.         ["4"] = 0xFFFF00,
  277.         ["7"] = 0x404040,
  278.         ["8"] = 0x7F7F7F,
  279.         d = 0x00FF00,
  280.         f = 0x000000
  281.     }
  282.  
  283.     local function blit(text, fg, bg)
  284.         if text == "" then return end
  285.         if #text ~= #fg or #fg ~= #bg then error("Unbalanced string lengths in blit", 2) end
  286.         if #text > term.getViewport() - term.getCursor() then
  287.             text = string.sub(text, 1, term.getViewport() - term.getCursor(), nil)
  288.             fg = string.sub(fg, 1, term.getViewport() - term.getCursor(), nil)
  289.             bg = string.sub(bg, 1, term.getViewport() - term.getCursor(), nil)
  290.         end
  291.         for i = 1, #text do
  292.             if ccColors[string.sub(fg, i, i)] == nil then error("Unknown color " .. string.sub(fg, i, i)) end
  293.             if ccColors[string.sub(bg, i, i)] == nil then error("Unknown color " .. string.sub(bg, i, i)) end
  294.             gpu.setForeground(ccColors[string.sub(fg, i, i)])
  295.             gpu.setBackground(ccColors[string.sub(bg, i, i)])
  296.             term.write(string.sub(text, i, i))
  297.         end
  298.     end
  299.  
  300.     print("")
  301.     for i = 1, string.len(ccart), 25 do
  302.         blit(string.sub(ccart, i, i+23), string.sub(gpu.getDepth() > 1 and ccart_adv_fg or ccart_fg, i, i+23), string.sub(gpu.getDepth() > 1 and ccart_adv_bg or ccart_bg, i, i+23))
  303.         term.write("  ")
  304.         if sysinfo[((i-1)/25)+1] ~= nil then blit(table.unpack(sysinfo[((i-1)/25)+1])) end
  305.         print("")
  306.     end
  307.     if #sysinfo > 16 then for i = 16, #sysinfo do
  308.         term.write(string.rep(" ", 26))
  309.         blit(table.unpack(sysinfo[i]))
  310.         print("")
  311.     end end
  312.     print("")
  313.     os.sleep(0.25)
  314.  
  315. else print("Unknown computer type") end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement