| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  | import * as plugins from './smartshell.plugins'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * a log handler for spawned logs | 
					
						
							|  |  |  |  * making sure the process doesn't run out of memory | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export class ShellLog { | 
					
						
							| 
									
										
										
										
											2019-05-28 10:43:54 +02:00
										 |  |  |   public logStore = Buffer.from(''); | 
					
						
							| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * log data to console | 
					
						
							| 
									
										
										
										
											2018-07-30 16:08:14 +02:00
										 |  |  |    * @param dataArg | 
					
						
							| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2019-05-28 10:43:54 +02:00
										 |  |  |   public writeToConsole(dataArg: string | Buffer): void { | 
					
						
							| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  |     // make sure we have the data as string
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:50:32 +01:00
										 |  |  |     process.stdout.write(dataArg); | 
					
						
							| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * add data to Buffer for later consumption | 
					
						
							|  |  |  |    * @param dataArg | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2019-05-28 10:43:54 +02:00
										 |  |  |   public addToBuffer(dataArg: string | Buffer): void { | 
					
						
							| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  |     // make sure we have the data as Buffer
 | 
					
						
							|  |  |  |     const dataBuffer: Buffer = (() => { | 
					
						
							|  |  |  |       if (!Buffer.isBuffer(dataArg)) { | 
					
						
							|  |  |  |         return Buffer.from(dataArg); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return dataArg; | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2018-07-30 16:08:14 +02:00
										 |  |  |     this.logStore = Buffer.concat([this.logStore, dataBuffer]); | 
					
						
							| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 10:43:54 +02:00
										 |  |  |   public logAndAdd(dataArg: string | Buffer): void { | 
					
						
							|  |  |  |     this.writeToConsole(dataArg); | 
					
						
							| 
									
										
										
										
											2018-07-30 16:03:48 +02:00
										 |  |  |     this.addToBuffer(dataArg); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-30 16:08:14 +02:00
										 |  |  | } |