coneko-term 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/animation.d.ts +18 -0
- package/dist/animation.js +72 -0
- package/dist/images.d.ts +116 -0
- package/dist/images.js +359 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +21 -0
- package/dist/input.d.ts +130 -0
- package/dist/input.js +313 -0
- package/dist/keyboard.d.ts +46 -0
- package/dist/keyboard.js +278 -0
- package/dist/kitty-keyboard.d.ts +55 -0
- package/dist/kitty-keyboard.js +332 -0
- package/dist/memory.d.ts +4 -0
- package/dist/memory.js +12 -0
- package/dist/renderer.d.ts +261 -0
- package/dist/renderer.js +870 -0
- package/dist/selection.d.ts +67 -0
- package/dist/selection.js +146 -0
- package/dist/terminal.d.ts +1006 -0
- package/dist/terminal.js +2020 -0
- package/dist/wasm/coneko_term_wasm.d.ts +728 -0
- package/dist/wasm/coneko_term_wasm.js +1776 -0
- package/dist/wasm/coneko_term_wasm_bg.wasm +0 -0
- package/dist/wasm/coneko_term_wasm_bg.wasm.d.ts +140 -0
- package/package.json +33 -4
- package/README.md +0 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** 行の並び(0 がスクロールバックの一番古い行。代替画面では画面の 0 行目)の中の位置。 */
|
|
2
|
+
export interface BufferPosition {
|
|
3
|
+
/** 行。 */
|
|
4
|
+
row: number;
|
|
5
|
+
/** 列(0 始まり)。 */
|
|
6
|
+
col: number;
|
|
7
|
+
}
|
|
8
|
+
/** 選択の範囲。`end` は含まない。 */
|
|
9
|
+
export interface SelectionRange {
|
|
10
|
+
start: BufferPosition;
|
|
11
|
+
end: BufferPosition;
|
|
12
|
+
}
|
|
13
|
+
/** 選択が、画面の中身を読むために使うもの。`Terminal` が渡す。 */
|
|
14
|
+
export interface SelectionHost {
|
|
15
|
+
/** 列の数。 */
|
|
16
|
+
readonly cols: number;
|
|
17
|
+
/** 行の数(スクロールバック + 画面)。 */
|
|
18
|
+
totalRows(): number;
|
|
19
|
+
/** スクロールバックの上から捨てた行の数の合計。 */
|
|
20
|
+
trimmed(): number;
|
|
21
|
+
/** `[開始の行, 開始の列, 終わりの行, 終わりの列]`(終わりは含まない)。 */
|
|
22
|
+
wordRange(row: number, col: number): number[];
|
|
23
|
+
/** 折り返しでつながった行全体。並びは `wordRange` と同じ。 */
|
|
24
|
+
lineRange(row: number): number[];
|
|
25
|
+
}
|
|
26
|
+
/** 選択のしかた。 */
|
|
27
|
+
export type SelectionKind = "cell" | "word" | "line";
|
|
28
|
+
/**
|
|
29
|
+
* 選択の状態。ドラッグで範囲、ダブルクリックで単語、トリプルクリックで行を選ぶ。
|
|
30
|
+
*
|
|
31
|
+
* 位置は、スクロールバックから行が捨てられても同じ行を指すように、`trimmed()` を足した
|
|
32
|
+
* 通し番号の行で覚える。範囲を返すときに、いまの行の番号に直す。
|
|
33
|
+
*/
|
|
34
|
+
export declare class SelectionModel {
|
|
35
|
+
private host;
|
|
36
|
+
private kind;
|
|
37
|
+
/** 最初に押した場所。単語・行のときは、その単語・行の `[a, b)`。 */
|
|
38
|
+
private a?;
|
|
39
|
+
private b?;
|
|
40
|
+
/** ドラッグしている場所。単語・行のときは、その場所の単語・行の `[ca, cb)`。 */
|
|
41
|
+
private cur?;
|
|
42
|
+
private curEnd?;
|
|
43
|
+
constructor(host: SelectionHost);
|
|
44
|
+
private stable;
|
|
45
|
+
private current;
|
|
46
|
+
private unit;
|
|
47
|
+
/** 押した場所から選び始める。`kind` が `word` か `line` なら、その単語・行をすぐ選ぶ。 */
|
|
48
|
+
start(kind: SelectionKind, at: BufferPosition): void;
|
|
49
|
+
/** ドラッグして `at` まで広げる(広げ始めていなければ何もしない)。 */
|
|
50
|
+
extend(at: BufferPosition): void;
|
|
51
|
+
/**
|
|
52
|
+
* Shift を押してクリックしたとき、いまの選択を `at` まで広げる。選択が無ければ、`at` から
|
|
53
|
+
* 選び始める。
|
|
54
|
+
*/
|
|
55
|
+
extendSelection(at: BufferPosition): void;
|
|
56
|
+
/** 全部を選ぶ。 */
|
|
57
|
+
selectAll(): void;
|
|
58
|
+
/** 選択を消す。 */
|
|
59
|
+
clear(): void;
|
|
60
|
+
/** 選択が空でないか。 */
|
|
61
|
+
get active(): boolean;
|
|
62
|
+
private clamp;
|
|
63
|
+
/**
|
|
64
|
+
* いまの範囲(`end` は含まない)。空のとき(まだ動かしていない、捨てられた行だけ)は `undefined`。
|
|
65
|
+
*/
|
|
66
|
+
range(): SelectionRange | undefined;
|
|
67
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
function cmp(a, b) {
|
|
2
|
+
return a.row - b.row || a.col - b.col;
|
|
3
|
+
}
|
|
4
|
+
function pos(row, col) {
|
|
5
|
+
return { row, col };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 選択の状態。ドラッグで範囲、ダブルクリックで単語、トリプルクリックで行を選ぶ。
|
|
9
|
+
*
|
|
10
|
+
* 位置は、スクロールバックから行が捨てられても同じ行を指すように、`trimmed()` を足した
|
|
11
|
+
* 通し番号の行で覚える。範囲を返すときに、いまの行の番号に直す。
|
|
12
|
+
*/
|
|
13
|
+
export class SelectionModel {
|
|
14
|
+
host;
|
|
15
|
+
kind = "cell";
|
|
16
|
+
/** 最初に押した場所。単語・行のときは、その単語・行の `[a, b)`。 */
|
|
17
|
+
a;
|
|
18
|
+
b;
|
|
19
|
+
/** ドラッグしている場所。単語・行のときは、その場所の単語・行の `[ca, cb)`。 */
|
|
20
|
+
cur;
|
|
21
|
+
curEnd;
|
|
22
|
+
constructor(host) {
|
|
23
|
+
this.host = host;
|
|
24
|
+
}
|
|
25
|
+
stable(p) {
|
|
26
|
+
return pos(p.row + this.host.trimmed(), p.col);
|
|
27
|
+
}
|
|
28
|
+
current(p) {
|
|
29
|
+
return pos(p.row - this.host.trimmed(), p.col);
|
|
30
|
+
}
|
|
31
|
+
unit(kind, p) {
|
|
32
|
+
const [r0, c0, r1, c1] = kind === "word"
|
|
33
|
+
? this.host.wordRange(p.row, p.col)
|
|
34
|
+
: this.host.lineRange(p.row);
|
|
35
|
+
return [pos(r0, c0), pos(r1, c1)];
|
|
36
|
+
}
|
|
37
|
+
/** 押した場所から選び始める。`kind` が `word` か `line` なら、その単語・行をすぐ選ぶ。 */
|
|
38
|
+
start(kind, at) {
|
|
39
|
+
const p = this.clamp(at);
|
|
40
|
+
this.kind = kind;
|
|
41
|
+
if (kind === "cell") {
|
|
42
|
+
this.a = this.stable(p);
|
|
43
|
+
this.b = undefined;
|
|
44
|
+
this.cur = this.a;
|
|
45
|
+
this.curEnd = undefined;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const [s, e] = this.unit(kind, p);
|
|
49
|
+
this.a = this.stable(s);
|
|
50
|
+
this.b = this.stable(e);
|
|
51
|
+
this.cur = this.a;
|
|
52
|
+
this.curEnd = this.b;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** ドラッグして `at` まで広げる(広げ始めていなければ何もしない)。 */
|
|
56
|
+
extend(at) {
|
|
57
|
+
if (!this.a)
|
|
58
|
+
return;
|
|
59
|
+
const p = this.clamp(at);
|
|
60
|
+
if (this.kind === "cell") {
|
|
61
|
+
this.cur = this.stable(p);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const [s, e] = this.unit(this.kind, p);
|
|
65
|
+
this.cur = this.stable(s);
|
|
66
|
+
this.curEnd = this.stable(e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Shift を押してクリックしたとき、いまの選択を `at` まで広げる。選択が無ければ、`at` から
|
|
71
|
+
* 選び始める。
|
|
72
|
+
*/
|
|
73
|
+
extendSelection(at) {
|
|
74
|
+
const r = this.range();
|
|
75
|
+
if (!r) {
|
|
76
|
+
this.start("cell", at);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const p = this.clamp(at);
|
|
80
|
+
this.kind = "cell";
|
|
81
|
+
this.b = undefined;
|
|
82
|
+
this.curEnd = undefined;
|
|
83
|
+
// 動かさない側を、最初に押した場所にする
|
|
84
|
+
const last = pos(r.end.row, r.end.col - 1);
|
|
85
|
+
const anchor = cmp(p, r.start) < 0 ? last : r.start;
|
|
86
|
+
this.a = this.stable(anchor);
|
|
87
|
+
this.cur = this.stable(p);
|
|
88
|
+
}
|
|
89
|
+
/** 全部を選ぶ。 */
|
|
90
|
+
selectAll() {
|
|
91
|
+
const total = this.host.totalRows();
|
|
92
|
+
if (total === 0)
|
|
93
|
+
return;
|
|
94
|
+
this.kind = "cell";
|
|
95
|
+
this.a = this.stable(pos(0, 0));
|
|
96
|
+
this.b = undefined;
|
|
97
|
+
this.cur = this.stable(pos(total - 1, this.host.cols - 1));
|
|
98
|
+
this.curEnd = undefined;
|
|
99
|
+
}
|
|
100
|
+
/** 選択を消す。 */
|
|
101
|
+
clear() {
|
|
102
|
+
this.a = this.b = this.cur = this.curEnd = undefined;
|
|
103
|
+
}
|
|
104
|
+
/** 選択が空でないか。 */
|
|
105
|
+
get active() {
|
|
106
|
+
return this.range() !== undefined;
|
|
107
|
+
}
|
|
108
|
+
clamp(p) {
|
|
109
|
+
const rows = Math.max(1, this.host.totalRows());
|
|
110
|
+
return pos(Math.max(0, Math.min(rows - 1, Math.trunc(p.row))), Math.max(0, Math.min(this.host.cols - 1, Math.trunc(p.col))));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* いまの範囲(`end` は含まない)。空のとき(まだ動かしていない、捨てられた行だけ)は `undefined`。
|
|
114
|
+
*/
|
|
115
|
+
range() {
|
|
116
|
+
if (!this.a || !this.cur)
|
|
117
|
+
return undefined;
|
|
118
|
+
let start;
|
|
119
|
+
let end;
|
|
120
|
+
if (this.kind === "cell") {
|
|
121
|
+
const a = this.current(this.a);
|
|
122
|
+
const c = this.current(this.cur);
|
|
123
|
+
if (cmp(a, c) === 0)
|
|
124
|
+
return undefined;
|
|
125
|
+
const [lo, hi] = cmp(a, c) < 0 ? [a, c] : [c, a];
|
|
126
|
+
start = lo;
|
|
127
|
+
end = pos(hi.row, hi.col + 1);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const a = this.current(this.a);
|
|
131
|
+
const b = this.current(this.b ?? this.a);
|
|
132
|
+
const ca = this.current(this.cur);
|
|
133
|
+
const cb = this.current(this.curEnd ?? this.cur);
|
|
134
|
+
start = cmp(a, ca) <= 0 ? a : ca;
|
|
135
|
+
end = cmp(b, cb) >= 0 ? b : cb;
|
|
136
|
+
}
|
|
137
|
+
// 捨てられた行にかかった分は切る
|
|
138
|
+
if (end.row < 0)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (start.row < 0)
|
|
141
|
+
start = pos(0, 0);
|
|
142
|
+
if (cmp(start, end) >= 0)
|
|
143
|
+
return undefined;
|
|
144
|
+
return { start, end };
|
|
145
|
+
}
|
|
146
|
+
}
|