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
|
||||
'';
|
||||
};
|
||||
devShell = pkgs.mkShell {
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
nodejs
|
||||
nodePackages.typescript
|
||||
@ -95,4 +95,4 @@
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ moduleAlias(__dirname + "../../../package.json");
|
||||
import "reflect-metadata";
|
||||
import cluster, { Worker } from "cluster";
|
||||
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 { config } from "dotenv";
|
||||
|
||||
@ -44,29 +44,25 @@ function getCommitOrFail() {
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
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(
|
||||
bold(`
|
||||
${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).)
|
||||
`),
|
||||
bold(centerString(unformatted, 64).replace(unformatted, formatted)),
|
||||
);
|
||||
|
||||
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) {
|
||||
console.log(yellow(`Warning: Git is not installed or not in PATH.`));
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import fs from "fs";
|
||||
import "missing-native-js-functions";
|
||||
|
||||
var util = require("util");
|
||||
|
||||
@ -26,6 +27,16 @@ var util = require("util");
|
||||
// };
|
||||
|
||||
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 {
|
||||
const data = readFileSync(__dirname + "/../../../assets/logo.png", {
|
||||
encoding: "base64",
|
||||
@ -48,48 +59,54 @@ export class KittyLogo {
|
||||
}
|
||||
|
||||
private static writeIcon(): void {
|
||||
const data = readFileSync(__dirname + "/../../../assets/icon.png", {
|
||||
encoding: "base64",
|
||||
});
|
||||
KittyLogo.writeImage({
|
||||
base64Data: data,
|
||||
base64Data: this.iconCache,
|
||||
width: 2,
|
||||
addNewline: false,
|
||||
});
|
||||
}
|
||||
|
||||
private static checkSupport(cb: void): boolean {
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.setRawMode(true);
|
||||
let resp = "";
|
||||
process.stdin.once("data", function (key) {
|
||||
console.log(util.inspect(key));
|
||||
process.stdin.setRawMode(false);
|
||||
process.stdin.pause();
|
||||
resp = key.toString();
|
||||
private static checkSupport(): Promise<boolean> {
|
||||
if (process.env.FORCE_KITTY) return Promise.resolve(true);
|
||||
// Check if we are running in a terminal
|
||||
if (!process.stdin.isTTY) return Promise.resolve(false);
|
||||
if (!process.stdout.isTTY) return Promise.resolve(false);
|
||||
|
||||
// Check if we are running in a Kitty terminal
|
||||
if (process.env.TERM == "xterm-kitty") return Promise.resolve(true);
|
||||
|
||||
// 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 {
|
||||
// Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
||||
// }
|
||||
|
||||
private static writeImage(request: KittyImageMetadata): void {
|
||||
if (this.checkSupport()) return;
|
||||
private static writeImage(request: KittyImageMetadata) {
|
||||
if (!this.isSupported) return;
|
||||
let pngData = request.base64Data;
|
||||
|
||||
// Ga=T,q=2,o=z,s=1022,v=181,X=5;
|
||||
const chunkSize = 1024;
|
||||
const chunkSize = 4096;
|
||||
|
||||
//#region Header
|
||||
let header = `\x1b_G`; // enable graphics
|
||||
@ -120,16 +137,25 @@ export class KittyLogo {
|
||||
}
|
||||
}
|
||||
|
||||
export class KittyImageMetadata {
|
||||
public base64Data: string;
|
||||
public width?: number;
|
||||
public height?: number;
|
||||
public widthPixels?: number;
|
||||
public heightPixels?: number;
|
||||
public addNewline?: boolean;
|
||||
export interface KittyImageMetadata {
|
||||
base64Data: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
widthPixels?: number;
|
||||
heightPixels?: number;
|
||||
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++) {
|
||||
|
@ -6,8 +6,8 @@ import { KittyLogo } from "./KittyLogo";
|
||||
|
||||
|
||||
export class Logo {
|
||||
public static printLogo() {
|
||||
KittyLogo.printLogo();
|
||||
public static async printLogo() {
|
||||
await KittyLogo.printLogo();
|
||||
// const chafaPath = findOnPath("chafa");
|
||||
// console.log("Chafa path: " + chafaPath);
|
||||
// const info = terminfo.parse({debug: true});
|
||||
|
Loading…
Reference in New Issue
Block a user