@celljs/ta-workspace 0.0.0-stage → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -2
- package/package.json +39 -4
- package/web/index.js +7289 -0
- package/web-src/browser.tsx +240 -0
- package/web-src/common.tsx +296 -0
- package/web-src/editors.tsx +471 -0
- package/web-src/explorer.tsx +479 -0
- package/web-src/file-icon.tsx +21 -0
- package/web-src/host.ts +121 -0
- package/web-src/i18n.ts +320 -0
- package/web-src/index.tsx +65 -0
- package/web-src/open-files.tsx +80 -0
- package/web-src/preview.tsx +132 -0
- package/web-src/react.ts +8 -0
- package/web-src/scm.tsx +388 -0
- package/web-src/search.tsx +485 -0
- package/web-src/style.ts +225 -0
- package/web-src/terminal.tsx +350 -0
- package/web-src/util/ansi.spec.ts +66 -0
- package/web-src/util/ansi.ts +438 -0
- package/web-src/util/file-icon.spec.ts +35 -0
- package/web-src/util/file-icon.ts +23 -0
- package/web-src/util/git.ts +203 -0
- package/web-src/util/keys.ts +56 -0
- package/web-src/util/preview.spec.ts +48 -0
- package/web-src/util/preview.ts +90 -0
- package/web-src/util/search.spec.ts +164 -0
- package/web-src/util/search.ts +274 -0
- package/web-src/util/seti-font.ts +6 -0
- package/web-src/util/seti.ts +761 -0
- package/web-src/util/workspace.spec.ts +191 -0
- package/web-src/util/workspace.ts +331 -0
- package/web-src/workspace-client.ts +119 -0
package/web-src/style.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { SETI_FONT } from './util/seti-font';
|
|
2
|
+
|
|
3
|
+
/** The styles of the views; only the --ta-* variables of the page, so they follow its theme. */
|
|
4
|
+
export const STYLE = `
|
|
5
|
+
.taw-view { --taw-git-added: var(--ta-green); --taw-git-deleted: var(--ta-red); --taw-git-modified: var(--ta-yellow); --taw-git-conflict: #e4676b; position: relative; display: flex; flex-direction: column; height: 100%; min-height: 0; color: var(--ta-text); font-size: 13px; }
|
|
6
|
+
:root[data-theme='light'] .taw-view { --taw-git-modified: #b8860b; --taw-git-conflict: #ad0707; }
|
|
7
|
+
.taw-view-head { display: flex; align-items: center; gap: 4px; height: 30px; padding: 0 8px 0 12px; flex: none; }
|
|
8
|
+
.taw-view-title { flex: 1; min-width: 0; font-size: 12px; font-weight: 600; color: var(--ta-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
9
|
+
.taw-actions { display: flex; gap: 2px; }
|
|
10
|
+
.taw-action { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex: none; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--ta-muted); cursor: pointer; }
|
|
11
|
+
.taw-action:hover:not(:disabled) { background: var(--ta-hover); color: var(--ta-text); }
|
|
12
|
+
.taw-action:disabled { opacity: 0.4; cursor: default; }
|
|
13
|
+
.taw-action.taw-on { background: var(--ta-selected); color: var(--ta-text); }
|
|
14
|
+
.taw-action:focus-visible, .taw-row:focus-visible, .taw-row-main:focus-visible, .taw-button:focus-visible { outline: 1px solid var(--ta-border-focus); outline-offset: -1px; }
|
|
15
|
+
.taw-list { flex: 1; min-height: 0; overflow: auto; padding: 0 4px 12px; }
|
|
16
|
+
.taw-row { position: relative; display: flex; align-items: center; gap: 6px; width: 100%; height: 24px; padding: 0 6px 0 8px; border: 0; border-radius: 6px; background: none; color: var(--ta-body); font: inherit; text-align: left; cursor: pointer; user-select: none; outline: none; }
|
|
17
|
+
.taw-row:hover { background: var(--ta-hover); }
|
|
18
|
+
.taw-row.taw-selected { background: var(--ta-selected); color: var(--ta-text); }
|
|
19
|
+
.taw-row:focus-visible { box-shadow: inset 0 0 0 1px var(--ta-border-focus); }
|
|
20
|
+
.taw-row > svg { flex: none; color: var(--ta-muted); }
|
|
21
|
+
.taw-row-actions { display: none; align-items: center; gap: 0; flex: none; margin-left: auto; }
|
|
22
|
+
.taw-row-actions .taw-action { width: 22px; height: 22px; border-radius: 5px; }
|
|
23
|
+
.taw-row:hover .taw-row-actions, .taw-row:focus-within .taw-row-actions, .taw-section-head:hover .taw-row-actions, .taw-section-head:focus-within .taw-row-actions { display: flex; }
|
|
24
|
+
.taw-row-actions + .taw-letter, .taw-row-actions + .taw-badge { margin-left: 4px; }
|
|
25
|
+
.taw-row:not(:hover):not(:focus-within) .taw-row-actions + .taw-letter, .taw-row:not(:hover):not(:focus-within) .taw-row-actions + .taw-badge { margin-left: auto; }
|
|
26
|
+
.taw-row.taw-selected .taw-row-actions.taw-keep { display: flex; }
|
|
27
|
+
.taw-ignored { opacity: 0.5; }
|
|
28
|
+
.taw-deleted .taw-name { text-decoration: line-through; }
|
|
29
|
+
.taw-tree-row { padding-right: 10px; }
|
|
30
|
+
.taw-guides { position: absolute; inset: 0; pointer-events: none; }
|
|
31
|
+
.taw-guide { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--ta-border); opacity: 0; transition: opacity 120ms; }
|
|
32
|
+
.taw-tree:hover .taw-guide { opacity: 1; }
|
|
33
|
+
.taw-editing { cursor: default; background: none !important; }
|
|
34
|
+
.taw-name-input { position: relative; flex: 1; min-width: 0; display: flex; }
|
|
35
|
+
.taw-input.taw-inline { height: 22px; padding: 0 4px; border-radius: 4px; font-size: 13px; }
|
|
36
|
+
.taw-input.taw-inline.taw-error { border-color: var(--ta-red); }
|
|
37
|
+
.taw-input.taw-inline.taw-warning { border-color: var(--ta-yellow); }
|
|
38
|
+
.taw-input-message { padding: 4px 6px; border-radius: 4px; font-size: 12px; line-height: 1.4; white-space: normal; }
|
|
39
|
+
.taw-name-input .taw-input-message { position: absolute; z-index: 5; top: 100%; left: 0; right: 0; margin-top: 1px; box-shadow: var(--ta-shadow-pop); }
|
|
40
|
+
.taw-input-message.taw-error { background: color-mix(in srgb, var(--ta-red) 16%, var(--ta-card)); border: 1px solid var(--ta-red); color: var(--ta-text); }
|
|
41
|
+
.taw-input-message.taw-warning { background: color-mix(in srgb, var(--ta-yellow) 16%, var(--ta-card)); border: 1px solid var(--ta-yellow); color: var(--ta-text); }
|
|
42
|
+
.taw-menu { position: fixed; z-index: 80; min-width: 210px; max-width: 320px; display: flex; flex-direction: column; gap: 1px; padding: 6px; border-radius: 12px; border: 1px solid var(--ta-border); background: var(--ta-side); box-shadow: var(--ta-shadow-pop); animation: taw-fade 100ms ease-out; }
|
|
43
|
+
.taw-menu-item { display: flex; align-items: center; justify-content: space-between; gap: 24px; flex: none; height: 30px; padding: 0 10px; border: 0; border-radius: 8px; background: none; color: var(--ta-text); font: inherit; font-size: 13px; text-align: left; cursor: pointer; outline: none; }
|
|
44
|
+
.taw-menu-item:hover:not(:disabled), .taw-menu-item:focus-visible { background: var(--ta-hover); }
|
|
45
|
+
.taw-menu-item:disabled { opacity: 0.45; cursor: default; }
|
|
46
|
+
.taw-menu-item kbd { font-family: inherit; font-size: 12px; color: var(--ta-muted); }
|
|
47
|
+
.taw-menu-line { flex: none; height: 1px; margin: 5px 8px; border: 0; background: var(--ta-border-muted); }
|
|
48
|
+
@keyframes taw-fade { from { opacity: 0; } }
|
|
49
|
+
.taw-section-head { display: flex; align-items: center; gap: 4px; height: 26px; margin-top: 6px; padding-right: 6px; border-radius: 6px; }
|
|
50
|
+
.taw-section-head:hover { background: var(--ta-hover); }
|
|
51
|
+
.taw-section-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; height: 100%; padding: 0 0 0 4px; border: 0; background: none; color: var(--ta-secondary); font: inherit; font-size: 12px; font-weight: 600; text-align: left; cursor: pointer; }
|
|
52
|
+
.taw-section-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
53
|
+
.taw-badge { flex: none; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--ta-chip); color: var(--ta-secondary); font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }
|
|
54
|
+
.taw-twisty { display: inline-flex; width: 14px; flex: none; color: var(--ta-muted); }
|
|
55
|
+
.taw-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
56
|
+
.taw-detail { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-muted); font-size: 12px; }
|
|
57
|
+
.taw-count { margin-left: auto; padding: 0 6px; border-radius: 8px; background: var(--ta-chip); color: var(--ta-secondary); font-size: 11px; line-height: 16px; }
|
|
58
|
+
.taw-letter { margin-left: auto; width: 14px; flex: none; text-align: center; font-size: 12px; font-weight: 600; }
|
|
59
|
+
.taw-group { display: flex; align-items: center; gap: 6px; margin: 8px 0 2px; padding: 0 8px; font-size: 11px; font-weight: 600; color: var(--ta-secondary); }
|
|
60
|
+
.taw-empty { padding: 12px; color: var(--ta-muted); font-size: 12px; line-height: 1.6; }
|
|
61
|
+
.taw-empty p { margin: 0 0 8px; }
|
|
62
|
+
.taw-error { color: var(--ta-red); }
|
|
63
|
+
.taw-note { color: var(--ta-muted); font-size: 12px; }
|
|
64
|
+
.taw-pad { padding: 8px; margin: 0; line-height: 1.6; }
|
|
65
|
+
.taw-button { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--ta-border); border-radius: 6px; background: var(--ta-card); color: var(--ta-text); font: inherit; cursor: pointer; }
|
|
66
|
+
.taw-button:hover { background: var(--ta-hover); }
|
|
67
|
+
.taw-search-form { display: flex; gap: 2px; padding: 4px 10px 6px 4px; flex: none; }
|
|
68
|
+
.taw-search-toggle { flex: none; width: 18px; display: flex; align-items: flex-start; justify-content: center; padding: 7px 0 0; border: 0; border-radius: 4px; background: none; color: var(--ta-muted); cursor: pointer; }
|
|
69
|
+
.taw-search-toggle:hover { background: var(--ta-hover); color: var(--ta-text); }
|
|
70
|
+
.taw-search-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
|
|
71
|
+
.taw-search-fields .taw-field { flex: none; align-items: flex-start; }
|
|
72
|
+
.taw-search-fields .taw-field .taw-action { margin-top: 3px; width: 22px; height: 22px; }
|
|
73
|
+
.taw-field .taw-input.taw-search-input { resize: none; height: auto; min-height: 28px; padding: 5px 4px 5px 8px; line-height: 18px; overflow: hidden; }
|
|
74
|
+
.taw-field.taw-invalid { border-color: var(--ta-red); }
|
|
75
|
+
.taw-replace-row { display: flex; align-items: center; gap: 2px; }
|
|
76
|
+
.taw-replace-row .taw-field { flex: 1; }
|
|
77
|
+
.taw-details-toggle { display: flex; justify-content: flex-end; margin: -4px 0 -6px; }
|
|
78
|
+
.taw-details-toggle .taw-action { width: 22px; height: 16px; }
|
|
79
|
+
.taw-search-details { display: flex; flex-direction: column; gap: 6px; }
|
|
80
|
+
.taw-search-label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--ta-secondary); }
|
|
81
|
+
.taw-search-label .taw-input { flex: none; height: 28px; font-size: 12.5px; }
|
|
82
|
+
.taw-results-head { display: flex; align-items: center; gap: 4px; min-height: 26px; padding: 0 8px 0 12px; flex: none; }
|
|
83
|
+
.taw-results-summary { flex: 1; min-width: 0; color: var(--ta-muted); font-size: 12px; }
|
|
84
|
+
.taw-results-summary .taw-summary { padding: 0; }
|
|
85
|
+
.taw-progress { display: block; width: 100%; height: 2px; border-radius: 1px; background: linear-gradient(90deg, transparent, var(--ta-accent), transparent) 0 0 / 40% 100% no-repeat; animation: taw-slide 1s linear infinite; }
|
|
86
|
+
.taw-progress-bar { position: absolute; left: 0; right: 0; top: 30px; height: 2px; background: linear-gradient(90deg, transparent, var(--ta-accent), transparent) 0 0 / 30% 100% no-repeat; animation: taw-slide 1.1s linear infinite; z-index: 2; }
|
|
87
|
+
@keyframes taw-slide { from { background-position: -40% 0; } to { background-position: 140% 0; } }
|
|
88
|
+
.taw-result-file { padding-right: 6px; }
|
|
89
|
+
.taw-commit { display: flex; flex-direction: column; gap: 8px; padding: 2px 10px 10px; flex: none; }
|
|
90
|
+
.taw-input.taw-commit-input { flex: none; resize: none; height: auto; min-height: 34px; max-height: 200px; padding: 7px 10px; border-radius: 8px; line-height: 18px; }
|
|
91
|
+
.taw-button.taw-commit-button { justify-content: center; height: 30px; border-radius: 8px; border-color: var(--ta-border); background: var(--ta-raised); color: var(--ta-secondary); font-weight: 500; transition: background 120ms, color 120ms, opacity 120ms; }
|
|
92
|
+
.taw-button.taw-commit-button:hover:not(:disabled) { background: var(--ta-hover-strong); color: var(--ta-text); }
|
|
93
|
+
/* With a message, it stands out a little, without a bright bar in the side panel. */
|
|
94
|
+
.taw-button.taw-commit-button.taw-ready { border-color: var(--ta-border-field); background: var(--ta-hover-strong); color: var(--ta-text); }
|
|
95
|
+
.taw-button.taw-commit-button.taw-ready:hover:not(:disabled) { background: var(--ta-hover-strong); opacity: 0.85; }
|
|
96
|
+
.taw-scm-title { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
|
|
97
|
+
.taw-scm-title > span:first-child { overflow: hidden; text-overflow: ellipsis; }
|
|
98
|
+
.taw-branch-title { display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 0 6px; height: 18px; border-radius: 9px; background: var(--ta-chip); color: var(--ta-secondary); font-weight: 500; }
|
|
99
|
+
.taw-branch-title > svg { flex: none; color: var(--ta-muted); }
|
|
100
|
+
.taw-sync { color: var(--ta-muted); font-weight: 500; font-variant-numeric: tabular-nums; }
|
|
101
|
+
.taw-scm-row { padding-right: 6px; }
|
|
102
|
+
.taw-field { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 1; padding-right: 2px; border: 1px solid var(--ta-border-field); border-radius: 6px; background: var(--ta-input); }
|
|
103
|
+
.taw-field:focus-within { border-color: var(--ta-border-focus); }
|
|
104
|
+
.taw-input { flex: 1; min-width: 0; height: 30px; padding: 0 8px; border: 1px solid var(--ta-border-field); border-radius: 6px; background: var(--ta-input); color: var(--ta-text); font: inherit; font-size: 13px; outline: none; }
|
|
105
|
+
.taw-input:focus { border-color: var(--ta-border-focus); }
|
|
106
|
+
.taw-field .taw-input { height: 28px; border: 0; background: none; }
|
|
107
|
+
.taw-summary { padding: 4px 8px 6px; color: var(--ta-muted); font-size: 12px; }
|
|
108
|
+
.taw-match { padding-left: 36px; padding-right: 6px; }
|
|
109
|
+
.taw-preview { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: pre; color: var(--ta-body); font-size: 12.5px; }
|
|
110
|
+
.taw-preview mark { background: color-mix(in srgb, var(--ta-yellow) 32%, transparent); color: inherit; border-radius: 2px; }
|
|
111
|
+
.taw-preview del { background: color-mix(in srgb, var(--ta-red) 22%, transparent); color: inherit; text-decoration: line-through; }
|
|
112
|
+
.taw-preview ins { background: color-mix(in srgb, var(--ta-green) 24%, transparent); color: inherit; text-decoration: none; }
|
|
113
|
+
.taw-chip { padding: 0 6px; border-radius: 8px; background: var(--ta-chip); font-size: 11px; line-height: 18px; }
|
|
114
|
+
.taw-editor { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--ta-main); color: var(--ta-text); }
|
|
115
|
+
.taw-editor-head { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 12px; border-bottom: 1px solid var(--ta-border-muted); font-size: 12px; color: var(--ta-secondary); flex: none; }
|
|
116
|
+
.taw-editor-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--ta-mono); }
|
|
117
|
+
.taw-view > .taw-editor { flex: 1; height: auto; }
|
|
118
|
+
.taw-browser { display: flex; flex-direction: column; height: 100%; min-height: 0; color: var(--ta-text); font-size: 13px; }
|
|
119
|
+
.taw-browser-bar { position: relative; display: flex; align-items: center; gap: 2px; height: 42px; padding: 0 8px; border-bottom: 1px solid var(--ta-border-muted); flex: none; }
|
|
120
|
+
.taw-browser-bar > .taw-action { width: 28px; height: 28px; border-radius: 7px; }
|
|
121
|
+
.taw-address { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; height: 30px; margin: 0 4px; padding: 0 3px 0 11px; border: 1px solid transparent; border-radius: 15px; background: var(--ta-chip); transition: background-color 120ms, border-color 120ms; }
|
|
122
|
+
.taw-address:hover { background: color-mix(in srgb, var(--ta-chip) 70%, var(--ta-text) 6%); }
|
|
123
|
+
.taw-address:focus-within { border-color: var(--ta-border-focus); background: var(--ta-input); }
|
|
124
|
+
.taw-address input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; background: none; color: var(--ta-text); font: inherit; font-size: 12.5px; outline: none; text-overflow: ellipsis; }
|
|
125
|
+
.taw-address input::placeholder { color: var(--ta-muted); }
|
|
126
|
+
.taw-address-icon { display: inline-flex; flex: none; color: var(--ta-muted); }
|
|
127
|
+
.taw-address-go { width: 24px; height: 24px; border-radius: 12px; }
|
|
128
|
+
.taw-spin { display: inline-flex; animation: taw-spin 0.9s linear infinite; }
|
|
129
|
+
@keyframes taw-spin { to { transform: rotate(360deg); } }
|
|
130
|
+
.taw-browser-loading { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: linear-gradient(90deg, transparent, var(--ta-accent), transparent) 0 0 / 30% 100% no-repeat; animation: taw-slide 1.1s linear infinite; pointer-events: none; }
|
|
131
|
+
.taw-browser-home { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; align-items: center; padding: 56px 20px 16px; }
|
|
132
|
+
.taw-browser-blank { padding-top: 16px; }
|
|
133
|
+
.taw-browser-blank .taw-browser-hero { margin: auto 0; }
|
|
134
|
+
.taw-browser-hero { display: flex; flex-direction: column; align-items: center; max-width: 380px; text-align: center; }
|
|
135
|
+
.taw-browser-mark { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; margin-bottom: 14px; border-radius: 14px; background: var(--ta-chip); color: var(--ta-secondary); }
|
|
136
|
+
.taw-browser-title { margin: 0; font-size: 14px; font-weight: 600; color: var(--ta-text); }
|
|
137
|
+
.taw-browser-sub { margin: 6px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--ta-muted); }
|
|
138
|
+
.taw-browser-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 16px; }
|
|
139
|
+
.taw-browser-chip { height: 26px; padding: 0 10px; border: 1px solid var(--ta-border); border-radius: 13px; background: none; color: var(--ta-secondary); font-family: var(--ta-mono); font-size: 11px; cursor: pointer; transition: background-color 120ms, color 120ms; }
|
|
140
|
+
.taw-browser-chip:hover { background: var(--ta-hover); color: var(--ta-text); }
|
|
141
|
+
.taw-browser-recent { width: 100%; max-width: 480px; margin-top: 32px; }
|
|
142
|
+
.taw-browser-heading { margin: 0 0 4px; padding: 0 10px; font-size: 11px; font-weight: 600; color: var(--ta-secondary); }
|
|
143
|
+
.taw-browser-site { display: flex; align-items: center; border-radius: 8px; }
|
|
144
|
+
.taw-browser-site:hover { background: var(--ta-hover); }
|
|
145
|
+
.taw-browser-site-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 4px 0 8px; border: 0; background: none; color: var(--ta-body); font: inherit; text-align: left; cursor: pointer; outline: none; }
|
|
146
|
+
.taw-browser-letter { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 22px; height: 22px; border-radius: 6px; background: var(--ta-chip); color: var(--ta-secondary); font-size: 11px; font-weight: 600; }
|
|
147
|
+
.taw-browser-host { flex: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-text); }
|
|
148
|
+
.taw-browser-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-muted); font-size: 12px; }
|
|
149
|
+
.taw-browser-remove { margin-right: 6px; opacity: 0; }
|
|
150
|
+
.taw-browser-site:hover .taw-browser-remove, .taw-browser-remove:focus-visible { opacity: 1; }
|
|
151
|
+
.taw-browser-site-main:focus-visible { box-shadow: inset 0 0 0 1px var(--ta-border-focus); border-radius: 8px; }
|
|
152
|
+
.taw-browser-foot { margin: auto 0 0; padding-top: 24px; max-width: 340px; text-align: center; font-size: 11.5px; line-height: 1.6; color: var(--ta-muted); opacity: 0.8; }
|
|
153
|
+
.taw-editor-tools { display: flex; align-items: center; gap: 8px; flex: none; min-width: 0; }
|
|
154
|
+
.taw-editor-tools .taw-note { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
155
|
+
.taw-warning { color: var(--ta-yellow); }
|
|
156
|
+
.taw-link { padding: 0; border: 0; background: none; color: var(--ta-link); font: inherit; cursor: pointer; }
|
|
157
|
+
.taw-link:hover { text-decoration: underline; }
|
|
158
|
+
.taw-button.taw-small { height: 24px; padding: 0 8px; font-size: 12px; flex: none; }
|
|
159
|
+
.taw-button:disabled { opacity: 0.6; cursor: default; }
|
|
160
|
+
.taw-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ta-text); }
|
|
161
|
+
.taw-segmented { display: inline-flex; flex: none; min-inline-size: 0; margin: 0; border: 0; padding: 2px; border-radius: 7px; background: var(--ta-chip); }
|
|
162
|
+
.taw-segmented > button { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border: 0; border-radius: 5px; background: none; color: var(--ta-secondary); font: inherit; font-size: 12px; cursor: pointer; }
|
|
163
|
+
.taw-segmented > button:hover { color: var(--ta-text); }
|
|
164
|
+
.taw-segmented > button.taw-on { background: var(--ta-main); color: var(--ta-text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
|
|
165
|
+
.taw-segmented > button:focus-visible { outline: 1px solid var(--ta-border-focus); outline-offset: -1px; }
|
|
166
|
+
.taw-preview-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--ta-main); }
|
|
167
|
+
.taw-preview-page { background: #fff; }
|
|
168
|
+
.taw-preview-media { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; background: var(--ta-code); }
|
|
169
|
+
.taw-preview-media video { max-width: 100%; max-height: 100%; border-radius: 8px; background: #000; outline: none; }
|
|
170
|
+
.taw-preview-media audio { width: min(480px, 100%); }
|
|
171
|
+
.taw-preview-image { background-color: var(--ta-code); background-image: linear-gradient(45deg, var(--ta-chip) 25%, transparent 25%, transparent 75%, var(--ta-chip) 75%), linear-gradient(45deg, var(--ta-chip) 25%, transparent 25%, transparent 75%, var(--ta-chip) 75%); background-size: 16px 16px; background-position: 0 0, 8px 8px; }
|
|
172
|
+
.taw-image-toggle { display: flex; align-items: center; justify-content: center; max-width: 100%; max-height: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
|
|
173
|
+
.taw-image-toggle:focus-visible { outline: 1px solid var(--ta-border-focus); outline-offset: 2px; }
|
|
174
|
+
.taw-preview-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
|
|
175
|
+
.taw-preview-image.taw-actual { align-items: flex-start; justify-content: flex-start; }
|
|
176
|
+
.taw-preview-image.taw-actual .taw-image-toggle { max-width: none; max-height: none; margin: auto; cursor: zoom-out; }
|
|
177
|
+
.taw-preview-image.taw-actual img { max-width: none; max-height: none; }
|
|
178
|
+
.taw-message { padding: 16px; color: var(--ta-muted); font-size: 13px; }
|
|
179
|
+
.taw-code { flex: 1; min-height: 0; overflow: auto; padding: 6px 0; background: var(--ta-code); font-family: var(--ta-mono); font-size: 12px; line-height: 20px; }
|
|
180
|
+
.taw-code-block { content-visibility: auto; }
|
|
181
|
+
.taw-code-line { display: flex; min-width: max-content; white-space: pre; }
|
|
182
|
+
.taw-code-line.taw-current { background: var(--ta-selected); }
|
|
183
|
+
.taw-gutter { position: sticky; left: 0; flex: none; width: var(--taw-gutter, 5ch); padding-right: 12px; background: var(--ta-code); color: var(--ta-muted); text-align: right; user-select: none; }
|
|
184
|
+
.taw-text { padding-right: 16px; }
|
|
185
|
+
.taw-hint { flex: none; padding: 4px 12px; border-bottom: 1px solid var(--ta-border-muted); background: var(--ta-raised); color: var(--ta-secondary); font-size: 12px; }
|
|
186
|
+
.taw-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #fff; }
|
|
187
|
+
.taw-terminal { position: relative; flex: 1; min-height: 0; overflow: auto; padding: 8px; background: var(--ta-code); color: var(--ta-text); cursor: text; font-family: var(--ta-mono); font-size: 12px; line-height: 18px; }
|
|
188
|
+
.taw-screen { margin: 0; font-family: var(--ta-mono); font-size: 12px; line-height: 18px; white-space: pre; }
|
|
189
|
+
.taw-screen-line { position: relative; min-height: 18px; }
|
|
190
|
+
.taw-cursor { position: absolute; top: 2px; width: 1ch; height: 14px; background: var(--ta-text); opacity: 0.55; pointer-events: none; }
|
|
191
|
+
.taw-terminal:not(:focus-within) .taw-cursor { background: none; outline: 1px solid var(--ta-muted); outline-offset: -1px; }
|
|
192
|
+
@media (pointer: coarse) {
|
|
193
|
+
.taw-row { height: 36px; }
|
|
194
|
+
.taw-action { width: 32px; height: 32px; }
|
|
195
|
+
.taw-row-actions { display: flex; }
|
|
196
|
+
.taw-guide { opacity: 1; }
|
|
197
|
+
.taw-input { height: 34px; font-size: 16px; }
|
|
198
|
+
.taw-field .taw-input, .taw-search-label .taw-input { height: 34px; font-size: 16px; }
|
|
199
|
+
.taw-field .taw-input.taw-search-input { min-height: 34px; padding-top: 7px; padding-bottom: 7px; line-height: 20px; }
|
|
200
|
+
.taw-search-fields .taw-field .taw-action { width: 30px; height: 30px; margin-top: 2px; }
|
|
201
|
+
.taw-search-toggle { width: 26px; padding-top: 10px; }
|
|
202
|
+
.taw-input.taw-commit-input { min-height: 40px; }
|
|
203
|
+
.taw-address input { font-size: 16px; }
|
|
204
|
+
.taw-browser-remove { opacity: 1; }
|
|
205
|
+
}
|
|
206
|
+
.taw-file-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; overflow: hidden; font-family: 'taw-seti'; font-style: normal; font-weight: normal; line-height: 1; color: var(--taw-icon); -webkit-font-smoothing: antialiased; speak: never; }
|
|
207
|
+
:root[data-theme='light'] .taw-file-icon { color: var(--taw-icon-light); }
|
|
208
|
+
.taw-terminal-tabs { display: flex; align-items: center; gap: 2px; min-height: 32px; padding: 0 6px; border-bottom: 1px solid var(--ta-border-muted); background: var(--ta-side); overflow-x: auto; scrollbar-width: none; flex: none; }
|
|
209
|
+
.taw-terminal-tab { display: flex; align-items: center; flex: none; max-width: 200px; border-radius: 6px; color: var(--ta-muted); }
|
|
210
|
+
.taw-terminal-tab:hover { background: var(--ta-hover); }
|
|
211
|
+
.taw-terminal-tab.taw-on { background: var(--ta-selected); color: var(--ta-text); }
|
|
212
|
+
.taw-terminal-tab > button:first-child { display: flex; align-items: center; gap: 6px; min-width: 0; height: 24px; padding: 0 2px 0 8px; border: 0; background: none; color: inherit; font: inherit; font-size: 12px; cursor: pointer; }
|
|
213
|
+
.taw-terminal-tab > button:first-child > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
214
|
+
.taw-terminal-tab > .taw-action { width: 20px; height: 20px; }
|
|
215
|
+
.taw-terminal-input { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; resize: none; }
|
|
216
|
+
`;
|
|
217
|
+
|
|
218
|
+
/** Adds the styles to the page; the function returned takes them away. */
|
|
219
|
+
export function injectStyle(): () => void {
|
|
220
|
+
const element = document.createElement('style');
|
|
221
|
+
element.dataset.taPackage = 'ta-workspace';
|
|
222
|
+
element.textContent = `@font-face { font-family: 'taw-seti'; src: url('${SETI_FONT}') format('woff'); font-display: block; }\n${STYLE}`;
|
|
223
|
+
document.head.appendChild(element);
|
|
224
|
+
return () => element.remove();
|
|
225
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import type { TaTerminalInfo } from '@celljs/ta-protocol';
|
|
2
|
+
import { Action, Empty, Glyph, type MenuItem, useContextMenu } from './common';
|
|
3
|
+
import { Host, pi } from './host';
|
|
4
|
+
import { t } from './i18n';
|
|
5
|
+
import { React } from './react';
|
|
6
|
+
import { AnsiScreen, AnsiUtil } from './util/ansi';
|
|
7
|
+
import { TerminalKeys } from './util/keys';
|
|
8
|
+
import { WorkspaceUtil } from './util/workspace';
|
|
9
|
+
|
|
10
|
+
const LINE_HEIGHT = 18;
|
|
11
|
+
const SCROLLBACK = 1000;
|
|
12
|
+
const RESIZE_MS = 120;
|
|
13
|
+
|
|
14
|
+
/** `pty` is false for a shell on pipes (the server has no `script`). */
|
|
15
|
+
type TerminalInfo = TaTerminalInfo;
|
|
16
|
+
|
|
17
|
+
interface Session {
|
|
18
|
+
info: TerminalInfo;
|
|
19
|
+
screen: AnsiScreen;
|
|
20
|
+
exitCode?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The terminals of this page and what they printed; they outlive the views that show them. */
|
|
24
|
+
export namespace Terminals {
|
|
25
|
+
const sessions = new Map<string, Session>();
|
|
26
|
+
/** Closed here: what the server still sends of them (their end) does not bring them back. */
|
|
27
|
+
const closed = new Set<string>();
|
|
28
|
+
const listeners = new Set<() => void>();
|
|
29
|
+
let list: Session[] = [];
|
|
30
|
+
let frame = 0;
|
|
31
|
+
|
|
32
|
+
export function all(): Session[] {
|
|
33
|
+
return list;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function get(id: string): Session | undefined {
|
|
37
|
+
return sessions.get(id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function subscribe(listener: () => void): () => void {
|
|
41
|
+
listeners.add(listener);
|
|
42
|
+
return () => listeners.delete(listener);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Output comes in bursts: views draw once a frame. */
|
|
46
|
+
function changed(): void {
|
|
47
|
+
list = [...sessions.values()];
|
|
48
|
+
if (!frame) {
|
|
49
|
+
frame = requestAnimationFrame(() => {
|
|
50
|
+
frame = 0;
|
|
51
|
+
for (const listener of listeners) {
|
|
52
|
+
listener();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function add(info: TerminalInfo): Session {
|
|
59
|
+
let session = sessions.get(info.terminalId);
|
|
60
|
+
if (!session) {
|
|
61
|
+
session = { info, screen: new AnsiScreen(80, 24, SCROLLBACK) };
|
|
62
|
+
sessions.set(info.terminalId, session);
|
|
63
|
+
changed();
|
|
64
|
+
}
|
|
65
|
+
return session;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function receive(terminalId: string, data: string, exitCode?: number): void {
|
|
69
|
+
if (closed.has(terminalId)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const session = sessions.get(terminalId) ?? add({ terminalId, cwd: '', shell: '', pty: true });
|
|
73
|
+
session.screen.feed(data);
|
|
74
|
+
// JSON has no undefined: a terminal that goes on sends null.
|
|
75
|
+
if (exitCode !== undefined && exitCode !== null) {
|
|
76
|
+
session.exitCode = exitCode;
|
|
77
|
+
session.screen.feed(`\r\n${t('terminalEnded', { code: exitCode })}\r\n`);
|
|
78
|
+
}
|
|
79
|
+
changed();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function remove(terminalId: string): void {
|
|
83
|
+
if (sessions.delete(terminalId)) {
|
|
84
|
+
closed.add(terminalId);
|
|
85
|
+
changed();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Takes back the shells of this page after a reconnect. */
|
|
90
|
+
export async function sync(): Promise<void> {
|
|
91
|
+
for (const info of await pi.terminals.listTerminals()) {
|
|
92
|
+
add(info);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function useTerminals(): Session[] {
|
|
98
|
+
return React.useSyncExternalStore(Terminals.subscribe, Terminals.all);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function title(session: Session): string {
|
|
102
|
+
return `${WorkspaceUtil.basename(session.info.shell) || t('terminal')} · ${WorkspaceUtil.basename(session.info.cwd)}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function close(session: Session): Promise<void> {
|
|
106
|
+
Terminals.remove(session.info.terminalId);
|
|
107
|
+
if (session.exitCode === undefined) {
|
|
108
|
+
await pi.terminals.closeTerminal(session.info.terminalId).catch(() => undefined);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function closeEach(sessions: readonly Session[]): void {
|
|
113
|
+
for (const session of sessions) {
|
|
114
|
+
void close(session);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The terminals of the page in one tab of the workbench: a row of them, and the one shown. The first opens with the view. */
|
|
119
|
+
export function TerminalView() {
|
|
120
|
+
const cwd = pi.ui.useCwd();
|
|
121
|
+
const sessions = useTerminals();
|
|
122
|
+
const [shown, setShown] = React.useState<string>();
|
|
123
|
+
const [error, setError] = React.useState<string>();
|
|
124
|
+
const opening = React.useRef(false);
|
|
125
|
+
const create = React.useCallback(async () => {
|
|
126
|
+
if (opening.current) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
opening.current = true;
|
|
130
|
+
try {
|
|
131
|
+
setError(undefined);
|
|
132
|
+
setShown(Terminals.add(await pi.terminals.openTerminal({ cwd, cols: 100, rows: 30 })).info.terminalId);
|
|
133
|
+
} catch (failure) {
|
|
134
|
+
setError(Host.message(failure));
|
|
135
|
+
} finally {
|
|
136
|
+
opening.current = false;
|
|
137
|
+
}
|
|
138
|
+
}, [cwd]);
|
|
139
|
+
// Once, when the view opens.
|
|
140
|
+
React.useEffect(() => {
|
|
141
|
+
Terminals.sync().then(
|
|
142
|
+
async () => {
|
|
143
|
+
if (Terminals.all().length === 0) {
|
|
144
|
+
await create();
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
failure => setError(Host.message(failure)),
|
|
148
|
+
);
|
|
149
|
+
}, []);
|
|
150
|
+
const current = sessions.find(session => session.info.terminalId === shown) ?? sessions[sessions.length - 1];
|
|
151
|
+
const [menu, openMenu] = useContextMenu();
|
|
152
|
+
const menuFor = (session: Session): MenuItem[] => {
|
|
153
|
+
const at = sessions.indexOf(session);
|
|
154
|
+
const others = sessions.filter(other => other !== session);
|
|
155
|
+
const left = sessions.slice(0, at);
|
|
156
|
+
const right = sessions.slice(at + 1);
|
|
157
|
+
const ended = sessions.filter(other => other.exitCode !== undefined);
|
|
158
|
+
return [
|
|
159
|
+
{ label: t('close'), run: () => void close(session) },
|
|
160
|
+
{ label: t('closeOthers'), run: () => closeEach(others), disabled: others.length === 0 },
|
|
161
|
+
{ label: t('closeToTheLeft'), run: () => closeEach(left), disabled: left.length === 0 },
|
|
162
|
+
{ label: t('closeTabsToTheRight'), run: () => closeEach(right), disabled: right.length === 0 },
|
|
163
|
+
'-',
|
|
164
|
+
{ label: t('closeEnded'), run: () => closeEach(ended), disabled: ended.length === 0 },
|
|
165
|
+
{ label: t('closeAll'), run: () => closeEach(sessions) },
|
|
166
|
+
'-',
|
|
167
|
+
{ label: t('newTerminal'), run: () => void create() },
|
|
168
|
+
];
|
|
169
|
+
};
|
|
170
|
+
return (
|
|
171
|
+
<div className="taw-view">
|
|
172
|
+
<header className="taw-terminal-tabs" role="tablist" aria-label={t('terminal')}>
|
|
173
|
+
{sessions.map(session => (
|
|
174
|
+
<div key={session.info.terminalId} className={`taw-terminal-tab ${session === current ? 'taw-on' : ''}`} title={session.info.cwd}>
|
|
175
|
+
<button
|
|
176
|
+
type="button"
|
|
177
|
+
role="tab"
|
|
178
|
+
aria-selected={session === current}
|
|
179
|
+
onClick={() => setShown(session.info.terminalId)}
|
|
180
|
+
onContextMenu={event => openMenu(event, menuFor(session))}
|
|
181
|
+
>
|
|
182
|
+
<Glyph name="SquareTerminal" size={13} />
|
|
183
|
+
<span>{title(session)}</span>
|
|
184
|
+
{session.exitCode !== undefined && <span className="taw-detail">{session.exitCode}</span>}
|
|
185
|
+
</button>
|
|
186
|
+
<Action icon="X" label={t('close')} onClick={() => void close(session)} />
|
|
187
|
+
</div>
|
|
188
|
+
))}
|
|
189
|
+
<Action icon="Plus" label={t('newTerminal')} onClick={() => void create()} />
|
|
190
|
+
</header>
|
|
191
|
+
{menu}
|
|
192
|
+
{error && <Empty tone="error">{t('failed', { message: error })}</Empty>}
|
|
193
|
+
{!error && sessions.length === 0 && (
|
|
194
|
+
<Empty>
|
|
195
|
+
<p>{t('noTerminals')}</p>
|
|
196
|
+
<button type="button" className="taw-button" onClick={() => void create()}>
|
|
197
|
+
<Glyph name="Plus" size={14} />
|
|
198
|
+
{t('newTerminal')}
|
|
199
|
+
</button>
|
|
200
|
+
</Empty>
|
|
201
|
+
)}
|
|
202
|
+
{current && <TerminalEditor key={current.info.terminalId} terminalId={current.info.terminalId} />}
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The size of a character of the terminal's font. */
|
|
208
|
+
function measure(element: HTMLElement): { width: number; height: number } {
|
|
209
|
+
const probe = document.createElement('span');
|
|
210
|
+
probe.textContent = 'MMMMMMMMMM';
|
|
211
|
+
probe.style.visibility = 'hidden';
|
|
212
|
+
probe.style.position = 'absolute';
|
|
213
|
+
element.appendChild(probe);
|
|
214
|
+
const width = probe.getBoundingClientRect().width / 10 || 8;
|
|
215
|
+
probe.remove();
|
|
216
|
+
return { width, height: LINE_HEIGHT };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function TerminalEditor({ terminalId }: { terminalId: string }) {
|
|
220
|
+
useTerminals();
|
|
221
|
+
const session = Terminals.get(terminalId);
|
|
222
|
+
const box = React.useRef<HTMLDivElement>(null);
|
|
223
|
+
const input = React.useRef<HTMLTextAreaElement>(null);
|
|
224
|
+
const composing = React.useRef(false);
|
|
225
|
+
const pinned = React.useRef(true);
|
|
226
|
+
const write = React.useCallback((data: string) => void pi.terminals.writeTerminal(terminalId, data).catch(() => undefined), [terminalId]);
|
|
227
|
+
|
|
228
|
+
React.useEffect(() => {
|
|
229
|
+
const element = box.current;
|
|
230
|
+
if (!element || !session) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
234
|
+
let last = '';
|
|
235
|
+
const observer = new ResizeObserver(() => {
|
|
236
|
+
// A hidden tab measures nothing: the terminal keeps its size.
|
|
237
|
+
if (!element.clientWidth || !element.clientHeight) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const cell = measure(element);
|
|
241
|
+
const cols = Math.max(20, Math.floor((element.clientWidth - 16) / cell.width));
|
|
242
|
+
const rows = Math.max(5, Math.floor((element.clientHeight - 16) / cell.height));
|
|
243
|
+
if (`${cols}x${rows}` === last) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
last = `${cols}x${rows}`;
|
|
247
|
+
session.screen.resize(cols, rows);
|
|
248
|
+
clearTimeout(timer);
|
|
249
|
+
timer = setTimeout(() => void pi.terminals.resizeTerminal(terminalId, cols, rows).catch(() => undefined), RESIZE_MS);
|
|
250
|
+
});
|
|
251
|
+
observer.observe(element);
|
|
252
|
+
return () => {
|
|
253
|
+
observer.disconnect();
|
|
254
|
+
clearTimeout(timer);
|
|
255
|
+
};
|
|
256
|
+
}, [session, terminalId]);
|
|
257
|
+
|
|
258
|
+
// The keys go to the terminal once it shows.
|
|
259
|
+
React.useEffect(() => input.current?.focus({ preventScroll: true }), []);
|
|
260
|
+
|
|
261
|
+
// Stays at the bottom while it is there.
|
|
262
|
+
React.useLayoutEffect(() => {
|
|
263
|
+
const element = box.current;
|
|
264
|
+
if (element && pinned.current) {
|
|
265
|
+
element.scrollTop = element.scrollHeight;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
if (!session) {
|
|
270
|
+
return <Empty>{t('noTerminals')}</Empty>;
|
|
271
|
+
}
|
|
272
|
+
const lines = session.screen.spans();
|
|
273
|
+
const cursor = session.screen.cursor();
|
|
274
|
+
const ended = session.exitCode !== undefined;
|
|
275
|
+
const onKeyDown = (event: React.KeyboardEvent) => {
|
|
276
|
+
if (composing.current || ended) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const sequence = TerminalKeys.sequence(event);
|
|
280
|
+
if (sequence !== undefined) {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
write(sequence);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
const flush = () => {
|
|
286
|
+
const element = input.current;
|
|
287
|
+
if (element?.value && !composing.current) {
|
|
288
|
+
if (!ended) {
|
|
289
|
+
write(element.value);
|
|
290
|
+
}
|
|
291
|
+
element.value = '';
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
return (
|
|
295
|
+
<div className="taw-editor">
|
|
296
|
+
{session.info.pty === false && <div className="taw-hint">{t('pipeMode')}</div>}
|
|
297
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: a click on the screen hands the keys to its input */}
|
|
298
|
+
<div
|
|
299
|
+
className="taw-terminal"
|
|
300
|
+
ref={box}
|
|
301
|
+
role="presentation"
|
|
302
|
+
onScroll={event => {
|
|
303
|
+
const element = event.currentTarget;
|
|
304
|
+
pinned.current = element.scrollHeight - element.scrollTop - element.clientHeight < LINE_HEIGHT;
|
|
305
|
+
}}
|
|
306
|
+
onMouseUp={() => {
|
|
307
|
+
if (!window.getSelection()?.toString()) {
|
|
308
|
+
input.current?.focus({ preventScroll: true });
|
|
309
|
+
}
|
|
310
|
+
}}
|
|
311
|
+
>
|
|
312
|
+
<pre className="taw-screen">
|
|
313
|
+
{lines.map((spans, row) => (
|
|
314
|
+
<div key={row} className="taw-screen-line">
|
|
315
|
+
{spans.map((span, index) => (
|
|
316
|
+
<span key={index} style={AnsiUtil.css(span.style)}>
|
|
317
|
+
{span.text}
|
|
318
|
+
</span>
|
|
319
|
+
))}
|
|
320
|
+
{row === cursor.row && !ended && <span className="taw-cursor" style={{ left: `${cursor.col}ch` }} />}
|
|
321
|
+
{'\n'}
|
|
322
|
+
</div>
|
|
323
|
+
))}
|
|
324
|
+
</pre>
|
|
325
|
+
<textarea
|
|
326
|
+
ref={input}
|
|
327
|
+
className="taw-terminal-input"
|
|
328
|
+
aria-label={t('terminal')}
|
|
329
|
+
autoCapitalize="off"
|
|
330
|
+
autoComplete="off"
|
|
331
|
+
autoCorrect="off"
|
|
332
|
+
spellCheck={false}
|
|
333
|
+
onKeyDown={onKeyDown}
|
|
334
|
+
onInput={flush}
|
|
335
|
+
onCompositionStart={() => (composing.current = true)}
|
|
336
|
+
onCompositionEnd={() => {
|
|
337
|
+
composing.current = false;
|
|
338
|
+
flush();
|
|
339
|
+
}}
|
|
340
|
+
onPaste={event => {
|
|
341
|
+
event.preventDefault();
|
|
342
|
+
if (!ended) {
|
|
343
|
+
write(TerminalKeys.paste(event.clipboardData.getData('text')));
|
|
344
|
+
}
|
|
345
|
+
}}
|
|
346
|
+
/>
|
|
347
|
+
</div>
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { AnsiScreen, AnsiUtil } from './ansi';
|
|
3
|
+
|
|
4
|
+
describe('AnsiScreen', () => {
|
|
5
|
+
it('writes lines, returns and backspaces', () => {
|
|
6
|
+
const screen = new AnsiScreen(20, 5);
|
|
7
|
+
screen.feed('hello\r\nworld');
|
|
8
|
+
screen.feed('\rW');
|
|
9
|
+
screen.feed('orl\b\bX');
|
|
10
|
+
expect(screen.text()).toBe('hello\nWoXld');
|
|
11
|
+
expect(screen.cursor()).toEqual({ row: 1, col: 3 });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('keeps colors, and a sequence cut in two', () => {
|
|
15
|
+
const screen = new AnsiScreen();
|
|
16
|
+
screen.feed('a\x1b[1;3');
|
|
17
|
+
screen.feed('1mred\x1b[0m b');
|
|
18
|
+
const [line] = screen.spans();
|
|
19
|
+
expect(line).toEqual([
|
|
20
|
+
{ text: 'a', style: {} },
|
|
21
|
+
{ text: 'red', style: { bold: true, fg: 1 } },
|
|
22
|
+
{ text: ' b', style: {} },
|
|
23
|
+
]);
|
|
24
|
+
screen.feed('\x1b[38;5;208mx\x1b[48;2;255;0;16my');
|
|
25
|
+
const spans = screen.spans()[0];
|
|
26
|
+
expect(spans[spans.length - 2].style).toEqual({ fg: 208 });
|
|
27
|
+
expect(spans[spans.length - 1].style).toEqual({ fg: 208, bg: '#ff0010' });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('drops titles and modes, and erases', () => {
|
|
31
|
+
const screen = new AnsiScreen(40, 5);
|
|
32
|
+
screen.feed('\x1b]2;title\x07\x1b]7;file://x\x1b\\\x1b[?2004h$ ls -la');
|
|
33
|
+
screen.feed('\x1b[3D\x1b[K');
|
|
34
|
+
expect(screen.text()).toBe('$ ls');
|
|
35
|
+
screen.feed('\r\n1\r\n2\x1b[2J\x1b[Hok');
|
|
36
|
+
expect(screen.text().split('\n').filter(Boolean).pop()).toBe('ok');
|
|
37
|
+
screen.feed('\x1b[3J');
|
|
38
|
+
expect(screen.text()).toBe('');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('wraps long lines and keeps at most so many', () => {
|
|
42
|
+
const screen = new AnsiScreen(4, 2, 3);
|
|
43
|
+
screen.feed('abcdefgh\r\n1\r\n2');
|
|
44
|
+
expect(screen.text()).toBe('efgh\n1\n2');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('moves the cursor within the screen', () => {
|
|
48
|
+
const screen = new AnsiScreen(10, 3);
|
|
49
|
+
screen.feed('one\r\ntwo\r\nthree\x1b[2;1HTWO\x1b[1G\x1b[2CX');
|
|
50
|
+
expect(screen.text()).toBe('one\nTWX\nthree');
|
|
51
|
+
screen.feed('\x1b7\x1b[3;1Hz\x1b8!');
|
|
52
|
+
expect(screen.text()).toBe('one\nTWX!\nzhree');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('AnsiUtil', () => {
|
|
57
|
+
it('maps the palette to the theme and to rgb', () => {
|
|
58
|
+
expect(AnsiUtil.color(1)).toBe('var(--ta-red)');
|
|
59
|
+
expect(AnsiUtil.color(8)).toBe('var(--ta-muted)');
|
|
60
|
+
expect(AnsiUtil.color(196)).toBe('rgb(255, 0, 0)');
|
|
61
|
+
expect(AnsiUtil.color(232)).toBe('rgb(8, 8, 8)');
|
|
62
|
+
expect(AnsiUtil.css({})).toBeUndefined();
|
|
63
|
+
expect(AnsiUtil.css({ inverse: true })).toEqual({ color: 'var(--ta-main)', background: 'var(--ta-text)' });
|
|
64
|
+
expect(AnsiUtil.css({ bold: true, fg: 2 })).toEqual({ color: 'var(--ta-green)', fontWeight: '600' });
|
|
65
|
+
});
|
|
66
|
+
});
|