nicer images with clmage
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
"""Markslider: a slideshow engine based on markdown."""
|
||||
|
||||
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
||||
__version__ = "1.3"
|
||||
__version__ = "1.3.1"
|
||||
|
||||
import sys, os, argparse, re, datetime
|
||||
from argparse import ArgumentParser
|
||||
@@ -28,6 +28,10 @@ import traceback, tty, termios, subprocess, signal
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||
import ansicodes, md_color
|
||||
try:
|
||||
import climage
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
HL = ">"
|
||||
EOS = "# End of Slides"
|
||||
@@ -59,6 +63,7 @@ class slide_reader:
|
||||
self.files = files
|
||||
self.reader = None
|
||||
self.opts = opts
|
||||
self.scrsize = get_console_size()
|
||||
self.pages = 0
|
||||
self.page = 0
|
||||
self.file_start_page = []
|
||||
@@ -236,8 +241,10 @@ class slide_reader:
|
||||
if command != None:
|
||||
return self.launch(command)
|
||||
image = self.re_image_convert.match(s)
|
||||
if image != None:
|
||||
try:
|
||||
return self.convert_image(image)
|
||||
except Exception:
|
||||
pass
|
||||
return [s]
|
||||
|
||||
def launch(self, command):
|
||||
@@ -263,17 +270,16 @@ class slide_reader:
|
||||
# return [s]
|
||||
|
||||
def convert_image(self, image):
|
||||
"""comnvert image using tags ![]()>
|
||||
"""convert image using tags ![]()>
|
||||
Remove empty lines from beginning and end of stdout.
|
||||
"""
|
||||
# ~ 2=title
|
||||
# ~ 3=image command
|
||||
output = subprocess.check_output(
|
||||
"convert %s JPEG:- | jp2a --colors --width=70 -" % (image.group(3),),
|
||||
shell=True,
|
||||
width = max(5, self.scrsize[1] - 10)
|
||||
output = climage.convert(
|
||||
image.group(3),
|
||||
is_unicode=True, is_truecolor=True, is_256color=False, is_16color=False, is_8color=False, width=width, palette="default"
|
||||
)
|
||||
if type(output) == bytes:
|
||||
output = output.decode("utf-8")
|
||||
output = output.split("\n")
|
||||
while len(output[0].strip()) == 0:
|
||||
if len(output) == 1:
|
||||
@@ -283,11 +289,8 @@ class slide_reader:
|
||||
if len(output) == 1:
|
||||
return [""]
|
||||
del output[-1]
|
||||
return_value = [image.group(1)]
|
||||
return_value.extend(output)
|
||||
# ~ return_value.append(image.group(4))
|
||||
return_value = [image.group(1), *output]
|
||||
return return_value
|
||||
# return [s]
|
||||
|
||||
def rename_duplicates(self):
|
||||
|
||||
@@ -382,7 +385,7 @@ Special syntaxes:
|
||||
* Text after a "# End of Slides" is not shown
|
||||
* Execute shell: ` command -switch `! Beware of malicious code!
|
||||
* Execute and print output: ` command `> Beware of malicious code!
|
||||
* Convert images to ASCII, with jp2a: >
|
||||
* Convert images to ANSI, with climage: >
|
||||
|
||||
Keyboard shortcuts:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user