@zinn-dev/cli 0.42.0 → 0.44.0
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/README.md +1 -1
- package/index.js +3 -3
- package/package.json +6 -4
- package/skills/zinn/SKILL.md +1 -1
- package/src/actor.d.ts +8 -0
- package/src/actor.js +5 -1
- package/src/capabilities-schema.d.ts +4 -4
- package/src/column-hint.js +3 -4
- package/src/errors.d.ts +40 -3
- package/src/errors.js +93 -21
- package/src/failure-log.d.ts +6 -0
- package/src/failure-log.js +167 -0
- package/src/input.d.ts +11 -0
- package/src/input.js +25 -1
- package/src/lib.d.ts +21 -10
- package/src/lib.js +116 -62
- package/src/list-continuation.d.ts +11 -0
- package/src/list-continuation.js +18 -0
- package/src/list-limit.d.ts +11 -0
- package/src/list-limit.js +17 -0
- package/src/overview.d.ts +10 -0
- package/src/overview.js +41 -0
- package/src/presentation/activity-presentation.d.ts +2 -0
- package/src/presentation/activity-presentation.js +112 -38
- package/src/presentation/column-presentation.d.ts +17 -2
- package/src/presentation/column-presentation.js +45 -6
- package/src/presentation/description-presentation.d.ts +3 -16
- package/src/presentation/description-presentation.js +22 -21
- package/src/presentation/info-presentation.js +36 -6
- package/src/presentation/project-presentation.d.ts +6 -2
- package/src/presentation/project-presentation.js +9 -1
- package/src/presentation/relation-presentation.d.ts +12 -3
- package/src/presentation/relation-presentation.js +50 -26
- package/src/presentation/row-layout.d.ts +1 -1
- package/src/presentation/row-layout.js +6 -5
- package/src/presentation/task-blame-presentation.d.ts +11 -0
- package/src/presentation/task-blame-presentation.js +56 -0
- package/src/presentation/task-presentation.d.ts +6 -1
- package/src/presentation/task-presentation.js +28 -10
- package/src/presentation/text-width.d.ts +2 -0
- package/src/presentation/text-width.js +43 -0
- package/src/presentation/time.d.ts +3 -1
- package/src/presentation/time.js +5 -2
- package/src/result-schemas.d.ts +529 -18
- package/src/result-schemas.js +66 -4
- package/src/routes/activity-router.d.ts +53 -1
- package/src/routes/activity-router.js +126 -15
- package/src/routes/info-router.js +3 -2
- package/src/routes/migrate-router.js +2 -2
- package/src/routes/project-router.d.ts +41 -1
- package/src/routes/project-router.js +76 -24
- package/src/routes/relation-router.d.ts +7 -3
- package/src/routes/relation-router.js +73 -56
- package/src/routes/restore-router.js +10 -7
- package/src/routes/router.js +77 -37
- package/src/routes/routes.d.ts +213 -8
- package/src/routes/task-router.d.ts +119 -6
- package/src/routes/task-router.js +177 -32
- package/src/routes/whoami-router.js +1 -1
- package/src/run-facts.d.ts +14 -0
- package/src/run-facts.js +14 -0
- package/src/store-folder.d.ts +5 -0
- package/src/store-folder.js +16 -0
- package/src/telemetry.d.ts +31 -0
- package/src/telemetry.js +329 -0
- package/src/text-input.js +1 -5
- package/src/timestamp-input.d.ts +3 -0
- package/src/timestamp-input.js +31 -0
- package/src/types.d.ts +4 -4
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { columnNameCell } from "./column-presentation.js";
|
|
1
|
+
import { relation } from "@zinn-dev/core";
|
|
2
|
+
import { columnNameCell, columnPlacement, createColumnBoard } from "./column-presentation.js";
|
|
3
3
|
import { formatCellSeparator, formatRows } from "./row-layout.js";
|
|
4
|
-
export function
|
|
4
|
+
export function presentRelationChange(entry, source, target) {
|
|
5
|
+
return {
|
|
6
|
+
id: entry.id,
|
|
7
|
+
type: entry.relation_type,
|
|
8
|
+
source: source.key,
|
|
9
|
+
source_task_id: source.id,
|
|
10
|
+
target: target.key,
|
|
11
|
+
target_task_id: target.id,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function presentRelations(taskMatch, board = createColumnBoard()) {
|
|
5
15
|
return relation.getAll(taskMatch.key, { include: { tasks: true } }).map((entry) => {
|
|
6
16
|
const isSource = entry.source_task_id === taskMatch.id;
|
|
7
17
|
const other = isSource ? entry.target : entry.source;
|
|
@@ -12,6 +22,9 @@ export function presentRelations(taskMatch) {
|
|
|
12
22
|
if (entry.relation_type !== "related") {
|
|
13
23
|
direction = isSource ? "outgoing" : "incoming";
|
|
14
24
|
}
|
|
25
|
+
const projectColumns = board(other.project_id);
|
|
26
|
+
const columnMatch = projectColumns.find((boardColumn) => boardColumn.id === other.column_id);
|
|
27
|
+
const placement = columnPlacement(projectColumns, other.column_id);
|
|
15
28
|
return {
|
|
16
29
|
id: entry.id,
|
|
17
30
|
type: entry.relation_type,
|
|
@@ -20,46 +33,57 @@ export function presentRelations(taskMatch) {
|
|
|
20
33
|
id: other.id,
|
|
21
34
|
key: other.key,
|
|
22
35
|
project_id: other.project_id,
|
|
23
|
-
column:
|
|
36
|
+
column: columnMatch.name,
|
|
24
37
|
column_id: other.column_id,
|
|
38
|
+
is_first: placement.is_first,
|
|
39
|
+
is_last: placement.is_last,
|
|
25
40
|
title: other.title,
|
|
26
41
|
status: other.archived_at == null ? "Active" : "Archived",
|
|
27
42
|
},
|
|
28
43
|
};
|
|
29
44
|
});
|
|
30
45
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
46
|
+
function formatRelationLabel(entry) {
|
|
47
|
+
const isOutgoing = entry.direction === "outgoing";
|
|
48
|
+
let label = entry.type;
|
|
49
|
+
switch (entry.type) {
|
|
50
|
+
case "related": {
|
|
51
|
+
label = "Related to";
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "dependency": {
|
|
55
|
+
label = isOutgoing ? "Depends on" : "Depended on by";
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case "subtask": {
|
|
59
|
+
label = isOutgoing ? "Parent" : "Subtask";
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case "duplicate": {
|
|
63
|
+
label = isOutgoing ? "Duplicate of" : "Duplicated by";
|
|
64
|
+
break;
|
|
52
65
|
}
|
|
66
|
+
}
|
|
67
|
+
return label;
|
|
68
|
+
}
|
|
69
|
+
export function formatRelationList(relations, options = {}) {
|
|
70
|
+
return formatRows(relations.map((entry) => {
|
|
71
|
+
const label = formatRelationLabel(entry);
|
|
53
72
|
const archived = entry.task.status === "Archived" ? `${formatCellSeparator()}Archived` : "";
|
|
54
73
|
return [
|
|
55
74
|
{ text: label },
|
|
56
75
|
{ text: entry.task.key },
|
|
57
|
-
columnNameCell(entry.task.column),
|
|
76
|
+
columnNameCell(entry.task.column, entry.task),
|
|
58
77
|
{ text: `${entry.task.title}${archived}` },
|
|
78
|
+
...(options.trailingCell === undefined ? [] : [options.trailingCell(entry)]),
|
|
59
79
|
];
|
|
60
80
|
}));
|
|
61
81
|
}
|
|
62
82
|
export function formatRelationChange(change, options) {
|
|
83
|
+
if (options.action === "replace") {
|
|
84
|
+
const previous = options.replaced.map((entry) => formatRelationChange(entry, { action: "create" }));
|
|
85
|
+
return `Replace these relations:\n${previous.join("\n")}\nWith:\n${formatRelationChange(change, { action: "create" })}?`;
|
|
86
|
+
}
|
|
63
87
|
if (options.action === "delete") {
|
|
64
88
|
return `Deleted ${change.type} relation from ${change.source} to ${change.target}`;
|
|
65
89
|
}
|
|
@@ -10,7 +10,7 @@ export declare function formatCell(cell: RowCell, width?: number): string;
|
|
|
10
10
|
export declare function formatCellSeparator(): string;
|
|
11
11
|
/**
|
|
12
12
|
* Lines rows up by padding each cell's text to its column's **widest** text.
|
|
13
|
-
* Widths
|
|
13
|
+
* Widths count terminal cells, so wide text and emoji align with ASCII.
|
|
14
14
|
* A row's last cell holds free text such as a title and is left unpadded.
|
|
15
15
|
*
|
|
16
16
|
* With `indentsContinuationLines`, a last cell that spans several lines starts each later line
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { styleOutputText } from "./color.js";
|
|
2
|
+
import { displayWidth } from "./text-width.js";
|
|
2
3
|
const CELL_SEPARATOR = " | ";
|
|
3
4
|
const LINE_BREAK_PATTERN = /\r?\n/;
|
|
4
|
-
export function formatCell(cell, width = cell.text
|
|
5
|
-
const paddedText = cell.text.
|
|
5
|
+
export function formatCell(cell, width = displayWidth(cell.text)) {
|
|
6
|
+
const paddedText = `${cell.text}${" ".repeat(Math.max(0, width - displayWidth(cell.text)))}`;
|
|
6
7
|
if (cell.style == null) {
|
|
7
8
|
return paddedText;
|
|
8
9
|
}
|
|
@@ -19,7 +20,7 @@ function indentContinuationLines(text, indentWidth) {
|
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Lines rows up by padding each cell's text to its column's **widest** text.
|
|
22
|
-
* Widths
|
|
23
|
+
* Widths count terminal cells, so wide text and emoji align with ASCII.
|
|
23
24
|
* A row's last cell holds free text such as a title and is left unpadded.
|
|
24
25
|
*
|
|
25
26
|
* With `indentsContinuationLines`, a last cell that spans several lines starts each later line
|
|
@@ -30,7 +31,7 @@ export function formatRows(rows, options = {}) {
|
|
|
30
31
|
const columnWidths = [];
|
|
31
32
|
for (const row of rows) {
|
|
32
33
|
row.forEach((cell, columnIndex) => {
|
|
33
|
-
columnWidths[columnIndex] = Math.max(columnWidths[columnIndex] ?? 0, cell.text
|
|
34
|
+
columnWidths[columnIndex] = Math.max(columnWidths[columnIndex] ?? 0, displayWidth(cell.text));
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
return rows
|
|
@@ -38,7 +39,7 @@ export function formatRows(rows, options = {}) {
|
|
|
38
39
|
const lastCellIndex = row.length - 1;
|
|
39
40
|
const lastCellStartColumn = columnWidths
|
|
40
41
|
.slice(0, lastCellIndex)
|
|
41
|
-
.reduce((total, width) => total + width + CELL_SEPARATOR
|
|
42
|
+
.reduce((total, width) => total + width + displayWidth(CELL_SEPARATOR), 0);
|
|
42
43
|
return row
|
|
43
44
|
.map((cell, columnIndex) => {
|
|
44
45
|
if (columnIndex !== lastCellIndex) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PresentedRelation, PresentedTaskBlame } from "../result-schemas.js";
|
|
2
|
+
export declare function formatTaskBlame(blame: PresentedTaskBlame, options: {
|
|
3
|
+
relations: Array<PresentedRelation>;
|
|
4
|
+
columnPlacement: {
|
|
5
|
+
is_first: boolean;
|
|
6
|
+
is_last: boolean;
|
|
7
|
+
};
|
|
8
|
+
isArchived: boolean;
|
|
9
|
+
/** Short forms of activity IDs, which `activity view` accepts as well as full IDs. */
|
|
10
|
+
activityIdPrefixes: Map<string, string>;
|
|
11
|
+
}): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { formatActor } from "./activity-presentation.js";
|
|
2
|
+
import { columnNameCell } from "./column-presentation.js";
|
|
3
|
+
import { formatRelationList } from "./relation-presentation.js";
|
|
4
|
+
import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
|
|
5
|
+
import { formatSection } from "./section.js";
|
|
6
|
+
import { formatLabelNames, taskPriorityCell } from "./task-presentation.js";
|
|
7
|
+
import { formatLocalTime } from "./time.js";
|
|
8
|
+
export function formatTaskBlame(blame, options) {
|
|
9
|
+
const events = new Map();
|
|
10
|
+
function reference(attribution) {
|
|
11
|
+
if (attribution === null) {
|
|
12
|
+
return "unrecorded";
|
|
13
|
+
}
|
|
14
|
+
events.set(attribution.id, attribution);
|
|
15
|
+
return options.activityIdPrefixes.get(attribution.id) ?? attribution.id;
|
|
16
|
+
}
|
|
17
|
+
function field(name, value, attribution) {
|
|
18
|
+
return `${name}: ${value} [${reference(attribution)}]`;
|
|
19
|
+
}
|
|
20
|
+
const { fields } = blame;
|
|
21
|
+
const labelNames = fields.labels.value.map((label) => label.name);
|
|
22
|
+
const content = [
|
|
23
|
+
`${blame.task.key} (${blame.task.id})${options.isArchived ? `${formatCellSeparator()}Archived` : ""}`,
|
|
24
|
+
formatSection("Fields", [
|
|
25
|
+
field("Title", fields.title.value, fields.title.attribution),
|
|
26
|
+
field("Column", formatCell(columnNameCell(fields.column.value.name, options.columnPlacement)), fields.column.attribution),
|
|
27
|
+
field("Priority", formatCell(taskPriorityCell(fields.priority.value, true)), fields.priority.attribution),
|
|
28
|
+
field("Due", fields.due_at.value === null
|
|
29
|
+
? "none"
|
|
30
|
+
: formatLocalTime(fields.due_at.value, { includesSeconds: true }), fields.due_at.attribution),
|
|
31
|
+
field("Labels", labelNames.length === 0 ? "none" : formatLabelNames(labelNames), fields.labels.attribution),
|
|
32
|
+
field("Parent", fields.parent.value?.key ?? "none", fields.parent.attribution),
|
|
33
|
+
].join("\n")),
|
|
34
|
+
];
|
|
35
|
+
if (options.relations.length > 0) {
|
|
36
|
+
const relationAttributions = new Map(blame.relations.map((entry) => [entry.id, entry.attribution]));
|
|
37
|
+
content.push(formatSection("Relations", formatRelationList(options.relations, {
|
|
38
|
+
trailingCell: (entry) => ({
|
|
39
|
+
text: `[${reference(relationAttributions.get(entry.id) ?? null)}]`,
|
|
40
|
+
}),
|
|
41
|
+
})));
|
|
42
|
+
}
|
|
43
|
+
if (blame.description.length > 0) {
|
|
44
|
+
content.push(formatSection("Description", formatRows(blame.description.map((line) => [
|
|
45
|
+
{ text: String(line.line) },
|
|
46
|
+
{ text: `[${reference(line.attribution)}]` },
|
|
47
|
+
{ text: line.text },
|
|
48
|
+
]))));
|
|
49
|
+
}
|
|
50
|
+
if (events.size > 0) {
|
|
51
|
+
content.push(formatSection("Attribution", [...events.values()]
|
|
52
|
+
.map((event) => `${event.id}\n${formatLocalTime(event.created_at, { includesSeconds: true })}\n${formatActor(event)}`)
|
|
53
|
+
.join("\n\n")));
|
|
54
|
+
}
|
|
55
|
+
return content.join("\n\n");
|
|
56
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { TaskWithKey } from "@zinn-dev/core";
|
|
2
|
+
import type { RowCell } from "./row-layout.js";
|
|
2
3
|
import type { PresentedTask, PresentedTaskDetail } from "../result-schemas.js";
|
|
3
|
-
|
|
4
|
+
import type { ColumnBoard } from "./column-presentation.js";
|
|
5
|
+
export declare function taskPriorityCell(priority: PresentedTask["priority"], showsFullPriority: boolean): RowCell;
|
|
6
|
+
/** A task's label names on their own, colored as in a task row. */
|
|
7
|
+
export declare function formatLabelNames(labelNames: Array<string>): string;
|
|
8
|
+
export declare function presentTask(taskMatch: TaskWithKey, board?: ColumnBoard): PresentedTask;
|
|
4
9
|
export declare function formatTaskList(presentedTasks: Array<PresentedTask>, options?: {
|
|
5
10
|
showsStatus?: boolean;
|
|
6
11
|
showsFullPriority?: boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { columnNameCell } from "./column-presentation.js";
|
|
1
|
+
import { label, task } from "@zinn-dev/core";
|
|
2
|
+
import { columnNameCell, columnPlacement, createColumnBoard } from "./column-presentation.js";
|
|
3
3
|
import { labelNameCell } from "./label-presentation.js";
|
|
4
4
|
import { formatCell, formatCellSeparator, formatRows } from "./row-layout.js";
|
|
5
5
|
import { formatLocalTime } from "./time.js";
|
|
6
6
|
const EMPTY_CELL_MARKER = "-";
|
|
7
7
|
const LABEL_NAME_SEPARATOR = ", ";
|
|
8
|
-
function taskPriorityCell(priority, showsFullPriority) {
|
|
8
|
+
export function taskPriorityCell(priority, showsFullPriority) {
|
|
9
9
|
if (priority == null) {
|
|
10
10
|
return { text: EMPTY_CELL_MARKER, style: "dim" };
|
|
11
11
|
}
|
|
@@ -19,20 +19,37 @@ function taskPriorityCell(priority, showsFullPriority) {
|
|
|
19
19
|
function getLabelColorsByName() {
|
|
20
20
|
return new Map(label.getAll().map((labelMatch) => [labelMatch.name, labelMatch.color]));
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
function formatTaskLabelNames(labelNames, labelColorsByName) {
|
|
23
|
+
return labelNames
|
|
24
|
+
.map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
|
|
25
|
+
.join(LABEL_NAME_SEPARATOR);
|
|
26
|
+
}
|
|
27
|
+
/** A task's label names on their own, colored as in a task row. */
|
|
28
|
+
export function formatLabelNames(labelNames) {
|
|
29
|
+
return formatTaskLabelNames(labelNames, getLabelColorsByName());
|
|
30
|
+
}
|
|
31
|
+
export function presentTask(taskMatch, board = createColumnBoard()) {
|
|
23
32
|
const labels = task.label.getAll(taskMatch.key);
|
|
33
|
+
const projectColumns = board(taskMatch.project_id);
|
|
34
|
+
const columnMatch = projectColumns.find((boardColumn) => boardColumn.id === taskMatch.column_id);
|
|
35
|
+
const placement = columnPlacement(projectColumns, taskMatch.column_id);
|
|
24
36
|
return {
|
|
25
37
|
id: taskMatch.id,
|
|
26
38
|
key: taskMatch.key,
|
|
27
39
|
project_id: taskMatch.project_id,
|
|
28
40
|
status: taskMatch.archived_at == null ? "Active" : "Archived",
|
|
29
|
-
column:
|
|
41
|
+
column: columnMatch.name,
|
|
30
42
|
column_id: taskMatch.column_id,
|
|
43
|
+
is_first: placement.is_first,
|
|
44
|
+
is_last: placement.is_last,
|
|
31
45
|
title: taskMatch.title,
|
|
32
46
|
description: taskMatch.description,
|
|
33
47
|
priority: taskMatch.priority,
|
|
48
|
+
due_at: taskMatch.due_at ?? null,
|
|
34
49
|
labels: labels.map((label) => label.name),
|
|
35
50
|
label_ids: labels.map((label) => label.id),
|
|
51
|
+
created_at: taskMatch.created_at,
|
|
52
|
+
updated_at: taskMatch.updated_at,
|
|
36
53
|
};
|
|
37
54
|
}
|
|
38
55
|
export function formatTaskList(presentedTasks, options = {}) {
|
|
@@ -43,16 +60,17 @@ export function formatTaskList(presentedTasks, options = {}) {
|
|
|
43
60
|
: [];
|
|
44
61
|
const hasLabels = presentedTask.labels.length > 0;
|
|
45
62
|
// The last cell is never padded, so the color codes in its separator and label names do not affect column widths.
|
|
46
|
-
const labelNames = presentedTask.labels
|
|
47
|
-
.map((labelName) => formatCell(labelNameCell(labelName, labelColorsByName.get(labelName))))
|
|
48
|
-
.join(LABEL_NAME_SEPARATOR);
|
|
63
|
+
const labelNames = formatTaskLabelNames(presentedTask.labels, labelColorsByName);
|
|
49
64
|
const labels = hasLabels ? `${formatCellSeparator()}${labelNames}` : "";
|
|
65
|
+
const deadline = presentedTask.due_at == null
|
|
66
|
+
? ""
|
|
67
|
+
: `${formatCellSeparator()}Due ${formatLocalTime(presentedTask.due_at, { includesSeconds: true })}`;
|
|
50
68
|
return [
|
|
51
69
|
{ text: `${options.prefix ?? ""}${presentedTask.key}` },
|
|
52
70
|
...statusCells,
|
|
53
|
-
columnNameCell(presentedTask.column),
|
|
71
|
+
columnNameCell(presentedTask.column, presentedTask),
|
|
54
72
|
taskPriorityCell(presentedTask.priority, options.showsFullPriority ?? false),
|
|
55
|
-
{ text: `${presentedTask.title}${labels}` },
|
|
73
|
+
{ text: `${presentedTask.title}${deadline}${labels}` },
|
|
56
74
|
];
|
|
57
75
|
}));
|
|
58
76
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const PRINTABLE_ASCII = /^[\x20-\x7e]*$/;
|
|
2
|
+
const ZERO_WIDTH_CODE_POINT = /^[\p{Mark}\p{Default_Ignorable_Code_Point}\p{Cc}]$/u;
|
|
3
|
+
// The constructor permits Unicode-set matching with the ES2023 declaration target.
|
|
4
|
+
const RGI_EMOJI = new RegExp("^\\p{RGI_Emoji}$", "v");
|
|
5
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
6
|
+
export function graphemes(text) {
|
|
7
|
+
return segmenter.segment(text);
|
|
8
|
+
}
|
|
9
|
+
function isWideEastAsian(codePoint) {
|
|
10
|
+
// Unicode EastAsianWidth.txt lists the Hangul, CJK, kana, Yi and fullwidth blocks below.
|
|
11
|
+
// https://www.unicode.org/Public/18.0.0/ucd/EastAsianWidth.txt
|
|
12
|
+
return ((codePoint >= 0x1100 && codePoint <= 0x115f) ||
|
|
13
|
+
codePoint === 0x2329 ||
|
|
14
|
+
codePoint === 0x232a ||
|
|
15
|
+
(codePoint >= 0x2e80 && codePoint <= 0xa4cf) ||
|
|
16
|
+
(codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
|
|
17
|
+
(codePoint >= 0xf900 && codePoint <= 0xfaff) ||
|
|
18
|
+
(codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
|
|
19
|
+
(codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
|
|
20
|
+
(codePoint >= 0xff01 && codePoint <= 0xff60) ||
|
|
21
|
+
(codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
|
|
22
|
+
(codePoint >= 0x1aff0 && codePoint <= 0x1afff) ||
|
|
23
|
+
(codePoint >= 0x1b000 && codePoint <= 0x1b2ff) ||
|
|
24
|
+
(codePoint >= 0x20000 && codePoint <= 0x3fffd));
|
|
25
|
+
}
|
|
26
|
+
export function displayWidth(text) {
|
|
27
|
+
if (PRINTABLE_ASCII.test(text)) {
|
|
28
|
+
return text.length;
|
|
29
|
+
}
|
|
30
|
+
let width = 0;
|
|
31
|
+
for (const { segment } of graphemes(text)) {
|
|
32
|
+
if ([...segment].every((point) => ZERO_WIDTH_CODE_POINT.test(point))) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (RGI_EMOJI.test(segment) || isWideEastAsian(segment.codePointAt(0))) {
|
|
36
|
+
width += 2;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
width += 1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return width;
|
|
43
|
+
}
|
package/src/presentation/time.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const MINUTES_PER_HOUR = 60;
|
|
2
|
-
export function formatLocalTime(timestamp) {
|
|
2
|
+
export function formatLocalTime(timestamp, options = {}) {
|
|
3
3
|
const date = new Date(timestamp);
|
|
4
4
|
const offsetMinutes = -date.getTimezoneOffset();
|
|
5
5
|
const offsetSign = offsetMinutes >= 0 ? "+" : "-";
|
|
@@ -7,7 +7,10 @@ export function formatLocalTime(timestamp) {
|
|
|
7
7
|
const offsetHours = Math.floor(absoluteOffsetMinutes / MINUTES_PER_HOUR);
|
|
8
8
|
const remainingOffsetMinutes = absoluteOffsetMinutes % MINUTES_PER_HOUR;
|
|
9
9
|
const pad = (value) => String(value).padStart(2, "0");
|
|
10
|
+
const milliseconds = date.getMilliseconds();
|
|
11
|
+
const fraction = milliseconds === 0 ? "" : `.${String(milliseconds).padStart(3, "0")}`;
|
|
12
|
+
const seconds = options.includesSeconds ? `:${pad(date.getSeconds())}${fraction}` : "";
|
|
10
13
|
return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
|
11
|
-
`${pad(date.getHours())}:${pad(date.getMinutes())} ` +
|
|
14
|
+
`${pad(date.getHours())}:${pad(date.getMinutes())}${seconds} ` +
|
|
12
15
|
`${offsetSign}${pad(offsetHours)}:${pad(remainingOffsetMinutes)}`);
|
|
13
16
|
}
|