summaryrefslogtreecommitdiff
path: root/extension/src/terminal/terminalEmulator.ts
blob: ba860b2458fa1971d0a3a42435a0b8c7ce465c02 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// /* Terminal emulator - commented because node-pty is causing problems. */

// import * as vscode from "vscode";
// import pty = require("node-pty");
// import os = require("os");
// import { extensionContext } from "../activation/activate";
// import { debugPanelWebview } from "../debugPanel"; // Need to consider having multiple panels, where to store this state.
// import {
//   CommandCaptureSnooper,
//   PythonTracebackSnooper,
//   TerminalSnooper,
// } from "./snoopers";

// export function tracebackToWebviewAction(traceback: string) {
//   if (debugPanelWebview) {
//     debugPanelWebview.postMessage({
//       type: "traceback",
//       value: traceback,
//     });
//   } else {
//     vscode.commands
//       .executeCommand("continue.openDebugPanel", extensionContext)
//       .then(() => {
//         // TODO: Waiting for the webview to load, but should add a hook to the onLoad message event. Same thing in autodebugTest command in commands.ts
//         setTimeout(() => {
//           debugPanelWebview?.postMessage({
//             type: "traceback",
//             value: traceback,
//           });
//         }, 500);
//       });
//   }
// }

// const DEFAULT_SNOOPERS = [
//   new PythonTracebackSnooper(tracebackToWebviewAction),
//   new CommandCaptureSnooper((data: string) => {
//     if (data.trim().startsWith("pytest ")) {
//       let fileAndFunctionSpecifier = data.split(" ")[1];
//       vscode.commands.executeCommand(
//         "continue.debugTest",
//         fileAndFunctionSpecifier
//       );
//     }
//   }),
// ];

// // Whenever a user opens a terminal, replace it with ours
// vscode.window.onDidOpenTerminal((terminal) => {
//   if (terminal.name != "Continue") {
//     terminal.dispose();
//     openCapturedTerminal();
//   }
// });

// function getDefaultShell(): string {
//   if (process.platform !== "win32") {
//     return os.userInfo().shell;
//   }
//   switch (process.platform) {
//     case "win32":
//       return process.env.COMSPEC || "cmd.exe";
//     // case "darwin":
//     //   return process.env.SHELL || "/bin/zsh";
//     // default:
//     //   return process.env.SHELL || "/bin/sh";
//   }
// }

// function getRootDir(): string | undefined {
//   var isWindows = os.platform() === "win32";
//   let cwd = isWindows ? process.env.USERPROFILE : process.env.HOME;
//   if (
//     vscode.workspace.workspaceFolders &&
//     vscode.workspace.workspaceFolders.length > 0
//   ) {
//     cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
//   }
//   return cwd;
// }

// export function openCapturedTerminal(
//   snoopers: TerminalSnooper<string>[] = DEFAULT_SNOOPERS
// ) {
//   // If there is another existing, non-Continue terminal, delete it
//   let terminals = vscode.window.terminals;
//   for (let i = 0; i < terminals.length; i++) {
//     if (terminals[i].name != "Continue") {
//       terminals[i].dispose();
//     }
//   }

//   let env = { ...(process.env as any) };
//   if (os.platform() !== "win32") {
//     env["PATH"] += ":" + ["/opt/homebrew/bin", "/opt/homebrew/sbin"].join(":");
//   }

//   var ptyProcess = pty.spawn(getDefaultShell(), [], {
//     name: "xterm-256color",
//     cols: 160, // TODO: Get size of vscode terminal, and change with resize
//     rows: 26,
//     cwd: getRootDir(),
//     env,
//     useConpty: true,
//   });

//   const writeEmitter = new vscode.EventEmitter<string>();

//   ptyProcess.onData((data: any) => {
//     // Let each of the snoopers see the new data
//     for (let snooper of snoopers) {
//       snooper.onData(data);
//     }

//     // Pass data through to terminal
//     writeEmitter.fire(data);
//   });
//   process.on("exit", () => ptyProcess.kill());

//   const newPty: vscode.Pseudoterminal = {
//     onDidWrite: writeEmitter.event,
//     open: () => {},
//     close: () => {},
//     handleInput: (data) => {
//       for (let snooper of snoopers) {
//         snooper.onWrite(data);
//       }
//       ptyProcess.write(data);
//     },
//   };
//   const terminal = vscode.window.createTerminal({
//     name: "Continue",
//     pty: newPty,
//   });
//   terminal.show();

//   setTimeout(() => {
//     ptyProcess.write("clear\r");
//   }, 500);
// }