Skip to content

Commit

Permalink
Introduce new setting (#1353)
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout authored May 15, 2024
1 parent 403eb6e commit 4cda7c3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@
"default": 10,
"markdownDescription": "Default number of rows in notebook terminal"
},
"runme.terminal.closeOnSuccess": {
"type": "boolean",
"default": true,
"markdownDescription": "If set to 'true', integrated terminal panel is being closed upon successful completion of cell/task."
},
"runme.actions.openViewInEditor": {
"type": "string",
"default": "split",
Expand Down Expand Up @@ -1118,4 +1123,4 @@
"yaml": "^2.3.2",
"zod": "^3.22.2"
}
}
}
8 changes: 6 additions & 2 deletions src/extension/executors/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
import { IRunnerEnvironment } from '../../runner/environment'
import { getAnnotations, getCellRunmeId, getTerminalByCell } from '../../utils'
import { postClientMessage } from '../../../utils/messaging'
import { isNotebookTerminalEnabledForCell } from '../../../utils/configuration'
import {
getCloseTerminalOnSuccess,
isNotebookTerminalEnabledForCell,
} from '../../../utils/configuration'
import { ITerminalState } from '../../terminal/terminalState'
import { toggleTerminal } from '../../commands'
import {
Expand Down Expand Up @@ -367,7 +370,8 @@ export const executeRunner: IKernelRunner = async ({
/**
* only close terminal if execution passed and desired by user
*/
if (e.exitCode === 0 && closeTerminalOnSuccess && !background) {
const closeIt = getCloseTerminalOnSuccess() && closeTerminalOnSuccess
if (e.exitCode === 0 && closeIt && !background) {
closeTerminalByEnvID(RUNME_ID)
}
})
Expand Down
4 changes: 3 additions & 1 deletion src/extension/executors/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getAnnotations, getTerminalRunmeId } from '../utils'
import { PLATFORM_OS, ENV_STORE } from '../constants'
import { DEFAULT_PROMPT_ENV } from '../../constants'
import { ResolveProgramRequest_Mode } from '../grpc/runner/v1'
import { getCloseTerminalOnSuccess } from '../../utils/configuration'

import {
getCmdShellSeq,
Expand Down Expand Up @@ -136,7 +137,8 @@ export const taskExecutor: IKernelExecutor = async (executor) => {
/**
* only close terminal if execution passed and desired by user
*/
if (e.exitCode === 0 && annotations.closeTerminalOnSuccess) {
const closeIt = getCloseTerminalOnSuccess() && annotations.closeTerminalOnSuccess
if (e.exitCode === 0 && closeIt) {
closeTerminalByEnvID(RUNME_ID)
}

Expand Down
6 changes: 6 additions & 0 deletions src/utils/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const notebookTerminalSchema = {
cursorWidth: z.number().min(1).optional(),
smoothScrollDuration: z.number().optional(),
scrollback: z.number().optional(),
closeOnSuccess: z.boolean().default(true),
}

const configurationSchema = {
Expand Down Expand Up @@ -274,6 +275,10 @@ const isNotebookTerminalEnabledForCell = (cell: NotebookCell): boolean => {
: isNotebookTerminalFeatureEnabled('nonInteractive')
}

const getCloseTerminalOnSuccess = () => {
return getRunmeTerminalConfigurationValue<boolean>('closeOnSuccess', true)
}

const getCodeLensEnabled = (): boolean => {
return getCodeLensConfigurationValue<boolean>('enable', true)
}
Expand Down Expand Up @@ -411,6 +416,7 @@ export {
getActionsOpenViewInEditor,
getBinaryPath,
getCLIUseIntegratedRunme,
getCloseTerminalOnSuccess,
getCodeLensEnabled,
getCodeLensPasteIntoTerminalNewline,
getNotebookExecutionOrder,
Expand Down
1 change: 1 addition & 0 deletions tests/extension/__snapshots__/configuration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Configuration > should get nullish from font family 1`] = `
{
"backgroundTask": true,
"closeOnSuccess": true,
"cursorBlink": undefined,
"cursorStyle": "bar",
"cursorWidth": undefined,
Expand Down
5 changes: 5 additions & 0 deletions tests/extension/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getCodeLensPasteIntoTerminalNewline,
getCLIUseIntegratedRunme,
getNotebookExecutionOrder,
getCloseTerminalOnSuccess,
} from '../../src/utils/configuration'
import { SERVER_PORT } from '../../src/constants'
import { RunmeIdentity } from '../../src/extension/grpc/serializerTypes'
Expand Down Expand Up @@ -142,6 +143,10 @@ suite('Configuration', () => {
).toStrictEqual(RunmeIdentity.CELL)
})

test('getCloseTerminalOnSuccess should return true by default', () => {
expect(getCloseTerminalOnSuccess()).toStrictEqual(true)
})

test('getCodeLensEnabled should return true by default', () => {
expect(getCodeLensEnabled()).toStrictEqual(true)
})
Expand Down

0 comments on commit 4cda7c3

Please sign in to comment.