119 lines
3.2 KiB
Plaintext
119 lines
3.2 KiB
Plaintext
#!/usr/bin/env luash
|
|
-- Interactive Luash Demo/REPL Alternative
|
|
-- Shows how to build interactive features within luash
|
|
|
|
print("🚀 Luash Interactive Demo")
|
|
print("This demonstrates interactive capabilities in luash")
|
|
print()
|
|
|
|
-- Simple command processor
|
|
function process_command(cmd)
|
|
cmd = cmd:match("^%s*(.-)%s*$") -- trim
|
|
|
|
if cmd == "help" then
|
|
print([[
|
|
Available commands:
|
|
sysinfo - Show system information
|
|
files - List files in current directory
|
|
env - Show environment variables
|
|
network - Test network connectivity
|
|
processes - Show running processes
|
|
disk - Show disk usage
|
|
quit - Exit
|
|
|
|
Or type any luash expression!]])
|
|
|
|
elseif cmd == "sysinfo" then
|
|
print("System Information:")
|
|
print(" OS: " .. `uname -s`)
|
|
print(" Architecture: " .. `uname -m`)
|
|
print(" Hostname: " .. `hostname`)
|
|
print(" User: " .. $USER)
|
|
print(" Uptime: " .. `uptime`)
|
|
|
|
elseif cmd == "files" then
|
|
print("Files in current directory:")
|
|
files = `ls -la`
|
|
print(files)
|
|
|
|
elseif cmd == "env" then
|
|
print("Key environment variables:")
|
|
print(" USER: " .. $USER)
|
|
print(" HOME: " .. $HOME)
|
|
print(" SHELL: " .. $SHELL)
|
|
print(" PATH: " .. `echo $PATH | cut -d: -f1-3`)
|
|
|
|
elseif cmd == "network" then
|
|
print("Network connectivity test:")
|
|
hosts = {"google.com", "github.com"}
|
|
for i = 1, #hosts do
|
|
local host = hosts[i]
|
|
local result = `ping -c 1 #{host} >/dev/null 2>&1 && echo "ok" || echo "fail"`
|
|
local status = result == "ok" and "✓" or "✗"
|
|
print(" " .. status .. " " .. host)
|
|
end
|
|
|
|
elseif cmd == "processes" then
|
|
print("Top processes:")
|
|
!ps aux | head -10
|
|
|
|
elseif cmd == "disk" then
|
|
print("Disk usage:")
|
|
!df -h
|
|
|
|
elseif cmd == "quit" or cmd == "exit" then
|
|
return false
|
|
|
|
else
|
|
-- Try to execute as luash code
|
|
if cmd ~= "" then
|
|
print("Executing: " .. cmd)
|
|
-- In a real REPL, we'd eval this
|
|
-- For demo, just show some dynamic examples
|
|
if cmd:match("^%$") then
|
|
print("Environment variable assignment")
|
|
elseif cmd:match("`.*`") then
|
|
print("Shell command execution")
|
|
else
|
|
print("Lua expression")
|
|
end
|
|
end
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
-- Main interaction loop
|
|
print("Type 'help' for commands, 'quit' to exit")
|
|
print()
|
|
|
|
-- Simulate some interactive commands
|
|
commands = {
|
|
"help",
|
|
"sysinfo",
|
|
"files",
|
|
"network",
|
|
"quit"
|
|
}
|
|
|
|
for i = 1, #commands do
|
|
local cmd = commands[i]
|
|
print("luash> " .. cmd)
|
|
|
|
if not process_command(cmd) then
|
|
break
|
|
end
|
|
|
|
if i < #commands then
|
|
print("\nPress Enter to continue...")
|
|
io.read() -- Wait for user input
|
|
end
|
|
end
|
|
|
|
print("\n✨ This shows how luash can build interactive applications!")
|
|
print("For a full REPL, we'd:")
|
|
print(" - Read input in a loop")
|
|
print(" - Parse and execute luash expressions")
|
|
print(" - Handle multiline input")
|
|
print(" - Maintain command history")
|