Make code formatting more consistent
This commit is contained in:
parent
4a8047a6d4
commit
4854796168
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* This is all the nasty ffi setup for the bun runtime
|
* This is all the nasty ffi setup for the bun runtime
|
||||||
*/
|
*/
|
||||||
import { dlopen, ptr, suffix } from "bun:ffi";
|
import { dlopen, ptr, suffix } from 'bun:ffi';
|
||||||
|
|
||||||
const getLib = (name: string) => {
|
const getLib = (name: string) => {
|
||||||
return dlopen(
|
return dlopen(
|
||||||
@ -21,17 +21,16 @@ const getLib = (name: string) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
let cStdLib = {symbols: {}};
|
let cStdLib = { symbols: {} };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cStdLib = getLib(`libc.${suffix}`);
|
cStdLib = getLib(`libc.${suffix}`);
|
||||||
} catch {
|
} catch {
|
||||||
try {
|
try {
|
||||||
cStdLib = getLib(`libc.${suffix}.6`);
|
cStdLib = getLib(`libc.${suffix}.6`);
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
throw new Error('Could not find c standard library');
|
throw new Error('Could not find c standard library');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* The main entrypoint when using Bun as the runtime
|
* The main entrypoint when using Bun as the runtime
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getTermios } from "../common/termios";
|
import { getTermios } from '../common/termios';
|
||||||
|
|
||||||
export async function main(): Promise<number> {
|
export async function main(): Promise<number> {
|
||||||
const t = await getTermios();
|
const t = await getTermios();
|
||||||
@ -18,7 +18,7 @@ export async function main(): Promise<number> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on("exit", (code) => {
|
process.on('exit', (code) => {
|
||||||
console.log(`Process exited with code ${code}`);
|
console.log(`Process exited with code ${code}`);
|
||||||
t.disableRawMode();
|
t.disableRawMode();
|
||||||
});
|
});
|
||||||
|
@ -41,4 +41,4 @@ export const importForRuntime = async (path: string) => {
|
|||||||
const importPath = base + cleanedPath + suffix;
|
const importPath = base + cleanedPath + suffix;
|
||||||
|
|
||||||
return await import(importPath);
|
return await import(importPath);
|
||||||
}
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { importForRuntime } from "./index.ts";
|
import { importForRuntime } from './index.ts';
|
||||||
|
|
||||||
export const STDIN_FILENO = 0;
|
export const STDIN_FILENO = 0;
|
||||||
export const STOUT_FILENO = 1;
|
export const STOUT_FILENO = 1;
|
||||||
@ -29,7 +29,8 @@ export interface ITermios {
|
|||||||
|
|
||||||
export const getTermios = async () => {
|
export const getTermios = async () => {
|
||||||
// Get the runtime-specific ffi wrappers
|
// Get the runtime-specific ffi wrappers
|
||||||
const { tcgetattr, tcsetattr, cfmakeraw, getPointer } = await importForRuntime('ffi');
|
const { tcgetattr, tcsetattr, cfmakeraw, getPointer } =
|
||||||
|
await importForRuntime('ffi');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation to toggle raw mode with Bun runtime
|
* Implementation to toggle raw mode with Bun runtime
|
||||||
@ -39,7 +40,7 @@ export const getTermios = async () => {
|
|||||||
* Are we in raw mode?
|
* Are we in raw mode?
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
#inRawMode:boolean;
|
#inRawMode: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The saved version of the termios struct for cooked/canonical mode
|
* The saved version of the termios struct for cooked/canonical mode
|
||||||
@ -110,4 +111,4 @@ export const getTermios = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Termios();
|
return new Termios();
|
||||||
}
|
};
|
||||||
|
@ -36,6 +36,6 @@ const cStdLib = Deno.dlopen(
|
|||||||
} as const,
|
} as const,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const { tcgetattr, tcsetattr, cfmakeraw} = cStdLib.symbols;
|
export const { tcgetattr, tcsetattr, cfmakeraw } = cStdLib.symbols;
|
||||||
|
|
||||||
export const getPointer = Deno.UnsafePointer.of;
|
export const getPointer = Deno.UnsafePointer.of;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* The main entrypoint when using Deno as the runtime
|
* The main entrypoint when using Deno as the runtime
|
||||||
*/
|
*/
|
||||||
import {getTermios} from "../common/termios.ts";
|
import { getTermios } from '../common/termios.ts';
|
||||||
|
|
||||||
export async function main(): Promise<number> {
|
export async function main(): Promise<number> {
|
||||||
const t = await getTermios()
|
const t = await getTermios();
|
||||||
t.enableRawMode();
|
t.enableRawMode();
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
@ -8,7 +8,7 @@ export enum RunTime {
|
|||||||
Unknown = 'common',
|
Unknown = 'common',
|
||||||
}
|
}
|
||||||
|
|
||||||
import { importForRuntime } from "./common/index.ts";
|
import { importForRuntime } from './common/index.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the runtime strategy, and go!
|
* Determine the runtime strategy, and go!
|
||||||
|
Loading…
Reference in New Issue
Block a user