Skip to content

Commit be9a442

Browse files
committed
feat(terminal): introduce terminal package with session management and UI components
- Added TerminalSession class for managing terminal sessions and handling input/output. - Implemented TerminalView component for rendering terminal UI using xterm.js. - Created utility functions for path normalization and hidden command formatting. - Established state management with Jotai atoms for terminal sessions. - Defined types for terminal session management and capabilities. - Included CSS modules for terminal styling. - Configured TypeScript and build settings for the new terminal package.
1 parent e655d66 commit be9a442

21 files changed

Lines changed: 211 additions & 27 deletions

packages/terminal/package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "@dotdirfm/terminal",
3+
"version": "0.1.0",
4+
"description": "Terminal session and xterm.js terminal React component for DotDir.",
5+
"type": "module",
6+
"main": "./dist/index.cjs",
7+
"module": "./dist/index.mjs",
8+
"types": "./dist/index.d.mts",
9+
"files": [
10+
"dist"
11+
],
12+
"sideEffects": [
13+
"**/*.css"
14+
],
15+
"exports": {
16+
".": {
17+
"import": "./dist/index.mjs",
18+
"require": "./dist/index.cjs",
19+
"types": "./dist/index.d.mts"
20+
},
21+
"./terminal.css": {
22+
"import": "./dist/terminal.css"
23+
}
24+
},
25+
"scripts": {
26+
"build": "tsdown",
27+
"dev": "tsdown --watch",
28+
"test": "vitest run",
29+
"typecheck": "tsc --noEmit"
30+
},
31+
"keywords": [
32+
"dotdir",
33+
"terminal",
34+
"xterm",
35+
"pty",
36+
"react"
37+
],
38+
"author": "Mikhail Isupov",
39+
"license": "ISC",
40+
"repository": {
41+
"type": "git",
42+
"url": "git+https://github.com/dotdirfm/dotdir.git"
43+
},
44+
"homepage": "https://github.com/dotdirfm/dotdir#readme",
45+
"bugs": {
46+
"url": "https://github.com/dotdirfm/dotdir/issues"
47+
},
48+
"publishConfig": {
49+
"access": "public"
50+
},
51+
"peerDependencies": {
52+
"react": "^19.0.0"
53+
},
54+
"dependencies": {
55+
"@dotdirfm/commands": "workspace:*",
56+
"@dotdirfm/ui-bridge": "workspace:*",
57+
"@dotdirfm/ui-focus": "workspace:*",
58+
"@dotdirfm/ui-utils": "workspace:*",
59+
"@xterm/addon-fit": "catalog:",
60+
"@xterm/xterm": "catalog:",
61+
"jotai": "catalog:"
62+
},
63+
"devDependencies": {
64+
"@tsdown/css": "catalog:",
65+
"@types/react": "catalog:",
66+
"tsdown": "catalog:",
67+
"typescript": "catalog:",
68+
"vitest": "^4.1.5"
69+
},
70+
"packageManager": "pnpm@10.30.3"
71+
}
File renamed without changes.

packages/ui/lib/features/terminal/TerminalView.tsx renamed to packages/terminal/src/TerminalView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCommandRegistry } from "@dotdirfm/commands";
22
import { DOTDIR_EXIT, SHOW_COMMAND_PALETTE, SHOW_EXTENSIONS, TOGGLE_HIDDEN_FILES, TOGGLE_PANELS } from "@dotdirfm/commands";
33
import { useFocusContext } from "@dotdirfm/ui-focus";
4-
import styles from "@/styles/terminal.module.css";
4+
import styles from "./terminal.module.css";
55
import { FitAddon } from "@xterm/addon-fit";
66
import { Terminal, type IDisposable } from "@xterm/xterm";
77
import "@xterm/xterm/css/xterm.css";
@@ -102,7 +102,7 @@ export function TerminalView({ session, expanded = false, focusRequestKey = 0 }:
102102
const w = body.clientWidth;
103103
const h = body.clientHeight;
104104
const last = lastFitSizeRef.current;
105-
if (last.w === w && last.h === h) return;
105+
if (last.w === last.h && last.h === h) return;
106106
lastFitSizeRef.current = { w, h };
107107
fit.fit();
108108
void session.resize(Math.max(2, term.cols), Math.max(1, term.rows));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module "*.module.css" {
2+
const classes: Record<string, string>;
3+
export default classes;
4+
}
5+
6+
declare module "*.css" {
7+
const content: string;
8+
export default content;
9+
}

packages/terminal/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export { TerminalSession } from "./TerminalSession";
2+
export { TerminalView } from "./TerminalView";
3+
export { normalizeTerminalPath, formatHiddenCd } from "./path";
4+
export { terminalSessionsAtom, terminalActiveSessionIdAtom } from "./terminalAtoms";
5+
export type {
6+
ManagedTerminalSession,
7+
PtyLaunchInfo,
8+
TerminalCapabilities,
9+
TerminalSessionEvent,
10+
TerminalSessionStatus,
11+
} from "./types";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.terminal-container {
2+
flex: 1 1 auto;
3+
min-height: 0;
4+
width: 100%;
5+
overflow: hidden;
6+
}
7+
8+
.terminal-container :global(.xterm) {
9+
height: 100%;
10+
padding: 0 0 0 4px;
11+
display: grid;
12+
padding-bottom: 1px;
13+
}
14+
15+
.terminal-container :global(.xterm-viewport) {
16+
height: 100% !important;
17+
overflow-y: auto !important;
18+
}
19+
20+
.terminal-container :global(.xterm .xterm-viewport) {
21+
position: absolute !important;
22+
top: 0 !important;
23+
bottom: 0 !important;
24+
left: 0 !important;
25+
right: 0 !important;
26+
}
File renamed without changes.
File renamed without changes.

packages/terminal/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "Bundler",
6+
"jsx": "react-jsx",
7+
"strict": true,
8+
"skipLibCheck": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
11+
"noFallthroughCasesInSwitch": true
12+
},
13+
"include": ["src"]
14+
}

0 commit comments

Comments
 (0)