mdless 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 721c2ba19c8a2e2fe201254c4d988855d208d8c9e339a435897d5ed08696cc33
4
- data.tar.gz: 0ffd801640a457d78ad076b05ddf44b2e735d8ca57928b94916db5c48f718663
3
+ metadata.gz: 32198570a885b3c03e6ec0e35c7d19f70f89330b9f3174270835a06f0efaec51
4
+ data.tar.gz: add6fadf749c0415363c6853c10f7de58a1a41a658ad1b12f1c4a692db425cb1
5
5
  SHA512:
6
- metadata.gz: '0380d39b79517ec7f1c278728b598c7780e5ccec1b1dd0fda74fd063430e20e18551a4d08bf6cc0d9091c68bb4ace60dac62ab5c78804dc10cca62cce81ab1b4'
7
- data.tar.gz: 19e1df9c6bb6a7cf4289463f52e74bdad480b5d41a8f387145ca99b935068149d8cc53a8815f0fa1c0cffeee2ef280bfbe5a3c72062b5568ff375a71901d53ce
6
+ metadata.gz: ab05974fb41187a1ba7b4fc95358ec65299a6c3496372bb7067e793bba209b66ec3a21daf0a78e133d63b26f6e93ee913420c968f3e746dcd147e4ea808f2a70
7
+ data.tar.gz: 2e1954c54a87c356b2a42bb847ea6c738df729da0bce1feefc13e9fb6c22b1a858bc53bedb63375e90e44e7d15e2d44de8770db7d92e19ae9d1630e4d782d2f2
@@ -41,9 +41,9 @@ module CLIMarkdown
41
41
 
42
42
  @options[:local_images] = false
43
43
  @options[:remote_images] = false
44
- opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires imgcat and iTerm2, default NONE). Does not work with pagers, use with -P' ) do |type|
45
- unless exec_available('imgcat')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
46
- @log.warn('images turned on but imgcat not found')
44
+ opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires chafa or imgcat, default NONE). imgcat does not work with pagers, use with -P' ) do |type|
45
+ unless exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
46
+ @log.warn('images turned on but imgcat/chafa not found')
47
47
  else
48
48
  if type =~ /^(r|b|a)/i
49
49
  @options[:local_images] = true
@@ -53,12 +53,12 @@ module CLIMarkdown
53
53
  end
54
54
  end
55
55
  end
56
- opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat and iTerm2)' ) do
57
- unless exec_available('imgcat')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
58
- @log.warn('images turned on but imgcat not found')
59
- else
56
+ opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)' ) do
57
+ if exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
60
58
  @options[:local_images] = true
61
59
  @options[:remote_images] = true
60
+ else
61
+ @log.warn('images turned on but imgcat/chafa not found')
62
62
  end
63
63
  end
64
64
 
@@ -847,20 +847,36 @@ module CLIMarkdown
847
847
  else
848
848
  tail = match[4].nil? ? '' : " "+match[4].strip
849
849
  result = nil
850
- if exec_available('imgcat') && @options[:local_images]
850
+ if (exec_available('imgcat') || exec_available('chafa')) && @options[:local_images]
851
851
  if match[3]
852
852
  img_path = match[3]
853
853
  if img_path =~ /^http/ && @options[:remote_images]
854
- begin
855
- res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
856
854
 
857
- if s.success?
855
+ if exec_available('chafa')
856
+ Dir.mktmpdir do |dir|
857
+ `curl -Sso #{img_path} 2> /dev/null`
858
+ tmp_img = File.join(dir, File.basename(img_path))
859
+ img = `chafa "#{tmp_img}"`
858
860
  pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
859
861
  post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
860
- result = pre + res + post
862
+ result = pre + img + post
863
+ end
864
+ else
865
+ if exec_available('imgcat')
866
+ begin
867
+ res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
868
+
869
+ if s.success?
870
+ pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
871
+ post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
872
+ result = pre + res + post
873
+ end
874
+ rescue => e
875
+ @log.error(e)
876
+ end
877
+ else
878
+ @log.warn("No viewer for remote images")
861
879
  end
862
- rescue => e
863
- @log.error(e)
864
880
  end
865
881
  else
866
882
  if img_path =~ /^[~\/]/
@@ -872,7 +888,11 @@ module CLIMarkdown
872
888
  if File.exists?(img_path)
873
889
  pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
874
890
  post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
875
- img = %x{imgcat "#{img_path}"}
891
+ if exec_available('chafa')
892
+ img = %x{chafa "#{img_path}"}
893
+ elsif exec_available('imgcat')
894
+ img = %x{imgcat "#{img_path}"}
895
+ end
876
896
  result = pre + img + post
877
897
  end
878
898
  end
@@ -963,16 +983,16 @@ module CLIMarkdown
963
983
 
964
984
  out = cleanup_tables(out)
965
985
  out = clean_markers(out)
966
- out = out.gsub(/\n+{2,}/m,"\n\n") + "\n#{xc}\n"
986
+ out = out.gsub(/\n{2,}/m,"\n\n") + "#{xc}"
967
987
 
968
988
  unless @options[:color]
969
989
  out.uncolor!
970
990
  end
971
991
 
972
992
  if @options[:pager]
973
- page("\n\n" + out)
993
+ page(out)
974
994
  else
975
- $stdout.puts ("\n\n" + out)
995
+ $stdout.puts (out)
976
996
  end
977
997
  end
978
998
 
@@ -990,6 +1010,9 @@ module CLIMarkdown
990
1010
  if f
991
1011
  if f.strip =~ /[ |]/
992
1012
  f
1013
+ elsif f == 'most'
1014
+ @log.warn('most not allowed as pager')
1015
+ false
993
1016
  else
994
1017
  system "which #{f}", :out => File::NULL, :err => File::NULL
995
1018
  end
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.15'
2
+ VERSION = '1.0.16'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.1.4
106
+ rubygems_version: 3.0.3
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A pager like less, but for Markdown files