{"id":13589852,"url":"https://github.com/sasadjolic/dom-terminal","last_synced_at":"2025-04-08T03:18:22.650Z","repository":{"id":49969931,"uuid":"3736914","full_name":"sasadjolic/dom-terminal","owner":"sasadjolic","description":"Command-line terminal that runs in a web browser","archived":false,"fork":false,"pushed_at":"2021-06-07T13:15:22.000Z","size":4892,"stargazers_count":197,"open_issues_count":15,"forks_count":59,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-25T08:42:35.269Z","etag":null,"topics":["javascript","terminal"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sasadjolic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-16T07:51:02.000Z","updated_at":"2024-03-07T21:02:12.000Z","dependencies_parsed_at":"2022-08-26T13:41:14.370Z","dependency_job_id":null,"html_url":"https://github.com/sasadjolic/dom-terminal","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasadjolic%2Fdom-terminal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasadjolic%2Fdom-terminal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasadjolic%2Fdom-terminal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasadjolic%2Fdom-terminal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sasadjolic","download_url":"https://codeload.github.com/sasadjolic/dom-terminal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767238,"owners_count":20992548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","terminal"],"created_at":"2024-08-01T16:00:35.361Z","updated_at":"2025-04-08T03:18:22.631Z","avatar_url":"https://github.com/sasadjolic.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"[![Build Status](https://secure.travis-ci.org/sasadjolic/dom-terminal.png)](http://travis-ci.org/sasadjolic/dom-terminal)\n\n# Terminal\n\nSimple command-line terminal for your browser app.\n\nWeb apps are great. But sometimes instead of all the double-clicks,\nmouse pointers, taps and swipes across the screen - you just want\ngood old keyboard input. This terminal runs in a browser, desktop or mobile. It provides a simple\nand easy way to extend the terminal with your own commands.\n\nEnjoy.\n\n## How to use\n\nInclude `terminal.js` and `terminal.css` in your HTML:\n\n```html\n\u003cscript src=\"terminal.min.js\"\u003e\u003c/script\u003e\n\u003clink rel=\"stylesheet\" media=\"all\" href=\"terminal.min.css\"\u003e\n```\n\nDefine an HTML div tag where the terminal will be contained:\n\n```html\n\u003cdiv id=\"terminal\"\u003e\u003c/div\u003e\n```\n\nCreate a new terminal instance and convert the DOM element\ninto a live terminal.\n\n```js\nvar terminal = new Terminal('terminal', {}, {});\n```\n\nThis won't be terribly useful because by default the terminal\ndoesn't define any commands. It's meant to be extended. Let's\ndefine some:\n\n```js\nvar terminal = new Terminal('terminal', {}, {\n  execute: function(cmd, args) {\n    switch (cmd) {\n      case 'clear':\n        terminal.clear();\n        return '';\n\n      case 'help':\n        return 'Commands: clear, help, theme, ver or version\u003cbr\u003eMore help available \u003ca class=\"external\" href=\"http://github.com/sasadjolic/dom-terminal\" target=\"_blank\"\u003ehere\u003c/a\u003e';\n\n      case 'theme':\n        if (args \u0026\u0026 args[0]) {\n          if (args.length \u003e 1) return 'Too many arguments';\n          else if (args[0].match(/^interlaced|modern|white$/)) { terminal.setTheme(args[0]); return ''; }\n          else return 'Invalid theme';\n        }\n        return terminal.getTheme();\n\n      case 'ver':\n      case 'version':\n        return '1.0.2';\n\n      default:\n        // Unknown command.\n        return false;\n    };\n  }\n});\n```\n\nThis gives us 4 commands: `clear`, `help`, `theme`, and `ver` or `version`.\n[Go ahead and try it out using our live example.](http://sasadjolic.github.com/dom-terminal/example.html)\n\n## Features\n\n### Welcome message\n\nThe default welcome message is empty but you can set it to be anything.\n\n```js\nvar terminal = new Terminal('terminal', {welcome: 'Welcome to awesome terminal!'}, {});\n```\n\n### Command-line history\n\nHistory is automatically kept track of. You can use up and down arrow keys to\ngo through the command-line history, just like a standard shell.\n\n### Prompt and separator\n\nYou can change the prompt. The default is an empty prompt with a `\u003e` separator.\nSet the prompt option to change.\n\n```js\nvar terminal = new Terminal('terminal', {prompt: 'C:\\\\', separator: '\u0026gt;'}, {});\n```\n\nThis will display the prompt like this: `C:\\\u003e`\n\n### Theme\n\nThere are 3 built-in themes:\n\n* `interlaced`\n* `modern`\n* `white`\n\n`modern` theme is the default\n\n`modern` is a clean modern theme that's white on black, while the `white` theme is\nblack on white.\n\nIf you're nostalgic about the old-school CRT monitors then the `interlaced` theme is for you.\n\nSet the theme in options:\n\n```js\nvar terminal = new Terminal('terminal', {theme: 'interlaced'}, {});\n```\n\nOr alternatively use the API to change the theme after creating the terminal object.\n\n### Command extensions\n\nThe default terminal doesn't provide any built-in commands. You must define your\nown set of commands. This can be done through options when creating the object.\n\n```js\nvar terminal = new Terminal('terminal', {}, {\n  execute: function(cmd, args) {\n    switch (cmd) {\n      case 'hello':\n        return 'world';\n\n      // Place your other commands here.\n\n      default:\n        // Unknown command.\n        return false;\n    };\n  }\n});\n```\n\nWhen executing commands you can run whatever code you want. Just return a string\nthat you want to be displayed in the terminal as the output of your command. The\nexample above would produce:\n\n```\n\u003e hello\nworld\n\u003e \n```\n\nReturn `false` to indicate that this is an unknown command.\n\nYou can have more than one command set and you can list them out one after another:\n\n```js\nvar terminal = new Terminal('terminal', {}, {\n  execute: function(cmd, args) {\n    switch (cmd) {\n      case 'hello': return 'world';\n      default: return false;\n    };\n  }\n},{\n  execute: function(cmd, args) {\n    switch (cmd) {\n      case 'echo': return args[0];\n      default: return false;\n    };\n  }\n});\n```\n\nYou might want to use multiple command sets, for example, if your app has modules\nthat hook into the terminal independently.\n\n### Local storage persistence\n\nCommand-line history is persisted using HTML5 local storage.\n\n## API\n\n### Clear the screen\n\n```js\nterminal.clear();\n```\n\n### Change the theme\n\n```js\nterminal.setTheme('interlaced');\n```\n\nSets CSS class `terminal-interlaced` on the terminal DOM element. The three built-in\nthemes are `interlaced`, `modern`, and `white`. You can also make your own theme and\npass in your theme's name into `setTheme`.\n\nTo retrieve the name of the active theme, use `getTheme`.\n\n```js\nconsole.log(terminal.getTheme());\n```\n\n### Set the prompt\n\n```js\nterminal.setPrompt('test');\n```\n\nBecause the default separator is `\u003e` this will display:\n\n```\ntest\u003e\n```\n\nYou can set the separator in options while creating the Terminal object. At this\ntime it's not possible to change the separator after the terminal is created.\n\nPrompt can be changed at any time.\n\n## Thank-yous\n\nI was inspired by the HTML5 Terminal demo for Chrome created by Eric Bidelman.\nThanks! You can find his demo and source code here:\nhttp://www.htmlfivewow.com/demos/terminal/terminal.html\nhttp://code.google.com/p/html5wow/source/browse/#hg%2Fsrc%2Fdemos%2Fterminal\n\nMy version of the terminal component is completely rewritten and has no code\nin common with the source, but it does borrow ideas from Eric's demo. It also\nworks for other browsers, whereas Eric's version is optimized for Chrome.\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012-2017 Sasa Djolic\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasadjolic%2Fdom-terminal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsasadjolic%2Fdom-terminal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasadjolic%2Fdom-terminal/lists"}