ChibraxOS 2
Changes: - kernel 6.0.2 - Broken init scripts - Switch to bun for better peroformance an easier ffi - Removed grup - Efi support without graphics (at least graphics werent tested) - Suppression de toutes les dépendance non libc - new splash - broken audio - typescript support - ls rewritten to be more reliable
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
const fs = require('fs')
|
||||
import * as fs from 'fs'
|
||||
const audiopath = '/dev/audio'
|
||||
|
||||
module.exports = (path) => {
|
||||
if(fs.existsSync(path) && fs.existsSync(audiopath)) {
|
||||
const data = fs.readFileSync(path)
|
||||
fs.writeFileSync(audiopath, data)
|
||||
export default function play(path) {
|
||||
if(fs.existsSync(audiopath)) {
|
||||
if(fs.existsSync(path)) {
|
||||
const data = fs.readFileSync(path)
|
||||
fs.writeFileSync(audiopath, data)
|
||||
}
|
||||
} else {
|
||||
console.log('Kernel doesn\'t have snd_pcm_oss or snd_seq_oss or snd_mixer_oss')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//@ts-check
|
||||
/** @type {{ [key: number]: string | undefined }} */
|
||||
module.exports = {
|
||||
export default {
|
||||
1: "EPERM", //Operation not permitted
|
||||
2: "ENOENT", //No such file or directory
|
||||
3: "ESRCH", //No such process
|
||||
@@ -82,7 +82,7 @@ module.exports = {
|
||||
81: "ELIBSCN", //lib section in a.out corrupted
|
||||
82: "ELIBMAX", //Attempting to link in too many shared libraries
|
||||
83: "ELIBEXEC", //Cannot exec a shared library directly
|
||||
84: "EILSEQ", //Illegal byte sequence
|
||||
84: "EILSEQ", //Illegal byte sequencerequire
|
||||
85: "ERESTART", //Interrupted system call should be restarted
|
||||
86: "ESTRPIPE", //Streams pipe error
|
||||
87: "EUSERS", //Too many users
|
||||
@@ -130,4 +130,4 @@ module.exports = {
|
||||
129: "EKEYREJECTED", //Key was rejected by service
|
||||
130: "EOWNERDEAD", //Owner died
|
||||
131: "ENOTRECOVERABLE",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
const jimp = require('jimp')
|
||||
import * as fs from 'fs'
|
||||
import * as jimp from 'jimp'
|
||||
|
||||
const screen = getScreenDimensions()
|
||||
const buffer = Buffer.alloc(screen.width * screen.height * screen.byteDepth)
|
||||
@@ -24,7 +24,7 @@ function getScreenDimensions() {
|
||||
/**
|
||||
* @param { Buffer } data
|
||||
*/
|
||||
function flip(data = buffer) {
|
||||
export function flip(data = buffer) {
|
||||
try {
|
||||
fs.writeFileSync('/dev/fb0', data, { encoding: 'binary' })
|
||||
} catch(e) {
|
||||
@@ -33,14 +33,14 @@ function flip(data = buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
export function clear() {
|
||||
buffer.fill(0)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filepath
|
||||
*/
|
||||
function removeFromCache(filepath) {
|
||||
export function removeFromCache(filepath) {
|
||||
delete imageCache[filepath]
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ function removeFromCache(filepath) {
|
||||
* @param {string} filepath
|
||||
* @returns { Promise<import('@jimp/core').Bitmap> } BGRA buffer
|
||||
*/
|
||||
async function readImgFile(filepath) {
|
||||
export async function readImgFile(filepath) {
|
||||
const img = await jimp.read(filepath)
|
||||
const bitmap = img.bitmap
|
||||
bitmap.data = rgbaTObgra(bitmap.data)
|
||||
@@ -60,7 +60,7 @@ async function readImgFile(filepath) {
|
||||
* @param { number } y
|
||||
* @param { import('@jimp/core').Bitmap | Pencil } bitmap
|
||||
*/
|
||||
function drawBitmap(x, y, bitmap, handleTransparency = true) {
|
||||
export function drawBitmap(x, y, bitmap, handleTransparency = true) {
|
||||
for(let dy = 0; dy < bitmap.height; dy++) {
|
||||
let bitmapLineEnd = bitmap.width * screen.byteDepth * (dy + 1)
|
||||
let bitmapLineStart = bitmap.width * screen.byteDepth * dy
|
||||
@@ -123,7 +123,7 @@ function drawBitmap(x, y, bitmap, handleTransparency = true) {
|
||||
* @description this function work fine but will use caching. to clear the cache you can use removeFromCache(filepath) or you can keep the cache on the
|
||||
* client side and use readImgFile and drawBitmap methods instead
|
||||
*/
|
||||
async function drawImgFile(x, y, filepath) {
|
||||
export async function drawImgFile(x, y, filepath) {
|
||||
//not caching would imply reading the image each time we want to write it to the screen even for small movement
|
||||
let bitmap;
|
||||
if(!imageCache[filepath]) {
|
||||
@@ -153,7 +153,7 @@ function rgbaTObgra(buff) {
|
||||
* @param { string } color
|
||||
* @returns { number[] }
|
||||
*/
|
||||
function parseHexColor(color) {
|
||||
export function parseHexColor(color) {
|
||||
if(!color.startsWith('#') || color.length !== 7) {
|
||||
throw new Error('invalid hex color code')
|
||||
}
|
||||
@@ -169,7 +169,7 @@ function parseHexColor(color) {
|
||||
* @param { number } y
|
||||
* @param { string | number[] } colorCode
|
||||
*/
|
||||
function setPixel(x, y, colorCode) {
|
||||
export function setPixel(x, y, colorCode) {
|
||||
if (screen.byteDepth !== 4) {
|
||||
throw new Error('Depth not supported yet')
|
||||
}
|
||||
@@ -179,5 +179,3 @@ function setPixel(x, y, colorCode) {
|
||||
}
|
||||
buffer.set(colorCode, (x + y * screen.width) * screen.byteDepth)
|
||||
}
|
||||
|
||||
module.exports = { flip, clear, getScreenDimensions, drawImgFile, readImgFile, drawBitmap, parseHexColor, setPixel, removeFromCache }
|
||||
@@ -1,52 +1,39 @@
|
||||
//@ts-check
|
||||
const { exec, fork, spawn } = require('child_process');
|
||||
/**
|
||||
* @param {string} path
|
||||
* @deprecated
|
||||
*/
|
||||
function hookTo(path) {
|
||||
exec(`node ${path}`)
|
||||
}
|
||||
import { spawnSync, spawn } from 'bun'
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
*/
|
||||
async function fHook(path) {
|
||||
const child = fork(path)
|
||||
return new Promise((res, rej) => {
|
||||
child.on('exit', () => {
|
||||
res()
|
||||
})
|
||||
})
|
||||
export async function fHook(path) {
|
||||
return await spawnAndWait([ '/usr/bin/bun', 'run', path ])
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } cmd
|
||||
* @param { import('child_process').SpawnOptionsWithoutStdio } [option]
|
||||
* @param { [string, ...string[]] } cmd
|
||||
* @param { import('bun').SpawnOptions.OptionsObject } [option]
|
||||
*/
|
||||
async function spawnAndWait(cmd, option) {
|
||||
const child = spawn(cmd, option)
|
||||
export async function spawnAndWait(cmd, option) {
|
||||
console.log('spawning ' + cmd.join(' '))
|
||||
return spawnSync(cmd, {
|
||||
...option,
|
||||
env: {
|
||||
PATH: "/bin:/sbin:/usr/bin:/usr/sbin",
|
||||
...process.env,
|
||||
...(option?.env || {})
|
||||
},
|
||||
|
||||
child.stdout.pipe(process.stdout)
|
||||
child.stderr.pipe(process.stderr)
|
||||
process.stdin.pipe(child.stdin)
|
||||
|
||||
await new Promise((res, rej) => {
|
||||
child.on('exit', () => {
|
||||
res()
|
||||
})
|
||||
stdout: "inherit",
|
||||
stdin: "inherit",
|
||||
stderr: "inherit"
|
||||
})
|
||||
process.stdin.unpipe(child.stdin)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } path
|
||||
* @param { string[] } [args]
|
||||
* @param { import('child_process').SpawnOptionsWithoutStdio } [options]
|
||||
* @param { import('bun').SpawnOptions.OptionsObject } [options]
|
||||
*/
|
||||
async function startjs(path, args = [], options = {}) {
|
||||
const arguments = args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')
|
||||
return spawnAndWait(`/usr/local/bin/node ${path} ${arguments}`, options)
|
||||
export async function startjs(path, args = [], options = {}) {
|
||||
const SpawnArguments = args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg})
|
||||
return spawnAndWait(['/usr/bin/bun', path, ...SpawnArguments ], options)
|
||||
}
|
||||
|
||||
module.exports = { hookTo, fHook, spawnAndWait, startjs }
|
||||
@@ -1,5 +1,8 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
import * as fs from 'fs'
|
||||
import { init } from './initd.js'
|
||||
import * as reboot from './reboot.js'
|
||||
import { fHook } from './hook.js'
|
||||
|
||||
function panic() {
|
||||
console.log("/!\\ INIT PANIK /!\\ LOSE CHIBRE")
|
||||
@@ -8,13 +11,9 @@ function panic() {
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const initd = require('./initd.js')
|
||||
const reboot = require('./reboot.js')
|
||||
const { fHook } = require("./hook.js")
|
||||
|
||||
console.clear()
|
||||
|
||||
await initd()
|
||||
await init()
|
||||
|
||||
//chainload into sheebr
|
||||
if(fs.existsSync("/usr/bin/sheebr.js")) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
/**
|
||||
* @typedef {{ name: string, before: string[], after: string[], init(): undefined | Promise<undefined> }} InitScript
|
||||
*/
|
||||
async function init() {
|
||||
export async function init() {
|
||||
|
||||
const initdFiles = fs.readdirSync('/etc/init.d/')
|
||||
const initdScripts = initdFiles.filter( (v) => v.endsWith('.js'))
|
||||
@@ -78,6 +78,3 @@ function processBefores(scripts) {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
module.exports = init
|
||||
@@ -5,23 +5,6 @@
|
||||
* @param {string} str
|
||||
* @returns
|
||||
*/
|
||||
async function input(str) {
|
||||
console.log(str)
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
let line = "";
|
||||
return new Promise((res, rej) => {
|
||||
process.stdin.on('data', function(chunk) {
|
||||
line += chunk
|
||||
if (chunk.toString('utf-8').endsWith('\n')) {
|
||||
process.stdin.pause()
|
||||
res(line.substring(0, line.length -1))
|
||||
}
|
||||
});
|
||||
process.stdin.on('error', function(err) {
|
||||
rej(err)
|
||||
})
|
||||
})
|
||||
export default async function input(str) {
|
||||
return await Bun.stdin.text()
|
||||
}
|
||||
|
||||
module.exports = input
|
||||
@@ -1,6 +0,0 @@
|
||||
//@ts-check
|
||||
//@ts-expect-error
|
||||
const { ioctl } = require('./ioctl.node')
|
||||
|
||||
|
||||
module.exports = { ioctl }
|
||||
@@ -1,7 +1,5 @@
|
||||
//@ts-check
|
||||
|
||||
//@ts-expect-error
|
||||
const ip = require('./ip.node')
|
||||
|
||||
const flags = {
|
||||
IFF_UP: 0x1, /* Interface is up. */
|
||||
@@ -51,4 +49,4 @@ function setIpv4(interface, address) {
|
||||
ip.setIpv4(interface, address.join('.'));
|
||||
}
|
||||
|
||||
module.exports = { setFlags, getFlags, setIpv4, flags }
|
||||
module.exports = { setFlags, getFlags, setIpv4, flags }
|
||||
@@ -1,26 +1,34 @@
|
||||
//@ts-check
|
||||
//@ts-expect-error
|
||||
const { syscall } = require('./syscall.node')
|
||||
const errno = require('./errno')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
import { dlopen, FFIType } from 'bun:ffi';
|
||||
import errno from './errno.js'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
const {
|
||||
symbols: {
|
||||
syscall,
|
||||
},
|
||||
} = dlopen('/usr/lib/libc.so.6', {
|
||||
syscall: {
|
||||
args: [ FFIType.int, FFIType.int, FFIType.cstring, FFIType.int ],
|
||||
returns: FFIType.int,
|
||||
},
|
||||
});
|
||||
|
||||
// TBD
|
||||
const SYSCALL_INIT_MODULE = 105
|
||||
const SYSCALL_FINIT_MODULE = 273
|
||||
|
||||
const doProcExists = () => fs.existsSync('/proc')
|
||||
export const doProcExists = () => fs.existsSync('/proc')
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} path
|
||||
* @param {string} params
|
||||
* @param {number} flags
|
||||
* @deprecated un tested dangerous
|
||||
* @deprecated untested very dangerous
|
||||
*/
|
||||
function finit_module(path, params = "", flags = 0) {
|
||||
export function finit_module(path, params = "", flags = 0) {
|
||||
const fileDescriptor = fs.openSync(path, 'r')
|
||||
const result = syscall(SYSCALL_FINIT_MODULE, fileDescriptor, params, flags)
|
||||
if(result > 0) {
|
||||
@@ -34,8 +42,8 @@ function finit_module(path, params = "", flags = 0) {
|
||||
}
|
||||
}
|
||||
|
||||
function uname() {
|
||||
if(!doProcExists) {
|
||||
export function uname() {
|
||||
if(!doProcExists()) {
|
||||
throw "Proc don't exists exception"
|
||||
}
|
||||
const linuxVersionString = fs.readFileSync('/proc/version').toString()
|
||||
@@ -44,8 +52,9 @@ function uname() {
|
||||
|
||||
/**
|
||||
* @param {string} modulename
|
||||
* @deprecated untested very dangerous
|
||||
*/
|
||||
function modprobe(modulename) {
|
||||
export function modprobe(modulename) {
|
||||
const name = uname()
|
||||
if(fs.existsSync(path.join('/lib/modules', name, 'kernel', modulename))) {
|
||||
finit_module(path.join('/lib/modules', name, 'kernel', modulename))
|
||||
@@ -55,11 +64,9 @@ function modprobe(modulename) {
|
||||
}
|
||||
|
||||
|
||||
function lsmod() {
|
||||
if(!doProcExists) {
|
||||
export function lsmod() {
|
||||
if(!doProcExists()) {
|
||||
throw "Proc don't exists exception"
|
||||
}
|
||||
return fs.readFileSync('/proc/modules').toString('utf-8').split('\n')
|
||||
}
|
||||
|
||||
module.exports = { modprobe, uname, finit_module, doProcExists, lsmod, syscall }
|
||||
@@ -1,18 +1,11 @@
|
||||
//@ts-check
|
||||
const fs =require('fs')
|
||||
/**
|
||||
* @type {{ mount: (device_path: string, mount_point: string, fs: string, flags: number, fsparams: string ) => number }}
|
||||
*///@ts-expect-error
|
||||
const nodemount = require("./mount.node")
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
const cmount = nodemount.mount
|
||||
|
||||
import * as fs from 'fs'
|
||||
import { dlopen, FFIType } from 'bun:ffi'
|
||||
import { filesystems } from './suportedFilesystems'
|
||||
|
||||
/* These are the fs-independent mount-flags: up to 16 flags are
|
||||
supported */
|
||||
const flags = {
|
||||
export const flags = {
|
||||
MS_RDONLY: 1, /* Mount read-only. */
|
||||
MS_NOSUID: 2, /* Ignore suid and sgid bits. */
|
||||
MS_NODEV: 4, /* Disallow access to device special files. */
|
||||
@@ -41,6 +34,19 @@ const flags = {
|
||||
MS_NOUSER: 1 << 31
|
||||
};
|
||||
|
||||
const {
|
||||
symbols: {
|
||||
mount,
|
||||
},
|
||||
} = dlopen('/usr/lib/libc.so.6', {
|
||||
mount: {
|
||||
args: [ FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.u64, FFIType.cstring ],
|
||||
returns: FFIType.int,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} devicePath
|
||||
* @param {string} mountPoint
|
||||
@@ -49,20 +55,13 @@ const flags = {
|
||||
* @param {string} fsparams
|
||||
* @returns {number}
|
||||
*/
|
||||
function mount(devicePath, mountPoint, fstype, flags, fsparams) {
|
||||
const supportedFilesystems = require('./suportedFilesystems')
|
||||
|
||||
const filesystem = supportedFilesystems.find( v => v.name === fstype)
|
||||
export function JSmount(devicePath, mountPoint, fstype, flags, fsparams) {
|
||||
const filesystem = filesystems.find( v => v.name === fstype)
|
||||
if(! filesystem) {
|
||||
throw "Invalid filesystem"
|
||||
}
|
||||
|
||||
if(! fs.existsSync(devicePath) && filesystem.hasdev)
|
||||
throw "Device don't exist"
|
||||
return cmount(devicePath, mountPoint, fstype, flags, fsparams)
|
||||
return mount(Buffer.from(devicePath), Buffer.from(mountPoint), Buffer.from(fstype), flags, Buffer.from(fsparams))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = { mount, cmount, flags }
|
||||
@@ -1,7 +1,4 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.21"
|
||||
},
|
||||
"dependencies": {
|
||||
"jimp": "^0.16.1"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
//@ts-check
|
||||
import { dlopen, FFIType } from 'bun:ffi';
|
||||
|
||||
/* Perform a hard reset now. */
|
||||
const RB_AUTOBOOT = 0x01234567
|
||||
|
||||
@@ -20,37 +22,40 @@ const RB_SW_SUSPEND = 0xd000fce2
|
||||
/* Reboot system into new kernel. */ //no idea how to use that but hey
|
||||
const RB_KEXEC = 0x45584543
|
||||
|
||||
/**
|
||||
@type {{
|
||||
reboot: (rebootid: number) => void //https://unix.superglobalmegacorp.com/Net2/newsrc/sys/syscall.h.html
|
||||
syscall: (syscallid: number) => void
|
||||
}}
|
||||
*///@ts-expect-error
|
||||
const syscalls = require('./syscall.node')
|
||||
|
||||
function disableCtrlAltSupr() {
|
||||
syscalls.reboot(RB_DISABLE_CAD)
|
||||
const {
|
||||
symbols: {
|
||||
reboot,
|
||||
},
|
||||
} = dlopen('/usr/lib/libc.so.6', {
|
||||
reboot: {
|
||||
args: [ FFIType.int ],
|
||||
returns: FFIType.int,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
export function disableCtrlAltSupr() {
|
||||
reboot(RB_DISABLE_CAD)
|
||||
}
|
||||
|
||||
function enableCtrlAltSupr() {
|
||||
syscalls.reboot(RB_ENABLE_CAD)
|
||||
export function enableCtrlAltSupr() {
|
||||
reboot(RB_ENABLE_CAD)
|
||||
}
|
||||
|
||||
function halt() {
|
||||
syscalls.reboot(RB_HALT_SYSTEM)
|
||||
export function halt() {
|
||||
reboot(RB_HALT_SYSTEM)
|
||||
}
|
||||
|
||||
function reboot() {
|
||||
syscalls.reboot(RB_AUTOBOOT)
|
||||
export function classicReboot() {
|
||||
reboot(RB_AUTOBOOT)
|
||||
}
|
||||
|
||||
function powerOff() {
|
||||
syscalls.reboot(RB_POWER_OFF)
|
||||
export function powerOff() {
|
||||
reboot(RB_POWER_OFF)
|
||||
}
|
||||
|
||||
function suspend() {
|
||||
syscalls.reboot(RB_SW_SUSPEND)
|
||||
export function suspend() {
|
||||
reboot(RB_SW_SUSPEND)
|
||||
}
|
||||
|
||||
|
||||
module.exports = { disableCtrlAltSupr, enableCtrlAltSupr, halt, reboot, powerOff, suspend }
|
||||
@@ -1,9 +1,7 @@
|
||||
async function mSleep(ms) {
|
||||
export async function mSleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
async function sleep(s) {
|
||||
export async function sleep(s) {
|
||||
return mSleep(s * 1000)
|
||||
}
|
||||
|
||||
module.exports = { mSleep, sleep }
|
||||
@@ -1,28 +0,0 @@
|
||||
//@ts-check
|
||||
//@ts-expect-error
|
||||
const csocket = require('./socket.node')
|
||||
|
||||
/**
|
||||
* @param { number } domain
|
||||
* @param { number } type
|
||||
* @param { number } protocol
|
||||
* @return { number }
|
||||
*/
|
||||
function socket(domain, type, protocol) {
|
||||
return csocket.socket(domain, type, protocol)
|
||||
}
|
||||
|
||||
const socketTypes = {
|
||||
SOCK_DGRAM : 1, /* Connectionless, unreliable datagrams of fixed maximum length. */
|
||||
SOCK_STREAM : 2, /* Sequenced, reliable, connection-based byte streams. */
|
||||
SOCK_RAW : 3, /* Raw protocol interface. */
|
||||
SOCK_RDM : 4, /* Reliably-delivered messages. */
|
||||
SOCK_SEQPACKET : 5, /* Sequenced, reliable, connection-based, datagrams of fixed maximum length. */
|
||||
SOCK_DCCP : 6, /* Datagram Congestion Control Protocol. */
|
||||
SOCK_PACKET : 10, /* Linux specific way of getting packets at the dev level. For writing rarp and other similar things on the user level. */
|
||||
|
||||
SOCK_CLOEXEC : 0o2000000, /* Atomically set close-on-exec flag for the new descriptor(s). */
|
||||
SOCK_NONBLOCK : 0o0000200 /* Atomically mark descriptor(s) as non-blocking. */
|
||||
}
|
||||
|
||||
module.exports = { socketTypes, socket }
|
||||
@@ -1,9 +1,7 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
import * as fs from 'fs'
|
||||
|
||||
const systems = fs.readFileSync('/proc/filesystems', { encoding: 'utf-8' }).split('\n')
|
||||
|
||||
const filesystems = systems.map(s => ({ hasdev: !s.includes('nodev'), name: s.includes('nodev') ? s.split('nodev')[1].trim() : s.trim() }))
|
||||
|
||||
module.exports = filesystems
|
||||
Object.freeze(module.exports)
|
||||
export const filesystems = systems.map(s => ({ hasdev: !s.includes('nodev'), name: s.includes('nodev') ? s.split('nodev')[1].trim() : s.trim() }))
|
||||
Object.freeze(filesystems)
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
//@ts-check
|
||||
const { cmount, mount, flags } = require('../../core/mount.js')
|
||||
import { JSmount, flags } from '../../core/mount.js'
|
||||
|
||||
async function init() {
|
||||
cmount("dummy", "/proc", "proc",
|
||||
export async function init() {
|
||||
/*cmount("dummy", "/proc", "proc",
|
||||
flags.MS_NODEV | flags.MS_RDONLY | flags.MS_NOSUID | flags.MS_RELATIME | flags.MS_NOEXEC
|
||||
, "")
|
||||
, "")*/
|
||||
|
||||
mount("dummy", "/sys", "sysfs", flags.MS_NODEV | flags.MS_NOSUID | flags.MS_RELATIME | flags.MS_NOEXEC, "")
|
||||
mount("dummy", "/tmp", "tmpfs", flags.MS_NODEV, "")
|
||||
JSmount("dummy", "/sys", "sysfs", flags.MS_NODEV | flags.MS_NOSUID | flags.MS_RELATIME | flags.MS_NOEXEC, "")
|
||||
JSmount("dummy", "/tmp", "tmpfs", flags.MS_NODEV, "")
|
||||
}
|
||||
|
||||
/**
|
||||
* @type { string[] }
|
||||
*/
|
||||
const after = [] // list of init script to load before
|
||||
export const after = [] // list of init script to load before
|
||||
/**
|
||||
* @type { string[] }
|
||||
*/
|
||||
const before = []
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
after,
|
||||
before
|
||||
}
|
||||
export const before = []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const ip = require('../../core/ip')
|
||||
const ip = require('../../core/ip.js.bak')
|
||||
//async is optional but recomended for optimisation (optimisations are yet to be implemented)
|
||||
async function init() {
|
||||
ip.setFlags('lo', ip.flags.IFF_UP | ip.flags.IFF_LOOPBACK | ip.flags.IFF_RUNNING)
|
||||
@@ -1,33 +1,32 @@
|
||||
//async is optional but recomended for optimisation (optimisations are yet to be implemented)
|
||||
async function init() {
|
||||
export async function init() {
|
||||
//code to execute
|
||||
console.log(`
|
||||
_______ _________ ______ _______ _______
|
||||
( ____ \\|\\ /|\\__ __/( ___ \\ ( ____ )( ___ )|\\ /|
|
||||
| ( \\/| ) ( | ) ( | ( ) )| ( )|| ( ) |( \\ / )
|
||||
| | | (___) | | | | (__/ / | (____)|| (___) | \\ (_) /
|
||||
| | | ___ | | | | __ ( | __)| ___ | ) _ (
|
||||
| | | ( ) | | | | ( \\ \\ | (\\ ( | ( ) | / ( ) \\
|
||||
| (____/\\| ) ( |___) (___| )___) )| ) \\ \\__| ) ( |( / \\ )
|
||||
(_______/|/ \\|\\_______/|/ \\___/ |/ \\__/|/ \\||/ \\|
|
||||
|
||||
_______ _______
|
||||
( ___ )( ____ \\
|
||||
| ( ) || ( \\/
|
||||
| | | || (_____
|
||||
| | | |(_____ )
|
||||
| | | | ) |
|
||||
| (___) |/\\____) |
|
||||
(_______)\\_______)
|
||||
_ _ _ _ _ _ _ _ _
|
||||
/\\ \\ / /\\ / /\\ /\\ \\ / /\\ /\\ \\ / /\\ /_/\\ /\\ \\
|
||||
/ \\ \\ / / / / / / \\ \\ \\ / / \\ / \\ \\ / / \\ \\ \\ \\ \\ \\_\\
|
||||
/ /\\ \\ \\ / /_/ / / / /\\ \\_\\ / / /\\ \\ / /\\ \\ \\ / / /\\ \\ \\ \\ \\__/ / /
|
||||
/ / /\\ \\ \\ / /\\ \\__/ / / / /\\/_/ / / /\\ \\ \\ / / /\\ \\_\\ / / /\\ \\ \\ \\ \\__ \\/_/
|
||||
/ / / \\ \\_\\ / /\\ \\___\\/ / / / / / / /\\ \\_\\ \\ / / /_/ / / / / / \\ \\ \\ \\/_/\\__/\\
|
||||
/ / / \\/_/ / / /\\/___/ / / / / / / /\\ \\ \\___\\ / / /__\\/ / / / /___/ /\\ \\ _/\\/__\\ \\
|
||||
/ / / / / / / / / / / / / / / \\ \\ \\__/ / / /_____/ / / /_____/ /\\ \\ / _/_/\\ \\ \\
|
||||
/ / /________ / / / / / /___/ / /__ / / /____\\_\\ \\ / / /\\ \\ \\ / /_________/\\ \\ \\ / / / \\ \\ \\
|
||||
/ / /_________\\/ / / / / //\\__\\/_/___\\/ / /__________\\/ / / \\ \\ \\/ / /_ __\\ \\_\\/ / / /_/ /
|
||||
\\/____________/\\/_/ \\/_/ \\/_________/\\/_____________/\\/_/ \\_\\/\\_\\___\\ /____/_/\\/_/ \\_\\/
|
||||
_ _ _
|
||||
/\\ \\ / /\\ /\\ \\
|
||||
/ \\ \\ / / \\ / \\ \\
|
||||
/ /\\ \\ \\ / / /\\ \\__ / /\\ \\ \\
|
||||
/ / /\\ \\ \\ / / /\\ \\___\\\\/_/\\ \\ \\
|
||||
/ / / \\ \\_\\ \\ \\ \\ \\/___/ / / /
|
||||
/ / / / / / \\ \\ \\ / / /
|
||||
/ / / / / /_ \\ \\ \\ / / / _
|
||||
/ / /___/ / //_/\\__/ / / / / /_/\\_\\
|
||||
/ / /____\\/ / \\ \\/___/ / / /_____/ /
|
||||
\\/_________/ \\_____\\/ \\________/
|
||||
|
||||
`)
|
||||
}
|
||||
|
||||
const after = [] // list of init script to load before
|
||||
const before = []
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
after,
|
||||
before
|
||||
}
|
||||
export const after = [] // list of init script to load before
|
||||
export const before = []
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
const audio = require('../../core/audio')
|
||||
import audio from '../../core/audio'
|
||||
|
||||
async function init() {
|
||||
export async function init() {
|
||||
audio('/core/sheeebr.wav')
|
||||
}
|
||||
|
||||
const after = [ "filesystem.js" ] // list of init script to load before
|
||||
const before = []
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
after,
|
||||
before
|
||||
}
|
||||
export const after = [ "filesystem.js" ] // list of init script to load before
|
||||
export const before = []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const fs = require('fs');
|
||||
import * as fs from 'fs'
|
||||
|
||||
if(process.argv.length >= 3){
|
||||
try{
|
||||
@@ -15,4 +15,4 @@ if(process.argv.length >= 3){
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//@ts-check
|
||||
const graphics = require('../../core/graphics')
|
||||
const shapes = require('../lib/shapes')
|
||||
const path = require('path')
|
||||
import * as graphics from '../../core/graphics'
|
||||
import * as shapes from '../lib/shapes'
|
||||
|
||||
graphics.clear()
|
||||
drawChibrax()
|
||||
@@ -141,4 +140,4 @@ function drawChibrax() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//@ts-check
|
||||
const ip = require('../../core/ip')
|
||||
const ip = require('../../core/ip.js.bak')
|
||||
const fs = require('fs')
|
||||
const { exit } = require('process')
|
||||
|
||||
@@ -70,4 +70,4 @@ if(flags & ip.flags.IFF_SLAVE) {
|
||||
if(flags & ip.flags.IFF_UP) {
|
||||
flagsStr += 'IFF_SLAVE\n'
|
||||
}
|
||||
console.log(flagsStr)
|
||||
console.log(flagsStr)
|
||||
@@ -1,5 +1,5 @@
|
||||
//@ts-check
|
||||
const ip = require('../../core/ip')
|
||||
const ip = require('../../core/ip.js.bak')
|
||||
const fs = require('fs')
|
||||
const { exit } = require('process')
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
const fs = require('fs')
|
||||
|
||||
|
||||
let paths = []
|
||||
let options = []
|
||||
|
||||
for(arg of process.argv.slice(3)){
|
||||
if(arg.startsWith('--')){
|
||||
options.push(arg)
|
||||
}
|
||||
else if(arg.startsWith('-')){
|
||||
for(let option of arg.slice(1)){
|
||||
options.push('-' + option);
|
||||
}
|
||||
}
|
||||
else{
|
||||
paths.push(arg)
|
||||
}
|
||||
}
|
||||
|
||||
if(paths.length == 0){
|
||||
paths = ['.'];
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
|
||||
listFiles(paths[0], options)
|
||||
}
|
||||
catch(e){
|
||||
switch(e.code){
|
||||
case "ENOENT":
|
||||
console.error(`path "${paths[0]}" does not exist`);
|
||||
break;
|
||||
default:
|
||||
console.error(`ls: ${e.code}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function listFiles(path, options){
|
||||
const files = ['.', '..'].concat(fs.readdirSync(paths[0]))
|
||||
const nonHiddenFiles = files.filter(file => file[0] != '.')
|
||||
colorList = JSON.parse(process.env.ls_color)
|
||||
if(options.includes('-l')){
|
||||
console.log(`total ${options.includes('-a') ? files.length : nonHiddenFiles.length}`)
|
||||
for(let file of options.includes('-a') ? files : nonHiddenFiles){
|
||||
|
||||
stats = fs.lstatSync(`${path}/${file}`);
|
||||
mode = stats.mode
|
||||
result = ""
|
||||
let color = []
|
||||
let defaultColor = "\x1b[0m"
|
||||
let fileType = "-"
|
||||
if(stats.isFile()){
|
||||
fileType = "-";
|
||||
if(stats.mode & 00100){ //owner can execute
|
||||
color = colorList.ex ? `\x1b[${colorList.ex[0]}m\x1b[${colorList.ex[1]}m` : "\x1b[0m"
|
||||
}
|
||||
}
|
||||
else if (stats.isDirectory()) {
|
||||
fileType = "d";
|
||||
color = colorList.di ? `\x1b[${colorList.di[0]}m\x1b[${colorList.di[1]}m` : "\x1b[0m"
|
||||
}
|
||||
else if (stats.isSymbolicLink()){
|
||||
fileType = "l"
|
||||
color = colorList.ln ? `\x1b[${colorList.ln[0]}m\x1b[${colorList.ln[1]}m` : "\x1b[0m"
|
||||
}
|
||||
result += fileType;
|
||||
permissions = "xwr"
|
||||
for(let i=8;i>=0;i--){
|
||||
result += parseInt(Math.pow(2,i).toString(2)) & mode ? permissions[i%3] : '-'
|
||||
}
|
||||
if(01000 & mode){ // check sticky bit
|
||||
color = "\x1b[40m\x1b[92m\x1b[7m"
|
||||
}
|
||||
let date = new Date(stats.mtimeMs*1000).toDateString().split(' ');
|
||||
result += ` ${usernameFromUID(stats.uid)}\t${groupnameFromGID(stats.gid)}\t${stats.size}\t${date[2]} ${date[1]}. ${options.includes('--color') ? color : ""}${file}${defaultColor}`
|
||||
console.log(result)
|
||||
}
|
||||
}
|
||||
else{
|
||||
result = ""
|
||||
const defaultColor = "\x1b[0m";
|
||||
if(options.includes('--color')){
|
||||
for(let file of options.includes('-a') ? files : nonHiddenFiles){
|
||||
stats = fs.lstatSync(`${path}/${file}`);
|
||||
let color = defaultColor
|
||||
if(stats.isDirectory()){
|
||||
color = colorList.di ? `\x1b[${colorList.di[1]}m\x1b[${colorList.di[0]}m` : defaultColor
|
||||
}
|
||||
else if (stats.isSymbolicLink()){
|
||||
color = colorList.ln ? `\x1b[${colorList.ln[1]}m\x1b[${colorList.ln[0]}m` : defaultColor
|
||||
}
|
||||
if(01000 & stats.mode){ // check sticky bit
|
||||
color = "\x1b[40m\x1b[92m\x1b[7m"
|
||||
}
|
||||
result += color + file + defaultColor + " ";
|
||||
}
|
||||
console.log(result)
|
||||
}else{
|
||||
console.log(options.includes('-a') ? files.join(' ') : nonHiddenFiles.join(' '))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function usernameFromUID(uid){
|
||||
const passwd = fs.readFileSync("/etc/passwd", {encoding: 'utf-8'}).split('\n');
|
||||
for(let line of passwd){
|
||||
let lineSplited = line.split(':')
|
||||
if(lineSplited[2] == uid){
|
||||
return lineSplited[0];
|
||||
}
|
||||
}
|
||||
return uid
|
||||
}
|
||||
|
||||
function groupnameFromGID(uid){
|
||||
const passwd = fs.readFileSync("/etc/passwd", {encoding: 'utf-8'}).split('\n');
|
||||
for(let line of passwd){
|
||||
let lineSplited = line.split(':')
|
||||
if(lineSplited[3] == uid){
|
||||
return lineSplited[0];
|
||||
}
|
||||
}
|
||||
return uid
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
'strict'
|
||||
import { file } from 'bun'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
|
||||
let paths: string[] = []
|
||||
let options = []
|
||||
|
||||
const defaultColors = {
|
||||
di: [1, 34],
|
||||
ln: [1, 36],
|
||||
ex: [1, 32]
|
||||
}
|
||||
|
||||
for(const arg of process.argv.slice(3)){
|
||||
if(arg.startsWith('--')){
|
||||
options.push(arg)
|
||||
}
|
||||
else if(arg.startsWith('-')){
|
||||
for(let option of arg.slice(1)){
|
||||
options.push('-' + option);
|
||||
}
|
||||
}
|
||||
else{
|
||||
paths.push(arg)
|
||||
}
|
||||
}
|
||||
|
||||
if(paths.length == 0){
|
||||
paths = [ process.cwd() ];
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
|
||||
listFiles(paths[0], options)
|
||||
}
|
||||
catch(e){
|
||||
switch(e.code){
|
||||
case 'ENOENT':
|
||||
console.error(`path '${paths[0]}' does not exist`);
|
||||
break;
|
||||
default:
|
||||
console.error(`ls: ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function listFiles(directory: string, options: string[]){
|
||||
if(!fs.existsSync(directory)) {
|
||||
console.error('Path not found')
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let files = ['.', '..', ...fs.readdirSync(paths[0])]
|
||||
|
||||
if(!options.includes('-a')) {
|
||||
files = files.filter(file => !file.startsWith('.') || file === '.' || file === '..')
|
||||
}
|
||||
|
||||
let colorList: typeof defaultColors
|
||||
|
||||
if(process.env.ls_color) {
|
||||
colorList = { ...defaultColors, ...JSON.parse(process.env.ls_color)}
|
||||
} else {
|
||||
colorList = defaultColors
|
||||
}
|
||||
|
||||
if(options.includes('-l')){
|
||||
console.log(`total ${file.length}`)
|
||||
for(let file of files){
|
||||
let result = ''
|
||||
const stats = fs.lstatSync(path.join(directory, file));
|
||||
let color = ''
|
||||
let defaultColor = '\x1b[0m'
|
||||
let fileType = '?'
|
||||
if(stats.isFile()){
|
||||
fileType = '-';
|
||||
if(stats.mode & 0o100){ //owner can execute
|
||||
color = colorList.ex ? `\x1b[${colorList.ex[0]}m\x1b[${colorList.ex[1]}m` : '\x1b[0m'
|
||||
}
|
||||
}
|
||||
else if (stats.isDirectory()) {
|
||||
fileType = 'd';
|
||||
color = colorList.di ? `\x1b[${colorList.di[0]}m\x1b[${colorList.di[1]}m` : '\x1b[0m'
|
||||
}
|
||||
else if (stats.isSymbolicLink()){
|
||||
fileType = 'l'
|
||||
color = colorList.ln ? `\x1b[${colorList.ln[0]}m\x1b[${colorList.ln[1]}m` : '\x1b[0m'
|
||||
}
|
||||
result += fileType;
|
||||
const permissions = 'xwr'
|
||||
for(let i=8;i>=0;i--){
|
||||
result += parseInt(Math.pow(2,i).toString(2)) & stats.mode ? permissions[i%3] : '-'
|
||||
}
|
||||
if(0o1000 & stats.mode){ // check sticky bit
|
||||
color = '\x1b[40m\x1b[92m\x1b[7m'
|
||||
}
|
||||
const date = stats.mtime.toDateString().split(' ');
|
||||
result += ` ${usernameFromUID(stats.uid)}\t${groupnameFromGID(stats.gid)}\t${stats.size}\t${date[2]} ${date[1]}. ${options.includes('--color') ? color : ''}${file}${defaultColor}`
|
||||
console.log(result)
|
||||
}
|
||||
}
|
||||
else{
|
||||
const defaultColor = '\x1b[0m';
|
||||
if(options.includes('--color')){
|
||||
let result = ''
|
||||
for(let file of files){
|
||||
const stats = fs.lstatSync(path.join(directory, file));
|
||||
let color = defaultColor
|
||||
if(0o1000 & stats.mode){ // check sticky bit
|
||||
color = '\x1b[40m\x1b[92m\x1b[7m'
|
||||
} else if(stats.isDirectory()){
|
||||
color = colorList.di ? `\x1b[${colorList.di[1]}m\x1b[${colorList.di[0]}m` : defaultColor
|
||||
} else if (stats.isSymbolicLink()){
|
||||
color = colorList.ln ? `\x1b[${colorList.ln[1]}m\x1b[${colorList.ln[0]}m` : defaultColor
|
||||
}
|
||||
|
||||
result += color + file + ' ' + defaultColor;
|
||||
}
|
||||
console.log(result)
|
||||
}else{
|
||||
console.log(files.join(' '))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function usernameFromUID(uid: string | number){
|
||||
if(uid == 0) return 'root'
|
||||
if(uid != 0) return 'unknown user'
|
||||
//TODO: add support for multiple users to the os
|
||||
return uid
|
||||
}
|
||||
|
||||
function groupnameFromGID(uid: string | number){
|
||||
if(uid == 0) return 'root'
|
||||
if(uid != 0) return 'unknown group'
|
||||
//TODO: add support for multiple groups to the os
|
||||
return uid
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
const { lsmod } = require('/chibrax/kernel.js')
|
||||
import { lsmod } from '../../core/kernel'
|
||||
|
||||
console.log(lsmod())
|
||||
console.log(lsmod())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const fs = require('fs')
|
||||
import * as fs from 'fs'
|
||||
|
||||
if(process.argv.length >= 3){
|
||||
fs.mkdir(process.argv[3], { recursive: true }, (err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//@ts-check
|
||||
const { finit_module, uname } = require('../../core/kernel.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import { finit_module, uname } from '../../core/kernel.js'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
const name = uname()
|
||||
const modulePath = path.join('/lib/modules', name, 'kernel')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const fs = require('fs')
|
||||
import * as fs from 'fs'
|
||||
|
||||
if(process.argv.length >= 3){
|
||||
let filesToRemove = process.argv.slice(3).filter((arg) => !arg.startsWith('-'));
|
||||
@@ -22,4 +22,4 @@ if(process.argv.length >= 3){
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//@ts-check
|
||||
const { Lexer } = require('../lib/sheebr/lexer')
|
||||
const { getline } = require('../lib/sheebr/utils')
|
||||
const fs = require('fs')
|
||||
let environment = require('../lib/sheebr/environment')
|
||||
let aliases = require("../lib/sheebr/aliases")
|
||||
const { startjs } = require('../../core/hook')
|
||||
|
||||
import { startjs } from '../../core/hook'
|
||||
import Lexer from '../lib/sheebr/lexer'
|
||||
import * as fs from 'fs'
|
||||
import environment from '../lib/sheebr/environment'
|
||||
import aliases from '../lib/sheebr/aliases'
|
||||
import * as path from 'path'
|
||||
|
||||
let current_dir = process.cwd()
|
||||
|
||||
@@ -12,9 +13,13 @@ start()
|
||||
|
||||
async function start(){
|
||||
while(true){
|
||||
const input = await getline("sheebr> ");
|
||||
const input = prompt("sheebr> ");
|
||||
if(input === "exit") break;
|
||||
if(!input) continue;
|
||||
if(!input) {
|
||||
//work around missing line break
|
||||
console.log()
|
||||
continue
|
||||
}
|
||||
else await evaluate(input);
|
||||
}
|
||||
}
|
||||
@@ -61,23 +66,30 @@ async function evaluate(input){
|
||||
* @param {string[]} args
|
||||
*/
|
||||
async function evaluateProgram(args){
|
||||
|
||||
let found = false;
|
||||
for(let path of environment.path.split(':')){
|
||||
for(const envPath of environment.path.split(':')){
|
||||
let tobreak = false;
|
||||
const files = fs.readdirSync(path);
|
||||
if(files.includes(`${args[0]}.js`)){
|
||||
if(!fs.existsSync(envPath)) continue
|
||||
|
||||
const jsPath = path.join(envPath, `${args[0]}.js`)
|
||||
const tsPath = path.join(envPath, `${args[0]}.ts`)
|
||||
|
||||
console.log(jsPath, tsPath, envPath)
|
||||
|
||||
if(fs.existsSync(jsPath) || fs.existsSync(tsPath) ){
|
||||
found = true;
|
||||
console.log('found it: ' + path + args[0])
|
||||
try {
|
||||
const cmd = `${path + '/' + args[0]}.js`
|
||||
const cmd = fs.existsSync(jsPath) ? jsPath : tsPath
|
||||
const options = {cwd: current_dir, env: environment, shell: true}
|
||||
console.log(args)
|
||||
await startjs(cmd, args, options)
|
||||
tobreak = true;
|
||||
console.log('\x1b[0m')
|
||||
tobreak = true
|
||||
} catch(e) {
|
||||
console.log("Program crashed")
|
||||
}
|
||||
}
|
||||
|
||||
if(tobreak) break;
|
||||
}
|
||||
if(!found){
|
||||
@@ -114,4 +126,4 @@ function evaluateAliases(args){
|
||||
return aliases[args[0]].concat(args.slice(1))
|
||||
}
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const fs = require('fs')
|
||||
import * as fs from 'fs'
|
||||
|
||||
if(process.argv.length >= 3){
|
||||
try{
|
||||
fs.openSync(process.argv[3], 'w');
|
||||
@@ -6,4 +7,4 @@ if(process.argv.length >= 3){
|
||||
catch(e){
|
||||
console.error(e.code + '\n' + e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const fs = require('fs');
|
||||
const { resolve } = require('path');
|
||||
import * as fs from 'fs'
|
||||
import { resolve } from 'path';
|
||||
|
||||
if(process.argv.length >= 3){
|
||||
// console.log(process.env.path)
|
||||
@@ -20,4 +20,4 @@ function recursiveSearch(dir, bin){
|
||||
result = result.concat(recursiveSearch(dirent.name, bin))
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
let os = require('os')
|
||||
console.log(os.userInfo().username);
|
||||
import { userInfo } from 'os'
|
||||
|
||||
console.log(userInfo().username);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* DICKPICK is a image drawing library
|
||||
*/
|
||||
|
||||
const graphics = require('../../core/graphics')
|
||||
import * as graphics from '../../core/graphics'
|
||||
|
||||
/**
|
||||
* @param { number } x
|
||||
@@ -12,7 +12,7 @@ const graphics = require('../../core/graphics')
|
||||
* @param { number } dy length on the y axis
|
||||
* @param { string } color
|
||||
*/
|
||||
function drawRect(x, y, dx, dy, color) {
|
||||
export function drawRect(x, y, dx, dy, color) {
|
||||
const bitmap = {
|
||||
data: Buffer.alloc(dx*dy*4, Buffer.from(graphics.parseHexColor(color))),
|
||||
width: dx,
|
||||
@@ -28,7 +28,7 @@ function drawRect(x, y, dx, dy, color) {
|
||||
* @param { number[] } color
|
||||
* @returns { Pencil }
|
||||
*/
|
||||
function pencilFromBitmap(Bitmap, color) {
|
||||
export function pencilFromBitmap(Bitmap, color) {
|
||||
return { ...Bitmap, color }
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ function pencilFromBitmap(Bitmap, color) {
|
||||
* @param { number } height
|
||||
* @returns
|
||||
*/
|
||||
function createBitmap(width, height) {
|
||||
export function createBitmap(width, height) {
|
||||
const data = Buffer.alloc(width * height * 4, Buffer.from([0, 0, 0, 0]));
|
||||
return { width, height, data }
|
||||
}
|
||||
@@ -47,7 +47,7 @@ function createBitmap(width, height) {
|
||||
* @param { number } x
|
||||
* @param { number } y
|
||||
*/
|
||||
function setPixel(pencil, x, y) {
|
||||
export function setPixel(pencil, x, y) {
|
||||
pencil.data.set(pencil.color, y*pencil.width*4 + x*4)
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ function setPixel(pencil, x, y) {
|
||||
* @param { number } yc
|
||||
* @param { Pencil } pencil
|
||||
*/
|
||||
function symetrie8Axes(xc, yc, x, y, pencil) {
|
||||
export function symetrie8Axes(xc, yc, x, y, pencil) {
|
||||
setPixel(pencil, x+xc, y+yc)
|
||||
setPixel(pencil, x+xc,-y+yc)
|
||||
setPixel(pencil, -x+xc,-y+yc)
|
||||
@@ -78,7 +78,7 @@ function symetrie8Axes(xc, yc, x, y, pencil) {
|
||||
* @param { number } yc
|
||||
* @param { number } r
|
||||
*/
|
||||
function drawCircle(pencil, xc, yc, r) {
|
||||
export function drawCircle(pencil, xc, yc, r) {
|
||||
let x = 0
|
||||
let y = r
|
||||
let d = 3 - (2 * r);
|
||||
@@ -96,6 +96,3 @@ function drawCircle(pencil, xc, yc, r) {
|
||||
symetrie8Axes(xc, yc, x, y, pencil);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { drawRect, setPixel, pencilFromBitmap, createBitmap, drawCircle }
|
||||
@@ -2,8 +2,6 @@
|
||||
/**
|
||||
* @type {{ [key: string]: string[] }}
|
||||
*/
|
||||
const aliases = {
|
||||
export default {
|
||||
ls: ["ls", "--color"]
|
||||
}
|
||||
|
||||
module.exports = aliases
|
||||
@@ -11,4 +11,4 @@ let environment = {
|
||||
}),
|
||||
}
|
||||
|
||||
module.exports = environment
|
||||
export default environment
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
//@ts-check
|
||||
const { isAlpha } = require('./utils')
|
||||
|
||||
|
||||
class Lexer{
|
||||
export default class Lexer{
|
||||
/**
|
||||
* @param { string } source
|
||||
*/
|
||||
@@ -55,8 +53,3 @@ class Lexer{
|
||||
// this.tokens.push(Token(tokenType, value))
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
Lexer
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as crypto from 'crypto'
|
||||
import { tmpdir } from 'os';
|
||||
import * as fs from 'fs'
|
||||
import * as childProc from 'child_process'
|
||||
import * as pathUtil from 'path'
|
||||
|
||||
var
|
||||
IS_WIN = process.platform === 'win32',
|
||||
|
||||
@@ -15,10 +21,7 @@ var
|
||||
ALGORITHM_HASH = 'sha256',
|
||||
DEFAULT_ERR_MSG = 'The current environment doesn\'t support interactive reading from TTY.',
|
||||
|
||||
fs = require('fs'),
|
||||
TTY = process.binding('tty_wrap').TTY,
|
||||
childProc = require('child_process'),
|
||||
pathUtil = require('path'),
|
||||
|
||||
defaultOptions = {
|
||||
/* eslint-disable key-spacing */
|
||||
@@ -91,7 +94,7 @@ function _execFileSync(options, execOptions) {
|
||||
function getTempfile(name) {
|
||||
var suffix = '',
|
||||
filepath, fd;
|
||||
tempdir = tempdir || require('os').tmpdir();
|
||||
tempdir = tempdir || tmpdir();
|
||||
|
||||
while (true) {
|
||||
filepath = pathUtil.join(tempdir, name + suffix);
|
||||
@@ -116,7 +119,6 @@ function _execFileSync(options, execOptions) {
|
||||
pathStderr = getTempfile('readline-sync.stderr'),
|
||||
pathExit = getTempfile('readline-sync.exit'),
|
||||
pathDone = getTempfile('readline-sync.done'),
|
||||
crypto = require('crypto'),
|
||||
hostArgs, shellPath, shellArgs, exitCode, extMessage, shasum, decipher, password;
|
||||
|
||||
shasum = crypto.createHash(ALGORITHM_HASH);
|
||||
|
||||
@@ -1,41 +1,9 @@
|
||||
//@ts-check
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @returns { Promise<string> }
|
||||
*/
|
||||
async function getline(str) {
|
||||
process.stdout.write(str)
|
||||
process.stdin.resume()
|
||||
process.stdin.setEncoding('utf8')
|
||||
let line = ""
|
||||
return new Promise((res, rej) => {
|
||||
process.stdin.on('data', function(chunk) {
|
||||
|
||||
line += chunk
|
||||
if (chunk.toString('utf-8').endsWith('\n')) {
|
||||
process.stdin.pause()
|
||||
res(line.substring(0, line.length -1))
|
||||
}
|
||||
})
|
||||
process.stdin.on('error', function(err) {
|
||||
rej(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } str
|
||||
* @returns
|
||||
*/
|
||||
function isAlpha(str){
|
||||
export function isAlpha(str){
|
||||
return /^[a-zA-Z]*$/.test(str)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
isAlpha, getline
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user