Simple coal feeder tui
authorOlav Bakke Svendsen <mail@olavbs.no>
Tue, 10 Oct 2023 15:11:08 +0000 (17:11 +0200)
committerOlav Bakke Svendsen <mail@olavbs.no>
Tue, 10 Oct 2023 15:11:08 +0000 (17:11 +0200)
steam/simple-coal-feeder.lua [new file with mode: 0644]

diff --git a/steam/simple-coal-feeder.lua b/steam/simple-coal-feeder.lua
new file mode 100644 (file)
index 0000000..641c416
--- /dev/null
@@ -0,0 +1,79 @@
+-- simple-coal-feeder.lua
+-- take coal from inventory and keep deployers stocked
+--
+-- usage: simple-coal-feeder
+--
+-- configuration: simple-coal-feeder.config
+-- { coal_inventory = "inventory_address"    -- where to take coal from
+-- , interval = 60                           -- how often to refill
+-- , engines =                               -- table of named engines
+--     { ["engine_one"] =                    -- table of deployers
+--         { "deployer_address_1"           
+--         , "deployer_address_2"
+--          [...]
+--         }
+--     , ["engine_two"] =
+--         { "deployer_adress_19"
+--          [...]
+--         }
+--     }
+-- }
+
+local config_path = "simple-coal-feeder.config"
+local config = nil
+
+local print_help = function()
+  print("> start engine_name\n  starts engine_name")
+  print("> stop engine_name\n  stopts engine_name")
+  print("> status [engine_name]\n  prints status")
+  print("> exit\n  exits program")
+  print("> help, ?\n  prints help")
+end
+
+local start_engine = function(engine)
+end
+
+  
+local parse_command = function(str)
+  local cmd, a = string.match(str, "^%s*(%w+)%s*(.*)")
+  local arg = string.gsub(a, "%s*$", "")
+  return string.lower(cmd), (arg ~= '' and arg)
+end
+
+local main = function()
+  local running = true
+  local case =
+    { ["test"] = function(a)
+        print("testing, one two, one two!")
+        print(a)
+      end
+
+    , ["exit"] = function()
+        print("exiting...")
+        running = false
+      end
+
+    , ["help"] = function()
+        print_help()
+      end
+
+    , ["?"] = function()
+        print_help()
+      end
+    }
+
+  while running do
+    local cmd, arg = parse_command(read())
+    for c,f in pairs(case) do
+      if cmd == c then v(arg); break end
+    end
+end
+  
+if fs.exists(config_path) then
+  config = dofile("simple-coal-feeder.config")
+  main()
+else
+  print("No configuration!")
+end
+
+