mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-22 02:12:40 +01:00
Kitty stuff works now
This commit is contained in:
parent
70cbd7d2de
commit
0a2be1cee9
@ -84,7 +84,7 @@
|
|||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
devShell = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
nodejs
|
nodejs
|
||||||
nodePackages.typescript
|
nodePackages.typescript
|
||||||
@ -95,4 +95,4 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ moduleAlias(__dirname + "../../../package.json");
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import cluster, { Worker } from "cluster";
|
import cluster, { Worker } from "cluster";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import { red, bold, yellow, cyan } from "picocolors";
|
import { red, bold, yellow, cyan, blueBright, redBright } from "picocolors";
|
||||||
import { initStats } from "./stats";
|
import { initStats } from "./stats";
|
||||||
import { config } from "dotenv";
|
import { config } from "dotenv";
|
||||||
|
|
||||||
@ -44,29 +44,25 @@ function getCommitOrFail() {
|
|||||||
|
|
||||||
if (cluster.isPrimary) {
|
if (cluster.isPrimary) {
|
||||||
const commit = getCommitOrFail();
|
const commit = getCommitOrFail();
|
||||||
Logo.printLogo();
|
// Logo.printLogo();
|
||||||
|
const unformatted = `spacebar-server | ! Pre-release build !`;
|
||||||
|
const formatted = `${blueBright("spacebar-server")} | ${redBright("⚠️ Pre-release build ⚠️")}`;
|
||||||
console.log(
|
console.log(
|
||||||
bold(`
|
bold(centerString(unformatted, 64).replace(unformatted, formatted)),
|
||||||
${centerString(
|
|
||||||
`spacebar-server | ${yellow(
|
|
||||||
`Pre-release (${
|
|
||||||
commit !== null
|
|
||||||
? commit.slice(0, 7)
|
|
||||||
: "Unknown (Git cannot be found)"
|
|
||||||
})`,
|
|
||||||
)}`,
|
|
||||||
64,
|
|
||||||
)}
|
|
||||||
|
|
||||||
Commit Hash: ${
|
|
||||||
commit !== null
|
|
||||||
? `${cyan(commit)} (${yellow(commit.slice(0, 7))})`
|
|
||||||
: "Unknown (Git cannot be found)"
|
|
||||||
}
|
|
||||||
Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
|
|
||||||
`),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const unformattedGitHeader = `Commit Hash: ${commit !== null ? commit : "Unknown (Git cannot be found)"}`;
|
||||||
|
const formattedGitHeader = `Commit Hash: ${commit !== null ? `${cyan(commit)} (${yellow(commit.slice(0, 7))})` : "Unknown (Git cannot be found)"}`;
|
||||||
|
console.log(
|
||||||
|
bold(
|
||||||
|
centerString(unformattedGitHeader, 64).replace(
|
||||||
|
unformattedGitHeader,
|
||||||
|
formattedGitHeader,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
console.log(`Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)`);
|
||||||
|
|
||||||
if (commit == null) {
|
if (commit == null) {
|
||||||
console.log(yellow(`Warning: Git is not installed or not in PATH.`));
|
console.log(yellow(`Warning: Git is not installed or not in PATH.`));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import "missing-native-js-functions";
|
||||||
|
|
||||||
var util = require("util");
|
var util = require("util");
|
||||||
|
|
||||||
@ -26,6 +27,16 @@ var util = require("util");
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
export class KittyLogo {
|
export class KittyLogo {
|
||||||
|
private static isSupported = false;
|
||||||
|
private static iconCache: string;
|
||||||
|
|
||||||
|
public static async initialise() {
|
||||||
|
this.isSupported = await this.checkSupport();
|
||||||
|
this.iconCache = readFileSync(__dirname + "/../../../assets/icon.png", {
|
||||||
|
encoding: "base64",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static printLogo(): void {
|
public static printLogo(): void {
|
||||||
const data = readFileSync(__dirname + "/../../../assets/logo.png", {
|
const data = readFileSync(__dirname + "/../../../assets/logo.png", {
|
||||||
encoding: "base64",
|
encoding: "base64",
|
||||||
@ -48,48 +59,54 @@ export class KittyLogo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static writeIcon(): void {
|
private static writeIcon(): void {
|
||||||
const data = readFileSync(__dirname + "/../../../assets/icon.png", {
|
|
||||||
encoding: "base64",
|
|
||||||
});
|
|
||||||
KittyLogo.writeImage({
|
KittyLogo.writeImage({
|
||||||
base64Data: data,
|
base64Data: this.iconCache,
|
||||||
width: 2,
|
width: 2,
|
||||||
addNewline: false,
|
addNewline: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static checkSupport(cb: void): boolean {
|
private static checkSupport(): Promise<boolean> {
|
||||||
process.stdin.setEncoding("utf8");
|
if (process.env.FORCE_KITTY) return Promise.resolve(true);
|
||||||
process.stdin.setRawMode(true);
|
// Check if we are running in a terminal
|
||||||
let resp = "";
|
if (!process.stdin.isTTY) return Promise.resolve(false);
|
||||||
process.stdin.once("data", function (key) {
|
if (!process.stdout.isTTY) return Promise.resolve(false);
|
||||||
console.log(util.inspect(key));
|
|
||||||
process.stdin.setRawMode(false);
|
// Check if we are running in a Kitty terminal
|
||||||
process.stdin.pause();
|
if (process.env.TERM == "xterm-kitty") return Promise.resolve(true);
|
||||||
resp = key.toString();
|
|
||||||
|
// Check if we are running in a common unsupported terminal
|
||||||
|
if (process.env.TERM == "xterm") return Promise.resolve(false);
|
||||||
|
if (process.env.TERM == "xterm-256color") return Promise.resolve(false);
|
||||||
|
|
||||||
|
return new Promise<boolean>((resolve) => {
|
||||||
|
(async () => {
|
||||||
|
process.stdin.setEncoding("utf8");
|
||||||
|
process.stdin.setRawMode(true);
|
||||||
|
let resp = "";
|
||||||
|
process.stdin.once("data", function (key) {
|
||||||
|
process.stdin.setRawMode(false);
|
||||||
|
process.stdin.pause();
|
||||||
|
resp = key.toString();
|
||||||
|
if (resp == "\x1B_Gi=31;OK\x1B\\\x1B[?62;c") resolve(true);
|
||||||
|
else resolve(false);
|
||||||
|
});
|
||||||
|
process.stdout.write(
|
||||||
|
"\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\x1b[c",
|
||||||
|
);
|
||||||
|
|
||||||
|
await sleep(5000);
|
||||||
|
resolve(false);
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
process.stdout.write(
|
|
||||||
"\x1b_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\\x1b[c",
|
|
||||||
);
|
|
||||||
|
|
||||||
while(resp == "") {
|
|
||||||
console.log("waiting");
|
|
||||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static sleep(ms: number): void {
|
private static writeImage(request: KittyImageMetadata) {
|
||||||
// Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
if (!this.isSupported) return;
|
||||||
// }
|
|
||||||
|
|
||||||
private static writeImage(request: KittyImageMetadata): void {
|
|
||||||
if (this.checkSupport()) return;
|
|
||||||
let pngData = request.base64Data;
|
let pngData = request.base64Data;
|
||||||
|
|
||||||
// Ga=T,q=2,o=z,s=1022,v=181,X=5;
|
// Ga=T,q=2,o=z,s=1022,v=181,X=5;
|
||||||
const chunkSize = 1024;
|
const chunkSize = 4096;
|
||||||
|
|
||||||
//#region Header
|
//#region Header
|
||||||
let header = `\x1b_G`; // enable graphics
|
let header = `\x1b_G`; // enable graphics
|
||||||
@ -120,16 +137,25 @@ export class KittyLogo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class KittyImageMetadata {
|
export interface KittyImageMetadata {
|
||||||
public base64Data: string;
|
base64Data: string;
|
||||||
public width?: number;
|
width?: number;
|
||||||
public height?: number;
|
height?: number;
|
||||||
public widthPixels?: number;
|
widthPixels?: number;
|
||||||
public heightPixels?: number;
|
heightPixels?: number;
|
||||||
public addNewline?: boolean;
|
addNewline?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
KittyLogo.printLogo();
|
(async () => {
|
||||||
|
await KittyLogo.initialise();
|
||||||
|
KittyLogo.printLogo();
|
||||||
|
|
||||||
|
for (let i = 0; i < 1000; i++) {
|
||||||
|
console.time("meow");
|
||||||
|
KittyLogo.printWithIcon("meow");
|
||||||
|
console.timeEnd("meow");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
//
|
//
|
||||||
// for (let i = 0; i < 10; i++) {
|
// for (let i = 0; i < 10; i++) {
|
||||||
|
@ -6,8 +6,8 @@ import { KittyLogo } from "./KittyLogo";
|
|||||||
|
|
||||||
|
|
||||||
export class Logo {
|
export class Logo {
|
||||||
public static printLogo() {
|
public static async printLogo() {
|
||||||
KittyLogo.printLogo();
|
await KittyLogo.printLogo();
|
||||||
// const chafaPath = findOnPath("chafa");
|
// const chafaPath = findOnPath("chafa");
|
||||||
// console.log("Chafa path: " + chafaPath);
|
// console.log("Chafa path: " + chafaPath);
|
||||||
// const info = terminfo.parse({debug: true});
|
// const info = terminfo.parse({debug: true});
|
||||||
|
Loading…
Reference in New Issue
Block a user