Skip to content

Commit

Permalink
chore: rename style utils
Browse files Browse the repository at this point in the history
  • Loading branch information
chenasraf committed Nov 24, 2023
1 parent 058e6c8 commit 7306e08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/help.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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
}
Expand All @@ -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 = ''
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/color.ts → src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
}

0 comments on commit 7306e08

Please sign in to comment.