How to use the @boost/terminal.screen.size function in @boost/terminal

To help you get started, we’ve selected a few @boost/terminal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github milesj / boost / packages / core / src / Output.ts View on Github external
// Mark first render
    if (this.state.first) {
      this.state.first = false;
      this.onFirst();
    }

    let content = this.toString(this.renderer());

    // Always end with a new line
    if (!content.endsWith('\n')) {
      content += '\n';
    }

    // Content cannot be higher than the terminal
    const lines = content.split('\n');
    const maxHeight = screen.size().rows - 1; // Buffer for input line

    if (lines.length >= maxHeight) {
      content = lines.slice(-maxHeight).join('\n');
    }

    // Write output
    this.console.out(content);

    // Mark output as complete if the final render
    if (this.isFinal()) {
      this.markComplete();

      // Otherwise calculate the height of the output
    } else {
      this.previousHeight = lines.length;
    }
github milesj / boost / packages / core / src / outputs / ProgressOutput.ts View on Github external
const percent = Math.floor(progress * 100);
    const elapsed = Date.now() - this.startTime;
    const estimated = percent === 100 ? 0 : elapsed * (total / current - 1);
    const rate = current / (elapsed / 1000);
    const partialTemplate = template
      .replace('{progress}', `${current}/${total}`)
      .replace('{current}', String(current))
      .replace('{elapsed}', formatMs(elapsed))
      .replace('{estimated}', formatMs(estimated))
      .replace('{percent}', `${percent.toFixed(0)}%`)
      .replace('{rate}', String(rate.toFixed(2)))
      .replace('{total}', String(total));

    // Render the progress bar
    const currentWidth = partialTemplate.replace('{bar}', '').length;
    const remainingWidth = screen.size().columns - currentWidth;
    const completed = Math.round(remainingWidth * progress);
    const [complete, incomplete] = STYLES[styleName];
    let bar = [
      complete.repeat(Math.max(0, completed)),
      (transparent ? ' ' : incomplete).repeat(Math.max(0, remainingWidth - completed)),
    ].join('');

    if (color) {
      if (percent >= 90) {
        bar = style.green(bar);
      } else if (percent >= 45) {
        bar = style.yellow(bar);
      } else {
        bar = style.red(bar);
      }
    }
github milesj / boost / packages / core / src / Reporter.ts View on Github external
size(): { columns: number; rows: number } {
    return screen.size();
  }