Skip to content

Commit

Permalink
Fix autocompletion event handling around up/down arrows. Fix filesyst…
Browse files Browse the repository at this point in the history
…em autocompleter
  • Loading branch information
unconed committed May 5, 2011
1 parent 944267a commit 971183d
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 51 deletions.
2 changes: 1 addition & 1 deletion HTML/client/shell.js
Expand Up @@ -24,7 +24,7 @@ tc.shell = function (client, environment, success) {

that.query('shell.environment', { }, function (message) {
that.environment = message.args;
success();
success(that);
});

});
Expand Down
3 changes: 2 additions & 1 deletion HTML/termkit.css
Expand Up @@ -140,6 +140,7 @@ body {
left: 15px;
top: 12px;
color: #ccc;
font-size: 12px;
}

.termkitCommand > span.sigil-ok {
Expand Down Expand Up @@ -272,7 +273,7 @@ body {
z-index: 2;
display: block;
white-space: nowrap;
height: 21px;
height: 23px;
z-index: 5;
}

Expand Down
2 changes: 1 addition & 1 deletion HTML/termkit.js
Expand Up @@ -8,7 +8,7 @@ $(document).ready(function () {

var client = new termkit.client();
client.onConnect = function () {
var shell = new termkit.client.shell(client, {}, function () {
var shell = new termkit.client.shell(client, {}, function (shell) {
var view = new termkit.commandView(shell);
$('#terminal').append(view.$element);
view.newCommand();
Expand Down
12 changes: 11 additions & 1 deletion HTML/tokenfield/autocomplete.js
Expand Up @@ -14,6 +14,7 @@ tf.autocomplete = function (caret) {
this.selected = 0;
this.token = null;
this.last = null;
this.animateTarget = 0;
};

tf.autocomplete.prototype = {
Expand Down Expand Up @@ -52,6 +53,7 @@ tf.autocomplete.prototype = {
this.prefix = '';
this.selected = 0;
this.token = null;
this.animateTarget = 0;

// Reset caret position.
//this.caret.$element.find('input').css('marginTop', 0);
Expand Down Expand Up @@ -90,7 +92,14 @@ tf.autocomplete.prototype = {
// Move caret element to active line.
var offsetY = $line.addClass('active').position().top;
//this.caret.$element.find('input').css('marginTop', offsetY);
that.$element.animate({ 'marginTop': -offsetY }, { duration: 30, queue: false });
that.$element.stop().css({
marginTop: that.animateTarget,
})
.animate({ 'marginTop': -offsetY }, {
duration: 30,
queue: false,
});
that.animateTarget = -offsetY;
}
else {
$e.empty().hide();
Expand Down Expand Up @@ -121,6 +130,7 @@ tf.autocomplete.prototype = {

onComplete: function (event) {
if (this.token && this.selected < this.items.length) {
event.charCode = 10; // LF \n
this.caret.setContents(this.items[this.selected] +' ', event);
this.remove();
}
Expand Down
7 changes: 4 additions & 3 deletions HTML/tokenfield/caret.js
Expand Up @@ -132,7 +132,6 @@ tf.caret.prototype = {
this.prefix = '';
this.$input.val(string);
this.suffix = '';

this.updateContents(event);
},

Expand All @@ -145,6 +144,8 @@ tf.caret.prototype = {
var old = this.token;
var updated = this.prefix + this.$input.val() + this.suffix;

console.log('caret.updateContents', updated, this.selection, event);

// Check for changes and apply them.
if (this.token.contents != updated) {
this.autocomplete.remove();
Expand All @@ -154,8 +155,8 @@ tf.caret.prototype = {
// (asynchronous to give the DOM time to finish event handling).
async.call(this, function () {
// Merge stored key/char codes in, effectively merging keydown/keypress info.
event.keyCode = this.keyCode;
event.charCode = this.charCode;
event.keyCode = event.keyCode || this.keyCode;
event.charCode = event.charCode || this.charCode;
this.onChange(this.token, event);

// TODO: replace with real autocomplete
Expand Down
6 changes: 4 additions & 2 deletions HTML/tokenfield/token.js
Expand Up @@ -60,10 +60,9 @@ tf.token.prototype = {
transmute: function (token) {
if (this.contents == token.contents) {
this.constructor = token.constructor;
this.checkSelf = token.checkSelf;
this.checkTriggers = token.checkTriggers;
this.type = token.type;
this.allowEmpty = token.allowEmpty;
this.__proto__ = token.prototype;
return true;
}
},
Expand All @@ -72,6 +71,9 @@ tf.token.prototype = {
// @return Array of replacement tokens for this token (optional).
checkTriggers: function (selection, event) {
var token = this, t = tf.token.triggers;

console.log('checkTriggers', event, token, selection.anchor.token);

// Apply type
var update, triggers = [].concat(t[this.type] || [], t['*'] || []);
$.each(triggers, function () {
Expand Down
3 changes: 3 additions & 0 deletions HTML/tokenfield/tokenfield.js
Expand Up @@ -102,6 +102,8 @@ tf.prototype = {
// Refresh the given token in response to input.
updateToken: function (token, event) {

console.log('tokenField.updateToken', token, event);

// Apply own rules.
var update = token.checkSelf(this.selection, event);
if (!update) {
Expand All @@ -111,6 +113,7 @@ tf.prototype = {

// Insert replacement tokens if given.
if (update) {
console.log(' .updateToken update', update);
// Allow both single replacement token as well as array of tokens.
if (update.length === undefined) update = [update];

Expand Down
3 changes: 2 additions & 1 deletion HTML/typography.css
Expand Up @@ -9,8 +9,9 @@ body {
}

.termkitCommandView pre {
font-family: "BitStream Vera Sans";
font-family: "BitStream Vera Sans Mono";
font-size: inherit;
font-size: 87.5%;
}

.termkitOutputView .widgetFile .name {
Expand Down
2 changes: 1 addition & 1 deletion License.txt
@@ -1,4 +1,4 @@
Copyright (c) 2009-2010, Steven Wittens
Copyright (c) 2009-2011, Steven Wittens
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
21 changes: 15 additions & 6 deletions Node/shell/autocomplete.js
Expand Up @@ -42,6 +42,7 @@ exports.autocomplete.prototype = {
var matches = [];
for (i in builtin.shellCommands) {
if (prefix == '' || i.indexOf(prefix) === 0) {
// TODO: Add space suffix / label
matches.push(i);
}
}
Expand All @@ -51,19 +52,26 @@ exports.autocomplete.prototype = {

filesystem: function (path, prefix, options, callback) {
var sticky = '';

path = path || process.cwd();

if (/[^\/]$/(path)) {
path += '/';
}
prefix = prefix || '';

if (prefix[0] == '/') {
prefix = prefix.substring(1);
sticky = '/';
path = '/';
}
else if (prefix.indexOf('/') != -1) {
var split = prefix.split(/\//);
path += '/' + split[0];
prefix = split[1];
sticky = split[0] + '/';

if (prefix.indexOf('/') != -1) {
var split = prefix.split(/\//g);
prefix = split.pop();
head = split.join('/') + '/';
path += head;
sticky += head;
}

if (typeof options == 'function') {
Expand All @@ -80,11 +88,12 @@ exports.autocomplete.prototype = {
matches.sort();
callback(matches);
});

fs.readdir(path, track(function (err, files) {
if (!err) {
for (i in files) (function (file) {
if (prefix == '' || file.indexOf(prefix) === 0) {
// TODO: stat file, and add appropriate suffix
matches.push(sticky + file);
}
})(files[i]);
Expand Down
6 changes: 4 additions & 2 deletions Node/shell/builtin.js
Expand Up @@ -51,19 +51,21 @@ exports.shellCommands = {
out.print("Error reading file (" + file + ")");
return;
}

var slice = buffer.slice(0, bytesRead);

if (position == 0) {
var headers = new meta.headers();
headers.set({
'Content-Type': meta.sniff(file, buffer),
'Content-Type': meta.sniff(file, slice),
'Content-Length': stats.size,
'Content-Disposition': [ 'attachment', { 'filename': file } ],
});

pipes.dataOut.write(headers.generate());
}

pipes.dataOut.write(buffer.slice(0, bytesRead));
pipes.dataOut.write(slice);
position += bytesRead;

if (position < stats.size) {
Expand Down
2 changes: 1 addition & 1 deletion Node/shell/meta.js
Expand Up @@ -403,7 +403,7 @@ exports.sniff = function (file, data) {
return mime.types[extension];
}

if (/[^\u0001-\u00FD]/('' + data)) {
if (/[^\u0001-\uFFFF]/('' + data)) {
return 'application/octet-stream';
}

Expand Down
5 changes: 4 additions & 1 deletion Node/shell/worker.js
Expand Up @@ -4,5 +4,8 @@ require.paths.unshift('shell');

var processor = require('processor');

// Change to home directory.
process.chdir(process.env.HOME);

// Set up processor.
var p = new processor.processor(process.openStdin(), process.stdout);
var p = new processor.processor(process.openStdin(), process.stdout);
8 changes: 5 additions & 3 deletions termkit.txt
Expand Up @@ -59,14 +59,16 @@ Good desktop citizen:
[X] Viewstream integration
[X] 5-pipe command execution
[ ] unix command execution
[ ] filesystem autocomplete
[.] filesystem autocomplete
[ ] http get/post data piping
[ ] command decoration
[ ] interactive execution
[ ] inline man-pages tips
[ ] version control
[ ] interactive quicklook
[X] OS X icon loading
[X] inline image display
[ ] regexp hinter

0.4: Network & Modularity
[ ] SSH tunneling
Expand Down Expand Up @@ -395,11 +397,11 @@ seq: set, callback
method: view.*


> shell-specific interaction rules are client-side.
> shell-specific interaction rules are server-side.
> rich widget lib for display, extensible
> widgets are streamed to client like termkit-ML. objects are smartly typed and have callback commands defined for them. callbacks can be stateful or stateless. though stateful is only intended to be used for interactive commands.

tableview / listcontainer -> generic, scales form simple list to tabled headers w/ simple syntax
tableview / listcontainer -> generic, scales from simple list to tabled headers w/ simple syntax
object references for files and other things. are multi-typed and annotated on server-side.

+++ --
Expand Down
43 changes: 16 additions & 27 deletions todo.txt
@@ -1,10 +1,9 @@
Tasks:
[ ] filesystem autocomplete
[:] filesystem autocomplete
[.] Viewstream integration
[ ] run unix
[ ] run pipeline test
[X] run built-in
[ ] run unix
[X] output formatter
[ ] cat/echo Piping + progress bar
[ ] 5-pipe command execution
[ ] unix command execution
[ ] command decoration
Expand All @@ -13,17 +12,12 @@ Tasks:
[ ] version control
[ ] interactive quicklook

[ ] File autocompletion
[ ] cat/echo Piping + progress bar
[ ] refactor/standardize view bridge onto standard DOM
[ ] file < input piping, use node-mime to detect type?
[ ] Improve typography of directory listing

Prototype:

1) UI prototypes

[alpha] Token field
[:] Token field
[X] plain text
[X] encapsed string
[X] token transmutation
Expand All @@ -45,22 +39,15 @@ Prototype:
[ ] caret.remove() shouldn't need to touch tokenList when pruning empties -> let triggers do it
[ ] | and >> token support

[?] write external bindings for tokenfield
=> tokenfield abstracts, interface for matching should be only multiregexp + callback
. on change -> process tokens, apply multiregexps
. register multiregexp
. execute command
[?] rewrite $element / $markup pattern to create new $markup on demand when doing insert/remove from DOM

[X] inline autocomplete
[:] inline autocomplete
[X] panel overlayed on token
[X] alignment
[X] keyboard controls up/down
[X] hit enter after autocomplete in empty token -> undefined
[X] escape to close popup
[ ] autocomplete icons, markup, widgets, etc

[ ] command view
[:] command view
[X] list of collapsible sections
[X] host token field
[X] context bar by command
Expand All @@ -79,10 +66,11 @@ Prototype:
[X] triggers system, unify with token field triggers a bit?
[X] autocomplete a string / command
[X] autocomplete empties
[ ] autocomplete commands
[ ] autocomplete filesystem
[ ] autocomplete dir / file distinction
[ ] badge tokens with one/many/command icons
[X] autocomplete commands
[X] autocomplete filesystem
+ [ ] autocomplete label / contents / icon
+ [ ] autocomplete dir / file distinction
+ [ ] badge tokens with one/many/command icons

3) Smart output with selectable things
[X] research FastCGI socket protocol
Expand All @@ -96,12 +84,13 @@ Prototype:
[X] list of files
[X] file icons
[X] implement view DOM v2 with path targeting
[ ] auto-layout mechanism w/ padded max-height on view
[X] auto-layout mechanism w/ padded max-height on view
[ ] intercontrol focus / caret, set up global manager
[ ] tab, switch between widgets.
[ ] working widget callbacks
[ ] auto-layout column width (preferred size from widgets + widget variant/style)
[ ] make file icons cacheable long-term in webkit cache
[ ] stable multi-column layout
[ ] intercontrol focus / caret, set up global manager
[ ] tab, switch between widgets.
[ ] smart tab-tabling layout for plain-text

4) NodeKit daemon
Expand All @@ -118,7 +107,7 @@ Prototype:
[X] simplify message format to raw json
[X] viewstream integration
[ ] arrange pipes for command/view for unix processes
[X] output formatter
+ [X] output formatter
[X] full mime header parser/generator
[ ] handle encodings
[ ] smart binary output
Expand Down

0 comments on commit 971183d

Please sign in to comment.