-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-common.js
More file actions
116 lines (89 loc) · 3.19 KB
/
ui-common.js
File metadata and controls
116 lines (89 loc) · 3.19 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
String.prototype.html = function () {
const escape = [
['>', '>'],
['<', '<'],
]
var html = this
escape.forEach(item => {
while (html.includes(item[0])) {
html = html.replace(item[0], item[1])
}
})
return html
}
String.prototype.insert = function(index, string) {
if (index == 0) {
return string + this
} else {
return this.substring(0, index) + string + this.substring(index, this.length)
}
}
function number_text(text, syntax_coloring, number_empty) {
text = text.replace(/;/g, '\x1e').html()
const lines = text.split('\n')
const pad_len = ('' + lines.length).length
var s = ''
var op_regex = new RegExp(`\\b(${__op_regex})\\b`, 'gi')
var pop_regex = new RegExp(`\\b(${__pop_regex})\\b`, 'gi')
var line_number = 0
for (var i = 0; i < lines.length; i++) {
var line = lines[i]
var line_display = '|'
if (number_empty !== false) {
line_display = i + 1
} else {
if (line.length != 0) {
line_display = line_number + 1
line_number++
}
}
n = (line_display + '').padStart(pad_len)
if (syntax_coloring) {
line = line.replace(/-?\b\d+/g, '<span class="number">$&</span>')
line = line.replace(op_regex, '<span class="opcode">$&</span>')
line = line.replace(pop_regex, '<span class="keyword">$&</span>')
line = line.replace(/\B(@|#|\$|\*|>|<|{|})/g, '<span class="address_mode">$&</span>')
}
if (line.includes('\x1e')) {
const idx = line.indexOf('\x1e')
if (syntax_coloring) {
const pre = line.substring(0, idx)
const post = line.substring(idx).replace(/<(?:.|\n)*?>/gm, '')
line = `${pre}<span class='comment'>${post}</span>`
}
line = line.replace(/\x1e/g, ';')
}
if (i % 10 == 9) {
s += `<u>${n}</u> ${line}<br>`
} else {
s += `<span class='num'>${n}</span> ${line}<br>`
}
}
return s
}
function number_assembly(text, syntax_coloring) {
const lines = text.split('\n')
const pad_len = ('' + lines.length).length
var s = ''
for (var i = 0; i < lines.length; i++) {
var line = lines[i]
n = (1 + i + '').padStart(pad_len)
if (syntax_coloring) {
num_length = ~~(line.length - 3) / 2
op = line.substring(0, 1)
ma = line.substring(1, 2)
va = line.substring(2, 2 + num_length)
mb = line.substring(2 + num_length, 3 + num_length)
vb = line.substring(3 + num_length, 3 + 2 * num_length)
line = `<span class='opcode'>${op}</span>` +
`<span class='address_mode'>${ma}</span><span class='number'>${va}</span>` +
`<span class='address_mode'>${mb}</span><span class='number'>${vb}</span>`
}
if (i % 10 == 9) {
s += `<u>${n}</u> ${line}<br>`
} else {
s += `<span class='num'>${n}</span> ${line}<br>`
}
}
return s
}