Something went wrong. Try again.
source dump of claude code forked from oppi.li/claude-code
Something went wrong. Try again.
1.1 kB · 46 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647// Tab expansion, inspired by Ghostty's Tabstops.zig// Uses 8-column intervals (POSIX default, hardcoded in terminals like Ghostty)
import { stringWidth } from './stringWidth.js'import { createTokenizer } from './termio/tokenize.js'
const DEFAULT_TAB_INTERVAL = 8
export function expandTabs( text: string, interval = DEFAULT_TAB_INTERVAL,): string { if (!text.includes('\t')) { return text }
const tokenizer = createTokenizer() const tokens = tokenizer.feed(text) tokens.push(...tokenizer.flush())
let result = '' let column = 0
for (const token of tokens) { if (token.type === 'sequence') { result += token.value } else { const parts = token.value.split(/(\t|\n)/) for (const part of parts) { if (part === '\t') { const spaces = interval - (column % interval) result += ' '.repeat(spaces) column += spaces } else if (part === '\n') { result += part column = 0 } else { result += part column += stringWidth(part) } } } }
return result}