omnifarious

# GaloisField

• R/O
• SSH

## コミット

#### よく使われているワード(クリックで追加)

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

### コミットメタ情報

リビジョン 77c204d9db398a5efe788d1372de67c20d6db6bf (tree) 2021-08-24 11:09:29 Eric Hopper Eric Hopper

### ログメッセージ

Color output support now more flexible via dependency injection.

### 差分

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 2 2 try: 3 3 import colorama 4 4 import blessings 5 5 nocolors = False 6 + TermType = blessings.Terminal 6 7 except ModuleNotFoundError: 7 8 nocolors = True 9 + TermType = None 8 10 9 11 __all__ = [ 10 12 'extended_gcd', 'print_group_table', 'mult_inverse', 'print_mult_inverses'
 @@ -68,9 +70,10 @@ 68 70 def print_group_table( 69 71 elements: Collection[T], 70 72 op: Callable[[T, T], T], 71 - highlight_map: Dict[T, int] = {} 73 + highlight_map: Dict[T, int] = {}, 74 + term: Optional[TermType] = None 72 75 ): 73 - if not nocolors: 76 + if (not nocolors) and (term is None): 74 77 colorama.init() 75 78 term = blessings.Terminal() 76 79 width = max(len(str(x)) for x in elements)
 @@ -78,7 +81,7 @@ 78 81 def element_str(a, width): 79 82 s = f'{a:{width}}' 80 83 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): 82 85 return spaces + term.color(highlight_map[a])(str(a)) 83 86 else: 84 87 return s