Skip to content

Commit

Permalink
chain logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonewu committed Jan 15, 2023
1 parent 857b090 commit f92fe94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "ssh-tunneling",
"version": "1.1.7",
"version": "1.1.8",
"description": "a ssh-tunneling client for nodejs",
"keywords": [
"ssh tunnel",
Expand Down
31 changes: 29 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const config: Record<Color, [number, number]> = {
bgMint: [0, 48],
}

type ChainLogger = Record<Color, (content: any) => ChainLogger> & { endLine: () => void; };

type Logger = Record<Color, (content: any, options?: { newLine?: boolean }) => void> & {
/** log one line */
Expand All @@ -99,6 +100,8 @@ type Logger = Record<Color, (content: any, options?: { newLine?: boolean }) => v
content: any,
}[]) => void;

startLine: () => ChainLogger;

lineGradient: (content: string) => void;

// lineGradient: (content: string[]) => void;
Expand All @@ -118,14 +121,34 @@ const logger: Logger = {
});
}
return pre;
}, {} as Omit<Logger, 'line' | 'lineGradient'>),
}, {} as Omit<Logger, 'line' | 'lineGradient' | 'startLine'>),

line(logs) {
logs.forEach((log, i) => {
logger[log.type || 'info'](log.content, { newLine: i === logs.length - 1 });
});
},

startLine() {
const newLogger = {
...Object.entries(config).reduce((pre, [type, config]) => {
const [fontColor, bgColor] = config;
pre[type] = (content) => {
colorOutput({
fontColor: fontColor || undefined,
bgColor: bgColor || undefined,
newLine: false,
content
});
return newLogger;
}
return pre;
}, {} as ChainLogger),
endLine() {
console.log('');
}
}
return newLogger;
},
lineGradient(content: string) {
const lines = content.split('\n');
// const colors = [
Expand Down Expand Up @@ -213,6 +236,10 @@ const logger: Logger = {
// ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝╚═╝
// `);

// logger.startLine().success('a').bgBlue(1).endLine();



export default logger;


Expand Down

0 comments on commit f92fe94

Please sign in to comment.