summaryrefslogtreecommitdiff
path: root/src/osc-notify-decorator.ts
blob: 7d32f1c592e84cca711d038b08117044664949b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import OscNotifyMiddleware from "./osc-notify-middleware";
import { Injectable } from "@angular/core";
import { TerminalDecorator, BaseSession, BaseTerminalTabComponent } from "tabby-terminal";

@Injectable()
export default class OscNotifyDecorator extends TerminalDecorator {
	attach(tab: BaseTerminalTabComponent<any>): void {
		// Subscribe to attach to future sessions in this tab
		tab.sessionChanged$.subscribe((session) => {
			if (session) {
				this.attachToSession(session, (<any>tab).title);
			}
		});

		// Attach the current session for this tab
		if (tab.session) {
			this.attachToSession(tab.session, (<any>tab).title);
		}
	}

	private attachToSession(session: BaseSession, tabTitle: string) {
		const middleware = new OscNotifyMiddleware(tabTitle);

		session.middleware.push(middleware);
	}
}