Skip to content

Commit

Permalink
Merge pull request #12 from tvnova-ogs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
adamjosefus authored Jan 10, 2022
2 parents 193ecac + 1ee3993 commit 8a71608
Show file tree
Hide file tree
Showing 18 changed files with 617 additions and 80 deletions.
14 changes: 14 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,19 @@
"command": "deno run -A ./bin/compile.ts",
"group": "build",
},
{
"label": "📦 PKG: Install",
"group": "build",
"options": { "cwd": "${cwd}", },
"command": "deno",
"args": ["run", "-A", "./main.ts", "--c=./lib/pkg.json", "--install"]
},
{
"label": "📦 PKG: Delete Current",
"group": "build",
"options": { "cwd": "${cwd}", },
"command": "deno",
"args": ["run", "-A", "./main.ts", "--c=./lib/pkg.json", "--delete"]
},
]
}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ deno run -A ./bin/bundle.ts
Bundle to /some/path/pkg/pkg.bundled.js
> deno bundle ./main.ts ./pkg.bundled.js
> Succeed
```
```



# VS Code Settings
Aby výstupný vhled byl nejkrásnější, nastavte ve **VS Code**:
```json
{
...
"terminal.integrated.drawBoldTextInBrightColors": false,
...
}
```
16 changes: 8 additions & 8 deletions bin/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { Color, Style } from "../lib/packages/deno-ascii-office/mod.ts";


const name = 'pkg.bundled.js';
Expand All @@ -13,8 +14,8 @@ const cmd = [
];

console.log("\n");
console.log(`Bundle to %c${path}`, "font-weight: bold;");
console.log(`%c> ${cmd.join(' ')}`, "color: grey");
console.log(Style.bold(`Bundle to %c${path}`));
console.log(Color.gray(`> ${cmd.join(' ')}`));

const process = await Deno.run({
cmd: cmd,
Expand All @@ -24,14 +25,13 @@ const process = await Deno.run({

const { success } = await process.status();


if (success) {
console.log(`%c> Succeed`, "color: grey");
console.log(Color.gray(`> Succeed`));
} else {
const outputBytes = await process.stderrOutput()
const output = (new TextDecoder()).decode(outputBytes);
console.log(`%c> Failed`, "color: grey");
console.log(`%c>> ${output}`, "color: grey");
console.log(Color.gray(`> Failed`));
console.log(Color.gray(`>> ${output}`));
}

console.log("\n");
console.log("\n");
17 changes: 11 additions & 6 deletions bin/compile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { Color, Style } from "../lib/packages/deno-ascii-office/mod.ts";


const name = (os => {
Expand All @@ -25,18 +26,22 @@ const cmd = [
];

console.log("\n");
console.log(`Compile to %c${path}`, "font-weight: bold;");
console.log(`%c> ${cmd.join(' ')}`, "color: grey");
console.log(Style.bold(`Compile to %c${path}`));
console.log(Color.gray(`> ${cmd.join(' ')}`));

const process = await Deno.run({
cmd: cmd,
stdout: 'piped',
stderr: 'piped',
})


const { success } = await process.status();

if (success) console.log(`%c> Succeed`, "color: grey");
else console.log(`%c> Failed`, "color: grey");
if (success) {
console.log(Color.gray(`> Succeed`));
} else {
console.log(Color.gray(`> Failed`));
}

console.log("\n");
console.log("\n");
22 changes: 22 additions & 0 deletions lib/exists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const exists = async (path: string): Promise<boolean> => {
try {
await Deno.stat(path);

return true;
} catch (error) {
if (error instanceof Deno.errors.NotFound) return false;
else throw error;
}
};


export const existsSync = (path: string): boolean => {
try {
Deno.statSync(path);

return true;
} catch (error) {
if (error instanceof Deno.errors.NotFound) return false;
else throw error;
}
};
4 changes: 3 additions & 1 deletion lib/packages/deno-arguments/lib/Arguments.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { parse } from "https://deno.land/std/flags/mod.ts";
import { parse } from "https://deno.land/std@0.117.0/flags/mod.ts";
import { ArgumentException } from "./ArgumentException.ts";
import { HelpException } from "./HelpException.ts";
import { ValueException } from "./ValueException.ts";


export type ExpectationProcessorType<V> = {
// deno-lint-ignore no-explicit-any
(value: any): V;
}


export type ExpectationType<V = unknown> = {
name: string | string[],
fallback?: V,
Expand Down
1 change: 1 addition & 0 deletions lib/packages/deno-ascii-office/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.vscode
5 changes: 5 additions & 0 deletions lib/packages/deno-ascii-office/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": false
}
27 changes: 27 additions & 0 deletions lib/packages/deno-ascii-office/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Deno Run",
"type": "shell",
"command": "deno run ./main.ts",
"group": "build",
"problemMatcher": "$deno",
"options": {
"cwd": "${cwd}",
}
},
{
"label": "Deno Run (Demo)",
"type": "shell",
"command": "deno run ./demo.ts",
"group": "build",
"problemMatcher": "$deno",
"options": {
"cwd": "${cwd}",
}
}
]
}
24 changes: 24 additions & 0 deletions lib/packages/deno-ascii-office/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Správné renderování

Pro správné renderování nastavte ve **VS Code** nasledující hodnoty:

Code → Preferences → Settings

```json
// Place your settings in this file to overwrite the default settings
{
// ...
"terminal.integrated.gpuAcceleration": "on",
// ...
}
```




## Ukázka

Pro ukázku spusťte demo:
```
deno run ./demo.ts
```
50 changes: 50 additions & 0 deletions lib/packages/deno-ascii-office/demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Box,
progress,
Table,
Style,
Color,
Formattable,
} from "./mod.ts";


function h(content: string): void {
console.log(`\n\n${content}:\n`);
}


function p(content: string): void {
console.log(`${content}`);
}


h("Progress");
p(progress(25, 100));
p(progress(5, 100));
p(progress(100, 100));


h("Tables");
p(Table.classic([
['Jméno', 'Jan\nEvangelista'],
['Příjmení', 'Purkyně'],
['Věk', 81],
]));

p(Table.classic([
[
new Formattable('R', (s) => Style.bold(Color.red(s))),
new Formattable('G', (s) => Style.bold(Color.green(s))),
new Formattable('B', (s) => Style.bold(Color.blue(s))),
],
]));


h("Boxes");
p(Box.classic('Box'));
p(Box.bold('Bold'));
p(Box.dashed('Dashed'));
p(Box.rounded('Rounded'));
p(Box.double('Double'));
p(Box.pretty('Pretty'));
p(Box.classic(new Formattable('Červená', (s) => Color.red(s))));
125 changes: 125 additions & 0 deletions lib/packages/deno-ascii-office/lib/boxes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { Formattable } from "./model/Formattable.ts";


type PartsType = {
left: string,
right: string,
top: string,
bottom: string,
corner1: string,
corner2: string,
corner3: string,
corner4: string,
}


export function custom(text: Formattable | string, parts: PartsType): string {
const regex = {
lineSpliter: /\n/g
}

const result: string[] = [];

const lines: (Formattable | string)[] = text.split(regex.lineSpliter);
const length = lines.reduce((v, l) => l.length > v ? l.length : v, 0);

lines.forEach((s, i, arr) => {
// First
if (i == 0) {
result.push(`${parts.corner1}${Array(length + 1).join(parts.top)}${parts.corner2}`);
}

result.push(`${parts.left}${s.toString()}${Array(length - s.length + 1).join(' ')}${parts.right}`);

// Last
if (arr.length - 1 == i) {
result.push(`${parts.corner4}${Array(length + 1).join(parts.bottom)}${parts.corner3}`);
}
});

return result.join('\n');
}


export function classic(text: Formattable | string): string {
return custom(text, {
left: '│ ',
right: ' │',
top: '─',
bottom: '─',
corner1: '┌─',
corner2: '─┐',
corner3: '─┘',
corner4: '└─',
});
}


export function bold(text: Formattable | string): string {
return custom(text, {
left: '┃ ',
right: ' ┃',
top: '━',
bottom: '━',
corner1: '┏━',
corner2: '━┓',
corner3: '━┛',
corner4: '┗━',
});
}


export function dashed(text: Formattable | string): string {
return custom(text, {
left: '╎ ',
right: ' ╎',
top: '╌',
bottom: '╌',
corner1: '┌╌',
corner2: '╌┐',
corner3: '╌┘',
corner4: '└╌',
});
}


export function rounded(text: Formattable | string): string {
return custom(text, {
left: '│ ',
right: ' │',
top: '─',
bottom: '─',
corner1: '╭─',
corner2: '─╮',
corner3: '─╯',
corner4: '╰─',
});
}


export function double(text: Formattable | string): string {
return custom(text, {
left: '║ ',
right: ' ║',
top: '═',
bottom: '═',
corner1: '╔═',
corner2: '═╗',
corner3: '═╝',
corner4: '╚═',
});
}


export function pretty(text: Formattable | string): string {
return custom(text, {
left: '│ ',
right: ' ┃',
top: '─',
bottom: '━',
corner1: '┌─',
corner2: '─┒',
corner3: '━┛',
corner4: '┕━',
});
}
Loading

0 comments on commit 8a71608

Please sign in to comment.