Skip to content

Commit

Permalink
(docs) add source command
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Sep 20, 2024
1 parent f7b1d92 commit 5998967
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/src/components/Terminal/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { JQueryTerminal, JQueryStatic } from 'jquery.terminal';

import data from '@site/dir.json';

function alow_data() {
const $ = (globalThis as any).$ as JQueryStatic;
if (!$.terminal.defaults.allowedAttributes.includes('data-path')) {
$.terminal.defaults.allowedAttributes.push('data-path');
}
}

export default function source(this: JQueryTerminal) {
alow_data();
setTimeout(() => {
this.less(tree(data));
}, 10);
}

type TreeNode = {
name: string | null;
path: string;
children?: TreeNode[];
}


function tree({ children, name, path }: TreeNode, prefix = '') {
let result = prefix ? `${prefix}[[;white;;;;{"data-path":"${path}"}]${name}]\n` : '/\n';
if (children) {
for (let i = 0; i < children.length; i++) {
const isLast = i === children.length - 1;
const newPrefix = prefix + (isLast ? '└── ' : '├── ');
const childPrefix = prefix + (isLast ? ' ' : '│ ');
result += tree(children[i], childPrefix).replace(childPrefix, newPrefix);
}
}

return result;
}
1 change: 1 addition & 0 deletions docs/src/components/Terminal/styles.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.term {
--background: white;
--color:#14232d;
--size: 1.2;
}
[data-theme='dark'] .term {
--background: #14232d;
Expand Down
2 changes: 2 additions & 0 deletions docs/src/components/Terminal/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { JQueryTerminal } from 'jquery.terminal';

import github from './github';
import echo from './echo';
import source from './source';

export function initTerminal() {
const $ = (globalThis as any).$;
Expand All @@ -14,6 +15,7 @@ export function initTerminal() {

const term = $term.terminal({
github,
source,
echo
}, {
processArguments: false,
Expand Down

0 comments on commit 5998967

Please sign in to comment.