Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add decorations to demo #170

Merged
merged 11 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _includes/demo.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="demo">
<div class="inner"></div>
</div>
<link rel="stylesheet" href="https://unpkg.com/xterm@4.15.0-beta.10/css/xterm.css" />
<link rel="stylesheet" href="https://unpkg.com/xterm@4.18.0/css/xterm.css" />
<style>
.xterm-viewport.xterm-viewport {
scrollbar-width: thin;
Expand All @@ -17,6 +17,6 @@
background-color: #ffffff20;
}
</style>
<script src="https://unpkg.com/xterm@4.15.0-beta.10/lib/xterm.js"></script>
<script src="https://unpkg.com/xterm@4.18.0/lib/xterm.js"></script>
<script src="https://unpkg.com/[email protected]/lib/xterm-addon-webgl.js"></script>
<script src="{{ "/js/demo.js" | prepend: site.baseurl }}"></script>
22 changes: 22 additions & 0 deletions css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ h4:hover, h5:hover, h6:hover {

}

.link-hint-decoration {
background-color: #5f5d5d;
padding: .2em .5em;
border-radius: 7px;
color: white;
border-top-right-radius: 0px;
margin-top: 8px;
font-size: 15px;
}

.link-hint-decoration::after {
border-bottom: 6px solid #5f5d5d;
border-left: 6px solid transparent;
content: "";
width: 0;
height: 0;
display: block;
position: absolute;
bottom: 100%;
right: 0px;
}

@import 'code';
@import 'home';
@import 'syntax_highlight';
43 changes: 33 additions & 10 deletions js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ $(function () {
' │ A screen reader mode is available Zero external dependencies │',
' │ │',
' │ \x1b[35;1mUnicode support \x1b[36mAnd much more...\x1b[0m │',
' │ Supports CJK 語 and emoji \u2764\ufe0f \x1b[3mLinks\x1b[0m, \x1b[3mthemes\x1b[0m, \x1b[3maddons\x1b[0m, \x1b[3mtyped API\x1b[0m │',
' │ ^ Try clicking italic text │',
' │ Supports CJK 語 and emoji \u2764\ufe0f \x1b[3mLinks\x1b[0m, \x1b[3mthemes\x1b[0m, \x1b[3maddons\x1b[0m, │',
' │ \x1b[3mtyped API\x1b[0m, \x1b[3mdecorations\x1b[0m │',
' │ │',
' └────────────────────────────────────────────────────────────────────────────┘',
''
].join('\n\r'));

term.writeln('Below is a simple emulated backend, try running `help`.');
addDecoration(term);
prompt(term);

term.onData(e => {
Expand Down Expand Up @@ -197,16 +198,26 @@ $(function () {
activate() {
window.open('/docs/guides/using-addons/', '_blank');
}
},
{
text: 'typed API',
range: { start: { x: 68, y: 14 }, end: { x: 76, y: 14 } },
activate() {
window.open('https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts', '_blank');
}
},
}
]);
return;
case 15: callback([
{
text: 'typed API',
range: { start: { x: 45, y: 15 }, end: { x: 53, y: 15 } },
activate() {
window.open('https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts', '_blank');
}
},
{
text: 'decorations',
range: { start: { x: 56, y: 15 }, end: { x: 66, y: 15 } },
activate() {
window.open('https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts#L947', '_blank');
}
},
]);
return;
}
callback(undefined);
}
Expand Down Expand Up @@ -288,3 +299,15 @@ $(function () {

runFakeTerminal();
});

function addDecoration(term) {
const marker = term.addMarker(15);
const decoration = term.registerDecoration({ marker, x: 44 });
decoration.onRender(element => {
element.classList.add('link-hint-decoration');
element.innerText = 'Try clicking italic text';
// must be inlined to override inlined width/height coming from xterm
element.style.height = '';
element.style.width = '';
});
}