Skip to content

Commit

Permalink
Update terminal.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaTheLEGEND authored Feb 4, 2024
1 parent e93029f commit f668b07
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion gs/terminal/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ascii_art() {
let commandHistory = [];
let commandIndex = 0;

let YOUR_FUNCTIONS = ["SearchGitHubProfile", "printInfoAboutDev", "help", "demo_menu", "exit", "hello", "cool", "ifconfig", "date", "whoami", "clear", "pwd", "ping","ascii_art"];
let YOUR_FUNCTIONS = ["SearchGitHubProfile", "printInfoAboutDev", "help", "demo_menu", "exit", "hello", "cool", "ifconfig", "date", "whoami", "clear", "pwd", "ping","ascii_art","curl"];

async function add_numbers() {
let number1 = await term3.input("First number to add");
Expand Down Expand Up @@ -212,6 +212,33 @@ async function demo_menu() {
}
}

async function curl() {
try {
// Ask the user for the URL
const url = await term3.input("Enter the URL to curl:");

if (!url) {
term3.output("URL not provided. Curl aborted.");
return;
}

// Add "https://" to the URL if it doesn't have it
const fullUrl = url.startsWith('http') ? url : `https://${url}`;

const response = await fetch(fullUrl);

if (!response.ok) {
throw new Error(`Failed to fetch data from ${fullUrl}. Status: ${response.status}`);
}

const content = await response.text();
term3.output(content);
} catch (error) {
term3.output(`Failed to execute curl - ${error.message}`);
}
}


//end of functions

document.querySelector('.termino-input').addEventListener('keydown', async (e) => {
Expand Down

0 comments on commit f668b07

Please sign in to comment.