From 76125f45ae8c101fafe34d3d8b7eb5c51c0cc980 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 15 Nov 2016 15:59:00 +0200 Subject: [PATCH] feature(package) console-io v3.0.0 --- HELP.md | 14 ++++++++++++++ lib/client/konsole.js | 24 +++++++++++++++++++----- lib/cloudcmd.js | 7 +++---- package.json | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/HELP.md b/HELP.md index 25157f8a..d5cf04fc 100644 --- a/HELP.md +++ b/HELP.md @@ -198,6 +198,20 @@ Console For more details see [console hot keys](https://github.com/cloudcmd/console#hot-keys "Console Hot Keys"). +Every program executed in `console` has these `environment` variables: + +- `ACTIVE_DIR` - directory that contains cursor +- `PASSIVE_DIR` - directory with no cursor +- `CURRENT_NAME` - name of a file under cursor +- `CURRENT_PATH` - path to file under cursor + +On Unix you can use it this way: + +```sh +~> echo $CURRENT_PATH +/home/coderaiser/cloudcmd/bin/cloudcmd.js +``` + Config --------------- ![Config](/img/screen/config.png "Config") diff --git a/lib/client/konsole.js b/lib/client/konsole.js index 5e0d9482..46470d44 100644 --- a/lib/client/konsole.js +++ b/lib/client/konsole.js @@ -30,7 +30,7 @@ Konsole.show, ]); - Element = DOM.load({ + Element = DOM.load({ name : 'div', className : 'console' }); @@ -48,11 +48,25 @@ return CloudCmd.PREFIX + '/console'; } + function getEnv() { + return { + ACTIVE_DIR: DOM.getCurrentDirPath.bind(DOM), + PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM), + CURRENT_NAME: DOM.getCurrentName.bind(DOM), + CURRENT_PATH: function() { + return DOM.CurrentInfo.path; + } + } + } + function create(callback) { - var prefix = getPrefix(), - socketPath = CloudCmd.PREFIX; + var options = { + env: getEnv(), + prefix: getPrefix(), + socketPath: CloudCmd.PREFIX, + }; - Console(Element, prefix, socketPath, function(spawn) { + Console(Element, options, function(spawn) { spawn.on('connect', exec.with(authCheck, spawn)); Util.exec(callback); }); @@ -62,7 +76,7 @@ var command = Console.getPromptText(), path = DOM.getCurrentDirPath(); - command += path; + command += path; Console.setPromptText(command); } }); diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index e4f56180..044181a1 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -18,7 +18,7 @@ var DIR = __dirname + '/', ponse = require('ponse'), mollify = require('mollify'), restafary = require('restafary'), - webconsole = require('console-io'), + konsole = require('console-io/legacy'), edward = require('edward/legacy'), dword = require('dword/legacy'), deepword = require('deepword/legacy'), @@ -147,9 +147,8 @@ function listen(prefix, socket) { authCheck: authCheck }); - config('console') && webconsole({ + config('console') && konsole.listen(socket, { prefix: prefix + '/console', - socket: socket, authCheck: authCheck }); } @@ -170,7 +169,7 @@ function cloudcmd(prefix) { }), funcs = [ - webconsole.middle({ + konsole({ prefix: prefix + '/console', minify: isMinify, online: isOnline diff --git a/package.json b/package.json index 016f3aa2..dd1496d4 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "apart": "^1.0.1", "chalk": "^1.1.0", "checkup": "^1.3.0", - "console-io": "^2.7.1", + "console-io": "^3.0.0", "copymitter": "^1.8.0", "criton": "^1.0.0", "deepword": "^1.1.2",