Skip to content

Instantly share code, notes, and snippets.

@EliterScripts
Created December 12, 2018 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EliterScripts/536d1ff3f64e2b1becdeb1bd02d8f6ab to your computer and use it in GitHub Desktop.
Save EliterScripts/536d1ff3f64e2b1becdeb1bd02d8f6ab to your computer and use it in GitHub Desktop.
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