我想在 tmux 的窗格中显示动画 GIF 或任何其他图像。
我正在使用腹水疗法来做到这一点,并修改了其中一个示例程序 (images.py( 以:
- 显示单个图像
- 在"Ctrl+C"上显示任何错误消息
- 接受单个命令行 arg"图像文件名">
这是我的脚本,唯一的问题是它似乎每 10 秒对正在显示的图像进行缓慢刷新 ~ 。由于映像是静态映像,如何删除此刷新?
image.py
from __future__ import division
from asciimatics.effects import BannerText, Print, Scroll
from asciimatics.renderers import ColourImageFile, FigletText, ImageFile
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from asciimatics.exceptions import ResizeScreenError
import sys
total = len(sys.argv)-1
if (total < 1):
print ("Usage: IMG")
sys.exit(1)
# Parsing args one by one
IMG = str(sys.argv[1])
def demo(screen):
scenes = []
effects = [
Print(screen,
ColourImageFile(
screen, IMG,
screen.height-2,
uni=screen.unicode_aware,
dither=screen.unicode_aware),
0,
stop_frame=200
)
]
scenes.append(Scene(effects))
screen.play(scenes, stop_on_resize=True)
# capture ctrl+c and exit nicely
import signal
import sys
def signal_handler(sig, frame):
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
if __name__ == "__main__":
while True:
try:
Screen.wrapper(demo)
#Screen.wrapper(demo, catch_interrupt=True)
sys.exit(0)
except ResizeScreenError:
sys.exit(0)
我只需要设置stop_frame=0
,它就可以按预期工作,如文档中指定的那样
示例用法
$ python image.py /images/fox.jpg
image.py
from __future__ import division
from asciimatics.effects import BannerText, Print, Scroll
from asciimatics.renderers import ColourImageFile, FigletText, ImageFile
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from asciimatics.exceptions import ResizeScreenError
import sys
total = len(sys.argv)-1
if (total < 1):
print ("Usage: IMG")
sys.exit(1)
# Parsing args one by one
IMG = str(sys.argv[1])
def demo(screen):
scenes = []
effects = [
Print(screen,
ColourImageFile(
screen, IMG,
screen.height-2,
uni=screen.unicode_aware,
dither=screen.unicode_aware),
0,
stop_frame=200
)
]
scenes.append(Scene(effects))
screen.play(scenes, stop_on_resize=True)
# capture ctrl+c and exit nicely
import signal
import sys
def signal_handler(sig, frame):
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
if __name__ == "__main__":
while True:
try:
Screen.wrapper(demo)
#Screen.wrapper(demo, catch_interrupt=True)
sys.exit(0)
except ResizeScreenError:
sys.exit(0)