Acode icon indicating copy to clipboard operation
Acode copied to clipboard

Termux integration

Open 7HR4IZ3 opened this issue 6 months ago • 3 comments

Added system.run and system.execute commands to the system plugin.

  • system.run(Command): Promise<PtyResponse>: It runs the command then returns a PtyResponse or throws a PtyError

  • system.execute(Command): Promise: It runs the command but dosen’t wait for the output or any error thrown.

Added pty module and export to acode

The pty.host.run function takes the RunCommand type as argument

Example Usage

System Run

system.run({
    command: "/data/data/com.termux/files/usr/bin/ls",
    workDir: "/data/data/com.termux/files/home", args: ["-a"],
    background: false, sessionAction: 3
  }).then(console.log)

Read this (TERMUX.RUN_COMMAND) for more info on sessionAction and other arguments

Using Acode PTY

You should use this for spawning and interacting with processes

let pty = acode.require("pty");

// Create new connection
let connection = await pty.host.run({
  command: "bash", args: [],
  onmessage(stdout) {
    console.log(stdout);
  }
});

// Add listeners
connection.addEventListener("open", () => {});
connection.addEventListener("close", () => {});
connection.addEventListener("error", () => {});
connection.addEventListener("message", () => {});
connection.addEventListener("reconnect", () => {});

// Kill connection
connection.kll();

Type Interface

Command

  • command: String: Represent the command to be executed
  • args: Array<String>: Arguments to be passed to the command
  • background: Boolean: Specify whether to run the command in the background as a task
  • homeDir: String: Path where the command should be executed from

PtyResponse

  • stderr: String
  • stdout: String
  • exitCode: Number
  • stderrLength: Number
  • stdoutLength: Number

PtyError

  • error: String
  • errorCode: Number
  • exitCode: Number

RunCommand

  • command: String: Represent the command to be executed
  • type: String: Specify connection type, should be either pty(pseudo terminal mode) or process(simply execute the command and relay putputs)
  • args: Array<String>: Arguments to be passed to the command
  • onmessage: Function(data): void : Specify function to be called when a message comes through
  • autoReconnect: Boolean: Auto reconnect to server in case of disconnection?
  • reconnectDelay: Number: How long to wait before attempting to reconnect
  • maxRetries: Number: How many times to try to reconnect before giving up

7HR4IZ3 avatar Jul 26 '24 21:07 7HR4IZ3