Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from argparse import Parser 

2from argparse import ValueType 

3from os.path import Path 

4from os import STDIN 

5from os import Stdin 

6from .iterm import write as iterm_write 

7from .kitty import write_png as kitty_write_png 

8from .terminal import GraphicsProtocol 

9from .terminal import get_preferred_graphics_protocol 

10 

11func main(argv: [string]): 

12 parser = Parser(version=__version__, 

13 help="Terminal images.") 

14 parser.add_positional("file", 

15 value_type=ValueType.Path, 

16 help="Image path, or - for stdin.") 

17 args = parser.parse(argv) 

18 

19 if args.value_of("file") == "-": 

20 image = STDIN.read() 

21 else: 

22 image = Path(args.value_of("file")).read_binary() 

23 

24 match get_preferred_graphics_protocol(): 

25 case GraphicsProtocol.Kitty: 

26 kitty_write_png(image) 

27 case GraphicsProtocol.ITerm: 

28 iterm_write(image) 

29 case _: 

30 raise SystemExitError("Unsupported terminal.")