1
0
term/js/terminal.js

151 lines
18 KiB
JavaScript
Raw Normal View History

2024-03-23 11:25:41 +00:00
$(function() {
var prompt = "[[b;#87cefa;]ai][[b;#FFFF00;]@aios] ~$ ";
let url = new URL(window.location.href);
let user = url.searchParams.get('user');
if (user) { prompt = "[[b;#87cefa;]" + user + "][[b;#FFFF00;]@aios] ~$ " };
var tab = "[[b;#87cefa;]<tab>]";
2024-04-04 05:28:44 +00:00
var command_all = ["ai","bsky"];
2024-03-23 11:25:41 +00:00
var handle = "yui.syui.ai";
var ascii_logo = '\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n
var ascii_ai = "\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
";
axios.get('https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=' + handle + '&collection=app.bsky.feed.post&limit=1')
.then(function (response) {
timeline = JSON.stringify(response.data.records[0].value,null,"\t");
})
axios.get('/json/ai.json')
.then(function (response) {
user_profile = JSON.stringify(response.data,null,"\t");
})
function print_slowly(term, paragraph, callback) {
var foo, i, lines;
lines = paragraph.split("\n");
term.pause();
i = 0;
foo = function(lines) {
return setTimeout((function() {
if (i < lines.length - 1) {
term.echo(lines[i]);
i++;
return foo(lines);
} else {
term.resume();
return callback();
}
}), 100);
};
return foo(lines);
}
function require_command(command_regex, terminal_history) {
var executed = true;
$.each(terminal_history, function(index, value) {
if (command_regex.test(value)) {
executed = true
}
});
return executed;
}
function interpreter(input, term) {
var command, inputs;
inputs = input.split(/ +/)
command = inputs[0];
if (inputs[0] === 'ai') {
print_slowly(term, ascii_logo);
term.echo(user_profile);
} else if (inputs[0] === 'bsky') {
print_slowly(term, timeline);
} else {
term.error(command + " is not a valid command");
term.echo(command_all);
}
}
function bash(inputs, term) {
var argument, echo, insert;
echo = term.echo;
insert = term.insert;
if (!inputs[1]) {
//return console.log("none");
} else {
argument = inputs[1];
if (/^\.\./.test(argument)) {
return echo("-bash: cd: " + argument + ": Permission denied");
} else {
return echo("-bash: cd: " + argument + ": No such file or directory");
}
}
}
$('#terminal').terminal(interpreter, {
prompt: prompt,
name: 'test',
greetings: "",
exit: false,
height: 450,
onInit: function(term) {
//term.insert("ai");
//print_slowly(term, ascii_ai);
},
completion: function(term, string, callback) {
var t = $(term[0]).text();
if (t.match(/none/)) {
term.clear();
} else {
callback(command_all);
term.history().clear();
}
},
tabcompletion: true
});
});