runtimejs / runtime

[not maintained] Lightweight JavaScript library operating system for the cloud
http://runtimejs.org
Apache License 2.0
1.93k stars 128 forks source link

Add run command and get features #60

Closed facekapow closed 9 years ago

facekapow commented 9 years ago

This adds a run commands feature to runtime.shell. If you get an error with the args parameter, add a space at the beginning of the string. Usage:

runtime.shell.runCommand(commandName, [arguments]);
// Example:
runtime.shell.runCommand("echo", " hey");

UPDATE: I just added a get function to runtime.tty, which allows you to get text from the user easily. It returns an EventController object that you can listen to. Usage:

var foo = runtime.tty.get();
foo.add(function(text) {
  runtime.tty.print(text);
  // or whatever you want to do with `text`
});
facekapow commented 9 years ago

@iefserge @kesla Should this be in runtime-shell? I'm not sure.

iefserge commented 9 years ago

Let's move readline logic into separate file, why EventController instead of callback? runCommand needs a callback, right?

facekapow commented 9 years ago

Ok, I'll get to work on that. I was also thinking of how to catch output from the command being run and pass it to the callback.

facekapow commented 9 years ago

@iefserge Could I make onInput.add pass an out parameter to the callback? So that it can be set to runtime.tty.print when running directly and it could be replaced with a different function in runCommand?

iefserge commented 9 years ago

as an idea, we could introduce stdio object passed to commands as well as shell

setCommand(function(args, stdio, cb) {
  stdio.write('enter your name: ');
  stdio.readLine(function(status, input) {
    // return some status code if user pressed CTRL+C
    stdio.write('hello ' + input);
    cb();
  });
})

And maybe expose IO object constructor to be able to catch input/output.

var myio = new runtime.tty.IO();
myio.onwrite = function(dataWritten) {};
myio.onreadline = function(cb) {};

runtime.shell.runCommand('test', myio, cb)
facekapow commented 9 years ago

I'm creating a stdio folder + some commands right now.

facekapow commented 9 years ago

@iefserge I created some stdio commands and updated command 1 to use it.

facekapow commented 9 years ago

Git refuses to push terminal.js?! Dont know why

facekapow commented 9 years ago

@iefserge I was able to add stdio and move the get command to a separate file.

iefserge commented 9 years ago

@ArielAbreu let's make an IO object a class, and then instantiate global one internally that uses tty functions

facekapow commented 9 years ago

@iefserge Right now i'm working on creating capturing IO in runCommand using EventEmmiter + callback.

facekapow commented 9 years ago

I think i've got a good (at least functional) IO and CaptureIO for runtime.

facekapow commented 9 years ago

What is this PR conflicting with? I closed #59, which I thought was the problem, but the conflict continues!

facekapow commented 9 years ago

AGH! I'm closing this, copying my work to another folder, deleting this branch, and doing everything again, step by step, until I hit the conflict.