Skip to content

Commit

Permalink
Merge pull request #9 from Aman-zishan/feat/styling
Browse files Browse the repository at this point in the history
feat(CLI): update CLI logo and delete function
  • Loading branch information
Aman-zishan authored Dec 28, 2023
2 parents 4c44179 + 905523d commit a2be14f
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ out
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.pnp.*


31 changes: 31 additions & 0 deletions dist/CLI/list-all.js

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

1 change: 1 addition & 0 deletions dist/CLI/list-all.js.map

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

25 changes: 18 additions & 7 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

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

28 changes: 28 additions & 0 deletions dist/utils/generate-logo.js

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

1 change: 1 addition & 0 deletions dist/utils/generate-logo.js.map

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

14 changes: 14 additions & 0 deletions src/CLI/list-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import loadSnippets from '../core/get-snippets';

export default async function listAll() {
const snippets = loadSnippets();
const detailedSnippetsPromises = snippets.map(async (snippet: Snippet) => {
return {
ID: snippet.id,
title: snippet.title,
language: snippet.language,
};
});
const detailedSnippets = await Promise.all(detailedSnippetsPromises);
console.table(detailedSnippets);
}
30 changes: 23 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import listSnippets from './core/list-interface';
import { saveSnippet } from './core/save-snippet';
import loadSnippets from './core/get-snippets';
import highlight, { supportsLanguage } from 'cli-highlight';
import generateLogo from './utils/generate-logo';
import listAll from './CLI/list-all';
import { deleteSnippet } from './core/delete-snippet';

const program = new Command();

// CSM logo in CLI
console.log(chalk.red(figlet.textSync('CSM', '3D Diagonal')));

const version = require('../package.json').version;
generateLogo();
program
.version('1.3.0')
.version(version)
.description(
chalk.green(
'A CLI Code Snippet Manager tool for managing code snippets directly from your terminal',
Expand All @@ -23,7 +25,17 @@ program
.option('-s, --save <filepath>', 'Save a code snippet')
.option('-ls, --list-all', 'List all snippets')
.option('-o, --output <snippet_title>', 'Output a particular snippet')
.option('-d, --delete <snippet_ID>', 'Delete snippet by ID')
.option('-l, --list', 'Open TUI')
.addHelpText(
'after',
`
Example:
$ csm-kit -s hello.py
$ csm-kit -ls
$ csm-kit -o hello.py
`,
)
.parse(process.argv);

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

if (options.listAll) {
const snippets = loadSnippets();
const titles = snippets.map((snippet: Snippet) => snippet.title);
titles.forEach((title: string) => console.log(chalk.green(title)));
listAll();
}

if (options.output) {
Expand Down Expand Up @@ -81,3 +91,9 @@ if (options.output) {
});
console.log(highlightedCode);
}

if (options.delete) {
const snippetId =
typeof options.delete === 'string' ? parseInt(options.delete) : 0;
console.log(deleteSnippet(snippetId));
}
27 changes: 27 additions & 0 deletions src/utils/generate-logo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import chalk from 'chalk';
import figlet from 'figlet';

export default function generateLogo() {
// Generate figlet text for both symbols
const arrow = figlet.textSync('>', { font: '3D-ASCII' });
const text = figlet.textSync('CSM', { font: '3D-ASCII' });

// Split the generated text into lines
const arrowLines = arrow.split('\n');
const textLines = text.split('\n');

// To ensure both pieces have the same number of lines
const maxLength = Math.max(arrowLines.length, textLines.length);

// Create a combined text with colored lines
const combinedLines = [];
for (let i = 0; i < maxLength; i++) {
const arrowLine = arrowLines[i] || '';
const textLine = textLines[i] || '';

combinedLines.push(chalk.green(arrowLine) + chalk.red(textLine));
}

// Print each combined line
combinedLines.forEach((line) => console.log(line));
}

0 comments on commit a2be14f

Please sign in to comment.