GithubHelp home page GithubHelp logo

term.js's Introduction

term.js

A full xterm clone written in javascript. Used by tty.js.

⚠️ This project is no longer maintained ⚠️. For a maintained fork take a look at sourcelair/xterm.js.

Example

Server:

var term = require('term.js');
app.use(term.middleware());
...

Client:

window.addEventListener('load', function() {
  var socket = io.connect();
  socket.on('connect', function() {
    var term = new Terminal({
      cols: 80,
      rows: 24,
      screenKeys: true
    });

    term.on('data', function(data) {
      socket.emit('data', data);
    });

    term.on('title', function(title) {
      document.title = title;
    });

    term.open(document.body);

    term.write('\x1b[31mWelcome to term.js!\x1b[m\r\n');

    socket.on('data', function(data) {
      term.write(data);
    });

    socket.on('disconnect', function() {
      term.destroy();
    });
  });
}, false);

Tmux-like

While term.js has always supported copy/paste using the mouse, it now also supports several keyboard based solutions for copy/paste.

term.js includes a tmux-like selection mode (enabled with the screenKeys option) which makes copy and paste very simple. Ctrl-A enters prefix mode, from here you can type Ctrl-V to paste. Press [ in prefix mode to enter selection mode. To select text press v (or space) to enter visual mode, use hjkl to navigate and create a selection, and press Ctrl-C to copy.

Ctrl-C (in visual mode) and Ctrl-V (in prefix mode) should work in any OS for copy and paste. y (in visual mode) will work for copying only on X11 systems. It will copy to the primary selection.

Note: Ctrl-C will also work in prefix mode for the regular OS/browser selection. If you want to select text with your mouse and copy it to the clipboard, simply select the text and type Ctrl-A + Ctrl-C, and Ctrl-A + Ctrl-V to paste it.

For mac users: consider Ctrl to be Command/Apple above.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work. </legalese>

License

Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)

term.js's People

Contributors

chjj avatar aus avatar risacher avatar amshali avatar chris-morgan avatar ionicabizau avatar jessetane avatar parisk avatar sufianrhazi avatar

Stargazers

Leon Ding avatar  avatar 启动 ٩( ´ω` )و avatar  avatar AxMachina avatar Stephen Wall avatar 东方飞鱼 avatar Bilal Hafri avatar  avatar Vladislav Sorokin avatar Buzhuzhao avatar Negesis23 avatar t. m. k. avatar Lan Qingyong avatar dp avatar 编程鼠鼠 avatar Sreeram Venkitesh avatar Ionut Cenac avatar BatryCC avatar flumpus avatar HaiGe avatar Zohad sikder avatar Mr Chen avatar Youth.霖 avatar Carmpan avatar voididea avatar @RandyMcMillan avatar Mike avatar  avatar d2gin avatar Orangey avatar  avatar  avatar  avatar 没电的废电池 avatar  avatar  avatar liudonghua avatar Param Siddharth avatar haoyue avatar Robert Kula avatar John Sundarraj avatar  avatar Ken Lin avatar 1derful avatar  avatar  avatar  avatar ZhaoBin avatar  avatar cenggel avatar  avatar Jamie Sparks avatar qsb avatar Alex Sitnikov avatar Johnny (Hao) Jiang avatar Edwin Kofler avatar Johan Holmerin avatar Jonghyouk Yun avatar 一只会飞的旺旺 avatar Zhiwei Li avatar  avatar Logan King (DarkComet) avatar LUÍS CARLOS DE SOUZA  MENEZES avatar 文小夫 avatar  avatar Bernd von Platen avatar David Adam Coffey avatar SimkoCarlos avatar zeroway avatar Nolan avatar  avatar  avatar Starsign68 avatar Roman Ledjajev avatar PR 花蜜 avatar Yasin ATEŞ avatar  avatar  avatar Roman Hossain Shaon avatar Jean-Michel Paris avatar  avatar Jason Lin avatar  avatar starrySky avatar  avatar Narcis-Ionuț B. avatar idoxtreme avatar Ke Wang avatar Rafael Kaissi avatar 谢超 avatar Peeyush Raj avatar  avatar Marvin avatar 程序员半夏 avatar Xi Zhang avatar Коренберг Марк avatar  avatar Connor Grady avatar Lynx avatar

Watchers

lijian avatar Carsten Strotmann avatar Michael Hoffer avatar tom zhou avatar Mehdi Lefebvre avatar roadlabs avatar javagg avatar  avatar Philip Moore avatar Alif avatar  avatar Adam Jimenez avatar zhaolei avatar  avatar 江江 赵 avatar Vincent Fiduccia avatar timelyportfolio avatar James Cloos avatar Kondal Rao Komaragiri avatar learningjs avatar  avatar DavidZ avatar Kevin M. Gallagher avatar Ygor Amaral avatar Michael Anthony avatar  avatar mebius avatar Łaurent ʘ❢Ŧ Ŧough avatar  avatar Sten Feldman avatar John Sundarraj avatar  avatar  avatar Marcel Miklosik avatar  avatar  avatar leo avatar Gawain avatar Giuliano Latini avatar  avatar Pasquale avatar Rick Blundell avatar Joe Young avatar  avatar Zahoor Wang avatar Mikhail avatar Caio Rordrigues avatar  avatar 龙华辉 avatar MaxBill avatar mbpk1134@163.com avatar  avatar

term.js's Issues

term.js on mobile?

term.js doesn't work to well on Chrome mobile. Input doesn't appear until you hit return.

I'm guessing this is because it is clashing with how you capture keys (I'm guessing a hidden input)?

Was term.js intended to support mobile devices? Is a fix possible?

My sample server.js script to make multiples independent connections (solved)

(Sorry no static server because it served by Apache, I use reverse proxy with ws mod)
It work like "Anyterm" (new process and kill for each websocket cnx).

var io = require("socket.io").listen(82);
var pty = require("pty.js");

io.sockets.on("connection", function(socket) {
 var buff = [];

 var term = pty.spawn("/usr/bin/ssh", ["root@localhost"], {
  name: "xterm-256color",
  cwd: process.env.HOME,
  env: process.env
 });

 term.on("data", function(data) {
  return !socket ? buff.push(data) : socket.emit("data", data);
 });

 while(buff.length) {
  socket.emit("data", buff.shift());
 }

 socket.on("data", function(data) {
  term.write(data);
 });

 socket.on("resize", function(resize) {
  term.resize(resize.cols, resize.rows);
 });

 socket.on("disconnect", function() {
  socket = null;
  term.kill();
 });
});

Invisible cursor

How to change cursor visibility? i wrote a small python websocket proxy to forward xen's "xm console" standard input and output to term.js. Everything seems to working fine (including midnight commander, vi, etc) except the cursor. It's always invisible. tput civis/cnorm and any escape sequence found on the net does not help.

Paste (and copy) are broken on Safari

Trying to copy/paste in safari using cmd + c / cmd + v on latest Safari and term.js (v0.0.7) doesn't work.

copy

The keypress handler swallows cmd + c, and doesn't let the browser do its thing.

paste

Paste events are tricky in Safari - you need some kind of input element or contenteditable target for the paste event to fire. Traditional workarounds include catching a keydown for cmd + v and quickly focusing an editable element and catching paste on that.

Wrong behavior of \b after line wrap

Currently \b is not allowed to go back up a line. This breaks editing of wrapped lines as well as all sorts of progress-bar-like displays which use \b to position the cursor.

I think \r handing has the same problem, but it's less painful because it doesn't come up in line editing.

Exception occurs when wrapping occurs on the final line with a scrolling region set

Minimal test case:

var t = new Terminal();
t.show();
t.resize(3, 1);
t.write("\x1b[1;2r...!");

(CSI Ps ; Ps r meaning “Set Scrolling Region [top;bottom]”.)

This causes an exception on line 1529:

              this.lines[this.y + this.ybase][this.x] = [this.curAttr, ch];

… because this.lines[this.y + this.ybase] is undefined.

I’m not certain what the “correct” behaviour here would be, but it definitely shouldn’t crash.

This was encountered by @codebutcher playing back a recorded Vim session in a Terminal instance that was too small in chris-morgan/tty-player#1.

Strange line breaks on hyphens

It seems like, on terminal prompts, term.js inserts a line break on the non-first last hyphen. That is, if there's one hyphen on the line, there is no break. If there are two, it breaks on the second. If there are three or more, it breaks on the last. It'll break dynamically as you are typing, but only as you type a character after the hyphen (in the picture attached, you need to type the b in a-b for it to break as a-<br>b

term js hyphen linebreak

abstract API to use with non-DOM ui

Hi,

I'd like to use term.js for standalone terminal implementation running in it's own X11 window (using node-x11).
Would you be interested in refactor that abstract [keyboard, mouse] -> [ lines buffer ] interaction with some kind of abstraction layer, and DOM document/window/events would be a concrete implementation on top of that layer (in my case - X11 events and custom widget - fixed grid of chars with attributes) ?

Question: term.js or tty.js? How to run example?

I want to use single terminal in my IDE(JS + node-webkit).
Which is module better suited for this purpose, term.js or tty.js?

Probably, I could add it using iframe, but I prefer to avoid it if that is possible.

So, it seems like term.js, tty.js depend on pty.js, which is Unix only, so it might not work well on Windows right?

Best Regards,
Boyan

chrome space bar problem

hi;

i'm using chrome 37.0.2062.124 and i have a space key problem. library not catch space key and not triggered data event. i'm testing on firefox 32 nothing problem.

thanks.

dynamic

Hi, how i can create dynamic console (auto scale)
my css is in 100% automatic, check it http://scr.hu/6gnm/hf54f && http://scr.hu/6gnm/cmryo

code:

var doc = document.getElementById('panel-body');
var term = new Terminal({
cols: (doc.clientWidth/6.36),
rows: 40,
useStyle: true,
});

    term.on('data', function(data) {
        socket.emit('data', data);
    });
    socket.on('data', function(data) {
        term.write(data);
    });
    term.on('close', function(data) {
        console.log('konsola zamknięta');
    });
    term.open(doc || document.body);
    socket.on('disconnect', function() {
        term.destroy();
    });

Double character input for everything in vim.

Everything works great except for when I open a file with vim, it defaults to REPLACE mode and then all characters I type are doubled. I can't even quit vim because all the characters are sent twice. Any ideas?

screen shot 2015-12-07 at 3 22 07 pm

Error

I'm getting this error message:

mac:term.js-master zane$ sudo npm install
|
> [email protected] install /Users/zane/Downloads/term.js-master/node_modules/pty.js
> node-gyp rebuild

  CXX(target) Release/obj.target/pty/src/unix/pty.o
../src/unix/pty.cc:487:10: error: use of undeclared identifier 'openpty'
  return openpty(amaster, aslave, name, (termios *)termp, (winsize *)winp);
         ^
../src/unix/pty.cc:533:10: error: use of undeclared identifier 'forkpty'
  return forkpty(amaster, name, (termios *)termp, (winsize *)winp);
         ^
2 errors generated.
make: *** [Release/obj.target/pty/src/unix/pty.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Darwin 14.1.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/zane/Downloads/term.js-master/node_modules/pty.js
gyp ERR! node -v v0.10.36
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the pty.js package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls pty.js
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/zane/Downloads/term.js-master
npm ERR! node -v v0.10.36
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0

when I try to install

a bug about double-width CJK character display

If it is fixed-width, it will incorrectly wrap (which line containing CJK characters), or it will be longer than under normal line.
I think that it should take two characters, or cutting trailing spaces.
There are many programs can output these characters correctly, such as clang, it requires a terminal with an appropriate font (the width of the CJK characters exactly twice the general character width font)
image

Paste not in the Context Menu on Chrome (42.0.2311.135m)

I am using Chrome and I don't see the Paste option in the Context Menu.
in the term.js I created I can not use the Ctrl + V, It is already used. So it looks like I stuck with the Paste from the General Menu of Chrome.
Is there another way to enable the Paste in the Context Menu?

Resizing issues

Hi,

I have a lot of issues when using term.resize(x, y)
It doesn't always resize the terminal (it seems only when it cames from a window event and not an interval or timeout); and it sometimes limit the text but keep the older size of the layout.

Thank you.

Clear scrollback

I can't see any way of clearing the scrollback and leaving only the last line / prompt in the terminal, as can be done in both iTerm and Mac OS X terminal with Command+K. Is it possible to add this functionality to the API?

Browser gets frozen when a command outputs too much data

When we type a command that outputs too much (or unlimited) data, for example find /proc or yes, the browser (Firefox, even Chrome) will be very slow or gets frozen. This performance issue is due to the algorithm you use when rendering output on screen : you first write the entire data into a buffer and then you display it. This means : the data is read twice.

I know this is not quite simple, but I wonder is it possible to do better to get higher performance so that the browser will not get frozen at least.

Issues in IE 10 browser

I see following issues when used term.js in IE 10 browser.

  1. Scroll bar does not work in IE 10 browser.

  2. When ever space bar is used to load more information focus is being out from the terminal to enter next command or to click space bar again, focus has to be brought back to the terminal by clicking on the terminal using mouse click.

how include this in a webpage and start with a command

i want to include a command prompt in my website and i have more then one ip address with username and password in a dropdown menu when i will select a ip then command prompt will connect automatically through telnet but i does not understand where i will set my telnet connection and how i will implement please help

Repo inactivity

Seems like the owner hasn't updated the repo since a long time and I could really use a lot of the pull requests that others have opened. Since it's open source, maybe we should consider opening all these PR's into a new fork to make sure everyone gets the so needed updates...

About the exposed methods

The function cancel is exposed on the 'Terminal' object

/**
 * Expose
 */

Terminal.EventEmitter = EventEmitter;
Terminal.inherits = inherits;
Terminal.on = on;
Terminal.off = off;
Terminal.cancel = cancel;

What is the purpose of this expose behavior? Allowing user to override these method through the Terminal object like below?

var oldCancel = Terminal.cancel;
Terminal.cancel = function(ev){
    if(blablabla){
        oldCancel(ev);
    }
}

If so, here is the problem, inside term.js all calls to cancel method is using the local variable cancel, but not 'Terminal.cancel' , like the code below:

if (self.vt200Mouse) {
  sendButton({ __proto__: ev, type: 'mouseup' });
  return cancel(ev);
}

Here is what i excepted:

if (self.vt200Mouse) {
  sendButton({ __proto__: ev, type: 'mouseup' });
  return Terminal.cancel(ev);
}

So i can control when to cancel the event and when not

Support for bright colortheme

Hi Christopher,

I found your terminal via the latest HN discussion and I'm really excited that there's now a working, up-to-date, actively maintained vt100 emulator for browsers! Thanks a lot!

For my current Terminal+Browser pet-project I'd like to have a light color scheme. Currently I use vt100.js from the shellinabox project, however it doesn't work very well with more "fancy" applications like vim or mc. Term.js does, however it seems to lack support for a bright colortheme, although I've found hints to that in the source. Do you plan to implement that? Should I give it a shot my self and send a pull request? I think it'd be great if it stored a css identifier/id with the characters which would allow the user/developer to customize the colors via css.

Thanks again for the great work!!

Lars

ctrl+shift+_ is not emmitted

the key sequence for undo in emacs is ctrl + shift + - (- becomes _ on shift)
this sequence is not sent to the terminal, i.e. nothing happens.

How to add scrollbar?

How can I add a scroll bar? Currently when I scroll it with mouse wheel it is okay, but I think it changes the dom to do so by having the exact number of divs as height, and modifying its content on mousewheel.

There is Terminal.prototype.bindMouse = function() { , by looking its context all I see it sends some characters but I am not sure. Any thoughts on this? I can at least bind two buttons, one up and down for emulating that mouse movement one by one.

Height of terminal changes with split tmux panes

I've noticed similar behavior in tty.js

Switching between two tmux windows is fine, and the size of the terminal remains consistent:

image

image

However, when I split tmux vertically, the terminal height increases:

image

It looks like it's one pixel per row. In this instance of 40 rows, it jumped from 600px to 639px in height. It's more pronounced with more rows.

My only guess is that it has something to do with the height of the pipe character – | – being used to split the panes, but I don't know why this doesn't cause issues in split Vim as well.

Any ideas?

Space button is deleting characters of the commandline input.

Hi
I am using term.js for supporting web based terminal, And it very good. But there is one issue related to space character. Pressing space is deleting character on the left of first user inserted space.

How to reproduce:

Character '|' denotes current cursor position.

yharsh@github>Hi my name is harsh|
yharsh@github>Hi my |na me is harsh -----> First space is inserted between characters 'a' and 'm' of word "name"
Now position the cursor to the left of this space and press space. Say I position cursor next to 'n' and press space button. Now it will delete characters 'a' and ' ', 'm', 'e' and so on on consecutive press.
yharsh@github>Hi my n|a me is harsh ------> Cursor is next to 'n'.
Press space button
yharsh@github>Hi my n | me is harsh -------> Space character has overwritten character 'a'.
Press space button
yharsh@github>Hi my n |me is harsh -------> Space character has overwritten character ' '.
Press space button
yharsh@github>Hi my n e is harsh -------> Space character has overwritten character 'm'.

Any help/fix in this regards is much appreciated.

Thanks
Harsh Yadav

Ctrl+W closes browser tab

When I am using vi on terminal, I usually open more than 1 files opened via ":sp" command. In order to toggle between different files inside vim is by pressing CTRL+W - which happens to be a key combinations for most browsers to close the current tab - no questions asked.

After a doing a bit of research / experiments, it looks like it's impossible to capture / preventDefault() the behavior of CTRL+W. I understand why browser makers adopted this policy, but I am a heavy vim user and I don't think I can live without having to use CTRL+W..

I don't know if there is any solution to this problem - other than not using :sp for vim (or remapping it to something other than CTRL+W..) but I just wanted to report this so that others might know different solutions to this problem.

Characters are removed from the end of lines when cols is reduced

Whenever the term.resize() is called with a number lower than the length of any line, the characters at the end are just popped off, and cannot be recovered.

Here's the offending line in term.js
// resize cols
j = this.cols;
if (j < x) {
ch = [this.defAttr, ' ']; // does xterm use the default attr?
i = this.lines.length;
while (i--) {
while (this.lines[i].length < x) {
this.lines[i].push(ch);
}
}
} else if (j > x) {
i = this.lines.length;
while (i--) {
while (this.lines[i].length > x) {
this.lines[i].pop();
}
}
}

That last line is just popping off the data! Unless I'm resizing it wrong, how am I supposed to prevent this? My current workaround is to not reduce the col number past 80.

Additional wide characters

Originally reported as ipython/ipython#8361 - 啊, U+554A, displays wider than a standard character, at least in the monospace font used in my browser. Using it term.js therefore breaks the layout. Adding it to isWide() fixes things. It's a Han character, and I assume that many of the nearby codepoints will behave similarly. But I don't know how many, or whether there are other fonts that fit them into a standard width.

Question: How do I determine in code that the Terminal is ready to use?

Hello,

I am trying to write a test that checks if a web application that uses term.js has properly loaded the Terminal and that the prompt is ready to use.

Basically I want to write a test that checks that when the page with the Terminal has finished loading that the Terminal prompt is indeed ready to use. Is it possible to validate that when the page has finished loading that the Terminal windows does in fact have a prompt like: userX@hostname:~$

For some testing I have done I usually use the an item's selector to find the item in the webpage and then check its value. For example, I might use a text box's id and then check that it has a value. Is it possible to do something similar with term.js and verify that the prompt loaded correctly?

Thanks.

Switch focus with multiple term.js instance on one page

Hi there,
first of all thanks for this great project. I like working with it a lot. Up today I used only one term.js session window per browser tab. I tried to enhance this, to multiple term.js windows in an tabbing widget.
This works so far, the instances are created, the data is received. The only issue I have is the focus of the windows. The focus for typing etc. always stays on the last opened window. Is there are a way to handle that?

Would be great to hear some ideas!

running screen

There is an issue with running screen in term.js. It simply doesn't work. Do you know about this issue? Any cure? Thanks?

Rendering of certain whole-screen applications (like mc) is broken.

Context

This originated as ipython/ipython#7782 on IPython, but it seems that it's better reported directly here. IPython uses term.js purely as a component, wrapped in terminado, a Tornado-based async server. It then exposes the terminals in the IPython Notebook application.

The issue

On Chrome on Linux, if I set the Consolas font to being my monospaced font, when running mc (Midnight Commander) in the terminal, the computation of the column width must be wrong, b/c the page misrenders:

image

This is even more evident when an error box is drawn:

image

Checking the value of Terminal.brokenBold in the JS Console returns true with Consolas. Yet, the fix in ipython/ipython#7242 isn't helping here.

For reference, switching to another monospaced font, such as DejaVu Sans Mono, fixes the problem. So at least there's a workaround.

But even if the bug is in Consolas, it would be nice if we could make it work correctly (if viable). Regular terminal emulators don't exhibit this behavior. As noted by @takluyver in ipython/ipython#7242, this may not be easily fixable without way too much work. If that's the case, so be it, at least this will document the problem for future users.

ps - for extra details on this issue from the IPython side, see ipython/ipython#7242.

alt key?

has anyone been able to get the alt key to work?

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.