forked from xtermjs/xterm.js
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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. Reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands Fixes: xtermjs#3260
- Loading branch information
1 parent
d5710af
commit a0ab52d
Showing
9 changed files
with
194 additions
and
13 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
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,25 @@ | ||
/** | ||
* Copyright (c) 2020 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { assert } from 'chai'; | ||
import { OscClipboardService } from 'common/services/OscClipboardService'; | ||
import { IOscClipboardService } from 'common/services/Services'; | ||
|
||
describe('OscClipboardService', () => { | ||
it('constructor', () => { | ||
const testData = 'Hello world!'; | ||
let oscClipboardService: IOscClipboardService; | ||
beforeEach(() => { | ||
oscClipboardService = new OscClipboardService(); | ||
}); | ||
it('should be able to write data to the clipboard', async () => { | ||
assert.ok(await oscClipboardService.putData(testData)); | ||
}); | ||
it('should be able to read data from the clipboard', async () => { | ||
const data = await oscClipboardService.readData(); | ||
assert.equal(data, testData); | ||
}); | ||
}); | ||
}); |
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,35 @@ | ||
/** | ||
* Copyright (c) 2022 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { IOscClipboardService } from 'common/services/Services'; | ||
|
||
/** | ||
* A service that handles OSC 52 clipboard data. | ||
* | ||
* This service is used to handle OSC 52 selection and clipboard data | ||
* manipulation. It uses the Clipboard API to write and read to and from the | ||
* clipboard. The OSC52 protocol supports writing and reading to and from | ||
* different selections. However, the browser Clipboard API only supports | ||
* reading and writing to the clipboard selection. | ||
*/ | ||
export class OscClipboardService implements IOscClipboardService { | ||
/** | ||
* Writes data to the clipboard. | ||
* | ||
* This is an async operation since we're using the Clipboard API. | ||
*/ | ||
public putData(data: string): Promise<void> { | ||
return navigator.clipboard.writeText(data); | ||
} | ||
|
||
/** | ||
* Reads data from the clipboard. | ||
* | ||
* This is an async operation since we're using the Clipboard API. | ||
*/ | ||
public readData(): Promise<string> { | ||
return navigator.clipboard.readText(); | ||
} | ||
} |
Oops, something went wrong.