mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
feat: fork ink and make it work nicely
This commit is contained in:
parent
cb79018977
commit
8760faf991
139 changed files with 24952 additions and 140 deletions
44
ui-tui/packages/hermes-ink/src/ink/tabstops.ts
Normal file
44
ui-tui/packages/hermes-ink/src/ink/tabstops.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue