• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonrubyphpgameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

A small kernel of code for playing with Galois fields of arbitrary characteristic


Commit MetaInfo

Révision77c204d9db398a5efe788d1372de67c20d6db6bf (tree)
l'heure2021-08-24 11:09:29
AuteurEric Hopper <hopper@omni...>
CommiterEric Hopper

Message de Log

Color output support now more flexible via dependency injection.

Change Summary

Modification

diff -r 0e11b6b32650 -r 77c204d9db39 numtheory_utils.py
--- a/numtheory_utils.py Sun Jul 18 15:56:59 2021 -0700
+++ b/numtheory_utils.py Mon Aug 23 19:09:29 2021 -0700
@@ -1,10 +1,12 @@
1-from typing import Any, Callable, TypeVar, Dict, Collection
1+from typing import Any, Callable, TypeVar, Dict, Collection, Optional
22 try:
33 import colorama
44 import blessings
55 nocolors = False
6+ TermType = blessings.Terminal
67 except ModuleNotFoundError:
78 nocolors = True
9+ TermType = None
810
911 __all__ = [
1012 'extended_gcd', 'print_group_table', 'mult_inverse', 'print_mult_inverses'
@@ -68,9 +70,10 @@
6870 def print_group_table(
6971 elements: Collection[T],
7072 op: Callable[[T, T], T],
71- highlight_map: Dict[T, int] = {}
73+ highlight_map: Dict[T, int] = {},
74+ term: Optional[TermType] = None
7275 ):
73- if not nocolors:
76+ if (not nocolors) and (term is None):
7477 colorama.init()
7578 term = blessings.Terminal()
7679 width = max(len(str(x)) for x in elements)
@@ -78,7 +81,7 @@
7881 def element_str(a, width):
7982 s = f'{a:{width}}'
8083 spaces = ' ' * (len(s) - len(str(a)))
81- if (not nocolors) and (a in highlight_map):
84+ if (term is not None) and (a in highlight_map):
8285 return spaces + term.color(highlight_map[a])(str(a))
8386 else:
8487 return s