functionalscript 0.11.2 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/text/sgr/module.f.d.ts
CHANGED
|
@@ -21,17 +21,40 @@ export declare const csi: (end: End) => Csi;
|
|
|
21
21
|
* https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
|
|
22
22
|
*/
|
|
23
23
|
export declare const sgr: Csi;
|
|
24
|
+
/** Resets all SGR styles to terminal defaults. */
|
|
24
25
|
export declare const reset: string;
|
|
26
|
+
/** Enables bold/intense text rendering when supported by the terminal. */
|
|
25
27
|
export declare const bold: string;
|
|
28
|
+
/** Applies red foreground color to subsequent text. */
|
|
26
29
|
export declare const fgRed: string;
|
|
30
|
+
/** Applies green foreground color to subsequent text. */
|
|
27
31
|
export declare const fgGreen: string;
|
|
28
32
|
export type Stdout = {
|
|
33
|
+
/** Writes a string to the output stream. */
|
|
29
34
|
readonly write: (s: string) => void;
|
|
30
35
|
};
|
|
36
|
+
/** Stateful writer that updates previously printed text in-place. */
|
|
31
37
|
export type WriteText = (text: string) => WriteText;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a stateful text writer that rewrites the previous value using backspaces.
|
|
40
|
+
*
|
|
41
|
+
* @param stdout - Destination output stream.
|
|
42
|
+
* @returns A recursive writer that replaces prior text on each call.
|
|
43
|
+
*/
|
|
32
44
|
export declare const createConsoleText: (stdout: Stdout) => WriteText;
|
|
33
45
|
export type CsiConsole = (s: string) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a TTY-aware console function.
|
|
48
|
+
*
|
|
49
|
+
* For TTY destinations, ANSI SGR sequences are preserved.
|
|
50
|
+
* For non-TTY destinations, ANSI SGR sequences are stripped.
|
|
51
|
+
*
|
|
52
|
+
* @param io - Runtime IO bindings.
|
|
53
|
+
* @returns A function that targets a writable stream.
|
|
54
|
+
*/
|
|
34
55
|
export declare const console: ({ fs: { writeSync } }: Io) => (w: Writable) => CsiConsole;
|
|
56
|
+
/** Writes to process stdout using a TTY-aware CSI console. */
|
|
35
57
|
export declare const stdio: (io: Io) => CsiConsole;
|
|
58
|
+
/** Writes to process stderr using a TTY-aware CSI console. */
|
|
36
59
|
export declare const stderr: (io: Io) => CsiConsole;
|
|
37
60
|
export {};
|
package/text/sgr/module.f.js
CHANGED
|
@@ -19,9 +19,13 @@ export const csi = (end) => code => `${begin}${code.toString()}${end}`;
|
|
|
19
19
|
* https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
|
|
20
20
|
*/
|
|
21
21
|
export const sgr = csi('m');
|
|
22
|
+
/** Resets all SGR styles to terminal defaults. */
|
|
22
23
|
export const reset = sgr(0);
|
|
24
|
+
/** Enables bold/intense text rendering when supported by the terminal. */
|
|
23
25
|
export const bold = sgr(1);
|
|
26
|
+
/** Applies red foreground color to subsequent text. */
|
|
24
27
|
export const fgRed = sgr(31);
|
|
28
|
+
/** Applies green foreground color to subsequent text. */
|
|
25
29
|
export const fgGreen = sgr(32);
|
|
26
30
|
const { max } = Math;
|
|
27
31
|
const replace = (old) => (text) => {
|
|
@@ -29,6 +33,12 @@ const replace = (old) => (text) => {
|
|
|
29
33
|
const suffixLength = max(0, len - text.length);
|
|
30
34
|
return backspace.repeat(len) + text + " ".repeat(suffixLength) + backspace.repeat(suffixLength);
|
|
31
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates a stateful text writer that rewrites the previous value using backspaces.
|
|
38
|
+
*
|
|
39
|
+
* @param stdout - Destination output stream.
|
|
40
|
+
* @returns A recursive writer that replaces prior text on each call.
|
|
41
|
+
*/
|
|
32
42
|
export const createConsoleText = (stdout) => {
|
|
33
43
|
const f = (old) => (text) => {
|
|
34
44
|
stdout.write(replace(old)(text));
|
|
@@ -36,11 +46,22 @@ export const createConsoleText = (stdout) => {
|
|
|
36
46
|
};
|
|
37
47
|
return f('');
|
|
38
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Creates a TTY-aware console function.
|
|
51
|
+
*
|
|
52
|
+
* For TTY destinations, ANSI SGR sequences are preserved.
|
|
53
|
+
* For non-TTY destinations, ANSI SGR sequences are stripped.
|
|
54
|
+
*
|
|
55
|
+
* @param io - Runtime IO bindings.
|
|
56
|
+
* @returns A function that targets a writable stream.
|
|
57
|
+
*/
|
|
39
58
|
export const console = ({ fs: { writeSync } }) => (w) => {
|
|
40
59
|
const { isTTY } = w;
|
|
41
60
|
return isTTY
|
|
42
61
|
? (s) => writeSync(w.fd, s + '\n')
|
|
43
62
|
: (s) => writeSync(w.fd, s.replace(/\x1b\[[0-9;]*m/g, '') + '\n');
|
|
44
63
|
};
|
|
64
|
+
/** Writes to process stdout using a TTY-aware CSI console. */
|
|
45
65
|
export const stdio = (io) => console(io)(io.process.stdout);
|
|
66
|
+
/** Writes to process stderr using a TTY-aware CSI console. */
|
|
46
67
|
export const stderr = (io) => console(io)(io.process.stderr);
|
|
@@ -16,10 +16,14 @@ export type DoK<O extends Operation, T, K extends O[0]> = DoKPR<O, T, K, Pr<O, K
|
|
|
16
16
|
export type Do<O extends Operation, T> = DoK<O, T, O[0]>;
|
|
17
17
|
export declare const pure: <T>(v: T) => Effect<never, T>;
|
|
18
18
|
export declare const doFull: <O extends Operation, T, K extends O[0]>(cmd: K, param: Pr<O, K>[0], cont: (input: Pr<O, K>[1]) => Effect<O, T>) => Effect<O, T>;
|
|
19
|
-
export
|
|
19
|
+
export type Param<O extends Operation> = F<O>[0];
|
|
20
|
+
export type Return<O extends Operation> = F<O>[1];
|
|
21
|
+
export declare const do_: <O extends Operation>(cmd: O[0]) => (param: Param<O>) => Effect<O, Return<O>>;
|
|
22
|
+
export declare const doRest: <O extends Operation>(cmd: O[0]) => (...param: Param<O>) => Effect<O, Return<O>>;
|
|
20
23
|
export declare const begin: Effect<never, void>;
|
|
21
24
|
export type ToAsyncOperationMap<O extends Operation> = {
|
|
22
25
|
readonly [K in O[0]]: (payload: Pr<O, K>[0]) => Promise<Pr<O, K>[1]>;
|
|
23
26
|
};
|
|
24
27
|
export type F<O extends Operation> = Pr<O, O[0]>;
|
|
25
|
-
export type Func<O extends Operation> = (_:
|
|
28
|
+
export type Func<O extends Operation> = (_: Param<O>) => Effect<O, Return<O>>;
|
|
29
|
+
export type RestFunc<O extends Operation> = (..._: Param<O>) => Effect<O, Return<O>>;
|
|
@@ -12,4 +12,5 @@ export const doFull = (cmd, param, cont) => ({
|
|
|
12
12
|
step: (f) => doFull(cmd, param, x => cont(x).step(f)),
|
|
13
13
|
});
|
|
14
14
|
export const do_ = (cmd) => (param) => doFull(cmd, param, pure);
|
|
15
|
+
export const doRest = (cmd) => (...param) => do_(cmd)(param);
|
|
15
16
|
export const begin = pure(undefined);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Vec } from '../../bit_vec/module.f.ts';
|
|
2
2
|
import type { Nominal } from '../../nominal/module.f.ts';
|
|
3
3
|
import type { Result } from '../../result/module.f.ts';
|
|
4
|
-
import { type Effect, type Func, type Operation, type ToAsyncOperationMap } from '../module.f.ts';
|
|
4
|
+
import { type Effect, type Func, type Operation, type RestFunc, type ToAsyncOperationMap } from '../module.f.ts';
|
|
5
5
|
export type IoResult<T> = Result<T, unknown>;
|
|
6
6
|
export type All = ['all', <T>(_: readonly Effect<never, T>[]) => readonly T[]];
|
|
7
7
|
/**
|
|
@@ -20,7 +20,7 @@ export type MakeDirectoryOptions = {
|
|
|
20
20
|
};
|
|
21
21
|
export type MkdirParam = readonly [string, MakeDirectoryOptions?];
|
|
22
22
|
export type Mkdir = readonly ['mkdir', (_: MkdirParam) => IoResult<void>];
|
|
23
|
-
export declare const mkdir:
|
|
23
|
+
export declare const mkdir: RestFunc<Mkdir>;
|
|
24
24
|
export type ReadFile = readonly ['readFile', (_: string) => IoResult<Vec>];
|
|
25
25
|
export declare const readFile: Func<ReadFile>;
|
|
26
26
|
/**
|
|
@@ -37,10 +37,10 @@ export type ReaddirOptions = {
|
|
|
37
37
|
};
|
|
38
38
|
export type ReaddirParam = readonly [string, ReaddirOptions];
|
|
39
39
|
export type Readdir = readonly ['readdir', (_: ReaddirParam) => IoResult<readonly Dirent[]>];
|
|
40
|
-
export declare const readdir:
|
|
40
|
+
export declare const readdir: RestFunc<Readdir>;
|
|
41
41
|
export type WriteFileParam = readonly [string, Vec];
|
|
42
42
|
export type WriteFile = readonly ['writeFile', (_: WriteFileParam) => IoResult<void>];
|
|
43
|
-
export declare const writeFile:
|
|
43
|
+
export declare const writeFile: RestFunc<WriteFile>;
|
|
44
44
|
export type Fs = Mkdir | ReadFile | Readdir | WriteFile;
|
|
45
45
|
export type Error = ['error', (_: string) => void];
|
|
46
46
|
export declare const error: Func<Error>;
|
|
@@ -54,6 +54,7 @@ export type RequestListener = (_: IncomingMessage) => ServerResponse;
|
|
|
54
54
|
export type CreateServer = ['createServer', (_: RequestListener) => Server];
|
|
55
55
|
export declare const createServer: Func<CreateServer>;
|
|
56
56
|
export type Listen = ['listen', (_: readonly [Server, number]) => void];
|
|
57
|
+
export declare const listen: RestFunc<Listen>;
|
|
57
58
|
export type Http = CreateServer | Listen;
|
|
58
59
|
export type NodeOp = All | Fetch | Console | Fs | Http;
|
|
59
60
|
export type NodeEffect<T> = Effect<NodeOp, T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { do_ } from "../module.f.js";
|
|
1
|
+
import { doRest, do_ } from "../module.f.js";
|
|
2
2
|
/**
|
|
3
3
|
* To run the operation `O` should be known by the runner/engine.
|
|
4
4
|
* This is the reason why we merge `O` with `All` in the resulted `Effect`.
|
|
@@ -9,10 +9,11 @@ import { do_ } from "../module.f.js";
|
|
|
9
9
|
export const all = (...a) => do_('all')(a);
|
|
10
10
|
export const both = (a) => (b) => all(a, b);
|
|
11
11
|
export const fetch = do_('fetch');
|
|
12
|
-
export const mkdir = (
|
|
12
|
+
export const mkdir = doRest('mkdir');
|
|
13
13
|
export const readFile = do_('readFile');
|
|
14
|
-
export const readdir = (
|
|
15
|
-
export const writeFile = (
|
|
14
|
+
export const readdir = doRest('readdir');
|
|
15
|
+
export const writeFile = doRest('writeFile');
|
|
16
16
|
export const error = do_('error');
|
|
17
17
|
export const log = do_('log');
|
|
18
18
|
export const createServer = do_('createServer');
|
|
19
|
+
export const listen = doRest('listen');
|