chore: rename style utils

This commit is contained in:
2023-11-24 15:52:36 +02:00
committed by Chen Asraf
parent edbde02618
commit 1b486c65b9
2 changed files with 6 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import z from 'zod'
import { format, StringStyle, stripColors } from './color'
import { format, StringStyle, stripStyle } from './style'
import { MassargCommand } from './command'
import { DeepRequired, strConcat, indent } from './utils'
@@ -242,7 +242,7 @@ export class HelpGenerator {
}
function wrap(text: string, maxRowLength: number): string {
const length = stripColors(text).length
const length = stripStyle(text).length
if (length <= maxRowLength) {
return text
}
@@ -251,7 +251,7 @@ function wrap(text: string, maxRowLength: number): string {
let currentRow = ''
for (const word of words) {
if (stripColors(currentRow).length + stripColors(word).length + 1 > maxRowLength) {
if (stripStyle(currentRow).length + stripStyle(word).length + 1 > maxRowLength) {
subRows.push(currentRow)
currentRow = ''
}
@@ -288,7 +288,7 @@ function generateHelpTable<T extends Partial<GenerateTableCommandConfig>>(
const table = rows.map((row) => {
const name = nameStyle(row.name.padEnd(maxNameLength + 2))
const description = descStyle(row.description)
const length = stripColors(name).length + stripColors(description).length
const length = stripStyle(name).length + stripStyle(description).length
if (length <= maxRowLength) {
const line = `${name}${description}`
if (!compact) {
@@ -301,7 +301,7 @@ function generateHelpTable<T extends Partial<GenerateTableCommandConfig>>(
let currentRow = name
for (const word of words) {
if (stripColors(currentRow).length + stripColors(word).length + 1 > maxRowLength) {
if (stripStyle(currentRow).length + stripStyle(word).length + 1 > maxRowLength) {
subRows.push(currentRow)
currentRow = ' '.repeat(maxNameLength + 2)
}

View File

@@ -45,6 +45,6 @@ export function format(string: string, style: StringStyle = {}): string {
return `${colorCode}${boldCode}${underlineCode}${string}${resetCode}`
}
export function stripColors(string: string): string {
export function stripStyle(string: string): string {
return string.replace(/\x1b\[\d+m/gi, '')
}