Skip to content

Commit

Permalink
App 2068 bugfix code snippet (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrloureed authored Jun 22, 2023
1 parent 284c8e9 commit 1c0c1c5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime",
"version": "0.2.13",
"version": "0.2.14",
"license": "Apache-2.0",
"type": "module",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions playground/src/tabs-test.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import example from '../../src/stories/assets/json-code-example';
import example from '../../src/stories/assets/cpp-code-example';
let selectedTab = $ref('Tab 2');
let jsonCodeExampleSrc = $ref(example);
Expand All @@ -9,7 +9,7 @@ setTimeout(() => {
null,
2
);
}, 2000);
}, 4000);
const handleTabSelect = (event: CustomEvent<{ value: string }>) => {
selectedTab = event.detail.value;
};
Expand Down
18 changes: 17 additions & 1 deletion src/elements/code-snippet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,29 @@ const highlight = async () => {
'font-family: Menlo, Monaco, "Courier New", monospace'
);
};
const formatCode = (input: string): string => {
const htmlEntities: Record<string, string> = {
'<': '&lt;',
'>': '&gt',
'/': '&#47;',
};
let formattedCode = input;
for (const [key, value] of Object.entries(htmlEntities)) {
formattedCode = formattedCode.replaceAll(key, value);
}
return formattedCode;
};
onMount(async () => {
await highlight();
});
$: {
if (element) {
element.innerHTML = code;
element.innerHTML = formatCode(code);
// eslint-disable-next-line no-void
void highlight();
}
Expand Down
35 changes: 35 additions & 0 deletions src/stories/assets/cpp-code-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export default `
#include <string>
#include <vector>
#include <boost/optional.hpp>
#include <viam/api/common/v1/common.pb.h>
#include <viam/api/robot/v1/robot.grpc.pb.h>
#include <viam/sdk/robot/client.hpp>
using namespace viam::sdk;
int main() {
std::string host("modal-main.f5cyhk55u2.viam.cloud");
DialOptions dial_opts;
// Replace "<SECRET>" (including brackets) with your robot's secret
Credentials credentials("<SECRET>");
dial_opts.set_credentials(credentials);
boost::optional<DialOptions> opts(dial_opts);
Options options(0, opts);
auto robot = RobotClient::at_address(host, options);
std::cout << "Resources:\n";
for (const ResourceName& resource: *robot->resource_names()) {
std::cout << resource.namespace_() << ":" << resource.type() << ":"
<< resource.subtype() << ":" << resource.name() << "\n";
}
return 0;
}
`;

0 comments on commit 1c0c1c5

Please sign in to comment.