Add Unicode math output formatting
This commit is contained in:
@@ -12,6 +12,7 @@ from .ai_client import AIClientError, ask_ai
|
||||
from .clipboard_capture import capture_clipboard
|
||||
from .config import AppConfig, load_config
|
||||
from .key_stepper import KeyStepper
|
||||
from .math_format import format_math_text
|
||||
|
||||
LOG = logging.getLogger("ai_typewriter")
|
||||
|
||||
@@ -43,16 +44,19 @@ class AITypewriterApp:
|
||||
LOG.info("Texte capturé: %r", selected)
|
||||
started_at = time.perf_counter()
|
||||
answer = ask_ai(selected, self.config)
|
||||
answer_to_type = format_math_text(answer, self.config.math_text_format)
|
||||
elapsed = time.perf_counter() - started_at
|
||||
LOG.info(
|
||||
"Réponse reçue en %.2f s: %d caractères. Premier caractère écrit automatiquement, %d restants au clavier.",
|
||||
"Réponse reçue en %.2f s: %d caractères (%d après formatage %s). Premier caractère écrit automatiquement, %d restants au clavier.",
|
||||
elapsed,
|
||||
len(answer),
|
||||
max(len(answer) - 1, 0),
|
||||
len(answer_to_type),
|
||||
self.config.math_text_format,
|
||||
max(len(answer_to_type) - 1, 0),
|
||||
)
|
||||
if self._stepper is not None:
|
||||
self._stepper.stop()
|
||||
self._stepper = KeyStepper(answer, delay=self.config.type_delay_seconds)
|
||||
self._stepper = KeyStepper(answer_to_type, delay=self.config.type_delay_seconds)
|
||||
self._stepper.start()
|
||||
except (AIClientError, FileNotFoundError, ValueError) as exc:
|
||||
LOG.error("%s", exc)
|
||||
@@ -84,9 +88,10 @@ def main(argv: list[str] | None = None) -> int:
|
||||
try:
|
||||
started_at = time.perf_counter()
|
||||
answer = ask_ai(args.ask, config)
|
||||
answer_to_type = format_math_text(answer, config.math_text_format)
|
||||
elapsed = time.perf_counter() - started_at
|
||||
LOG.info("Réponse générée en %.2f s: %d caractères.", elapsed, len(answer))
|
||||
print(answer)
|
||||
LOG.info("Réponse générée en %.2f s: %d caractères (%d après formatage %s).", elapsed, len(answer), len(answer_to_type), config.math_text_format)
|
||||
print(answer_to_type)
|
||||
return 0
|
||||
except AIClientError as exc:
|
||||
LOG.error("%s", exc)
|
||||
|
||||
Reference in New Issue
Block a user