Skip to content

Commit

Permalink
Merge pull request #44 from guicassolato/running-image
Browse files Browse the repository at this point in the history
Animated 'loading' image while running commands in a separate shell in the background
  • Loading branch information
guicassolato authored Feb 15, 2023
2 parents 3dc6438 + 183b56d commit 2d7daed
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This file is structured according to the [Keep a Changelog](http://keepachangelo

## [Unreleased]

- Animated 'loading' image while running commands in a separate shell in the background

## [v0.6.0] - 2022-01-10

### Changed
Expand Down
29 changes: 17 additions & 12 deletions media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
//connect to the vscode api
const vscode = acquireVsCodeApi();

const updateOutputPanel = (id, html) => {
const panel = document.getElementById(`${id}-out`);
if (panel) {
panel.innerHTML = html;
return;
}
const target = document.getElementById(id);
if (!target) {
return;
}
target.insertAdjacentHTML('afterend', `<p>Output:</p><div class="tothom-code-output" id="${id}-out">${html}</div>`);
};

document.body.addEventListener('click', event => {
const node = event && event.target;
while (node) {
Expand Down Expand Up @@ -49,19 +62,11 @@
const message = event.data; // The JSON data our extension sent

switch (message.command) {
case 'tothom.showRunning':
updateOutputPanel(message.data.codeId, `<img src="${document.body.dataset.running}" alt="Running" class="running">`);
break;
case 'tothom.terminalOutput':
const id = message.data.codeId;
const el = document.getElementById(id);
if (!el) {
return;
}
const out = document.getElementById(`${id}-out`);
const html = `<code>${message.data.text}</code>`;
if (out) {
out.innerHTML = html;
} else {
el.insertAdjacentHTML('afterend', `<p>Output:</p><pre class="tothom-code-output" id="${id}-out">${html}</pre>`);
}
updateOutputPanel(message.data.codeId, `<pre><code>${message.data.text}</code></pre>`);
break;
}
});
Expand Down
Binary file added media/running.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions media/tothom.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
.tothom-body pre a.tothom-code-action:hover {
color: var(--color-accent-fg);
}

.tothom-body img.running {
width: 1.5em;
}
8 changes: 8 additions & 0 deletions samples/tothom.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [Interpolation](#interpolation)
- [Multiline](#multiline)
- [Carrying values](#carrying-values)
- [Loading](#loading)
- [Compatibility](#compatibility)
- [Formatting](#formatting)
- [Attributes](#attributes)
Expand Down Expand Up @@ -71,6 +72,13 @@ echo "Time was: $TIME\nTime now is: $(date)"
unset TIME
```

### Loading

```sh
sleep 3
echo 'Done.'
```

## Compatibility

### Formatting
Expand Down
8 changes: 7 additions & 1 deletion src/tothom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class Tothom {
${baseTag}
<script defer="true" src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
</head>
<body class="tothom-body ${colorScheme}" data-uri="${uri}">
<body class="tothom-body ${colorScheme}" data-uri="${uri}" data-running="${this.mediaFilePath(webview, 'running.gif')}">
<div class="tothom-content">
${htmlContent}
</div>
Expand Down Expand Up @@ -300,6 +300,12 @@ export class Tothom {
commandWithEnv += `\nenv > ${envFile}`;
}

preview.panel.webview.postMessage({
uri: uri.fsPath,
command: 'tothom.showRunning',
data: { codeId: codeId }
});

exec(commandWithEnv, { encoding: "utf8", cwd: workspaceRoot }, callback);
};

Expand Down

0 comments on commit 2d7daed

Please sign in to comment.