Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Add rename tab functionality #62

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/app/src/nativeBridge/modules/applicationModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export class ApplicationModule extends NativeBridgeModule {
return Logger.getInstance().getLogPath();
}

@moduleFunction()
public async renameTab(
_mainWindow: BrowserWindow,
tabId: number,
newTabName: string,
): Promise<void> {
// Implement the logic to rename the tab
}

@moduleEvent('on')
public onLog(
_mainWindow: BrowserWindow,
Expand Down
10 changes: 10 additions & 0 deletions packages/app/src/nativeBridge/modules/configModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Logger } from './common/logger';
export class ConfigModule extends NativeBridgeModule {
private configPath: string = '';
private config: ResolvedConfig = DEFAULT_CONFIG;
private tabNames: Record<number, string> = {};

@moduleFunction()
public async getConfig(_mainWindow: BrowserWindow): Promise<ResolvedConfig> {
Expand All @@ -32,6 +33,15 @@ export class ConfigModule extends NativeBridgeModule {
return this.configPath;
}

@moduleFunction()
public async renameTab(
_mainWindow: BrowserWindow,
tabId: number,
newTabName: string,
): Promise<void> {
this.tabNames[tabId] = newTabName;
}

public onRegistered(mainWindow: BrowserWindow): void {
const configPathCandidates: string[] = [
path.join(
Expand Down
50 changes: 40 additions & 10 deletions packages/terminal/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import _ from 'lodash';
import dynamic from 'next/dynamic';
import { useCallback, useEffect, useState } from 'react';
import { FiMenu, FiPlus, FiX } from 'react-icons/fi';
import { FiMenu, FiPlus, FiX, FiEdit2 } from 'react-icons/fi';

import SettingsPage from '../components/SettingsPage';
import { useConfigContext } from '../hooks/ConfigContext';
Expand All @@ -19,6 +19,7 @@ const Tab = dynamic(() => import('../components/Tab'), {

type UserTab = {
tabId: number;
tabName: string;
};

const Page = () => {
Expand All @@ -41,6 +42,7 @@ const Page = () => {
...userTabs,
{
tabId: newTabId,
tabName: `Tab ${newTabId}`,
shellName:
config.shells.length === 1 ? config.defaultShellName : null,
},
Expand Down Expand Up @@ -134,6 +136,16 @@ const Page = () => {
switchToTab(9);
}, [switchToTab]);

const renameTab = useCallback(
(targetTabId: number, newTabName: string) => {
const newTabs = userTabs.map((t) =>
t.tabId === targetTabId ? { ...t, tabName: newTabName } : t,
);
setUserTabs(newTabs);
},
[userTabs],
);

useEffect(() => {
commands.on('createTab', createTab);
commands.on('closeTab', closeCurrentTab);
Expand Down Expand Up @@ -187,6 +199,7 @@ const Page = () => {
setUserTabs([
{
tabId: 1,
tabName: 'Tab 1',
},
]);
}
Expand Down Expand Up @@ -234,16 +247,32 @@ const Page = () => {
setTabId(userTab.tabId);
}}
>
{userTab.tabId}
{userTab.tabName}
{userTab.tabId === tabId && (
<button
className="btn btn-ghost btn-square btn-xs opacity-50 hover:bg-transparent hover:opacity-100 ml-2"
onClick={() => {
closeTab(tabId);
}}
>
<FiX />
</button>
<>
<button
className="btn btn-ghost btn-square btn-xs opacity-50 hover:bg-transparent hover:opacity-100 ml-2"
onClick={() => {
closeTab(tabId);
}}
>
<FiX />
</button>
<button
className="btn btn-ghost btn-square btn-xs opacity-50 hover:bg-transparent hover:opacity-100 ml-2"
onClick={() => {
const newTabName = prompt(
'Enter new tab name:',
userTab.tabName,
);
if (newTabName) {
renameTab(tabId, newTabName);
}
}}
>
<FiEdit2 />
</button>
</>
)}
</a>
))}
Expand Down Expand Up @@ -275,6 +304,7 @@ const Page = () => {
key={userTab.tabId}
active={tabId === userTab.tabId}
tabId={userTab.tabId}
tabName={userTab.tabName}
close={() => {
closeTab(userTab.tabId);
}}
Expand Down
2 changes: 2 additions & 0 deletions packages/terminal/components/Tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { TerminalTreeNode } from '../TerminalTreeNode';

const Tab = ({
tabId,
tabName,
active,
close,
}: {
tabId: number;
tabName: string;
active: boolean;
close: () => void;
}) => {
Expand Down
14 changes: 13 additions & 1 deletion packages/terminal/components/TitleBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { PropsWithChildren, useEffect, useState } from 'react';
import { flushSync } from 'react-dom';
import { FiMaximize2, FiMinimize2, FiMinus, FiX } from 'react-icons/fi';
import { FiMaximize2, FiMinimize2, FiMinus, FiX, FiEdit2 } from 'react-icons/fi';

import styles from './index.module.css';

Expand Down Expand Up @@ -72,6 +72,18 @@ function TitleBar(props: PropsWithChildren) {
>
<FiX size="16" />
</button>
<button
className="btn btn-sm btn-ghost btn-square tab tab-lifted"
title="Rename Tab"
onClick={() => {
const newTabName = prompt('Enter new tab name:');
if (newTabName) {
window.TerminalOne?.app.renameTab(newTabName);
}
}}
>
<FiEdit2 size="16" />
</button>
</div>
)}
</div>
Expand Down
Loading