在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:jcubic/jquery.terminal开源软件地址:https://github.com/jcubic/jquery.terminal开源编程语言:JavaScript 92.8%开源软件介绍:
JavaScript Library for Web Based Terminal Emulators SummaryjQuery Terminal Emulator is a plugin for creating command line interpreters in your applications. It can automatically call JSON-RPC service when a user types commands or you can provide your own function in which you can parse user commands. It's ideal if you want to provide additional functionality for power users. It can also be used to debug your application. You can use this JavaScript library to create a web based terminal on any website. Because with this library you need to code all the commands yourself, you can call it fake terminal emulator. In contrast to library that will give you access to real terminal like online SSH. To have real online SSH I suggest to use xterm.js library. Features:
DemoYou can test current version at this URL: or if it doesn't use latest version (because of jsDelivr cache) you can force it with this URL: And development version using: You can use any version you want, everything what jsDelivr GH API accepts. InstallationInclude jQuery library, you can use cdn from https://jquery.com/download/ <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> Then include js/jquery.terminal-2.33.3.min.js and css/jquery.terminal-2.33.3.min.css You can grab the files from CDN: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.33.3/js/jquery.terminal.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.33.3/css/jquery.terminal.min.css" rel="stylesheet"/> or <script src="https://cdn.jsdelivr.net/npm/[email protected]/js/jquery.terminal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/jquery.terminal.min.css"> If you always want latest version, you can get it from unpkg without specifying version, it will redirect to the latest ones: <script src="https://unpkg.com/jquery.terminal/js/jquery.terminal.min.js"></script>
<link href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet"/> Bleeding Edge VersionIf you want to test bleeding edge, development version of jQuery Terminal. You can use those files: <script src="https://cdn.jsdelivr.net/gh/jcubic/jquery.terminal@devel/js/jquery.terminal.min.js"></script>
<link href="https://cdn.jsdelivr.net/gh/jcubic/jquery.terminal@devel/css/jquery.terminal.min.css" rel="stylesheet"/> but it's not refreshed as fast as rawgit was, because it's CDN and need to be propagated to different servers. Keyboard key polyfillNOTE: From version 1.0.0 if you want to support old browsers then you'll need to use key event property polyfill. You can check the support for it on can I use. <script src="https://unpkg.com/[email protected]/keyboard.js"></script> Command LineYou can also install jQuery Terminal using command line, from bower repository:
or npm registry:
Example of usageThis is code that uses low level function, that gives you full control of the commands, just pass anything that the user types into a function. jQuery(function($, undefined) {
$('#term_demo').terminal(function(command) {
if (command !== '') {
var result = window.eval(command);
if (result != undefined) {
this.echo(String(result));
}
}
}, {
greetings: 'Javascript Interpreter',
name: 'js_demo',
height: 200,
width: 450,
prompt: 'js> '
});
}); Here is a higher level call, using an object as an interpreter, By default the terminal will parse commands that a user types and replace number like strings with real numbers regex with regexes and process escape characters in double quoted strings. jQuery(function($, undefined) {
$('#term_demo').terminal({
add: function(a, b) {
this.echo(a + b);
},
re: function(re, str) {
if (re instanceof RegExp && re.test(str)) {
this.echo(str + ' [[;green;]match]');
}
},
foo: 'foo.php',
bar: {
sub: function(a, b) {
this.echo(a - b);
}
}
}, {
height: 200,
width: 450,
prompt: 'demo> '
});
}); command Command command command By default arguments are required but you can disable the check like this: jQuery(function($, undefined) {
$('#term_demo').terminal({
add: function(...args) {
this.echo(args.reduce((a,b) => a + b));
}
}, {
checkArity: false
});
}); And add command will accept any number of argments and it will sum them up (if they are numbers). You can create JSON-RPC interpreter with authentication in just one line: $('#term_demo').terminal('service.php', {login: true}); The rest of the code can be on the server, so you can write fully working application, without any front-end, that can be tested in browser. First argument to terminal can also be array with objects strings and functions, with one requirement, that only one function can be used as last fallback for commands that was not found in RPC or in objects. jQuery(function($, undefined) {
$('#term_demo').terminal([{
add: function(...args) {
this.echo(args.reduce((a,b) => a + b));
}
} 'foo.php', function(command) {
this.echo("You've typed " + command, {formatters: false, exec: false});
}], {
checkArity: false
});
}); More examples here. You can also check Full Documentation or Getting Started Guide on Wiki. Quick Start TutorialsIf you want to start with jQuery Terminal you can look at those tutorials:
SecurityBecause of security in version 1.20.0 links with protocols different than ftp or http(s) (it was
possible to enter javascript protocol, that could lead to XSS if author of the app echo user input
and save it in DB) was turn off by default. To enable it, you need to use In version 1.21.0 executing terminal methods using extendend commands The features are safe to enable, if you don't save user input in DB and don't echo it back to different users (like with chat application). It's also safe if you escape formatting before you echo stuff. If you don't save user input in DB but allow to echo back what user types and have enabled
NOTE: To disable exec if you have ContributorsIf you want to contribute read CONTRIBUTING.md first. Here are project contributors: jQuery Terminal Website contributors:
AcknowledgeProjects include with the source code:
Other code used inside the project or inspired by:
Personal thanks:
Paid SupportYou can request paid support, you can find details at support.jcubic.pl. LicenseLicensed under MIT license Copyright (c) 2011-2021 Jakub T. Jankiewicz |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论