import Symbols from './Symbols';

class CommandLine {
  public write(results: ResultInterface[], level: number = 0): void {
    results.forEach((result) => {
      this.print(result.getTitle(), result.getStatus(), level);
      const r = result.getResults();

      if (r !== null) {
        this.write(r, level + 1);
      }
    });
  }

  public print(message: string, status: string, level: number): void {
    console.log('%s%s  %s', Array(level * 4).join(' '), this.getFormattedSymbol(status), message);
  }

  public getFormattedSymbol(status: string) {
    switch (status) {
      case 'SUCCESSFUL':
        return '\x1b[32m' + Symbols.success + '\x1b[0m';
      case 'UNSUCCESSFUL':
        return '\x1b[33m' + Symbols.warning + '\x1b[0m';
      case 'ERROR':
        return '\x1b[31m' + Symbols.error + '\x1b[0m';
    }
    return '\x1b[34m' + Symbols.info + '\x1b[0m';
  }
}

export default CommandLine;

import Symbols from './Symbols';

class CommandLine {
  public write(results: ResultInterface[], level: number = 0): void {
    results.forEach((result) => {
      const r = result.getResults();

      if ((r !== null && r.length > 0) || level > 0) {
        this.print(result.getTitle(), result.getStatus(), level);
      }

      if (r !== null) {
        this.write(r, level + 1);
      }
    });
  }

  public print(message: string, status: string, level: number): void {
    console.log('%s%s  %s', Array(level * 4).join(' '), this.getFormattedSymbol(status), message);
  }

  public getFormattedSymbol(status: string) {
    switch (status) {
      case 'SUCCESSFUL':
        return '\x1b[32m' + Symbols.success + '\x1b[0m';
      case 'UNSUCCESSFUL':
        return '\x1b[33m' + Symbols.warning + '\x1b[0m';
      case 'ERROR':
        return '\x1b[31m' + Symbols.error + '\x1b[0m';
    }
    return '\x1b[34m' + Symbols.info + '\x1b[0m';
  }
}

export default CommandLine;

Fix report when grep param is used
Fix report when grep param is used

If the user wanted to run just one or more tests from security,
the report also contained HTML successful message.
