v1.14.0 - Added the download command (Halyde equivalent of wget) and clipboard pasting support.

This commit is contained in:
TheWahlolly
2025-07-02 12:34:14 +03:00
parent 97f411180d
commit fb4c80f3a0
6 changed files with 241 additions and 164 deletions
+57
View File
@@ -0,0 +1,57 @@
local url = ...
local component = import("component")
local fs = import("filesystem")
if not component.list("internet")() then
print("\27[91mThis program requires an internet card to run.")
return
end
if not url then
print("Please enter a URL to download from.")
shell.run("help download")
return
end
if url:sub(-1, -1) == "/" then
url = url:sub(1, -2)
end
local internet = component.internet
local request, data, tmpdata = nil, "", nil
local status, errorMessage = pcall(function()
request = internet.request(url)
request:finishConnect()
end)
if not status then
print("\27[91mDownload failed: " .. errorMessage)
end
local responseCode = request:response()
if responseCode and responseCode ~= 200 then
print("\27[91mDownload failed: " .. tostring(responseCode))
end
repeat
tmpdata = request.read(math.huge)
data = data .. (tmpdata or "")
until not tmpdata
local saveLocation
local saveLocationOK = false
repeat
saveLocation = read(nil, "File save location: ", fs.concat(shell.workingDirectory, url:match("/([^/]+)$")))
if fs.isDirectory(saveLocation) then
print("\27[91mThe specified location is a directory.")
elseif fs.exists(saveLocation) then
local answer = read(nil, "\27[91mThere is already a file at the specified directory. Overwrite it? [Y/n]")
if answer:lower() ~= "n" then
saveLocationOK = true
end
else
saveLocationOK = true
end
until saveLocationOK
local handle = fs.open(saveLocation, "w")
handle:write(data)
handle:close()
print("File downloaded successfully.")
+1
View File
@@ -4,6 +4,7 @@ All default Halyde shell commands:
cd Changes directory.
clear Clears the screen.
cp Copies a file.
download Downloads a file from the internet.
echo Prints a message.
edit Opens the text editor.
fetch Displays system information.
+7
View File
@@ -0,0 +1,7 @@
Usage: download [URL]
Downloads a file from the internet.
URL Specifies the URL from which to download the file from.
Examples:
download https://github.com/ Downloads github.com.