/ opencodehub / cli / src / lib / formatter.ts
swadhinbiswas docs: complete documentation overhaul and changelog update · 1/21/2026
bba9bff
79 lines · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * Message Formatter - Boxed messages and tables
 */

import boxen from "boxen";
import chalk from "chalk";

/**
 * Create a success box
 */
export function successBox(title: string, content: string[]): void {
    const text = [
        chalk.green.bold(title),
        "",
        ...content.map(line => chalk.white(line)),
    ].join("\n");

    console.log(boxen(text, {
        padding: 1,
        margin: 1,
        borderStyle: "round",
        borderColor: "green",
    }));
}

/**
 * Create an error box  
 */
export function errorBox(title: string, content: string[]): void {
    const text = [
        chalk.red.bold(title),
        "",
        ...content.map(line => chalk.white(line)),
    ].join("\n");

    console.log(boxen(text, {
        padding: 1,
        margin: 1,
        borderStyle: "round",
        borderColor: "red",
    }));
}

/**
 * Create an info box
 */
export function infoBox(title: string, content: string[]): void {
    const text = [
        chalk.cyan.bold(title),
        "",
        ...content.map(line => chalk.white(line)),
    ].join("\n");

    console.log(boxen(text, {
        padding: 1,
        margin: 1,
        borderStyle: "round",
        borderColor: "cyan",
    }));
}

/**
 * Create a warning box
 */
export function warningBox(title: string, content: string[]): void {
    const text = [
        chalk.yellow.bold(title),
        "",
        ...content.map(line => chalk.white(line)),
    ].join("\n");

    console.log(boxen(text, {
        padding: 1,
        margin: 1,
        borderStyle: "round",
        borderColor: "yellow",
    }));
}