A klammer set's Python speaks through the log
Assembled from development commit d5f9c20b94b3. Since 5c29da5: a print() in
@eval, or in any Python a klammer set runs, is a log line -- on the
error stream under the command's name at -v 1, silent otherwise, never
in the document -- and K_log(level, text) is the builtin behind it; a
Python script using the binding keeps its own stdout. Previously such
output was lost, or on a terminal landed in the document.
This commit is contained in:
1 parent
5c29da52dc
commit
fc2e848e91
7 files changed
+126
-3
No files matched your search
+12
-2
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import inspect
|
||||
import html_util
|
||||
from html_util import E
|
||||
@@ -14,9 +15,18 @@ def blue_text(text):
|
||||
def red_text(text):
|
||||
return f"\033[31m{text}\033[0m"
|
||||
|
||||
def msg(text=""):
|
||||
def msg(text="", level=1):
|
||||
"""A message from the klammer set: the engine's log (K_log, a builtin
|
||||
under ktext), shown at -v LEVEL or higher on stderr, never in the
|
||||
document. Outside a Machine (a module run by hand) it goes to stderr.
|
||||
Until 2026-09-25 this was a print(): embedded Python's stdout, which no
|
||||
user ever saw."""
|
||||
frame = inspect.currentframe().f_back
|
||||
print(blue_text(f"[{os.path.basename(frame.f_code.co_filename)}:{frame.f_lineno}]"), text)
|
||||
where = f"[{os.path.basename(frame.f_code.co_filename)}:{frame.f_lineno}]"
|
||||
try:
|
||||
K_log(level, f"{where} {text}")
|
||||
except NameError:
|
||||
print(where, text, file=sys.stderr)
|
||||
|
||||
|
||||
def escape(s):
|
||||
|
||||
Reference in new issue
Block a user