-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
518 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
|
||
export * from './tools'; | ||
export * from './models'; | ||
export * from './qlog/bclip'; | ||
export QLog from './qlog'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
/* eslint-disable no-plusplus */ | ||
/** | ||
* Created by Lucas Teske on 25/05/18. | ||
* @flow | ||
*/ | ||
|
||
import { | ||
undefinedOrNull, | ||
} from '../tools'; | ||
|
||
import { | ||
stripColors, | ||
} from '../colors/tools'; | ||
|
||
const FullSizeLUT = { | ||
// region Numbers | ||
0: '0', | ||
1: '1', | ||
2: '2', | ||
3: '3', | ||
4: '4', | ||
5: '5', | ||
6: '6', | ||
7: '7', | ||
8: '8', | ||
9: '9', | ||
// endregion | ||
// region Upper Case | ||
A: 'A', | ||
B: 'B', | ||
C: 'C', | ||
D: 'D', | ||
E: 'E', | ||
F: 'F', | ||
G: 'G', | ||
H: 'H', | ||
I: 'I', | ||
J: 'J', | ||
K: 'K', | ||
L: 'L', | ||
M: 'M', | ||
N: 'N', | ||
O: 'O', | ||
P: 'P', | ||
Q: 'Q', | ||
R: 'R', | ||
S: 'S', | ||
T: 'T', | ||
U: 'U', | ||
V: 'V', | ||
W: 'W', | ||
X: 'X', | ||
Y: 'Y', | ||
Z: 'Z', | ||
// endregion | ||
// region Lower Case | ||
a: 'a', | ||
b: 'b', | ||
c: 'c', | ||
d: 'd', | ||
e: 'e', | ||
f: 'f', | ||
g: 'g', | ||
h: 'h', | ||
i: 'i', | ||
j: 'j', | ||
k: 'k', | ||
l: 'l', | ||
m: 'm', | ||
n: 'n', | ||
o: 'o', | ||
p: 'p', | ||
q: 'q', | ||
r: 'r', | ||
s: 's', | ||
t: 't', | ||
u: 'u', | ||
v: 'v', | ||
w: 'w', | ||
x: 'x', | ||
y: 'y', | ||
z: 'z', | ||
// endregion | ||
// region Meta | ||
',': ',', | ||
'.': '.', | ||
':': ':', | ||
';': ';', | ||
'!': '!', | ||
'?': '?', | ||
'"': '"', | ||
'\'': ''', | ||
'`': '`', | ||
'^': '^', | ||
'~': '~', | ||
_: '_', | ||
'&': '&', | ||
'@': '@', | ||
'#': '#', | ||
'%': '%', | ||
'+': '+', | ||
'-': '-', | ||
'*': '*', | ||
'=': '=', | ||
'<': '<', | ||
'>': '>', | ||
'(': '(', | ||
')': ')', | ||
'[': '[', | ||
']': ']', | ||
'{': '{', | ||
'}': '}', | ||
'|': '|', | ||
'/': '/', | ||
'\\': '\', | ||
$: '$', | ||
// endregion | ||
}; | ||
|
||
const BClipLut = [ | ||
' ', | ||
' ▄████▄ ', | ||
' ▐▌ ▐▌ ', | ||
' ▄▀▀█▀ ▐▌ ', | ||
' ▄ ▐▄ ▐▌▀▀▄ ', | ||
' ▐▀ ▄▄ ▀▌ ▄▀▀ ▀▄ ▀ ', | ||
' ▐ ▀██▀ ▌▐ ▄██▄ ▌ ', | ||
' ▀▄ ▄▄▀ ▐ ▀▀ ▌ ', | ||
' █ ▀▄▄ ▄▀ ', | ||
' █ █ █ ▐ ', | ||
' █ █ ▐▌ █ ', | ||
' █ █ ▐▌ █ ', | ||
' ▐▌▐▌ █ █ ', | ||
' ▐▌ █▄ ▐▌ █ ', | ||
' █ ▀▀▀ ▐▌ ', | ||
' ▐▌ █ ', | ||
' █▄ ▄█ ', | ||
' ▀████▀ ', | ||
' ', | ||
]; | ||
|
||
const BClipEmpty = ' '; | ||
|
||
export const toFullSize = msg => msg | ||
.split('') | ||
.map(c => (!undefinedOrNull(FullSizeLUT[c]) ? FullSizeLUT[c] : c)) | ||
.join(''); | ||
|
||
export const boxMessage = (msg) => { | ||
const lines = msg.split('\n'); | ||
const outLines = []; | ||
const maxWidth = lines | ||
.map(l => stripColors(l).length) | ||
.reduce((a, b) => (a > b ? a : b)); | ||
|
||
outLines.push(` ${'╔'.white}${'═'.repeat(maxWidth + 2).white}${'╗'.white}`); | ||
|
||
lines | ||
.map(l => ` ${'║'.white} ${l}${' '.repeat(maxWidth - stripColors(l).length)} ${'║'.white}`) | ||
.forEach((l) => { outLines.push(l); }); | ||
|
||
outLines.push(` ${'╚'.white}${'═'.repeat(maxWidth + 2).white}${'╝'.white}`); | ||
|
||
return outLines.join('\n'); | ||
}; | ||
|
||
export const bclipMessage = (title, msg) => { | ||
const lines = msg.split('\n'); | ||
const titleFull = title; // toFullSize(title); :(( broken on box | ||
const outLines = []; | ||
let curClipLine = 0; | ||
|
||
const maxWidth = lines | ||
.map(l => (stripColors(l).length + ' '.length)) | ||
.reduce((a, b) => (a > b ? a : b)); | ||
|
||
const titlePadding = (maxWidth - stripColors(titleFull).length) / 2; | ||
|
||
outLines.push(`${BClipLut[curClipLine++]}`); | ||
outLines.push(`${BClipLut[curClipLine++]}${' '.repeat(titlePadding)}${titleFull}${' '.repeat(titlePadding)}`); | ||
outLines.push(`${BClipLut[curClipLine++]}`); | ||
outLines.push(`${BClipLut[curClipLine++]}`); | ||
|
||
lines.forEach((l) => { | ||
const bclipLine = curClipLine > (BClipLut.length - 1) ? BClipEmpty : BClipLut[curClipLine]; | ||
outLines.push(`${bclipLine} ${l}`); | ||
curClipLine += 1; | ||
}); | ||
|
||
for (let i = curClipLine; i < BClipLut.length; i++) { | ||
outLines.push(BClipLut[i]); | ||
} | ||
|
||
return outLines.join('\n'); | ||
}; | ||
|
||
export const bclipError = (excpt: Error) => { | ||
const [name, ...rest] = excpt.stack.split('\n'); | ||
const title = name.red.bold; | ||
const lines = rest; | ||
|
||
|
||
if (lines[lines.length - 1] === '\u001b[39m') { | ||
lines[lines.length - 2] += '\u001b[39m'; | ||
lines.splice(lines.length - 1, 1); | ||
} | ||
|
||
const outLines = []; | ||
outLines.push('Looks like your app is crash.'.warn); | ||
outLines.push('Do you need any help?'.warn.bold); | ||
outLines.push(''); | ||
|
||
for (let i = 0; i < lines.length; i++) { | ||
const line = lines[i]; | ||
if (stripColors(line).length > 80) { | ||
let curLine = line; | ||
outLines.push(`${curLine.substr(0, 80)} `); | ||
curLine = curLine.substr(80); | ||
while (curLine.length !== 0) { | ||
outLines.push(` ${curLine.substr(0, 80)} `); | ||
curLine = curLine.substr(80); | ||
} | ||
} else { | ||
outLines.push(line); | ||
} | ||
} | ||
|
||
return bclipMessage(title, outLines.join('\n')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters