Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
c9fe9e0d
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c9fe9e0d
编写于
6月 17, 2018
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Expose the Terminal on the TerminalRenderer
上级
a361c53d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
6 deletion
+61
-6
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+34
-4
src/vs/workbench/api/node/extHostTerminalService.ts
src/vs/workbench/api/node/extHostTerminalService.ts
+27
-2
未找到文件。
src/vs/vscode.proposed.d.ts
浏览文件 @
c9fe9e0d
...
...
@@ -339,13 +339,13 @@ declare module 'vscode' {
/**
* Fires when the terminal's pty slave pseudo-device is written to. In other words, this
* provides access to the raw data stream from the process running within the terminal,
* including
ANSI
sequences.
* including
VT
sequences.
*/
onData
:
Event
<
string
>
;
}
/**
* Represents dimensions of a terminal.
* Represents
the
dimensions of a terminal.
*/
export
interface
TerminalDimensions
{
/**
...
...
@@ -367,11 +367,18 @@ declare module 'vscode' {
* Note that an instance of [Terminal](#Terminal) will be created when a TerminalRenderer is
* created with all its APIs available for use by extensions. When using the Terminal object
* of a TerminalRenderer it acts just like normal only the extension that created the
* TerminalRenderer essentially acts as a process
of a normal terminal. For example whe
n
*
an
[Terminal.onData](#Terminal.onData) listener is registered, that will fire when
* TerminalRenderer essentially acts as a process
. For example when a
n
* [Terminal.onData](#Terminal.onData) listener is registered, that will fire when
* [TerminalRenderer.write](#TerminalRenderer.write) is called. Similarly when
* [Terminal.sendText](#Terminal.sendText) is triggered that will fire the
* [TerminalRenderer.onInput](#TerminalRenderer.onInput) event.
*
* **Example:** Create a terminal renderer, show it and write hello world in red
* ```typescript
* const renderer = window.createTerminalRenderer('foo');
* renderer.terminal.then(t => t.show());
* renderer.write('\x1b[31mHello world\x1b[0m');
* ```
*/
export
interface
TerminalRenderer
{
/**
...
...
@@ -383,6 +390,14 @@ declare module 'vscode' {
* The dimensions of the terminal, the rows and columns of the terminal can only be set to
* a value smaller than the maximum value, if this is undefined the terminal will auto fit
* to the maximum value [maximumDimensions](TerminalRenderer.maximumDimensions).
*
* **Example:** Override the dimensions of a TerminalRenderer to 20 columns and 10 rows
* ```typescript
* terminalRenderer.dimensions = {
* cols: 20,
* rows: 10
* };
* ```
*/
dimensions
:
TerminalDimensions
;
...
...
@@ -394,6 +409,11 @@ declare module 'vscode' {
*/
readonly
maximumDimensions
:
TerminalDimensions
;
/**
* The corressponding [Terminal](#Terminal) for this TerminalRenderer.
*/
readonly
terminal
:
Thenable
<
Terminal
>
;
/**
* Write text to the terminal. Unlike [Terminal.sendText](#Terminal.sendText) which sends
* text to the underlying _process_, this will write the text to the terminal itself.
...
...
@@ -416,6 +436,16 @@ declare module 'vscode' {
* An event which fires on keystrokes in the terminal or when an extension calls
* [Terminal.sendText](#Terminal.sendText). Keystrokes are converted into their
* corresponding VT sequence representation.
*
* **Example:** Simulate interaction with the terminal from an outside extension or a
* workbench command such as `workbench.action.terminal.runSelectedText`
* ```typescript
* const terminalRenderer = window.createTerminalRenderer('test');
* terminalRenderer.onInput(data => {
* cosole.log(data); // 'Hello world'
* });
* terminalRenderer.terminal.then(t => t.sendText('Hello world'));
* ```
*/
onInput
:
Event
<
string
>
;
...
...
src/vs/workbench/api/node/extHostTerminalService.ts
浏览文件 @
c9fe9e0d
...
...
@@ -179,9 +179,15 @@ export class ExtHostTerminalRenderer extends BaseExtHostTerminal implements vsco
return
this
.
_onDidChangeMaximumDimensions
&&
this
.
_onDidChangeMaximumDimensions
.
event
;
}
public
get
terminal
():
Promise
<
ExtHostTerminal
>
{
console
.
log
(
'
terminal
'
+
this
.
_id
);
return
this
.
_fetchTerminal
(
this
.
_id
);
}
constructor
(
proxy
:
MainThreadTerminalServiceShape
,
private
_name
:
string
private
_name
:
string
,
private
_fetchTerminal
:
(
id
:
number
)
=>
Promise
<
ExtHostTerminal
>
)
{
super
(
proxy
);
this
.
_proxy
.
$createTerminalRenderer
(
this
.
_name
).
then
(
id
=>
{
...
...
@@ -240,7 +246,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
}
public
createTerminalRenderer
(
name
:
string
):
vscode
.
TerminalRenderer
{
const
renderer
=
new
ExtHostTerminalRenderer
(
this
.
_proxy
,
name
);
const
renderer
=
new
ExtHostTerminalRenderer
(
this
.
_proxy
,
name
,
(
id
)
=>
this
.
_getTerminalByIdEventually
(
id
)
);
this
.
_terminalRenderers
.
push
(
renderer
);
return
renderer
;
}
...
...
@@ -395,6 +401,25 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
this
.
_proxy
.
$sendProcessExit
(
id
,
exitCode
);
}
private
_getTerminalByIdEventually
(
id
:
number
,
retries
:
number
=
3
):
Promise
<
ExtHostTerminal
>
{
return
new
Promise
(
c
=>
{
if
(
retries
===
0
)
{
c
(
undefined
);
return
;
}
const
terminal
=
this
.
_getTerminalById
(
id
);
if
(
terminal
)
{
c
(
terminal
);
}
else
{
// This should only be needed immediately after createTerminalRenderer is called
setTimeout
(()
=>
{
c
(
this
.
_getTerminalByIdEventually
(
retries
-
1
));
},
100
);
}
});
}
private
_getTerminalById
(
id
:
number
):
ExtHostTerminal
{
return
this
.
_getTerminalObjectById
(
this
.
_terminals
,
id
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录