better touch exit
This commit is contained in:
parent
a2d96928b7
commit
63bf3b01a4
|
@ -125,6 +125,9 @@ function get_messages(buffer)
|
|||
-- request data and measure elapsed time
|
||||
local timer_id = os.startTimer(options.timeout)
|
||||
system.modem.transmit(channel, channel, 'print')
|
||||
|
||||
-- keep track of exit condition
|
||||
local touchExit = false
|
||||
while true do
|
||||
-- get next pull event
|
||||
local event, _, senderChannel, _, message, _ = os.pullEvent()
|
||||
|
@ -140,13 +143,21 @@ function get_messages(buffer)
|
|||
system.timeout = true
|
||||
return
|
||||
elseif event == 'monitor_touch' then
|
||||
system.index = system.index % #system.components + 1
|
||||
break
|
||||
touchExit = true
|
||||
end
|
||||
end
|
||||
|
||||
-- cancel timer on success
|
||||
os.cancelTimer(timer_id)
|
||||
|
||||
-- increment index and clear terminal on exit by touch
|
||||
if touchExit then
|
||||
term.clear()
|
||||
system.index = system.index % #system.components + 1
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- main program
|
||||
|
@ -161,8 +172,7 @@ function main()
|
|||
term.setCursorPos(1, 1)
|
||||
|
||||
local buffer = {}
|
||||
get_messages(buffer)
|
||||
display_messages(buffer)
|
||||
if get_messages(buffer) then display_messages(buffer) end
|
||||
end
|
||||
|
||||
-- reset terminal
|
||||
|
|
Loading…
Reference in New Issue
Block a user