Git Product home page Git Product logo

gritty's Introduction

Gritty License NPM version Dependency Status Build Status Coverage Status

Web terminal emulator. Based on node-pty and xterm.js.

Gritty

Install

npm i gritty -g

Usage

Usage: gritty [options]
Options:
  -h, --help              display this help and exit
  -v, --version           output version information and exit
  --path                  output path of a gritty and exit
  --port                  set port number
  --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

Windows

On Windows there is no build tools by default. When can't install gritty try to install windows-build-tools first.

npm i windows-build-tools -g
npm i gritty -g

Gritty

Use as standalone

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

API

Client API

gritty(element [, options])

const prefix = '/gritty'; // default
const env = {}; // default
const fontFamily = 'Courier'; // default

gritty('body', {
    prefix,
    env,
    fontFamily,
});

Server API

gritty.listen(socket, [, options])

Gritty could be used as middleware:

const prefix = '/gritty'; // default

const auth = (accept, reject) => (username, password) => {
    accept();
};

gritty.listen(socket, {
    prefix,
    auth, // optional
})

gritty(options)

Middleware function:

const prefix = '/gritty'; // default

gritty({
    prefix,
});

Usage as middleware

To use gritty in your programs you should make local install:

npm i gritty socket.io express --save

And use it this way:

// server.js

const gritty = require('gritty');
const http = require('http');
const express = require('express');
const io = require('socket.io');

const app = express();
const server = http.createServer(app);
const socket = io.listen(server);

const port = 1337;
const ip = '0.0.0.0';

app.use(gritty())
app.use(express.static(__dirname));

gritty.listen(socket, {
    command: 'mc',      // optional
    autoRestart: true,  // default
});

server.listen(port, ip);

If you want dinamically change env variables, you can use socket.request for this purpose:

socket.use((socket, next) => {
    socket.request.env = {
        HELLO: 'world'
    };
    
    next();
});
<!-- index.html -->

<div class="gritty"></div>
<script src="/gritty/gritty.js"></script>
<script>
    const options = {
        prefix: 'console',
        command: 'bash', // optional
        autoRestart: true, // optional
        cwd: '/', // optional
        env: {
            TERMINAL: 'gritty',
            CURRENT: getCurrentFile,
        }
    };
    
    gritty('.terminal', options);
    
    function getCurrentFile() {
        return 'filename.txt';
    }
</script>

License

MIT

gritty's People

Contributors

coderaiser avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.