π File detail
ink/hooks/use-terminal-title.ts
π§© .tsπ 32 linesπΎ 1,020 bytesπ text
β Back to All Filesπ― Use case
This file lives under βink/β, which covers Ink terminal UI (layouts, TTY IO, keyboard, renderer components). On the API surface it exposes useTerminalTitle β mainly functions, hooks, or classes. Dependencies touch React UI and strip-ansi. It composes internal code from termio and useTerminalNotification (relative imports).
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
import { useContext, useEffect } from 'react' import stripAnsi from 'strip-ansi' import { OSC, osc } from '../termio/osc.js' import { TerminalWriteContext } from '../useTerminalNotification.js'
π€ Exports (heuristic)
useTerminalTitle
π External import roots
Package roots from from "β¦" (relative paths omitted).
reactstrip-ansi
π₯οΈ Source preview
import { useContext, useEffect } from 'react'
import stripAnsi from 'strip-ansi'
import { OSC, osc } from '../termio/osc.js'
import { TerminalWriteContext } from '../useTerminalNotification.js'
/**
* Declaratively set the terminal tab/window title.
*
* Pass a string to set the title. ANSI escape sequences are stripped
* automatically so callers don't need to know about terminal encoding.
* Pass `null` to opt out β the hook becomes a no-op and leaves the
* terminal title untouched.
*
* On Windows, uses `process.title` (classic conhost doesn't support OSC).
* Elsewhere, writes OSC 0 (set title+icon) via Ink's stdout.
*/
export function useTerminalTitle(title: string | null): void {
const writeRaw = useContext(TerminalWriteContext)
useEffect(() => {
if (title === null || !writeRaw) return
const clean = stripAnsi(title)
if (process.platform === 'win32') {
process.title = clean
} else {
writeRaw(osc(OSC.SET_TITLE_AND_ICON, clean))
}
}, [title, writeRaw])
}