1// Copyright 2023 The Pigweed Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may not 4// use this file except in compliance with the License. You may obtain a copy of 5// the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12// License for the specific language governing permissions and limitations under 13// the License. 14 15import * as vscode from 'vscode'; 16import logger from './logging'; 17 18type InitScript = 'activate' | 'bootstrap'; 19 20/** 21 * Generate the configuration to launch an activated or bootstrapped terminal. 22 * 23 * @param initScript The name of the script to be sourced on launch 24 * @returns Options to be provided to terminal launch functions 25 */ 26function getShellConfig( 27 initScript: InitScript = 'activate', 28): vscode.TerminalOptions { 29 const shell = vscode.workspace 30 .getConfiguration('pigweed') 31 .get('terminalShell') as string; 32 33 return { 34 name: 'Pigweed Terminal', 35 shellPath: shell, 36 shellArgs: ['-c', `. ./${initScript}.sh; exec ${shell} -i`], 37 }; 38} 39 40/** 41 * Launch an activated terminal. 42 */ 43export function launchTerminal() { 44 const shellConfig = getShellConfig(); 45 logger.info(`Launching activated terminal with: ${shellConfig.shellPath}`); 46 vscode.window.createTerminal(shellConfig).show(); 47} 48 49/** 50 * Launch a activated terminal by bootstrapping it. 51 */ 52export function launchBootstrapTerminal() { 53 const shellConfig = getShellConfig(); 54 logger.info(`Launching bootstrapepd terminal with: ${shellConfig.shellPath}`); 55 vscode.window.createTerminal(getShellConfig('bootstrap')).show(); 56} 57