nicer images with clmage
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
"""Markslider: a slideshow engine based on markdown."""
|
"""Markslider: a slideshow engine based on markdown."""
|
||||||
|
|
||||||
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
||||||
__version__ = "1.3"
|
__version__ = "1.3.1"
|
||||||
|
|
||||||
import sys, os, argparse, re, datetime
|
import sys, os, argparse, re, datetime
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
@@ -28,6 +28,10 @@ import traceback, tty, termios, subprocess, signal
|
|||||||
|
|
||||||
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||||
import ansicodes, md_color
|
import ansicodes, md_color
|
||||||
|
try:
|
||||||
|
import climage
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
HL = ">"
|
HL = ">"
|
||||||
EOS = "# End of Slides"
|
EOS = "# End of Slides"
|
||||||
@@ -59,6 +63,7 @@ class slide_reader:
|
|||||||
self.files = files
|
self.files = files
|
||||||
self.reader = None
|
self.reader = None
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
self.scrsize = get_console_size()
|
||||||
self.pages = 0
|
self.pages = 0
|
||||||
self.page = 0
|
self.page = 0
|
||||||
self.file_start_page = []
|
self.file_start_page = []
|
||||||
@@ -236,8 +241,10 @@ class slide_reader:
|
|||||||
if command != None:
|
if command != None:
|
||||||
return self.launch(command)
|
return self.launch(command)
|
||||||
image = self.re_image_convert.match(s)
|
image = self.re_image_convert.match(s)
|
||||||
if image != None:
|
try:
|
||||||
return self.convert_image(image)
|
return self.convert_image(image)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return [s]
|
return [s]
|
||||||
|
|
||||||
def launch(self, command):
|
def launch(self, command):
|
||||||
@@ -263,17 +270,16 @@ class slide_reader:
|
|||||||
# return [s]
|
# return [s]
|
||||||
|
|
||||||
def convert_image(self, image):
|
def convert_image(self, image):
|
||||||
"""comnvert image using tags ![]()>
|
"""convert image using tags ![]()>
|
||||||
Remove empty lines from beginning and end of stdout.
|
Remove empty lines from beginning and end of stdout.
|
||||||
"""
|
"""
|
||||||
# ~ 2=title
|
# ~ 2=title
|
||||||
# ~ 3=image command
|
# ~ 3=image command
|
||||||
output = subprocess.check_output(
|
width = max(5, self.scrsize[1] - 10)
|
||||||
"convert %s JPEG:- | jp2a --colors --width=70 -" % (image.group(3),),
|
output = climage.convert(
|
||||||
shell=True,
|
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")
|
output = output.split("\n")
|
||||||
while len(output[0].strip()) == 0:
|
while len(output[0].strip()) == 0:
|
||||||
if len(output) == 1:
|
if len(output) == 1:
|
||||||
@@ -283,11 +289,8 @@ class slide_reader:
|
|||||||
if len(output) == 1:
|
if len(output) == 1:
|
||||||
return [""]
|
return [""]
|
||||||
del output[-1]
|
del output[-1]
|
||||||
return_value = [image.group(1)]
|
return_value = [image.group(1), *output]
|
||||||
return_value.extend(output)
|
|
||||||
# ~ return_value.append(image.group(4))
|
|
||||||
return return_value
|
return return_value
|
||||||
# return [s]
|
|
||||||
|
|
||||||
def rename_duplicates(self):
|
def rename_duplicates(self):
|
||||||
|
|
||||||
@@ -382,7 +385,7 @@ Special syntaxes:
|
|||||||
* Text after a "# End of Slides" is not shown
|
* Text after a "# End of Slides" is not shown
|
||||||
* Execute shell: ` command -switch `! Beware of malicious code!
|
* Execute shell: ` command -switch `! Beware of malicious code!
|
||||||
* Execute and print output: ` command `> 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:
|
Keyboard shortcuts:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ setup(
|
|||||||
keywords=["Markdown", "Slideshow"],
|
keywords=["Markdown", "Slideshow"],
|
||||||
entry_points = {'console_scripts': 'markslider = markslider.markslider:main'},
|
entry_points = {'console_scripts': 'markslider = markslider.markslider:main'},
|
||||||
install_requires = [
|
install_requires = [
|
||||||
'pygments'
|
'pygments', 'climage'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ _qCol() {
|
|||||||
for ((arg=1;arg<=$#;arg++)) {
|
for ((arg=1;arg<=$#;arg++)) {
|
||||||
val=${!arg}
|
val=${!arg}
|
||||||
[[ ${color_keys} = *" $val "* ]] || { echo "No such color code '${val}'" >&2; return 1; }
|
[[ ${color_keys} = *" $val "* ]] || { echo "No such color code '${val}'" >&2; return 1; }
|
||||||
printf ${!val}
|
printf "${!val}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
28
skel/Makefile
Normal file
28
skel/Makefile
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
|
||||||
|
help: ## *:・゚✧*:・゚✧ This help *:・゚✧*:・゚✧
|
||||||
|
@printf "\033[36;1m %14s \033[0;32;1m %s\033[0m\n" Target Description
|
||||||
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
|
||||||
|
awk ' \
|
||||||
|
BEGIN {FS = ":.*?## "}; \
|
||||||
|
{ if ( $$1 != "-") { \
|
||||||
|
printf "\033[31;1;40m[ \033[36;1;40m%14s \033[31;1;40m]\033[0;32;1m %s\033[0m\n", $$1, $$2 \
|
||||||
|
} else { \
|
||||||
|
printf " \033[0;33;1m=^= %-25s =^=\033[0m\n", $$2 \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
'
|
||||||
|
|
||||||
|
-: ## Building
|
||||||
|
###################################
|
||||||
|
|
||||||
|
build: ## Build image
|
||||||
|
echo docker build -t image .
|
||||||
|
|
||||||
|
-: ## Running
|
||||||
|
###################################
|
||||||
|
|
||||||
|
|
||||||
|
run: ## Run image
|
||||||
|
echo docker run image
|
||||||
Reference in New Issue
Block a user