-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to ANSI OSC52 sequence to manipulate selection and clipboard data. The sequence specs supports multiple selections but due to the browser limitations (Clipboard API), this PR only supports manipulating the clipboard selection. This adds a new `registerClipboardService` method to allow headless xtermjs to register their own clipboard service. The browser uses a clipboard service that use the Clipboard API to read/write from and to the clipboard. Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands Fixes: #3260
- Loading branch information
1 parent
cd0dd52
commit 7cb2104
Showing
13 changed files
with
242 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2022 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { assert } from 'chai'; | ||
import { ClipboardService } from 'browser/services/ClipboardService'; | ||
import { IClipboardService } from 'common/services/Services'; | ||
import { ClipboardType } from 'common/Types'; | ||
|
||
describe('OscClipboardService', () => { | ||
it('constructor', () => { | ||
const testData = 'Hello world!'; | ||
let clipboardService: IClipboardService; | ||
beforeEach(() => { | ||
clipboardService = new ClipboardService(); | ||
}); | ||
it('should be able to write data to the clipboard', async () => { | ||
assert.ok(await clipboardService.putData(ClipboardType.CLIPBOARD, testData)); | ||
}); | ||
it('should be able to read data from the clipboard', async () => { | ||
const data = await clipboardService.readData(ClipboardType.CLIPBOARD); | ||
assert.equal(data, testData); | ||
}); | ||
it('should be able to clear data from the clipboard', async () => { | ||
await clipboardService.clearData(ClipboardType.CLIPBOARD); | ||
assert.equal(await clipboardService.readData(ClipboardType.CLIPBOARD), ''); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) 2022 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { IClipboardService } from 'common/services/Services'; | ||
import { ClipboardType } from 'common/Types'; | ||
|
||
export class ClipboardService implements IClipboardService { | ||
public serviceBrand: any; | ||
|
||
public clearData(clipboard: ClipboardType): Promise<void> { | ||
return this.putData(clipboard, ''); | ||
} | ||
public putData(clipboard: ClipboardType, data: string): Promise<void> { | ||
return navigator.clipboard.writeText(data); | ||
} | ||
public readData(clipboard: ClipboardType): Promise<string> { | ||
return navigator.clipboard.readText(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.