projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Have bootstrap log the site_config at program initialization.
[python_utils.git]
/
ansi.py
diff --git
a/ansi.py
b/ansi.py
index 5fde4af56c9ef18254cd562ca19b10d853597e93..1633fddbcb31714d3ae7342daca37c1c4034b4c6 100755
(executable)
--- a/
ansi.py
+++ b/
ansi.py
@@
-1,11
+1,11
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
-from abc import abstractmethod
import difflib
import io
import logging
import re
import sys
import difflib
import io
import logging
import re
import sys
+from abc import abstractmethod
from typing import Any, Callable, Dict, Iterable, Optional, Tuple
from overrides import overrides
from typing import Any, Callable, Dict, Iterable, Optional, Tuple
from overrides import overrides
@@
-1773,14
+1773,10
@@
def fg(
green = 0
if blue is None:
blue = 0
green = 0
if blue is None:
blue = 0
- if (
- is_16color(red) and is_16color(green) and is_16color(blue)
- ) or force_16color:
+ if (is_16color(red) and is_16color(green) and is_16color(blue)) or force_16color:
logger.debug("Using 16-color strategy")
return fg_16color(red, green, blue)
logger.debug("Using 16-color strategy")
return fg_16color(red, green, blue)
- if (
- is_216color(red) and is_216color(green) and is_216color(blue)
- ) or force_216color:
+ if (is_216color(red) and is_216color(green) and is_216color(blue)) or force_216color:
logger.debug("Using 216-color strategy")
return fg_216color(red, green, blue)
logger.debug("Using 24-bit color strategy")
logger.debug("Using 216-color strategy")
return fg_216color(red, green, blue)
logger.debug("Using 24-bit color strategy")
@@
-1840,6
+1836,7
@@
def guess_name(name: str) -> str:
return best_guess
return best_guess
+@logging_utils.squelch_repeated_log_messages(1)
def bg(
name: Optional[str] = "",
red: Optional[int] = None,
def bg(
name: Optional[str] = "",
red: Optional[int] = None,
@@
-1878,14
+1875,10
@@
def bg(
green = 0
if blue is None:
blue = 0
green = 0
if blue is None:
blue = 0
- if (
- is_16color(red) and is_16color(green) and is_16color(blue)
- ) or force_16color:
+ if (is_16color(red) and is_16color(green) and is_16color(blue)) or force_16color:
logger.debug("Using 16-color strategy")
return bg_16color(red, green, blue)
logger.debug("Using 16-color strategy")
return bg_16color(red, green, blue)
- if (
- is_216color(red) and is_216color(green) and is_216color(blue)
- ) or force_216color:
+ if (is_216color(red) and is_216color(green) and is_216color(blue)) or force_216color:
logger.debug("Using 216-color strategy")
return bg_216color(red, green, blue)
logger.debug("Using 24-bit color strategy")
logger.debug("Using 216-color strategy")
return bg_216color(red, green, blue)
logger.debug("Using 24-bit color strategy")
@@
-1894,19
+1887,19
@@
def bg(
class StdoutInterceptor(io.TextIOBase):
def __init__(self):
class StdoutInterceptor(io.TextIOBase):
def __init__(self):
- self.saved_stdout:
Optional[io.TextIOBase]
= None
+ self.saved_stdout:
io.TextIO
= None
self.buf = ''
@abstractmethod
def write(self, s: str):
pass
self.buf = ''
@abstractmethod
def write(self, s: str):
pass
- def __enter__(self)
-> None
:
+ def __enter__(self):
self.saved_stdout = sys.stdout
sys.stdout = self
self.saved_stdout = sys.stdout
sys.stdout = self
- return
None
+ return
self
- def __exit__(self, *args) ->
bool
:
+ def __exit__(self, *args) ->
Optional[bool]
:
sys.stdout = self.saved_stdout
print(self.buf)
return None
sys.stdout = self.saved_stdout
print(self.buf)
return None
@@
-1942,9
+1935,6
@@
if __name__ == '__main__':
_ = pick_contrasting_color(possibility)
xf = fg(None, _[0], _[1], _[2])
xb = bg(None, _[0], _[1], _[2])
_ = pick_contrasting_color(possibility)
xf = fg(None, _[0], _[1], _[2])
xb = bg(None, _[0], _[1], _[2])
- print(
- f'{f}{xb}{possibility}{reset()}\t\t\t'
- f'{b}{xf}{possibility}{reset()}'
- )
+ print(f'{f}{xb}{possibility}{reset()}\t\t\t' f'{b}{xf}{possibility}{reset()}')
main()
main()