Repository navigation
Expand file tree
/
Copy pathBox.ts
More file actions
116 lines (107 loc) · 2.47 KB
/
Copy pathBox.ts
File metadata and controls
116 lines (107 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { SelectionInterface } from './SelectionInterface'
export class Box {
private option: number = 0
constructor(
private readonly width: number,
private readonly height: number,
private readonly top: number,
private readonly start: number,
private options: any,
private readonly index: number,
private readonly main: any,
private readonly callback: any,
) {
if (!this.options) this.genOpt()
}
generateOpt(opt: any) {
const a = this.top + this.height
let o: any[] = []
let k: any[] = []
let id = 0
opt.forEach((optt: any) => {
o.push({
opt: optt.opt,
onSelect: optt.onSelect,
})
k.push(
SelectionInterface(
' ',
id,
{
start: this.start,
opt: optt.opt,
width: this.width,
},
this.main,
),
)
id++
})
this.main.layers[this.index][a] = {
len: this.width,
width: this.width,
defaultBG: '\x1b[0m\x1b[47m\x1b[30m',
start: this.start,
selectonly: true,
options: k,
}
this.options = []
this.options = o
}
onKey(key: any) {
if (key === '\u001B\u005B\u0041') {
if (this.option > 0) {
this.option--
this.main.update()
}
}
if (key === '\u001B\u005B\u0042') {
if (this.option < this.options.length - 1) {
this.option++
this.main.update()
}
}
if (key === '\u000D') {
this.runOpt(this.option)
}
}
runOpt(opt: any) {
if (!this.options[opt] || !this.options[opt].onSelect) return
const b = this.options[opt].onSelect(this)
if (b === 'remove') return this.remove()
}
remove() {
this.main.removeBox(this.index)
if (this.callback) this.callback()
}
genOpt() {
const a = this.top + this.height
this.main.layers[this.index][a] = {
len: this.width,
width: this.width,
defaultBG: '\x1b[0m\x1b[47m\x1b[30m',
start: this.start,
selectonly: true,
options: [
SelectionInterface(
this.main.centerHor('[Close]', this.width),
0,
{
start: this.start,
opt: '[Close]',
width: this.width,
},
this.main,
),
],
}
this.options = []
this.options[0] = {
text: this.main.centerHor('[Close]', this.width),
opt: '[Close]',
onSelect: () => {
return 'remove'
},
}
}
}