Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to set custom html #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore built files except build/index.js
dist
dist-dev
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Options:
--command command to run in terminal (shell by default)
--auto-restart restart command when on exit
--no-auto-restart do not restart command on exit
--html-path set path to html used to show terminal
```

### Windows
Expand All @@ -37,6 +38,55 @@ npm i gritty -g

Start `gritty`, and go to url `http://localhost:1337`

## Customize the container of output

![Gritty](https://raw.githubusercontent.com/cloudcmd/gritty/master/img/custom-html.png "Gritty with a html customized")

Use the argument `html-path` to set the html path that will show the terminal:
```bash
gritty --html-path="/project/folder"
```
Could be used a html like that:
```html
<!DOCTYPE html>
<html>
<head>
<title>My custom title</title>
<style>
html {
height: 100%;
}
body {
height: 100%;
padding: 0;
margin: 20px 40px 40px 40px;
background-color: #ccc;
overflow: hidden;
}
.gritty {
height: calc(100% - 80px);
border-radius: 20px;
background-color: #000;
overflow: hidden;
}
.terminal {
padding: 20px;
height: 100%;
}
</style>
</head>
<body>
<span>My custom html!</span><br /><br />
<div class="gritty"></div>
<script src="/gritty/gritty.js"></script>
<script>
gritty(".gritty");
</script>
</body>
</html>
```


## API

### Client API
Expand Down
7 changes: 5 additions & 2 deletions bin/gritty.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const args = require('yargs-parser')(process.argv.slice(2), {
],
string: [
'command',
'html-path',
],
alias: {
help: 'h',
Expand Down Expand Up @@ -42,6 +43,7 @@ function main() {
start({
port: args.port,
command: args.command,
htmlPath: args.htmlPath,
autoRestart: args.autoRestart,
});
}
Expand All @@ -58,12 +60,13 @@ function start(options) {
port,
command,
autoRestart,
htmlPath,
} = options;

check(port);

const DIR = __dirname + '/../';

const DIR = htmlPath || __dirname + '/../';
console.log(DIR);
const gritty = require('../');
const http = require('http');

Expand Down
3 changes: 2 additions & 1 deletion help.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"--port ": "set port number",
"--command ": "command to run (shell by default)",
"--auto-restart ": "restart command on exit",
"--no-auto-restart ": "do not restart command on exit"
"--no-auto-restart ": "do not restart command on exit",
"--html-path ": "set path to html used to show terminal"
}
Binary file added img/custom-html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions server/gritty.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const pty = require('node-pty');
const stringArgv = require('string-to-argv');

const terminalFn = currify(_terminalFn);
const staticFn = currify(_staticFn);
const connectionWraped = wraptile(connection);

const CMD = process.platform === 'win32' ? 'cmd.exe' : 'bash';
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = (options = {}) => {

router.route(prefix + '/*')
.get(terminalFn(options))
.get(staticFn);
.get(staticFn(options));

return router;
};
Expand All @@ -60,7 +61,7 @@ function _terminalFn(options, req, res, next) {
next();
}

function staticFn(req, res) {
function _staticFn(options, req, res) {
const file = path.normalize(DIR_ROOT + req.url);
res.sendFile(file);
}
Expand Down