2024-05-31 23:37:49 +00:00
|
|
|
local config = require "config"
|
2024-06-01 14:20:00 +00:00
|
|
|
local tabview = require "tabview"
|
2024-06-01 16:08:57 +00:00
|
|
|
local winhlp = require "winhlp"
|
|
|
|
|
2024-06-01 14:20:00 +00:00
|
|
|
local header_lines = 2
|
2024-05-31 23:12:12 +00:00
|
|
|
|
|
|
|
-- display working state
|
|
|
|
local currently_working = true
|
|
|
|
-- schedule immediate reload
|
|
|
|
local immediate_reload = false
|
2024-06-01 14:20:00 +00:00
|
|
|
-- window for tabview
|
|
|
|
local tabview_window = nil
|
2024-05-31 23:12:12 +00:00
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function display()
|
2024-05-31 23:12:12 +00:00
|
|
|
local tw,th = term.getSize()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setBackgroundColor(colors.yellow)
|
|
|
|
term.setTextColor(colors.black)
|
2024-06-02 15:40:22 +00:00
|
|
|
local activeTab = tabview.currentTab()
|
|
|
|
if activeTab ~= nil then
|
|
|
|
term.clearLine()
|
2024-05-31 23:12:12 +00:00
|
|
|
|
2024-06-02 15:40:22 +00:00
|
|
|
term.write(" " .. string.upper(activeTab.name) .. " ")
|
|
|
|
term.setCursorPos(tw-8,1)
|
|
|
|
if currently_working then
|
|
|
|
term.write(" w ")
|
|
|
|
else
|
|
|
|
term.write(" R ")
|
|
|
|
end
|
|
|
|
term.write(" ^ v ")
|
2024-06-02 00:35:00 +00:00
|
|
|
|
2024-06-02 15:40:22 +00:00
|
|
|
term.setBackgroundColor(colors.black)
|
|
|
|
term.setTextColor(colors.gray)
|
|
|
|
term.setCursorPos(1,2)
|
|
|
|
if tabview_window ~= nil then
|
|
|
|
local tabviewW, tabviewH = tabview_window.getSize()
|
|
|
|
local estimatedHeight = "?"
|
|
|
|
if activeTab.estimatedHeight ~= nil then
|
|
|
|
estimatedHeight = activeTab.estimatedHeight()
|
|
|
|
end
|
2024-06-02 15:51:21 +00:00
|
|
|
local paginationInfo = activeTab.scrollPos .. "-" .. (activeTab.scrollPos+tabviewH-1) .. "/" .. estimatedHeight
|
2024-06-02 15:40:22 +00:00
|
|
|
local padding = winhlp.alignRightPadding(term, #paginationInfo)
|
|
|
|
term.write(string.format("%" .. padding-1 .. "s", " "))
|
|
|
|
term.write(paginationInfo)
|
|
|
|
term.write(" ")
|
|
|
|
else
|
|
|
|
term.clearLine()
|
|
|
|
end
|
|
|
|
term.setTextColor(colors.white)
|
2024-05-31 23:12:12 +00:00
|
|
|
|
2024-06-02 15:40:22 +00:00
|
|
|
for name, tab in pairs(tabview.allTabs()) do
|
|
|
|
tab.displayTab(tab)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
term.setBackgroundColor(colors.black)
|
|
|
|
term.clear()
|
|
|
|
term.setBackgroundColor(colors.yellow)
|
|
|
|
term.clearLine()
|
|
|
|
term.write(" NO ACTIVE TAB ")
|
2024-05-31 23:12:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function on_touch(touch_x, touch_y)
|
2024-05-31 23:12:12 +00:00
|
|
|
local tw,th = term.getSize()
|
|
|
|
if touch_y == 1 then
|
2024-06-01 14:20:00 +00:00
|
|
|
if touch_x > tw-3 and touch_x <= tw then
|
|
|
|
tabview.currentTab().pageDown()
|
|
|
|
return true
|
|
|
|
elseif touch_x > tw-6 and touch_x < tw-2 then
|
|
|
|
tabview.currentTab().pageUp()
|
2024-05-31 23:12:12 +00:00
|
|
|
return true
|
|
|
|
elseif currently_working == false and touch_x > tw-9 and touch_x < tw-5 then
|
2024-06-01 02:39:41 +00:00
|
|
|
-- reload button
|
2024-05-31 23:12:12 +00:00
|
|
|
immediate_reload = true
|
|
|
|
return true
|
2024-06-01 14:20:00 +00:00
|
|
|
elseif touch_x < (#tabview.currentTab().name + 2) then
|
|
|
|
tabview.switchTab()
|
2024-05-31 23:12:12 +00:00
|
|
|
return true
|
|
|
|
end
|
2024-06-01 16:08:57 +00:00
|
|
|
elseif tabview_window ~= nil and
|
|
|
|
winhlp.contains(tabview_window, touch_x, touch_y) and
|
|
|
|
tabview.onTouch(winhlp.translate(tabview_window, touch_x, touch_y)) then
|
|
|
|
return true
|
2024-05-31 23:12:12 +00:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 14:20:00 +00:00
|
|
|
local function update_windows()
|
|
|
|
if tabview_window then
|
|
|
|
local tw, th = term.getSize()
|
|
|
|
tabview_window.reposition(1, 1+header_lines, tw, th-header_lines)
|
|
|
|
tabview.updateSize()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
local function wait_for(time_secs)
|
2024-05-31 23:12:12 +00:00
|
|
|
display()
|
|
|
|
local timer_id = os.startTimer(time_secs)
|
|
|
|
while true do
|
|
|
|
local event_data = {os.pullEvent()}
|
|
|
|
if event_data[1] == "monitor_touch" or (event_data[1] == "mouse_click" and event_data[2] == 1) then
|
|
|
|
if on_touch(event_data[3], event_data[4]) then
|
|
|
|
display()
|
|
|
|
end
|
|
|
|
if immediate_reload == true then
|
2024-06-01 02:39:41 +00:00
|
|
|
os.cancelTimer(timer_id)
|
2024-05-31 23:12:12 +00:00
|
|
|
immediate_reload = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
elseif event_data[1] == "timer" then
|
|
|
|
if event_data[2] == timer_id then
|
|
|
|
break
|
|
|
|
end
|
2024-06-01 14:20:00 +00:00
|
|
|
elseif event_data[1] == "term_resize" then
|
|
|
|
update_windows()
|
|
|
|
display()
|
2024-05-31 23:12:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 14:20:00 +00:00
|
|
|
local function init()
|
|
|
|
if peripheral.isPresent(config.monitor_side) then
|
|
|
|
local monitor = peripheral.wrap(config.monitor_side)
|
|
|
|
monitor.setTextScale(config.monitor_scale)
|
|
|
|
term.redirect(monitor)
|
|
|
|
end
|
|
|
|
|
2024-06-02 00:35:00 +00:00
|
|
|
term.setCursorBlink(false)
|
|
|
|
term.setBackgroundColor(colors.black)
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,2)
|
|
|
|
term.write("Booting test.lua")
|
|
|
|
|
2024-06-01 14:20:00 +00:00
|
|
|
local tw, th = term.getSize()
|
|
|
|
tabview_window = window.create(term.current(), 1, 1+header_lines, tw, th-header_lines)
|
|
|
|
tabview.setTerm(tabview_window)
|
|
|
|
|
|
|
|
-- to display requests and answer with an ME interface
|
|
|
|
tabview.addTab(require "requests", 1)
|
|
|
|
-- to display colony work orders
|
|
|
|
tabview.addTab(require "orders", 2)
|
|
|
|
|
2024-06-02 20:46:50 +00:00
|
|
|
tabview.addTab(require "inspect", 3)
|
|
|
|
|
2024-06-01 14:20:00 +00:00
|
|
|
tabview.showTab(config.initial_tab)
|
2024-05-31 23:12:12 +00:00
|
|
|
end
|
|
|
|
|
2024-06-01 14:20:00 +00:00
|
|
|
|
|
|
|
local function main()
|
|
|
|
init()
|
|
|
|
while true do
|
|
|
|
currently_working = true
|
|
|
|
for name, tab in pairs(tabview.allTabs()) do
|
|
|
|
tab.fetch(wait_for)
|
|
|
|
end
|
|
|
|
currently_working = false
|
|
|
|
wait_for(config.round_sleep_time)
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
2024-05-31 23:12:12 +00:00
|
|
|
end
|
2024-06-01 14:20:00 +00:00
|
|
|
|
|
|
|
main()
|