diff --git a/docs/source/FAQ.rst b/docs/source/FAQ.rst index e3e62f9..b39a162 100644 --- a/docs/source/FAQ.rst +++ b/docs/source/FAQ.rst @@ -16,5 +16,12 @@ View的宽度有两种,``width``, ``real_width`` 具体参照 https://github.com/gojuukaze/terminal_layout/blob/master/demo/demo6(get_width).py +屏幕闪烁 +-------------------------------- + +输出的文本太大会出现界面闪烁的情况,这时要调大sys.stdout的缓冲区。具体情况见: https://github.com/gojuukaze/terminal_layout/issues/3 + +可通过 ``ctl.set_buffer_size()`` 函数调大缓冲区。(建议在draw之前调用) + diff --git a/setup.py b/setup.py index 223a274..c8d6d02 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="terminal_layout", - version="2.0.0", + version="2.0.1", description="The project help you to quickly build layouts in terminal (命令行ui布局工具)", long_description=open("README.rst").read(), diff --git a/terminal_layout/ctl.py b/terminal_layout/ctl.py index b85edf2..bcd7d1d 100644 --- a/terminal_layout/ctl.py +++ b/terminal_layout/ctl.py @@ -33,6 +33,15 @@ def __init__(self, layout=None): ) self.refresh_thread.daemon = True + def set_buffer_size(self, size): + """ + 当输出的文本太大会出现界面闪烁的情况,这时要调大sys.stdout的缓冲区 + (见 https://github.com/gojuukaze/terminal_layout/issues/3 ) + 建议在draw之前调用 + """ + self.buffering = size + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', self.buffering, encoding='utf-8') + def is_stop(self): return self._stop_flag