2024-02-05 04:13:02 +08:00
|
|
|
import {el, scrollIntoViewIfNeeded, value_to_dom_el, join} from './domutils.js'
|
2022-10-17 02:49:21 +08:00
|
|
|
import {exec} from '../index.js'
|
2023-07-31 23:17:48 +03:00
|
|
|
import {header} from '../value_explorer_utils.js'
|
2024-01-01 18:33:46 +08:00
|
|
|
import {with_version_number_of_log} from '../cmd.js'
|
2022-10-17 02:49:21 +08:00
|
|
|
|
|
|
|
|
export class Logs {
|
|
|
|
|
constructor(ui, el) {
|
|
|
|
|
this.el = el
|
|
|
|
|
this.ui = ui
|
|
|
|
|
this.el.addEventListener('keydown', (e) => {
|
|
|
|
|
|
2022-10-25 04:43:35 +08:00
|
|
|
if(e.key == 'Escape') {
|
|
|
|
|
this.ui.editor.focus()
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 02:49:21 +08:00
|
|
|
if(e.key == 'Enter') {
|
|
|
|
|
// TODO reselect call node that was selected previously by calling
|
|
|
|
|
// 'calltree.navigate_logs_position'
|
|
|
|
|
this.ui.editor.focus()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(e.key == 'F1') {
|
|
|
|
|
this.ui.editor.focus_value_explorer(this.el)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(e.key == 'F3') {
|
|
|
|
|
this.ui.editor.focus()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(e.key == 'ArrowDown' || e.key == 'j'){
|
2024-03-07 09:29:20 +08:00
|
|
|
// prevent scroll
|
|
|
|
|
e.preventDefault()
|
2022-10-17 02:49:21 +08:00
|
|
|
exec('calltree.navigate_logs_increment', 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(e.key == 'ArrowUp' || e.key == 'k'){
|
2024-03-07 09:29:20 +08:00
|
|
|
// prevent scroll
|
|
|
|
|
e.preventDefault()
|
2022-10-17 02:49:21 +08:00
|
|
|
exec('calltree.navigate_logs_increment', -1)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-01 18:33:46 +08:00
|
|
|
rerender_logs(state, logs) {
|
2022-11-29 05:43:34 +08:00
|
|
|
this.el.innerHTML = ''
|
2024-01-01 18:33:46 +08:00
|
|
|
this.render_logs(state, null, logs)
|
2022-11-29 05:43:34 +08:00
|
|
|
}
|
2022-10-17 02:49:21 +08:00
|
|
|
|
2024-01-01 18:33:46 +08:00
|
|
|
render_logs(state, prev_logs, logs) {
|
2022-11-29 05:43:34 +08:00
|
|
|
for(
|
|
|
|
|
let i = prev_logs == null ? 0 : prev_logs.logs.length ;
|
|
|
|
|
i < logs.logs.length;
|
|
|
|
|
i++
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
const log = logs.logs[i]
|
|
|
|
|
this.el.appendChild(
|
|
|
|
|
el('div',
|
|
|
|
|
'log call_header '
|
|
|
|
|
+ (log.log_fn_name == 'error' ? 'error' : '')
|
|
|
|
|
// Currently console.log calls from native fns (like Array::map)
|
|
|
|
|
// are not recorded, so next line is dead code
|
|
|
|
|
+ (log.module == null ? ' native' : '')
|
|
|
|
|
,
|
|
|
|
|
el('a', {
|
|
|
|
|
href: 'javascript: void(0)',
|
|
|
|
|
click: () => exec('calltree.navigate_logs_position', i),
|
|
|
|
|
},
|
|
|
|
|
(log.module == '' ? '*scratch*' : log.module)
|
|
|
|
|
+ ': '
|
|
|
|
|
+ (
|
|
|
|
|
log.toplevel
|
|
|
|
|
? 'toplevel'
|
|
|
|
|
: 'fn ' + (log.parent_name == '' ? 'anonymous' : log.parent_name)
|
|
|
|
|
)
|
|
|
|
|
+ ':'
|
|
|
|
|
),
|
|
|
|
|
' ',
|
2024-02-05 04:13:02 +08:00
|
|
|
...join(with_version_number_of_log(state, log, () =>
|
|
|
|
|
log.args.map(a => value_to_dom_el(a))
|
|
|
|
|
))
|
2022-10-17 02:49:21 +08:00
|
|
|
)
|
2022-11-29 05:43:34 +08:00
|
|
|
)
|
2022-10-17 02:49:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(prev_logs?.log_position != logs.log_position) {
|
2022-10-17 16:07:38 +08:00
|
|
|
if(prev_logs?.logs == logs.logs && prev_logs?.log_position != null) {
|
2022-10-17 02:49:21 +08:00
|
|
|
this.el.children[prev_logs.log_position].classList.remove('active')
|
|
|
|
|
}
|
|
|
|
|
if(logs.log_position != null) {
|
|
|
|
|
const active_child = this.el.children[logs.log_position]
|
|
|
|
|
active_child.classList.add('active')
|
|
|
|
|
scrollIntoViewIfNeeded(this.el, active_child)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|