diff --git a/packages/app/src/nativeBridge/modules/applicationModule.ts b/packages/app/src/nativeBridge/modules/applicationModule.ts index a95b6f2..2afddab 100644 --- a/packages/app/src/nativeBridge/modules/applicationModule.ts +++ b/packages/app/src/nativeBridge/modules/applicationModule.ts @@ -59,6 +59,15 @@ export class ApplicationModule extends NativeBridgeModule { return Logger.getInstance().getLogPath(); } + @moduleFunction() + public async renameTab( + _mainWindow: BrowserWindow, + tabId: number, + newTabName: string, + ): Promise { + // Implement the logic to rename the tab + } + @moduleEvent('on') public onLog( _mainWindow: BrowserWindow, diff --git a/packages/app/src/nativeBridge/modules/configModule.ts b/packages/app/src/nativeBridge/modules/configModule.ts index ed8711c..264531a 100644 --- a/packages/app/src/nativeBridge/modules/configModule.ts +++ b/packages/app/src/nativeBridge/modules/configModule.ts @@ -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 = {}; @moduleFunction() public async getConfig(_mainWindow: BrowserWindow): Promise { @@ -32,6 +33,15 @@ export class ConfigModule extends NativeBridgeModule { return this.configPath; } + @moduleFunction() + public async renameTab( + _mainWindow: BrowserWindow, + tabId: number, + newTabName: string, + ): Promise { + this.tabNames[tabId] = newTabName; + } + public onRegistered(mainWindow: BrowserWindow): void { const configPathCandidates: string[] = [ path.join( diff --git a/packages/terminal/app/page.tsx b/packages/terminal/app/page.tsx index 83143d0..9edd291 100644 --- a/packages/terminal/app/page.tsx +++ b/packages/terminal/app/page.tsx @@ -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'; @@ -19,6 +19,7 @@ const Tab = dynamic(() => import('../components/Tab'), { type UserTab = { tabId: number; + tabName: string; }; const Page = () => { @@ -41,6 +42,7 @@ const Page = () => { ...userTabs, { tabId: newTabId, + tabName: `Tab ${newTabId}`, shellName: config.shells.length === 1 ? config.defaultShellName : null, }, @@ -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); @@ -187,6 +199,7 @@ const Page = () => { setUserTabs([ { tabId: 1, + tabName: 'Tab 1', }, ]); } @@ -234,16 +247,32 @@ const Page = () => { setTabId(userTab.tabId); }} > - {userTab.tabId} + {userTab.tabName} {userTab.tabId === tabId && ( - + <> + + + )} ))} @@ -275,6 +304,7 @@ const Page = () => { key={userTab.tabId} active={tabId === userTab.tabId} tabId={userTab.tabId} + tabName={userTab.tabName} close={() => { closeTab(userTab.tabId); }} diff --git a/packages/terminal/components/Tab/index.tsx b/packages/terminal/components/Tab/index.tsx index e4849e1..5d79550 100644 --- a/packages/terminal/components/Tab/index.tsx +++ b/packages/terminal/components/Tab/index.tsx @@ -5,10 +5,12 @@ import { TerminalTreeNode } from '../TerminalTreeNode'; const Tab = ({ tabId, + tabName, active, close, }: { tabId: number; + tabName: string; active: boolean; close: () => void; }) => { diff --git a/packages/terminal/components/TitleBar/index.tsx b/packages/terminal/components/TitleBar/index.tsx index 1dea0a0..2b549c1 100644 --- a/packages/terminal/components/TitleBar/index.tsx +++ b/packages/terminal/components/TitleBar/index.tsx @@ -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'; @@ -72,6 +72,18 @@ function TitleBar(props: PropsWithChildren) { > + )}