Skip to content

Commit

Permalink
adding TSP icon to terminal. (#45)
Browse files Browse the repository at this point in the history
Removing "New Connection" from connection dropdown and automatically
assume a new connection is desired if the input to the "TSP: Connect"
input box has no results and is a valid connection string. removing
unused functions
  • Loading branch information
jharajeev55 authored Sep 5, 2024
1 parent 350bf28 commit f1d1784
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
{
"command": "InstrumentsExplorer.connect",
"title": "Connect",
"title": "New Connection",
"icon": {
"light": "resources/light/connect.svg",
"dark": "resources/dark/connect.svg"
Expand Down
5 changes: 5 additions & 0 deletions resources/dark/tsp-terminal-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions resources/light/tsp-terminal-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 65 additions & 58 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import {
RELATIVE_TSP_CONFIG_FILE_PATH,
updateConfiguration,
} from "./workspaceManager"
import { LOG_DIR } from "./utility"
import { LoggerManager } from "./logging"

let _activeConnectionManager: CommunicationManager
//let _terminationMgr: TerminationManager
Expand Down Expand Up @@ -372,34 +370,77 @@ async function onDidSaveTextDocument(textDocument: vscode.TextDocument) {

async function pickConnection(connection_info?: string): Promise<void> {
const connections: string[] = FriendlyNameMgr.fetchConnListForPicker()
let selection = ""
if (connection_info != undefined) {
selection = connection_info
} else {
selection =
(await vscode.window.showQuickPick(
["New Connection"].concat(connections),
{ placeHolder: "Select a connection" },
)) || ""

if (selection === undefined) {
return
if (connection_info !== undefined) {
const options: vscode.InputBoxOptions = {
prompt: "Enter instrument IP in <insName>@<IP> format",
validateInput: _connHelper.instrIPValidator,
}
if (selection !== "New Connection") {
await createTerminal(selection)
const Ip = await vscode.window.showInputBox(options)
if (Ip === undefined) {
return
}
}
await connect(Ip)
} else {
const options: vscode.QuickPickItem[] = connections.map(
(connection) => ({
label: connection,
}),
)
const quickPick = vscode.window.createQuickPick()
quickPick.items = options
quickPick.placeholder = "Enter instrument IP in <insName>@<IP> format"
if (options.length > 0) {
quickPick.placeholder =
"Select connection from existing list or Enter instrument IP in <insName>@<IP> format"
}

const options: vscode.InputBoxOptions = {
prompt: "Enter instrument IP in <insName>@<IP> format",
validateInput: _connHelper.instrIPValidator,
}
const Ip = await vscode.window.showInputBox(options)
if (Ip === undefined) {
return
quickPick.onDidChangeValue((value) => {
if (!options.some((option) => option.label === value)) {
const new_item = { label: value }
if (new_item.label.length > 0) {
quickPick.items = [new_item, ...options]
}
}
})

quickPick.onDidAccept(async () => {
const selectedItem = quickPick.selectedItems[0]
quickPick.busy = true
try {
// Validate connection string
const validationResult = _connHelper.instrIPValidator(
selectedItem.label,
)
if (validationResult) {
throw new Error(validationResult)
}

if (
options.some(
(option) => option.label === selectedItem.label,
)
) {
await createTerminal(selectedItem.label)
} else {
const Ip = selectedItem.label
if (Ip === undefined) {
return
}
await connect(Ip)
}
} catch (error) {
vscode.window.showErrorMessage(
`Error: ${(error as Error).message}`,
)
} finally {
quickPick.busy = false
quickPick.hide()
}
})

quickPick.show()
}
return connect(Ip)
}

async function connect(
Expand Down Expand Up @@ -427,40 +468,6 @@ async function connect(
return
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function startInstrDiscovery(): Promise<void> {
const wait_time = await vscode.window.showInputBox({
prompt: "Input how long to wait for instrument responses",
value: "15",
})
if (wait_time === undefined) {
return
}
const logger = LoggerManager.instance().add_logger("TSP Discovery")

if (parseInt(wait_time)) {
const term = vscode.window.createTerminal({
name: "Discovery",
shellPath: EXECUTABLE,
shellArgs: [
"--log-file",
join(
LOG_DIR,
`${new Date().toISOString().substring(0, 10)}-kic.log`,
),
"--log-socket",
`${logger.host}:${logger.port}`,
"discover",
"all",
"--timeout",
wait_time,
],
iconPath: vscode.Uri.file("/keithley-logo.ico"),
})
term.show()
}
}

//function startTerminateAllConn() {
// void _terminationMgr.terminateAllConn()
//}
Expand Down
46 changes: 43 additions & 3 deletions src/resourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,26 @@ export class KicCell extends EventEmitter {
"lan",
unique_id,
],
iconPath: vscode.Uri.file("/keithley-logo.ico"),
iconPath: {
light: vscode.Uri.file(
join(
__dirname,
"..",
"resources",
"light",
"tsp-terminal-icon.svg",
),
),
dark: vscode.Uri.file(
join(
__dirname,
"..",
"resources",
"dark",
"tsp-terminal-icon.svg",
),
),
},
})
} else {
this._term = vscode.window.createTerminal({
Expand All @@ -369,15 +388,36 @@ export class KicCell extends EventEmitter {
"usb",
unique_id,
],
iconPath: vscode.Uri.file("/keithley-logo.ico"),
iconPath: {
light: vscode.Uri.file(
join(
__dirname,
"..",
"resources",
"light",
"tsp-terminal-icon.svg",
),
),
dark: vscode.Uri.file(
join(
__dirname,
"..",
"resources",
"dark",
"tsp-terminal-icon.svg",
),
),
},
})
}

vscode.window.onDidCloseTerminal((t) => {
if (
t.creationOptions.iconPath !== undefined &&
// eslint-disable-next-line @typescript-eslint/no-base-to-string
t.creationOptions.iconPath.toString().search("keithley-logo") &&
t.creationOptions.iconPath
.toString()
.search("tsp-terminal-icon") &&
t.exitStatus !== undefined &&
t.exitStatus.reason !== vscode.TerminalExitReason.Process
) {
Expand Down

0 comments on commit f1d1784

Please sign in to comment.