Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #42 from RommelVR/patch-1

Inbuffer now matches input behaviour (irc.client.js)
  • Loading branch information...
commit fa04e4419f0d926d219bc8babf0c235fba217e34 2 parents 218d37a + 4ce0942
@mscdex authored
Showing with 15 additions and 11 deletions.
  1. +15 −11 examples/irc.client.js
View
26 examples/irc.client.js
@@ -111,17 +111,13 @@ function setupWindow(win, conn) {
window.top();
nc.redraw();
});
- } else if (i === nc.keys.BACKSPACE && win.curx > 0) {
- var prev_x = win.curx-1;
- win.delch(win.height-1, prev_x);
- win.inbuffer = win.inbuffer.substring(0, prev_x) + win.inbuffer.substring(prev_x+1);
- win.cursor(win.height-1, prev_x);
+ } else if (i === nc.keys.BACKSPACE && win.curx > 0) {
+ win.inbuffer = win.inbuffer.substring(0, win.curx - 1) + win.inbuffer.substring(win.curx);
+ win.delch(win.height-1, win.curx - 1);
win.refresh();
} else if (i === nc.keys.DEL) {
- var prev_x = win.curx;
+ win.inbuffer = win.inbuffer.substring(0, win.curx) + win.inbuffer.substring(win.curx + 1);
win.delch(win.height-1, win.curx);
- win.inbuffer = win.inbuffer.substring(0, win.curx-1) + win.inbuffer.substring(win.curx);
- win.cursor(win.height-1, prev_x);
win.refresh();
} else if (i === nc.keys.LEFT && win.curx > 0) {
win.cursor(win.height-1, win.curx-1);
@@ -269,8 +265,16 @@ function setupWindow(win, conn) {
win.refresh();
}
} else if (i >= 32 && i <= 126 && win.curx < win.width-1) {
- win.echochar(i);
- win.inbuffer += c;
+ win.inbuffer = win.inbuffer.slice(0, win.curx) + c + win.inbuffer.slice(win.curx);
+
+ if (win.curx < win.inbuffer.length) {
+ win.insch(i);
+ win.cursor(win.height - 1, win.curx + 1);
+ } else {
+ win.addch(i);
+ }
+
+ win.refresh();
}
});
win.scrollok(true);
@@ -490,4 +494,4 @@ var COLOR_TOPIC = nc.colorPair(4, nc.colors.BLACK, nc.colors.WHITE);
var COLOR_ACTION = nc.colorPair(5);
var COLOR_QUIT = nc.colorPair(6);
-addConnection('irc.freenode.net', 'ncursestest' + Math.ceil(Math.random()*100));
+addConnection('irc.freenode.net', 'ncursestest' + Math.ceil(Math.random()*100));
Please sign in to comment.
Something went wrong with that request. Please try again.