Skip to content

Commit

Permalink
Cut off outputs (#1844)
Browse files Browse the repository at this point in the history
* Save XTerm buffer

* Remove serializer from extension XTerm
  • Loading branch information
peraltafederico authored Dec 10, 2024
1 parent 54f25fb commit 8a2464f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/extension/executors/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
getServerRunnerVersion,
isNotebookTerminalEnabledForCell,
} from '../../../utils/configuration'
import { ITerminalState } from '../../terminal/terminalState'
import { ITerminalState, XTermState } from '../../terminal/terminalState'
import { toggleTerminal } from '../../commands'
import { closeTerminalByEnvID, openTerminalByEnvID } from '../task'
import {
Expand Down Expand Up @@ -243,6 +243,10 @@ export const executeRunner: IKernelRunner = async ({

let mimeType = cellMimeType
if (interactive) {
if (terminalState instanceof XTermState) {
terminalState.cleanBuffer()
}

if (revealNotebookTerminal) {
program.registerTerminalWindow('notebook')
await program.setActiveTerminalWindow('notebook')
Expand Down
21 changes: 15 additions & 6 deletions src/extension/terminal/terminalState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Terminal as XTerm } from '@xterm/headless'
import { SerializeAddon } from '@xterm/addon-serialize'

import { OutputType } from '../../constants'
import { RunnerExitReason } from '../runner'
Expand All @@ -26,17 +25,14 @@ export class XTermState implements ITerminalState {
readonly outputType = OutputType.terminal

protected xterm: XTerm
private serializer: SerializeAddon
private processInfo: IProcessInfoState | undefined
protected buffer: string = ''

constructor() {
// TODO: lines/cols
this.xterm = new XTerm({
allowProposedApi: true,
})

this.serializer = new SerializeAddon()
this.xterm.loadAddon(this.serializer)
}

setProcessInfo(processInfo?: IProcessInfoState) {
Expand All @@ -48,11 +44,24 @@ export class XTermState implements ITerminalState {
}

serialize(): string {
return this.serializer.serialize()
return this.buffer
}

write(data: string | Uint8Array): void {
this.xterm.write(data)
this.addToBuffer(data)
}

addToBuffer(data: string | Uint8Array): void {
if (typeof data === 'string') {
this.buffer = this.buffer + data
} else {
this.buffer = this.buffer + new TextDecoder().decode(data)
}
}

cleanBuffer(): void {
this.buffer = ''
}

input(data: string, wasUserInput: boolean): void {
Expand Down

0 comments on commit 8a2464f

Please sign in to comment.