Skip to content

Commit a2be14f

Browse files
authored
Merge pull request #9 from Aman-zishan/feat/styling
feat(CLI): update CLI logo and delete function
2 parents 4c44179 + 905523d commit a2be14f

File tree

10 files changed

+147
-16
lines changed

10 files changed

+147
-16
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,6 @@ out
127127
.yarn/unplugged
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130-
.pnp.*
130+
.pnp.*
131+
132+

dist/CLI/list-all.js

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/CLI/list-all.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/utils/generate-logo.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/utils/generate-logo.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CLI/list-all.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import loadSnippets from '../core/get-snippets';
2+
3+
export default async function listAll() {
4+
const snippets = loadSnippets();
5+
const detailedSnippetsPromises = snippets.map(async (snippet: Snippet) => {
6+
return {
7+
ID: snippet.id,
8+
title: snippet.title,
9+
language: snippet.language,
10+
};
11+
});
12+
const detailedSnippets = await Promise.all(detailedSnippetsPromises);
13+
console.table(detailedSnippets);
14+
}

src/index.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import listSnippets from './core/list-interface';
77
import { saveSnippet } from './core/save-snippet';
88
import loadSnippets from './core/get-snippets';
99
import highlight, { supportsLanguage } from 'cli-highlight';
10+
import generateLogo from './utils/generate-logo';
11+
import listAll from './CLI/list-all';
12+
import { deleteSnippet } from './core/delete-snippet';
1013

1114
const program = new Command();
1215

13-
// CSM logo in CLI
14-
console.log(chalk.red(figlet.textSync('CSM', '3D Diagonal')));
15-
16+
const version = require('../package.json').version;
17+
generateLogo();
1618
program
17-
.version('1.3.0')
19+
.version(version)
1820
.description(
1921
chalk.green(
2022
'A CLI Code Snippet Manager tool for managing code snippets directly from your terminal',
@@ -23,7 +25,17 @@ program
2325
.option('-s, --save <filepath>', 'Save a code snippet')
2426
.option('-ls, --list-all', 'List all snippets')
2527
.option('-o, --output <snippet_title>', 'Output a particular snippet')
28+
.option('-d, --delete <snippet_ID>', 'Delete snippet by ID')
2629
.option('-l, --list', 'Open TUI')
30+
.addHelpText(
31+
'after',
32+
`
33+
Example:
34+
$ csm-kit -s hello.py
35+
$ csm-kit -ls
36+
$ csm-kit -o hello.py
37+
`,
38+
)
2739
.parse(process.argv);
2840

2941
const options = program.opts();
@@ -47,9 +59,7 @@ if (options.list) {
4759
}
4860

4961
if (options.listAll) {
50-
const snippets = loadSnippets();
51-
const titles = snippets.map((snippet: Snippet) => snippet.title);
52-
titles.forEach((title: string) => console.log(chalk.green(title)));
62+
listAll();
5363
}
5464

5565
if (options.output) {
@@ -81,3 +91,9 @@ if (options.output) {
8191
});
8292
console.log(highlightedCode);
8393
}
94+
95+
if (options.delete) {
96+
const snippetId =
97+
typeof options.delete === 'string' ? parseInt(options.delete) : 0;
98+
console.log(deleteSnippet(snippetId));
99+
}

src/utils/generate-logo.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import chalk from 'chalk';
2+
import figlet from 'figlet';
3+
4+
export default function generateLogo() {
5+
// Generate figlet text for both symbols
6+
const arrow = figlet.textSync('>', { font: '3D-ASCII' });
7+
const text = figlet.textSync('CSM', { font: '3D-ASCII' });
8+
9+
// Split the generated text into lines
10+
const arrowLines = arrow.split('\n');
11+
const textLines = text.split('\n');
12+
13+
// To ensure both pieces have the same number of lines
14+
const maxLength = Math.max(arrowLines.length, textLines.length);
15+
16+
// Create a combined text with colored lines
17+
const combinedLines = [];
18+
for (let i = 0; i < maxLength; i++) {
19+
const arrowLine = arrowLines[i] || '';
20+
const textLine = textLines[i] || '';
21+
22+
combinedLines.push(chalk.green(arrowLine) + chalk.red(textLine));
23+
}
24+
25+
// Print each combined line
26+
combinedLines.forEach((line) => console.log(line));
27+
}

0 commit comments

Comments
 (0)