add more console commands; support shift-tab to navigate backwards
This commit is contained in:
parent
3b039c177b
commit
60e50e902f
2 changed files with 33 additions and 26 deletions
|
@ -26,9 +26,13 @@ export default class AutocompleteLine extends LineEdit {
|
||||||
}
|
}
|
||||||
|
|
||||||
_input(event: InputEvent): void {
|
_input(event: InputEvent): void {
|
||||||
if (this.has_focus() && this.suppress_focus_change && event.is_action_pressed(Action.FocusNext)) {
|
if (this.has_focus() && this.suppress_focus_change)
|
||||||
|
if (event.is_action_pressed(Action.FocusPrevious)) {
|
||||||
this.accept_event()
|
this.accept_event()
|
||||||
this.autocomplete()
|
this.autocomplete(-1)
|
||||||
|
} else if (event.is_action_pressed(Action.FocusNext)) {
|
||||||
|
this.accept_event()
|
||||||
|
this.autocomplete(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +64,9 @@ export default class AutocompleteLine extends LineEdit {
|
||||||
this.caret_column = this.text.length + 1
|
this.caret_column = this.text.length + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
autocomplete() {
|
autocomplete(direction: (-1 | 1)) {
|
||||||
if (this.current_suggestions.length > 0) {
|
if (this.current_suggestions.length > 0) {
|
||||||
this.suggestion_index = (this.suggestion_index + 1) % this.current_suggestions.length
|
this.suggestion_index = (this.suggestion_index + direction) % this.current_suggestions.length
|
||||||
this.text = this.current_suggestions.at(this.suggestion_index) || ''
|
this.text = this.current_suggestions.at(this.suggestion_index) || ''
|
||||||
this.suggestion.clear()
|
this.suggestion.clear()
|
||||||
this.set_caret_to_end()
|
this.set_caret_to_end()
|
||||||
|
|
|
@ -11,11 +11,10 @@ export const Action = {
|
||||||
Down: 'ui_down',
|
Down: 'ui_down',
|
||||||
TextComplete: 'ui_text_completion_replace',
|
TextComplete: 'ui_text_completion_replace',
|
||||||
FocusNext: 'ui_focus_next',
|
FocusNext: 'ui_focus_next',
|
||||||
FocusPrevious: 'ui_focus_prev',
|
FocusPrevious: 'ui_focus_prev'
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export default class DevConsole extends CanvasLayer {
|
export default class DevConsole extends CanvasLayer {
|
||||||
|
|
||||||
@onready("Container/VBoxContainer/Output")
|
@onready("Container/VBoxContainer/Output")
|
||||||
private output!: RichTextLabel
|
private output!: RichTextLabel
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ export default class DevConsole extends CanvasLayer {
|
||||||
this.input.autocomplete_list = method_names.toArray()
|
this.input.autocomplete_list = method_names.toArray()
|
||||||
this.parse_callable = Callable.create(
|
this.parse_callable = Callable.create(
|
||||||
this,
|
this,
|
||||||
this.submit_command
|
this._submit_command
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +85,6 @@ export default class DevConsole extends CanvasLayer {
|
||||||
this.input.set_caret_to_end()
|
this.input.set_caret_to_end()
|
||||||
}
|
}
|
||||||
|
|
||||||
_autocomplete() {
|
|
||||||
this.input.autocomplete()
|
|
||||||
}
|
|
||||||
|
|
||||||
async _show() {
|
async _show() {
|
||||||
await this.get_tree().process_frame.as_promise()
|
await this.get_tree().process_frame.as_promise()
|
||||||
|
|
||||||
|
@ -114,44 +109,52 @@ export default class DevConsole extends CanvasLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print(value: string) {
|
_print(value: string) {
|
||||||
this.output.append_text(value)
|
this.output.append_text(value)
|
||||||
this.output.append_text('\n')
|
this.output.append_text('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_in_tag(text: string, tag: [string, string]): string {
|
_wrap_in_tag(text: string, tag: [string, string]): string {
|
||||||
return `[${tag[0]}=${tag[1]}]${text}[/${tag[0]}]`
|
return `[${tag[0]}=${tag[1]}]${text}[/${tag[0]}]`
|
||||||
}
|
}
|
||||||
|
|
||||||
format(text: string, tags: Record<string, string>): string {
|
_format(text: string, tags: Record<string, string>): string {
|
||||||
return Object.entries(tags).reduce(this.wrap_in_tag, text)
|
return Object.entries(tags).reduce(this._wrap_in_tag, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
print_error(error: string) {
|
_print_error(error: string) {
|
||||||
this.print(this.format(error, { color: 'red' }))
|
this._print(this._format(error, { color: 'red' }))
|
||||||
}
|
}
|
||||||
|
|
||||||
echo(command: string) {
|
_echo(command: string) {
|
||||||
this.print(this.format(`> ${command}`, { color: 'white' }))
|
this._print(this._format(`> ${command}`, { color: 'white' }))
|
||||||
}
|
}
|
||||||
|
|
||||||
submit_command(command: string) {
|
_submit_command(command: string) {
|
||||||
this.input.clear()
|
this.input.clear()
|
||||||
this.history.push(command)
|
this.history.push(command)
|
||||||
this.echo(command)
|
this._echo(command)
|
||||||
const error = this.expression.parse(command)
|
const error = this.expression.parse(command)
|
||||||
|
|
||||||
if (error !== GError.OK) {
|
if (error !== GError.OK) {
|
||||||
this.print_error(this.expression.get_error_text())
|
this._print_error(this.expression.get_error_text())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = this.expression.execute(new GArray(), this)
|
const result = this.expression.execute(new GArray(), this)
|
||||||
|
|
||||||
if (this.expression.has_execute_failed()) {
|
if (this.expression.has_execute_failed()) {
|
||||||
this.print_error(this.expression.get_error_text())
|
this._print_error(this.expression.get_error_text())
|
||||||
} else {
|
} else {
|
||||||
this.print(result.toString())
|
this._print(result.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this.output.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
echo(...args: any) {
|
||||||
|
this._print(args.map((arg: any) => arg.toString()).join(' '))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue