- crates/terminal: portable-pty sessions (ConPTY on Windows) with reader, writer and waiter threads, UTF-8 chunking, a 1 MiB output buffer with backpressure, a non-blocking input queue, resize, kill and exit codes; default shell pwsh -> powershell -> cmd on Windows, $SHELL or /bin/sh. - Engine: terminal.create/input/resize/close, terminalOutput (capped per terminal and per pump, round-robin) and terminalExited through the pump; terminals close with the project and on app.quit. - UI: Terminal tab in the bottom panel (tabs next to Find), xterm.js with the fit addon, sub-tabs, copy/paste, a focus rule that leaves plain Ctrl keys to the shell, terminal.open (Mod+Shift+T), --lt-terminal-* ANSI tokens in both themes (text colours AA) and a 4.5:1 minimum contrast. - Tests: real-shell crate tests (UTF-8, backpressure), engine and TCP control tests, Vitest with a mocked xterm; live check on port 7936; docs and parity rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
344 lines
9.1 KiB
Vue
344 lines
9.1 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* The bottom panel of the main window: tool windows docked under the
|
|
* editor (Find since M2.4, Terminal since M3.6; later Problems and others).
|
|
* A header with the title, a collapse/expand button and a close button, the
|
|
* content slot, and a splitter on the top edge to resize it.
|
|
*
|
|
* Tabs (M3.6): with `tabs`, the header shows one tab per tool window
|
|
* instead of the title; a click (or Left/Right on a focused tab) emits
|
|
* `update:active`. The owner shows the active tool window's content in the
|
|
* slot, and closing hides the active one.
|
|
*
|
|
* The splitter is dragged with the pointer or moved with Up/Down (Shift for
|
|
* larger steps) when focused. Collapsed, only the header shows. Height and
|
|
* expansion are view state, emitted through `v-model:height` and
|
|
* `v-model:open`; the close button emits `close`, and the owner decides
|
|
* what closing means.
|
|
*/
|
|
import { ChevronDown, ChevronUp, X } from "@lucide/vue";
|
|
import { computed, nextTick, ref } from "vue";
|
|
import { t } from "../../i18n";
|
|
|
|
/** A tab of the bottom panel. */
|
|
export interface BottomTab {
|
|
/** Tool window id. */
|
|
id: string;
|
|
/** Its title. */
|
|
title: string;
|
|
}
|
|
|
|
/** Props of the bottom panel. */
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
/** Title shown in the header and as the accessible name. */
|
|
title: string;
|
|
/** Height of the content in CSS pixels, header excluded. */
|
|
height?: number;
|
|
/** Smallest height the splitter allows. */
|
|
minHeight?: number;
|
|
/** Largest height the splitter allows. */
|
|
maxHeight?: number;
|
|
/** Whether the panel is expanded (true) or collapsed to its header. */
|
|
open?: boolean;
|
|
/** Tool windows shown as tabs in the header; none shows the title. */
|
|
tabs?: readonly BottomTab[];
|
|
/** Id of the active tab. */
|
|
active?: string;
|
|
}>(),
|
|
{ height: 240, minHeight: 80, maxHeight: 900, open: true, tabs: () => [], active: "" },
|
|
);
|
|
|
|
/** Events of the bottom panel. */
|
|
const emit = defineEmits<{
|
|
/** New height after a resize. */
|
|
"update:height": [height: number];
|
|
/** New expansion after collapse or expand. */
|
|
"update:open": [open: boolean];
|
|
/** The close button was pressed. */
|
|
close: [];
|
|
/** A tab was chosen. */
|
|
"update:active": [id: string];
|
|
}>();
|
|
|
|
/** The tab list element, to move the focus between tabs. */
|
|
const tabList = ref<HTMLElement | null>(null);
|
|
|
|
/**
|
|
* Moves between tabs with Left/Right and activates the new one.
|
|
*
|
|
* @param event - the key event on a tab.
|
|
* @param index - the index of that tab.
|
|
*/
|
|
async function onTabKey(event: KeyboardEvent, index: number): Promise<void> {
|
|
const count = props.tabs.length;
|
|
let next: number;
|
|
if (event.key === "ArrowRight") {
|
|
next = (index + 1) % count;
|
|
} else if (event.key === "ArrowLeft") {
|
|
next = (index - 1 + count) % count;
|
|
} else {
|
|
return;
|
|
}
|
|
event.preventDefault();
|
|
const tab = props.tabs[next];
|
|
if (!tab) {
|
|
return;
|
|
}
|
|
emit("update:active", tab.id);
|
|
await nextTick();
|
|
tabList.value?.querySelectorAll<HTMLElement>("[role=tab]")[next]?.focus();
|
|
}
|
|
|
|
/** Inline style carrying the current height. */
|
|
const bodyStyle = computed(() => ({ height: `${String(props.height)}px` }));
|
|
|
|
/**
|
|
* Emits a height clamped to the allowed range.
|
|
*
|
|
* @param height - the wanted height.
|
|
*/
|
|
function setHeight(height: number): void {
|
|
emit("update:height", Math.round(Math.min(props.maxHeight, Math.max(props.minHeight, height))));
|
|
}
|
|
|
|
/**
|
|
* Starts a pointer drag on the splitter; dragging up makes the panel taller.
|
|
*
|
|
* @param event - the pointer-down event.
|
|
*/
|
|
function onSplitterDown(event: PointerEvent): void {
|
|
const target = event.currentTarget;
|
|
if (!(target instanceof HTMLElement)) {
|
|
return;
|
|
}
|
|
const startY = event.clientY;
|
|
const startHeight = props.height;
|
|
target.setPointerCapture(event.pointerId);
|
|
const move = (e: PointerEvent): void => {
|
|
setHeight(startHeight - (e.clientY - startY));
|
|
};
|
|
const up = (e: PointerEvent): void => {
|
|
target.releasePointerCapture(e.pointerId);
|
|
target.removeEventListener("pointermove", move);
|
|
target.removeEventListener("pointerup", up);
|
|
};
|
|
target.addEventListener("pointermove", move);
|
|
target.addEventListener("pointerup", up);
|
|
}
|
|
|
|
/**
|
|
* Resizes with the keyboard when the splitter has focus.
|
|
*
|
|
* @param event - the key event.
|
|
*/
|
|
function onSplitterKey(event: KeyboardEvent): void {
|
|
const step = event.shiftKey ? 48 : 12;
|
|
if (event.key === "ArrowUp") {
|
|
setHeight(props.height + step);
|
|
} else if (event.key === "ArrowDown") {
|
|
setHeight(props.height - step);
|
|
} else {
|
|
return;
|
|
}
|
|
event.preventDefault();
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<section
|
|
class="bottom-panel"
|
|
:aria-label="title"
|
|
data-test="bottom-panel"
|
|
>
|
|
<div
|
|
v-if="open"
|
|
class="bottom-panel__splitter"
|
|
role="separator"
|
|
aria-orientation="horizontal"
|
|
tabindex="0"
|
|
:aria-valuenow="height"
|
|
:aria-valuemin="minHeight"
|
|
:aria-valuemax="maxHeight"
|
|
:aria-label="t('common.toolWindow.resize', { title })"
|
|
data-test="bottom-panel-splitter"
|
|
@pointerdown="onSplitterDown"
|
|
@keydown="onSplitterKey"
|
|
/>
|
|
<header class="bottom-panel__header">
|
|
<span
|
|
v-if="tabs.length === 0"
|
|
class="bottom-panel__title"
|
|
>{{ title }}</span>
|
|
<span
|
|
v-else
|
|
ref="tabList"
|
|
class="bottom-panel__tabs"
|
|
role="tablist"
|
|
:aria-label="t('common.toolWindow.bottomTabs')"
|
|
>
|
|
<button
|
|
v-for="(tab, index) in tabs"
|
|
:key="tab.id"
|
|
type="button"
|
|
role="tab"
|
|
class="bottom-panel__tab"
|
|
:class="{ 'bottom-panel__tab--active': tab.id === active }"
|
|
:aria-selected="tab.id === active"
|
|
:tabindex="tab.id === active ? 0 : -1"
|
|
:data-test="`bottom-tab-${tab.id}`"
|
|
@click="emit('update:active', tab.id)"
|
|
@keydown="onTabKey($event, index)"
|
|
>{{ tab.title }}</button>
|
|
</span>
|
|
<span class="bottom-panel__actions">
|
|
<button
|
|
type="button"
|
|
class="bottom-panel__button"
|
|
:title="open ? t('common.toolWindow.collapse', { title }) : t('common.toolWindow.expand', { title })"
|
|
:aria-label="open ? t('common.toolWindow.collapse', { title }) : t('common.toolWindow.expand', { title })"
|
|
:aria-expanded="open"
|
|
data-test="bottom-panel-toggle"
|
|
@click="emit('update:open', !open)"
|
|
>
|
|
<ChevronDown
|
|
v-if="open"
|
|
:size="16"
|
|
/>
|
|
<ChevronUp
|
|
v-else
|
|
:size="16"
|
|
/>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="bottom-panel__button"
|
|
:title="t('common.toolWindow.hide', { title })"
|
|
:aria-label="t('common.toolWindow.hide', { title })"
|
|
data-test="bottom-panel-close"
|
|
@click="emit('close')"
|
|
>
|
|
<X :size="16" />
|
|
</button>
|
|
</span>
|
|
</header>
|
|
<div
|
|
v-if="open"
|
|
class="bottom-panel__body"
|
|
:style="bodyStyle"
|
|
>
|
|
<slot />
|
|
</div>
|
|
</section>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.bottom-panel {
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex: none;
|
|
max-height: 75%;
|
|
background: var(--lt-bg);
|
|
border-top: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.bottom-panel__header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
flex: none;
|
|
height: var(--lt-header-height, 28px);
|
|
padding: 0 var(--lt-space-s, 4px) 0 var(--lt-space-m, 8px);
|
|
border-bottom: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.bottom-panel__title {
|
|
font-weight: 600;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.bottom-panel__tabs {
|
|
display: inline-flex;
|
|
align-self: stretch;
|
|
gap: var(--lt-space-xs, 2px);
|
|
min-width: 0;
|
|
}
|
|
|
|
.bottom-panel__tab {
|
|
padding: 0 var(--lt-space-m, 8px);
|
|
color: var(--lt-fg-muted);
|
|
font: inherit;
|
|
font-weight: 600;
|
|
background: transparent;
|
|
border: none;
|
|
border-bottom: 2px solid transparent;
|
|
cursor: pointer;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.bottom-panel__tab:hover {
|
|
color: var(--lt-fg);
|
|
}
|
|
|
|
.bottom-panel__tab--active {
|
|
color: var(--lt-fg);
|
|
border-bottom-color: var(--lt-accent);
|
|
}
|
|
|
|
.bottom-panel__tab:focus-visible {
|
|
outline: 2px solid var(--lt-accent);
|
|
outline-offset: -2px;
|
|
}
|
|
|
|
.bottom-panel__actions {
|
|
display: inline-flex;
|
|
gap: var(--lt-space-xs, 2px);
|
|
}
|
|
|
|
.bottom-panel__body {
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 0;
|
|
flex-shrink: 1;
|
|
}
|
|
|
|
.bottom-panel__button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: var(--lt-space-xs, 2px);
|
|
color: var(--lt-fg-muted);
|
|
background: transparent;
|
|
border: none;
|
|
border-radius: var(--lt-radius, 4px);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.bottom-panel__button:hover {
|
|
color: var(--lt-fg);
|
|
background: color-mix(in srgb, var(--lt-fg) 8%, transparent);
|
|
}
|
|
|
|
.bottom-panel__button:focus-visible {
|
|
outline: 2px solid var(--lt-accent);
|
|
}
|
|
|
|
.bottom-panel__splitter {
|
|
position: absolute;
|
|
top: -3px;
|
|
right: 0;
|
|
left: 0;
|
|
height: 6px;
|
|
cursor: row-resize;
|
|
z-index: 1;
|
|
}
|
|
|
|
.bottom-panel__splitter:hover,
|
|
.bottom-panel__splitter:focus-visible {
|
|
outline: none;
|
|
background: color-mix(in srgb, var(--lt-accent) 50%, transparent);
|
|
}
|
|
</style>
|