effective-progress 0.5.0 → 0.5.2
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/dist/index.d.mts +179 -0
- package/dist/index.mjs +815 -0
- package/package.json +16 -7
- package/index.ts +0 -1
- package/src/api.ts +0 -197
- package/src/index.ts +0 -4
- package/src/ink-renderer/app.tsx +0 -31
- package/src/ink-renderer/columns/amount-column.tsx +0 -17
- package/src/ink-renderer/columns/bar-column.tsx +0 -31
- package/src/ink-renderer/columns/description-column.tsx +0 -7
- package/src/ink-renderer/columns/elapsed-column.tsx +0 -7
- package/src/ink-renderer/columns/eta-column.tsx +0 -18
- package/src/ink-renderer/columns/index.ts +0 -6
- package/src/ink-renderer/columns/types.ts +0 -11
- package/src/ink-renderer/format.ts +0 -55
- package/src/ink-renderer/index.ts +0 -1
- package/src/ink-renderer/layout.ts +0 -145
- package/src/ink-renderer/model.ts +0 -24
- package/src/ink-renderer/service.tsx +0 -121
- package/src/ink-renderer/task-row.tsx +0 -53
- package/src/ink-renderer/tree.ts +0 -62
- package/src/ink-renderer/types.ts +0 -18
- package/src/runtime.ts +0 -396
- package/src/terminal.ts +0 -61
- package/src/types.ts +0 -143
- package/src/utils.ts +0 -20
package/src/terminal.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
|
|
3
|
-
export interface ProgressTerminalService {
|
|
4
|
-
readonly isTTY: Effect.Effect<boolean>;
|
|
5
|
-
readonly stderrRows: Effect.Effect<number | undefined>;
|
|
6
|
-
readonly stderrColumns: Effect.Effect<number | undefined>;
|
|
7
|
-
readonly writeStderr: (text: string) => Effect.Effect<void>;
|
|
8
|
-
readonly withRawInputCapture: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const withRawInputCapture: ProgressTerminalService["withRawInputCapture"] = (effect) =>
|
|
12
|
-
Effect.suspend(() => {
|
|
13
|
-
if (!process.stdin.isTTY) {
|
|
14
|
-
return effect;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const stdin = process.stdin;
|
|
18
|
-
const wasRaw = Boolean(stdin.isRaw);
|
|
19
|
-
const onData = (chunk: Buffer) => {
|
|
20
|
-
if (chunk.length === 1 && chunk[0] === 3) {
|
|
21
|
-
process.kill(process.pid, "SIGINT");
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return Effect.acquireUseRelease(
|
|
26
|
-
Effect.sync(() => {
|
|
27
|
-
stdin.resume();
|
|
28
|
-
stdin.setRawMode?.(true);
|
|
29
|
-
stdin.on("data", onData);
|
|
30
|
-
}),
|
|
31
|
-
() => effect,
|
|
32
|
-
() =>
|
|
33
|
-
Effect.sync(() => {
|
|
34
|
-
try {
|
|
35
|
-
stdin.off("data", onData);
|
|
36
|
-
stdin.setRawMode?.(wasRaw);
|
|
37
|
-
stdin.pause();
|
|
38
|
-
} catch {
|
|
39
|
-
// Best effort terminal restoration.
|
|
40
|
-
}
|
|
41
|
-
}),
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const defaultTerminalService: ProgressTerminalService = {
|
|
46
|
-
isTTY: Effect.sync(() => Boolean(process.stderr.isTTY)),
|
|
47
|
-
stderrRows: Effect.sync(() => process.stderr.rows),
|
|
48
|
-
stderrColumns: Effect.sync(() => process.stderr.columns),
|
|
49
|
-
writeStderr: (text) =>
|
|
50
|
-
Effect.sync(() => {
|
|
51
|
-
process.stderr.write(text);
|
|
52
|
-
}),
|
|
53
|
-
withRawInputCapture,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export class ProgressTerminal extends Context.Tag("stromseng.dev/ProgressTerminal")<
|
|
57
|
-
ProgressTerminal,
|
|
58
|
-
ProgressTerminalService
|
|
59
|
-
>() {
|
|
60
|
-
static readonly Default = Layer.succeed(ProgressTerminal, defaultTerminalService);
|
|
61
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Brand, Context, Effect, Option, Schema } from "effect";
|
|
2
|
-
|
|
3
|
-
const TaskIdSchema = Schema.Number.pipe(Schema.brand("TaskId"));
|
|
4
|
-
|
|
5
|
-
export type TaskId = typeof TaskIdSchema.Type;
|
|
6
|
-
export const TaskId = Brand.nominal<TaskId>();
|
|
7
|
-
|
|
8
|
-
export const TaskStatusSchema = Schema.Literal("running", "done", "failed");
|
|
9
|
-
|
|
10
|
-
export type TaskStatus = typeof TaskStatusSchema.Type;
|
|
11
|
-
|
|
12
|
-
export interface AddTaskOptions {
|
|
13
|
-
readonly description: string;
|
|
14
|
-
readonly total?: number;
|
|
15
|
-
readonly transient?: boolean;
|
|
16
|
-
readonly parentId?: TaskId;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface UpdateTaskOptions {
|
|
20
|
-
readonly description?: string;
|
|
21
|
-
readonly completed?: number;
|
|
22
|
-
readonly total?: number;
|
|
23
|
-
readonly transient?: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type TrackOptions = Exclude<AddTaskOptions, "parentId">;
|
|
27
|
-
|
|
28
|
-
export class DeterminateTaskUnits extends Schema.TaggedClass<DeterminateTaskUnits>()(
|
|
29
|
-
"DeterminateTaskUnits",
|
|
30
|
-
{
|
|
31
|
-
completed: Schema.Number,
|
|
32
|
-
total: Schema.Number,
|
|
33
|
-
},
|
|
34
|
-
) {}
|
|
35
|
-
|
|
36
|
-
export class IndeterminateTaskUnits extends Schema.TaggedClass<IndeterminateTaskUnits>()(
|
|
37
|
-
"IndeterminateTaskUnits",
|
|
38
|
-
{
|
|
39
|
-
spinnerFrame: Schema.Number,
|
|
40
|
-
},
|
|
41
|
-
) {}
|
|
42
|
-
|
|
43
|
-
export const TaskUnitsSchema = Schema.Union(DeterminateTaskUnits, IndeterminateTaskUnits);
|
|
44
|
-
|
|
45
|
-
export type TaskUnits = typeof TaskUnitsSchema.Type;
|
|
46
|
-
|
|
47
|
-
export class TaskSnapshot extends Schema.TaggedClass<TaskSnapshot>()("TaskSnapshot", {
|
|
48
|
-
id: TaskIdSchema,
|
|
49
|
-
parentId: Schema.NullOr(TaskIdSchema),
|
|
50
|
-
description: Schema.String,
|
|
51
|
-
status: TaskStatusSchema,
|
|
52
|
-
transient: Schema.Boolean,
|
|
53
|
-
units: TaskUnitsSchema,
|
|
54
|
-
startedAt: Schema.Number,
|
|
55
|
-
completedAt: Schema.NullOr(Schema.Number),
|
|
56
|
-
}) {}
|
|
57
|
-
|
|
58
|
-
export interface RenderRow {
|
|
59
|
-
readonly id: TaskId;
|
|
60
|
-
readonly depth: number;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface TaskStore {
|
|
64
|
-
readonly tasks: Map<TaskId, TaskSnapshot>;
|
|
65
|
-
readonly renderOrder: ReadonlyArray<RenderRow>;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface ProgressService {
|
|
69
|
-
readonly addTask: (options: AddTaskOptions) => Effect.Effect<TaskId>;
|
|
70
|
-
readonly updateTask: (taskId: TaskId, options: UpdateTaskOptions) => Effect.Effect<void>;
|
|
71
|
-
readonly advanceTask: (taskId: TaskId, amount?: number) => Effect.Effect<void>;
|
|
72
|
-
readonly completeTask: (taskId: TaskId) => Effect.Effect<void>;
|
|
73
|
-
readonly failTask: (taskId: TaskId) => Effect.Effect<void>;
|
|
74
|
-
readonly log: (...args: ReadonlyArray<unknown>) => Effect.Effect<void>;
|
|
75
|
-
readonly getTask: (taskId: TaskId) => Effect.Effect<Option.Option<TaskSnapshot>>;
|
|
76
|
-
readonly listTasks: Effect.Effect<ReadonlyArray<TaskSnapshot>>;
|
|
77
|
-
readonly runTask: {
|
|
78
|
-
<A, E, R>(
|
|
79
|
-
effect: Effect.Effect<A, E, R>,
|
|
80
|
-
options: AddTaskOptions,
|
|
81
|
-
): Effect.Effect<A, E, Exclude<R, Task>>;
|
|
82
|
-
<A, E, R>(
|
|
83
|
-
options: AddTaskOptions,
|
|
84
|
-
): (effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Task>>;
|
|
85
|
-
};
|
|
86
|
-
readonly withTask: {
|
|
87
|
-
<A, E, R>(
|
|
88
|
-
effect: Effect.Effect<A, E, R>,
|
|
89
|
-
options: AddTaskOptions,
|
|
90
|
-
): Effect.Effect<A, E, Exclude<R, Task>>;
|
|
91
|
-
<A, E, R>(
|
|
92
|
-
options: AddTaskOptions,
|
|
93
|
-
): (effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Task>>;
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export class Task extends Context.Tag("stromseng.dev/effective-progress/Task")<Task, TaskId>() {}
|
|
98
|
-
|
|
99
|
-
export class TaskAddedEvent extends Schema.TaggedClass<TaskAddedEvent>()("TaskAdded", {
|
|
100
|
-
taskId: TaskIdSchema,
|
|
101
|
-
parentId: Schema.NullOr(TaskIdSchema),
|
|
102
|
-
description: Schema.String,
|
|
103
|
-
total: Schema.optional(Schema.Number),
|
|
104
|
-
transient: Schema.Boolean,
|
|
105
|
-
}) {}
|
|
106
|
-
|
|
107
|
-
export class TaskUpdatedEvent extends Schema.TaggedClass<TaskUpdatedEvent>()("TaskUpdated", {
|
|
108
|
-
taskId: TaskIdSchema,
|
|
109
|
-
description: Schema.optional(Schema.String),
|
|
110
|
-
completed: Schema.optional(Schema.Number),
|
|
111
|
-
total: Schema.optional(Schema.Number),
|
|
112
|
-
transient: Schema.optional(Schema.Boolean),
|
|
113
|
-
}) {}
|
|
114
|
-
|
|
115
|
-
export class TaskAdvancedEvent extends Schema.TaggedClass<TaskAdvancedEvent>()("TaskAdvanced", {
|
|
116
|
-
taskId: TaskIdSchema,
|
|
117
|
-
amount: Schema.Number,
|
|
118
|
-
}) {}
|
|
119
|
-
|
|
120
|
-
export class TaskCompletedEvent extends Schema.TaggedClass<TaskCompletedEvent>()("TaskCompleted", {
|
|
121
|
-
taskId: TaskIdSchema,
|
|
122
|
-
}) {}
|
|
123
|
-
|
|
124
|
-
export class TaskFailedEvent extends Schema.TaggedClass<TaskFailedEvent>()("TaskFailed", {
|
|
125
|
-
taskId: TaskIdSchema,
|
|
126
|
-
}) {}
|
|
127
|
-
|
|
128
|
-
export class TaskRemovedEvent extends Schema.TaggedClass<TaskRemovedEvent>()("TaskRemoved", {
|
|
129
|
-
taskId: TaskIdSchema,
|
|
130
|
-
}) {}
|
|
131
|
-
|
|
132
|
-
export const ProgressTaskEventSchema = Schema.Union(
|
|
133
|
-
TaskAddedEvent,
|
|
134
|
-
TaskUpdatedEvent,
|
|
135
|
-
TaskAdvancedEvent,
|
|
136
|
-
TaskCompletedEvent,
|
|
137
|
-
TaskFailedEvent,
|
|
138
|
-
TaskRemovedEvent,
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
export type ProgressTaskEvent = typeof ProgressTaskEventSchema.Type;
|
|
142
|
-
|
|
143
|
-
export const decodeProgressTaskEvent = Schema.decodeUnknownSync(ProgressTaskEventSchema);
|
package/src/utils.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export const inferTotal = (iterable: Iterable<unknown>): number | undefined => {
|
|
2
|
-
if (Array.isArray(iterable)) {
|
|
3
|
-
return iterable.length;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (typeof iterable === "string") {
|
|
7
|
-
return iterable.length;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const candidate = iterable as { length?: unknown; size?: unknown };
|
|
11
|
-
if (typeof candidate.length === "number") {
|
|
12
|
-
return candidate.length;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (typeof candidate.size === "number") {
|
|
16
|
-
return candidate.size;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return undefined;
|
|
20
|
-
};
|