Skip to content

Commit

Permalink
mistake made with #348, now fixed in 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel.benychou committed Jul 15, 2024
1 parent 9907f95 commit 2f94618
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
63 changes: 31 additions & 32 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const filename = !runAsMainProgram
: resolve(homedir(), ".local-traffic.json"),
);
const crashTest = argv.some(arg => arg === "--crash-test");

const screenWidth = 64;
const instantTime = (): bigint => {
return (
hrtime.bigint?.() ??
Expand Down Expand Up @@ -254,7 +254,10 @@ const log = async function (
);
stdout.write(
`${getCurrentTime(state?.config?.simpleLogs)}${renderedColors
.map(e => `\u001b[48;5;${e.color}m${"".padEnd((e.length ?? 64) + 1)}`)
.map(
e =>
`\u001b[48;5;${e.color}m${"".padEnd((e.length ?? screenWidth) + 1)}`,
)
.join("▐")}\u001b[0m\n`,
);

Expand All @@ -269,7 +272,7 @@ const log = async function (
),
);
stdout.write(logTexts[i]);
offset += (element[i].length ?? 64) + 2;
offset += (element[i].length ?? screenWidth) + 2;
}
stdout.write("\u001b[0m\n");
for (let simpleText of simpleTexts)
Expand Down Expand Up @@ -2908,50 +2911,46 @@ const serve = async function (
state.config.logAccessInTerminal &&
!targetUrl.pathname.startsWith("/:/")
) {
const requestMethodLength = (inboundRequest.method?.length ?? 3) + 2;
const keyToDisplay =
state.config.logAccessInTerminal === "with-mapping" ? key ?? "" : "";
const keyLength = keyToDisplay.length ? keyToDisplay.length + 2 : 0;
const keyLength = keyToDisplay.length
? Math.min(screenWidth - requestMethodLength - 2, keyToDisplay.length + 2)
: 0;
const requestLength = Math.max(
2,
screenWidth - requestMethodLength - keyLength,
);
await state.log([
[
{
color:
inboundRequest.method === "GET"
? 22
: inboundRequest.method === "POST"
? 52
: inboundRequest.method === "PUT"
? 94
: inboundRequest.method === "DELETE"
? 244
: inboundRequest.method === "OPTIONS"
? 19
: inboundRequest.method === "PATCH"
? 162
: inboundRequest.method === "HEAD"
? 53
: inboundRequest.method === "TRACE"
? 6
: inboundRequest.method === "CONNECT"
? 2
: 0,
{
GET: 22,
POST: 52,
PUT: 94,
DELETE: 244,
OPTIONS: 19,
PATCH: 162,
HEAD: 53,
TRACE: 6,
CONNECT: 2,
}[inboundRequest.method ?? ""] ?? 0,
text: (inboundRequest.method ?? "GET").toString(),
length: inboundRequest.method?.length,
length: requestMethodLength - 2,
},
{
color: 32,
text: keyToDisplay,
length: keyToDisplay.length,
text: keyToDisplay.substring(0, keyLength - 2),
length: keyLength - 2,
},
{
color: 8,
text: targetUrl.pathname
.toString()
.padStart(62 - (inboundRequest.method?.length ?? 3) - keyLength)
.substring(
0,
62 - (inboundRequest.method?.length ?? 3) - keyLength,
),
length: 62 - (inboundRequest.method?.length ?? 3) - keyLength,
.padStart(requestLength)
.substring(0, requestLength),
length: requestLength,
},
],
]);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "local-traffic",
"version": "0.1.2",
"version": "0.1.3",
"main": "./dist/local-traffic.js",
"private": false,
"keywords": [
Expand Down

0 comments on commit 2f94618

Please sign in to comment.