1
0
term/js/terminal.js

161 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] ~$ ";
var u = window.location.pathname.split('/').slice(-1)[0];
if (u) {
prompt = "[[b;#87cefa;]" + u + "][[b;#FFFF00;]@aios] ~$ ";
};
var tab = "[[b;#87cefa;]<tab>]";
var command_all = ["ai","bsky", "w"];
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<EFBFBD>
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://card.syui.ai/json/card.json')
.then(function (response) {
all_card = JSON.stringify(response.data,null,"\t");
})
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/u.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);
} else if (inputs[0] === 'w') {
term.echo(user_profile);
} else if (inputs[0] === 'bsky') {
print_slowly(term, timeline);
} else if (inputs[0] === 'card') {
term.echo(all_card);
} 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
});
});