Skip to content

Instantly share code, notes, and snippets.

@EliterScripts EliterScripts/Input Thread Secret
Created Dec 12, 2018

Embed
What would you like to do?
require('love.system')
do
local userOutChannel = love.thread.getChannel( "command-line-user-input" )
local globalKillChannel = love.thread.getChannel( "global-kill-thread" )
local printOutChannel = love.thread.getChannel( "printed-output" )
local running = true
local function printDebug(debugType, message)
--if(wait ~= false)then
-- printOutChannel:supply({type = debugType, message = message})
--else
printOutChannel:supply({message})
--end
end
local function sendCommand(commandInput)
userOutChannel:push({commandInput})
end
local function killMyself()
running = false
if(wholeScreen == true)then
printDebug("info", "disabliing Fancy CLI features...")
local exit = io.popen'tput rmcup \necho _$?':read'*a':match'.*%D(%d+)'+0
if(exit ~= 0)then
printDebug("warning", "Error while disabling Fancy CLI Features: 'tput rmcup' returned with non-zero exit status.")
else
wholeScreen = false
printDebug("info", "Fancy CLI features disabled.")
end
end
end
local function checkKillChannel()
local value = globalKillChannel:peek()
if(value == "command-line-user-input")then
globalKillChannel:pop()
killMyself()
elseif(value == "*")then
killMyself()
end
end
local wholeScreen = false
if(love.system.getOS() == "Linux")then
printDebug("info", "enabling Fancy CLI features...")
local exit = io.popen'tput smcup \necho _$?':read'*a':match'.*%D(%d+)'+0
if(exit ~= 0)then
printDebug("warning", "Error while enabling Fancy CLI Features: 'tput smcup' returned with non-zero exit status.")
else
wholeScreen = true
printDebug("info", "Fancy CLI features enabled.")
end
else
printDebug("warning", "not enabling Fancy CLI features, since it is only for Linux systems.")
end
while(running)do
checkKillChannel()
--local input = io.read()
local input = io.read()
checkKillChannel()
sendCommand(input)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.