跳到主要内容
知仓学习社ZHICANG

cli-progress-bar-setup

Configure cli-progress with custom formatters, multi-bar support, and ETA calculations for CLI progress indication.

不碰外部(只输出文字)无严重或高危命中a5c-ai/babysitter

它会碰到什么

扫了多少2 个文本文件,6 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

CLI Progress Bar Setup

Configure cli-progress for advanced progress indication.

Capabilities

  • Configure single and multi-bar progress
  • Create custom bar formatters
  • Set up ETA calculations
  • Implement payload data display
  • Create progress bar presets
  • Generate progress utilities

Usage

Invoke this skill when you need to:

  • Show download/upload progress
  • Display multi-task progress
  • Create custom progress formats
  • Implement ETA calculations

Inputs

| Parameter | Type | Required | Description |

|-----------|------|----------|-------------|

| language | string | Yes | Target language |

| format | string | No | Bar format template |

| presets | array | No | Progress bar presets |

Generated Patterns

TypeScript Progress Utilities

import cliProgress, { SingleBar, MultiBar, Presets } from 'cli-progress';
import chalk from 'chalk';

// Custom format with colors
const defaultFormat = chalk.cyan('{bar}') +
  ' {percentage}% | ETA: {eta}s | {value}/{total} | {filename}';

// Create single progress bar
export function createProgressBar(options?: {
  format?: string;
  barSize?: number;
}): SingleBar {
  return new SingleBar({
    format: options?.format || defaultFormat,
    barCompleteChar: '\u2588',
    barIncompleteChar: '\u2591',
    barsize: options?.barSize || 40,
    hideCursor: true,
    clearOnComplete: false,
    stopOnComplete: true,
  }, Presets.shades_classic);
}

// Multi-bar for parallel tasks
export function createMultiBar(): MultiBar {
  return new MultiBar({
    format: '{name} |' + chalk.cyan('{bar}') + '| {percentage}% | {value}/{total}',
    barCompleteChar: '\u2588',
    barIncompleteChar: '\u2591',
    hideCursor: true,
    clearOnComplete: false,
    stopOnComplete: false,
  }, Presets.shades_grey);
}

// Download progress with speed
export function createDownloadBar(): SingleBar {
  return new SingleBar({
    format: 'Downloading |' + chalk.cyan('{bar}') +
      '| {percentage}% | {speed} MB/s | {value}/{total} MB',
    barCompleteChar: '\u2588',
    barIncompleteChar: '\u2591',
    barsize: 30,
    formatValue: (value, options, type) => {
      if (type === 'value' || type === 'total') {
        return (value / 1024 / 1024).toFixed(2);
      }
      return String(value);
    },
  }, Presets.shades_classic);
}

// Wrapper for async operations
export async function withProgress<T>(
  total: number,
  fn: (update: (current: number, payload?: Record<string, any>) => void) => Promise<T>,
  options?: { format?: string }
): Promise<T> {
  const bar = createProgressBar(options);
  bar.start(total, 0);

  try {
    const result = await fn((current, payload) => {
      bar.update(current, payload);
    });
    bar.stop();
    return result;
  } catch (error) {
    bar.stop();
    throw error;
  }
}

// Batch processing with progress
export async function processBatch<T, R>(
  items: T[],
  processor: (item: T, index: number) => Promise<R>,
  options?: { label?: string }
): Promise<R[]> {
  const bar = createProgressBar({
    format: `${options?.label || 'Processing'} |{bar}| {percentage}% | {value}/{total}`,
  });

  bar.start(items.length, 0);
  const results: R[] = [];

  for (let i = 0; i < items.length; i++) {
    results.push(await processor(items[i], i));
    bar.update(i + 1);
  }

  bar.stop();
  return results;
}

// Parallel processing with multi-bar
export async function processParallel<T, R>(
  tasks: Array<{
    name: string;
    items: T[];
    processor: (item: T) => Promise<R>;
  }>
): Promise<Map<string, R[]>> {
  const multiBar = createMultiBar();
  const bars = new Map<string, SingleBar>();
  const results = new Map<string, R[]>();

  // Create bars for each task
  for (const task of tasks) {
    const bar = multiBar.create(task.items.length, 0, { name: task.name.padEnd(15) });
    bars.set(task.name, bar);
    results.set(task.name, []);
  }

  // Process all tasks in parallel
  await Promise.all(tasks.map(async (task) => {
    const bar = bars.get(task.name)!;
    const taskResults = results.get(task.name)!;

    for (let i = 0; i < task.items.length; i++) {
      taskResults.push(await task.processor(task.items[i]));
      bar.update(i + 1);
    }
  }));

  multiBar.stop();
  return results;
}

Dependencies

{
  "dependencies": {
    "cli-progress": "^3.12.0",
    "chalk": "^5.0.0"
  },
  "devDependencies": {
    "@types/cli-progress": "^3.11.0"
  }
}

Target Processes

  • progress-status-indicators
  • cli-output-formatting
  • cli-application-bootstrap

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 1,796
本站分层T1
该仓技能数2115
原文件路径library/specializations/cli-mcp-development/skills/cli-progress-bar-setup/SKILL.md

同一个仓库里的其他技能

看这个仓库的全部 2115 个技能