import { CommandInterface } from '../Commands' ; import { Variables } from './Variables' ; import { Variable } from './Variable' ; export class Scope extends Variable { constructor ( name ) { super ( ) ; this . _name = name ; Variables . addReferenceTo ( this ) ; } public typename ( ) { return 'scope' ; } public extendedTypename ( ) { return this . typename ( ) ; } public loads ( type ) { return false ; } public loadNew ( name , type , runtime , callback ) { } private static readonly HEADER_REGEX = /^\s*Variables .* the current scope:$/ ; private static readonly SPACE_REGEX = /\s+/ ; public listChildren ( runtime , count , start , callback ) { let matchesHeader = false ; let vars = '' ; runtime . evaluate ( `who ${ this . name ( ) }` , ( output ) => { output . forEach ( line => { if ( matchesHeader ) { vars += ' ' + line ; } else if ( line . match ( Scope . HEADER_REGEX ) !== null ) { matchesHeader = true ; } } ) ; if ( vars . length !== 0 ) { const names = vars . trim ( ) . split ( Scope . SPACE_REGEX ) . sort ( ) ; Variables . listVariables ( names , runtime , callback ) ; } else { callback ( new Array < Variable > ( ) ) ; } } ) ; } }