Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

  1. -- General collection of parsers for various linux utilities
  2. local parsers = {}
  3. parsers.upower = function(data)
  4. -- this shit was born in a fever dream, that's the only reasonable explanation i can give to this.
  5. local struct = {}
  6. local layer = 1
  7. local leaf = struct
  8. local history = {}
  9. data:gsub("\n?\r?([%s]*)([^\n]*)",function(block,line)
  10. if block == "" then block = " " end
  11. block = block:len()
  12. if line:match("%S") then
  13. if block > layer then
  14. history[layer] = leaf
  15. local pos = #leaf
  16. local key = leaf[pos]
  17. table.remove(leaf,pos)
  18. leaf[key] = {}
  19. leaf = leaf[key]
  20. layer = block
  21. end
  22. if block < layer then
  23. leaf = history[block]
  24. layer = block
  25. end
  26. table.insert(leaf,line)
  27. end
  28. end)
  29. local function prettify(t)
  30. for k,v in ipairs(t) do
  31. if v:find(":") then
  32. t[v:match("^(.-):")] = v:match("^.-:%s*(.*)")
  33. t[k] = nil
  34. end
  35. end
  36. for k,v in pairs(t) do
  37. if type(v) == "table" then
  38. t[k] = prettify(v)
  39. end
  40. end
  41. return t
  42. end
  43. return prettify(struct)
  44. end
  45. return parsers