Console
* Add STDIO and STDERR support. * Add toggle to hide STDOUT entries altogether. * Improved styling.
This commit is contained in:
parent
555fe97833
commit
5d80a963ae
@ -7,11 +7,12 @@ init 1702 python in _console:
|
||||
class ConsoleHistoryEntry(object):
|
||||
lines = 0
|
||||
|
||||
def __init__(self, command, result=None, is_error=False):
|
||||
def __init__(self, command, result=None, is_error=False, is_stdio=False):
|
||||
self.command = command
|
||||
self.result = result
|
||||
self.is_error = is_error
|
||||
self.timestamp = datetime.datetime.now().timestamp()
|
||||
self.is_stdio = is_stdio
|
||||
|
||||
def update_lines(self):
|
||||
|
||||
@ -136,6 +137,21 @@ init 1702 python in _console:
|
||||
|
||||
stdio_lines[:] = _list()
|
||||
|
||||
def stdout_line(self, l):
|
||||
if not (config.console or config.developer):
|
||||
return
|
||||
|
||||
he = ConsoleHistoryEntry(l, is_stdio=True)
|
||||
he.update_lines()
|
||||
self.history.append(he)
|
||||
|
||||
def stderr_line(self, l):
|
||||
if not (config.console or config.developer):
|
||||
return
|
||||
|
||||
he = ConsoleHistoryEntry(l, is_error=True, is_stdio=True)
|
||||
he.update_lines()
|
||||
|
||||
def can_renpy(self):
|
||||
"""
|
||||
Returns true if we can run Ren'Py code.
|
||||
@ -287,6 +303,8 @@ init 1702 python in _console:
|
||||
raise Exception("Matching labels:\n %s" % matching)
|
||||
|
||||
renpy.config.at_exit_callbacks.append(console.backup)
|
||||
renpy.config.stdout_callbacks.append(console.stdout_line)
|
||||
renpy.config.stderr_callbacks.append(console.stderr_line)
|
||||
|
||||
init python in _console:
|
||||
import pygame
|
||||
@ -542,6 +560,7 @@ screen console:
|
||||
$ history = _console.console.history
|
||||
$ scripting = _console.console.renpy_scripting
|
||||
default is_modal = True
|
||||
default include_stdout = True
|
||||
default consoleinput = _console.ConsoleInput("", style="console_input_text", exclude="", replaces=True, copypaste=True)
|
||||
|
||||
if is_modal:
|
||||
@ -555,7 +574,8 @@ screen console:
|
||||
|
||||
hbox:
|
||||
yfill False
|
||||
textbutton "Modal" action ToggleScreenVariable("is_modal", True, False)
|
||||
textbutton "Modal: [is_modal]" action ToggleScreenVariable("is_modal", True, False)
|
||||
textbutton "Include STDOUT: [include_stdout]" action ToggleScreenVariable("include_stdout", True, False)
|
||||
text "Ren'py Scripting: [scripting]"
|
||||
|
||||
viewport:
|
||||
@ -570,17 +590,21 @@ screen console:
|
||||
|
||||
for entry in history:
|
||||
|
||||
if not include_stdout and entry.is_stdio:
|
||||
continue
|
||||
|
||||
$ timestamp = datetime.datetime.fromtimestamp(entry.timestamp).strftime('%H:%M:%S')
|
||||
$ timestamp = f"{{size=-2}}{{color=#ffffff80}}{timestamp}{{/color}}{{/size}}"
|
||||
$ stdout = " $ " if entry.is_stdio else " "
|
||||
$ info = f"{{size=-2}}{{color=#ffffff80}}{timestamp}{{/color}}{{color=#228b22}}{stdout}{{/color}}{{/size}}"
|
||||
|
||||
if entry.command is not None:
|
||||
text "[timestamp!i] [entry.command!q]" style "console_command_text"
|
||||
text "[info!i][entry.command!q]" style "console_command_text"
|
||||
|
||||
if entry.result is not None:
|
||||
if entry.is_error:
|
||||
text "[timestamp!i] {unicode}➥{/unicode} [entry.result!q]" style "console_error_text"
|
||||
text "[info!i]{unicode}➥{/unicode} [entry.result!q]" style "console_error_text"
|
||||
else:
|
||||
text "[timestamp!i] {unicode}➥{/unicode} [entry.result!q]" style "console_result_text"
|
||||
text "[info!i]{unicode}➥{/unicode} [entry.result!q]" style "console_result_text"
|
||||
|
||||
hbox:
|
||||
text "Command:"
|
||||
@ -598,6 +622,7 @@ style console_text:
|
||||
outlines [(1, "#000000", 1, 0)]
|
||||
size 14
|
||||
font "gui/creamy_pumpkin_pie/fonts/Hack-Regular.ttf"
|
||||
adjust_spacing False
|
||||
|
||||
style console_button_text is console_text
|
||||
|
||||
@ -609,5 +634,4 @@ style console_error_text is console_text:
|
||||
style console_result_text is console_text:
|
||||
color "#ffffff"
|
||||
|
||||
style console_input_text is console_text:
|
||||
adjust_spacing False
|
||||
style console_input_text is console_text
|
||||
|
Loading…
Reference in New Issue
Block a user