@@ -36,10 +36,7 @@ export class Commands {
3636 /**
3737 * Create and run command in a new shell. Allows you to listen to the output and kill the command.
3838 */
39- async runBackground (
40- command : string | string [ ] ,
41- opts ?: Omit < ShellRunOpts , "name" >
42- ) {
39+ async runBackground ( command : string | string [ ] , opts ?: ShellRunOpts ) {
4340 const disposableStore = new DisposableStore ( ) ;
4441 const onOutput = new Emitter < string > ( ) ;
4542 disposableStore . add ( onOutput ) ;
@@ -67,15 +64,24 @@ export class Commands {
6764 true
6865 ) ;
6966
67+ const details = {
68+ type : "command" ,
69+ command,
70+ name : opts ?. name ,
71+ } ;
72+
7073 // Only way for us to differentiate between a command and a terminal
7174 this . pitcherClient . clients . shell . rename (
7275 shell . shellId ,
73- `COMMAND-${ shell . shellId } `
76+ // We embed some details in the name to properly show the command that was run
77+ // , the name and that it is an actual command
78+ JSON . stringify ( details )
7479 ) ;
7580
7681 const cmd = new Command (
7782 this . pitcherClient ,
78- shell as protocol . shell . CommandShellDTO
83+ shell as protocol . shell . CommandShellDTO ,
84+ details
7985 ) ;
8086
8187 return cmd ;
@@ -98,10 +104,24 @@ export class Commands {
98104
99105 return shells
100106 . filter (
101- ( shell ) =>
102- shell . shellType === "TERMINAL" && shell . name . startsWith ( "COMMAND-" )
107+ ( shell ) => shell . shellType === "TERMINAL" && isCommandShell ( shell )
103108 )
104- . map ( ( shell ) => new Command ( this . pitcherClient , shell ) ) ;
109+ . map (
110+ ( shell ) =>
111+ new Command ( this . pitcherClient , shell , JSON . parse ( shell . name ) )
112+ ) ;
113+ }
114+ }
115+
116+ export function isCommandShell (
117+ shell : protocol . shell . ShellDTO
118+ ) : shell is protocol . shell . CommandShellDTO {
119+ try {
120+ const parsed = JSON . parse ( shell . name ) ;
121+
122+ return parsed . type === "command" ;
123+ } catch {
124+ return false ;
105125 }
106126}
107127
@@ -133,10 +153,24 @@ export class Command {
133153 */
134154 status : CommandStatus = "RUNNING" ;
135155
156+ /**
157+ * The command that was run
158+ */
159+ command : string ;
160+
161+ /**
162+ * The name of the command
163+ */
164+ name ?: string ;
165+
136166 constructor (
137167 private pitcherClient : IPitcherClient ,
138- private shell : protocol . shell . ShellDTO & { buffer ?: string [ ] }
168+ private shell : protocol . shell . ShellDTO & { buffer ?: string [ ] } ,
169+ details : { command : string ; name ?: string }
139170 ) {
171+ this . command = details . command ;
172+ this . name = details . name ;
173+
140174 this . disposable . addDisposable (
141175 pitcherClient . clients . shell . onShellExited ( ( { shellId, exitCode } ) => {
142176 if ( shellId === this . shell . shellId ) {
@@ -171,6 +205,20 @@ export class Command {
171205 ) ;
172206 }
173207
208+ /**
209+ * Open the command and get its current output, subscribes to future output
210+ */
211+ async open ( dimensions = DEFAULT_SHELL_SIZE ) : Promise < string > {
212+ const shell = await this . pitcherClient . clients . shell . open (
213+ this . shell . shellId ,
214+ dimensions
215+ ) ;
216+
217+ this . output = shell . buffer ;
218+
219+ return this . output . join ( "\n" ) ;
220+ }
221+
174222 /**
175223 * Wait for the command to finish with its returned output
176224 */
0 commit comments