feat(v0.2): tab title = current folder (from OSC title)
- title-util.ts: folderFromTitle() parses 'user@host:~/path' → last folder segment (home stays ~); pure, dependency-free, 7 unit tests - terminal-session.ts: onTitleChange → folderFromTitle so the tab auto-names to the cwd folder and updates live on cd - Browser-verified: ~ → cd project → 'web-terminal' → cd docs → 'docs' → cd ~ → '~'. 198 tests green, typecheck + build ok.
This commit is contained in:
33
test/title-util.test.ts
Normal file
33
test/title-util.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { folderFromTitle } from '../public/title-util.js'
|
||||
|
||||
describe('folderFromTitle', () => {
|
||||
it('extracts the folder from user@host:~/path', () => {
|
||||
expect(folderFromTitle('yiukai@Mac:~/Documents/git/web-terminal')).toBe('web-terminal')
|
||||
})
|
||||
|
||||
it('keeps ~ for the home directory', () => {
|
||||
expect(folderFromTitle('yiukai@Yiukais-MacBook-Pro:~')).toBe('~')
|
||||
})
|
||||
|
||||
it('takes the basename of an absolute path', () => {
|
||||
expect(folderFromTitle('user@host:/Users/yiukai/web')).toBe('web')
|
||||
})
|
||||
|
||||
it('strips a trailing slash', () => {
|
||||
expect(folderFromTitle('user@host:~/web/')).toBe('web')
|
||||
})
|
||||
|
||||
it('handles a title with no user@host: prefix', () => {
|
||||
expect(folderFromTitle('web-terminal')).toBe('web-terminal')
|
||||
})
|
||||
|
||||
it('returns the last path segment when the whole title is a path', () => {
|
||||
expect(folderFromTitle('/var/log/nginx')).toBe('nginx')
|
||||
})
|
||||
|
||||
it('returns null for an empty/whitespace title', () => {
|
||||
expect(folderFromTitle(' ')).toBeNull()
|
||||
expect(folderFromTitle('')).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user