Skip to content

Commit

Permalink
Perfect: You can clear the console before print
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaming743 committed Jul 10, 2020
1 parent 978df75 commit db81bbb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 27 deletions.
39 changes: 30 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var print = {
log: function (info) {
log: function (info, clear) {
if (clear)
print.clear();
console.log(info);
},
warn: function (info) {
warn: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[31;33m' + info + '\x1b[0m');
},
error: function (info) {
error: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[31;40m' + info + '\x1b[0m');
},
success: function (info) {
success: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[42;30m' + info + '\x1b[0m');
},
tip: function (info) {
tip: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[40;32m' + info + '\x1b[0m');
},
red: function (info) {
red: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[31m' + info + '\x1b[39m');
},
green: function (info) {
green: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[32m' + info + '\x1b[39m');
},
white: function (info) {
white: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[37m' + info + '\x1b[39m');
},
yellow: function (info) {
yellow: function (info, clear) {
if (clear)
print.clear();
console.log('\x1b[31;33m' + info + '\x1b[0m');
},
clear: function () {
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
},
};
exports.default = print;
39 changes: 30 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
const print = {
log(info: string): void {
log(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log(info)
},
warn(info: string): void {
warn(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[31;33m' + info + '\x1b[0m')
},
error(info: string): void {
error(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[31;40m' + info + '\x1b[0m')
},
success(info: string): void {
success(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[42;30m' + info + '\x1b[0m')
},
tip(info: string): void {
tip(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[40;32m' + info + '\x1b[0m')
},
red(info: string): void {
red(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[31m' + info + '\x1b[39m')
},
green(info: string): void {
green(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[32m' + info + '\x1b[39m')
},
white(info: string): void {
white(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[37m' + info + '\x1b[39m')
},
yellow(info: string): void {
yellow(info: string, clear?: boolean): void {
if (clear) print.clear()

console.log('\x1b[31;33m' + info + '\x1b[0m')
},
clear(): void {
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H')
},
}

export default print
19 changes: 10 additions & 9 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
declare const print: {
log(info: string): void;
warn(info: string): void;
error(info: string): void;
success(info: string): void;
tip(info: string): void;
red(info: string): void;
green(info: string): void;
white(info: string): void;
yellow(info: string): void;
log(info: string, clear?: boolean | undefined): void;
warn(info: string, clear?: boolean | undefined): void;
error(info: string, clear?: boolean | undefined): void;
success(info: string, clear?: boolean | undefined): void;
tip(info: string, clear?: boolean | undefined): void;
red(info: string, clear?: boolean | undefined): void;
green(info: string, clear?: boolean | undefined): void;
white(info: string, clear?: boolean | undefined): void;
yellow(info: string, clear?: boolean | undefined): void;
clear(): void;
};
export default print;

0 comments on commit db81bbb

Please sign in to comment.