Archived
1
0

Fix syntax highlighting, process spawning, extensions, terminals (#22)

* Fix syntax highlighting, process spawning, extensions, terminals

* Replace colons in toISOString

* Move pathSets included in task
This commit is contained in:
Kyle Carberry
2019-01-28 11:14:06 -06:00
parent 9b1a635d63
commit b4798d1a48
31 changed files with 300 additions and 46 deletions

View File

@ -161,7 +161,7 @@ export class Client {
* @param options Options to execute for the command
*/
public spawn(command: string, args: string[] = [], options?: SpawnOptions): ChildProcess {
return this.doSpawn(command, args, options, false);
return this.doSpawn(command, args, options, false, false);
}
/**
@ -272,6 +272,7 @@ export class Client {
tmpDirectory: init.getTmpDirectory(),
workingDirectory: init.getWorkingDirectory(),
os: opSys,
shell: init.getShell(),
};
this.initDataEmitter.emit(this._initData);
} else if (message.hasEvalDone()) {
@ -316,7 +317,14 @@ export class Client {
if (!s) {
return;
}
s.pid = message.getIdentifySession()!.getPid();
const pid = message.getIdentifySession()!.getPid();
if (typeof pid !== "undefined") {
s.pid = pid;
}
const title = message.getIdentifySession()!.getTitle();
if (typeof title !== "undefined") {
s.title = title;
}
} else if (message.hasConnectionEstablished()) {
const c = this.connections.get(message.getConnectionEstablished()!.getId());
if (!c) {
@ -347,6 +355,7 @@ export class Client {
} else if (message.hasSharedProcessActive()) {
this.sharedProcessActiveEmitter.emit({
socketPath: message.getSharedProcessActive()!.getSocketPath(),
logPath: message.getSharedProcessActive()!.getLogPath(),
});
} else if (message.hasServerEstablished()) {
const s = this.servers.get(message.getServerEstablished()!.getId());

View File

@ -26,6 +26,7 @@ export interface ChildProcess {
readonly killed?: boolean;
readonly pid: number | undefined;
readonly title?: string;
kill(signal?: string): void;
@ -45,6 +46,7 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
public readonly stderr = new stream.Readable({ read: (): boolean => true });
private _pid: number | undefined;
private _title: string | undefined;
private _killed: boolean = false;
private _connected: boolean = false;
@ -69,6 +71,14 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
this._connected = true;
}
public get title(): string | undefined {
return this._title;
}
public set title(title: string | undefined) {
this._title = title;
}
public get connected(): boolean {
return this._connected;
}

View File

@ -113,7 +113,7 @@ export class FS {
}
public createWriteStream = (): void => {
throw new Error("not implemented");
throw new Error("createWriteStream not implemented");
}
public exists = (path: fs.PathLike, callback: (exists: boolean) => void): void => {

View File

@ -20,8 +20,10 @@ export interface InitData {
readonly workingDirectory: string;
readonly homeDirectory: string;
readonly tmpDirectory: string;
readonly shell: string;
}
export interface ISharedProcessData {
readonly socketPath: string;
readonly logPath: string;
}

View File

@ -35,6 +35,7 @@ export const handleNewSession = (connection: SendableConnection, newSession: New
]);
let process: Process;
let processTitle: string | undefined;
const env: { [key: string]: string } = {};
newSession.getEnvMap().forEach((value, key) => {
@ -42,12 +43,31 @@ export const handleNewSession = (connection: SendableConnection, newSession: New
});
if (newSession.getTtyDimensions()) {
// Spawn with node-pty
process = nodePty.spawn(newSession.getCommand(), newSession.getArgsList(), {
const ptyProc = nodePty.spawn(newSession.getCommand(), newSession.getArgsList(), {
cols: newSession.getTtyDimensions()!.getWidth(),
rows: newSession.getTtyDimensions()!.getHeight(),
cwd: newSession.getCwd(),
env,
});
const timer = setInterval(() => {
if (ptyProc.process !== processTitle) {
processTitle = ptyProc.process;
const id = new IdentifySessionMessage();
id.setId(newSession.getId());
id.setTitle(processTitle);
const sm = new ServerMessage();
sm.setIdentifySession(id);
connection.send(sm.serializeBinary());
}
}, 200);
ptyProc.on("exit", () => {
clearTimeout(timer);
});
process = ptyProc;
processTitle = ptyProc.process;
} else {
const options = {
cwd: newSession.getCwd(),
@ -129,6 +149,9 @@ export const handleNewSession = (connection: SendableConnection, newSession: New
const id = new IdentifySessionMessage();
id.setId(newSession.getId());
id.setPid(process.pid);
if (processTitle) {
id.setTitle(processTitle);
}
const sm = new ServerMessage();
sm.setIdentifySession(id);
connection.send(sm.serializeBinary());

View File

@ -86,6 +86,9 @@ export class Server {
throw new Error(`unrecognized platform "${platform}"`);
}
initMsg.setOperatingSystem(operatingSystem);
if (process.env.SHELL) {
initMsg.setShell(process.env.SHELL);
}
const srvMsg = new ServerMessage();
srvMsg.setInit(initMsg);
connection.send(srvMsg.serializeBinary());

View File

@ -60,4 +60,5 @@ message WorkingInitMessage {
Mac = 2;
}
OperatingSystem operating_system = 5;
string shell = 6;
}

View File

@ -253,6 +253,9 @@ export class WorkingInitMessage extends jspb.Message {
getOperatingSystem(): WorkingInitMessage.OperatingSystem;
setOperatingSystem(value: WorkingInitMessage.OperatingSystem): void;
getShell(): string;
setShell(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): WorkingInitMessage.AsObject;
static toObject(includeInstance: boolean, msg: WorkingInitMessage): WorkingInitMessage.AsObject;
@ -270,6 +273,7 @@ export namespace WorkingInitMessage {
dataDirectory: string,
workingDirectory: string,
operatingSystem: WorkingInitMessage.OperatingSystem,
shell: string,
}
export enum OperatingSystem {

View File

@ -1593,7 +1593,8 @@ proto.WorkingInitMessage.toObject = function(includeInstance, msg) {
tmpDirectory: msg.getTmpDirectory(),
dataDirectory: msg.getDataDirectory(),
workingDirectory: msg.getWorkingDirectory(),
operatingSystem: msg.getOperatingSystem()
operatingSystem: msg.getOperatingSystem(),
shell: msg.getShell()
};
if (includeInstance) {
@ -1650,6 +1651,10 @@ proto.WorkingInitMessage.deserializeBinaryFromReader = function(msg, reader) {
var value = /** @type {!proto.WorkingInitMessage.OperatingSystem} */ (reader.readEnum());
msg.setOperatingSystem(value);
break;
case 6:
var value = /** @type {string} */ (reader.readString());
msg.setShell(value);
break;
default:
reader.skipField();
break;
@ -1723,6 +1728,13 @@ proto.WorkingInitMessage.prototype.serializeBinaryToWriter = function (writer) {
f
);
}
f = this.getShell();
if (f.length > 0) {
writer.writeString(
6,
f
);
}
};
@ -1810,6 +1822,21 @@ proto.WorkingInitMessage.prototype.setOperatingSystem = function(value) {
};
/**
* optional string shell = 6;
* @return {string}
*/
proto.WorkingInitMessage.prototype.getShell = function() {
return /** @type {string} */ (jspb.Message.getFieldProto3(this, 6, ""));
};
/** @param {string} value */
proto.WorkingInitMessage.prototype.setShell = function(value) {
jspb.Message.setField(this, 6, value);
};
/**
* @enum {number}
*/

View File

@ -35,10 +35,12 @@ message SessionDoneMessage {
int64 exit_status = 2;
}
// Identifies a session with a PID.
// Identifies a session with a PID and a title.
// Can be sent multiple times when title changes.
message IdentifySessionMessage {
uint64 id = 1;
uint64 pid = 2;
string title = 3;
}
// Writes data to a session.

View File

@ -118,6 +118,9 @@ export class IdentifySessionMessage extends jspb.Message {
getPid(): number;
setPid(value: number): void;
getTitle(): string;
setTitle(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): IdentifySessionMessage.AsObject;
static toObject(includeInstance: boolean, msg: IdentifySessionMessage): IdentifySessionMessage.AsObject;
@ -132,6 +135,7 @@ export namespace IdentifySessionMessage {
export type AsObject = {
id: number,
pid: number,
title: string,
}
}

View File

@ -867,7 +867,8 @@ proto.IdentifySessionMessage.prototype.toObject = function(opt_includeInstance)
proto.IdentifySessionMessage.toObject = function(includeInstance, msg) {
var f, obj = {
id: msg.getId(),
pid: msg.getPid()
pid: msg.getPid(),
title: msg.getTitle()
};
if (includeInstance) {
@ -912,6 +913,10 @@ proto.IdentifySessionMessage.deserializeBinaryFromReader = function(msg, reader)
var value = /** @type {number} */ (reader.readUint64());
msg.setPid(value);
break;
case 3:
var value = /** @type {string} */ (reader.readString());
msg.setTitle(value);
break;
default:
reader.skipField();
break;
@ -964,6 +969,13 @@ proto.IdentifySessionMessage.prototype.serializeBinaryToWriter = function (write
f
);
}
f = this.getTitle();
if (f.length > 0) {
writer.writeString(
3,
f
);
}
};
@ -1006,6 +1018,21 @@ proto.IdentifySessionMessage.prototype.setPid = function(value) {
};
/**
* optional string title = 3;
* @return {string}
*/
proto.IdentifySessionMessage.prototype.getTitle = function() {
return /** @type {string} */ (jspb.Message.getFieldProto3(this, 3, ""));
};
/** @param {string} value */
proto.IdentifySessionMessage.prototype.setTitle = function(value) {
jspb.Message.setField(this, 3, value);
};
/**
* Generated by JsPbCodeGenerator.

View File

@ -3,4 +3,5 @@ syntax = "proto3";
// Sent when a shared process becomes active
message SharedProcessActiveMessage {
string socket_path = 1;
string log_path = 2;
}

View File

@ -7,6 +7,9 @@ export class SharedProcessActiveMessage extends jspb.Message {
getSocketPath(): string;
setSocketPath(value: string): void;
getLogPath(): string;
setLogPath(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): SharedProcessActiveMessage.AsObject;
static toObject(includeInstance: boolean, msg: SharedProcessActiveMessage): SharedProcessActiveMessage.AsObject;
@ -20,6 +23,7 @@ export class SharedProcessActiveMessage extends jspb.Message {
export namespace SharedProcessActiveMessage {
export type AsObject = {
socketPath: string,
logPath: string,
}
}

View File

@ -56,7 +56,8 @@ proto.SharedProcessActiveMessage.prototype.toObject = function(opt_includeInstan
*/
proto.SharedProcessActiveMessage.toObject = function(includeInstance, msg) {
var f, obj = {
socketPath: msg.getSocketPath()
socketPath: msg.getSocketPath(),
logPath: msg.getLogPath()
};
if (includeInstance) {
@ -97,6 +98,10 @@ proto.SharedProcessActiveMessage.deserializeBinaryFromReader = function(msg, rea
var value = /** @type {string} */ (reader.readString());
msg.setSocketPath(value);
break;
case 2:
var value = /** @type {string} */ (reader.readString());
msg.setLogPath(value);
break;
default:
reader.skipField();
break;
@ -142,6 +147,13 @@ proto.SharedProcessActiveMessage.prototype.serializeBinaryToWriter = function (w
f
);
}
f = this.getLogPath();
if (f.length > 0) {
writer.writeString(
2,
f
);
}
};
@ -169,4 +181,19 @@ proto.SharedProcessActiveMessage.prototype.setSocketPath = function(value) {
};
/**
* optional string log_path = 2;
* @return {string}
*/
proto.SharedProcessActiveMessage.prototype.getLogPath = function() {
return /** @type {string} */ (jspb.Message.getFieldProto3(this, 2, ""));
};
/** @param {string} value */
proto.SharedProcessActiveMessage.prototype.setLogPath = function(value) {
jspb.Message.setField(this, 2, value);
};
goog.object.extend(exports, proto);