kramdown-ansi 0.0.0 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7249444853b46b626b782ea417e62827627ba0d1da6f54cc8801f8459839f775
4
- data.tar.gz: 75884f2bf3c0e3b06e71c28f9f4775315745b76ab9cf0d73ec57e49829cd7f6f
3
+ metadata.gz: abe5c3ac6431c1a6f2997c3c1414aa57fbfdb1c8eb2938b0bb9b7c59273c33ce
4
+ data.tar.gz: c1baef27fc70c8b613f911e5d7c945d9b8739faa0ef3b95e1cf771d705606a0e
5
5
  SHA512:
6
- metadata.gz: 10c992685654c67686a24e4a323ab04619d8957faa61a119569e16dbdb82119278b2756b3cf8d3ba921f7343997d12ddb6632fc8fc3379b00be844862e730d4a
7
- data.tar.gz: d3342cdf38698f5f59035b0a06dff0341a3fc66127d4de3fd7de46d25d55831175a087f6375fb2052f5e10ff1aabb026026361ab3e73f9a87329b19f3be2d05d
6
+ metadata.gz: 46da2186b55e0974b27ee06bbc5432b98e3dc2df22077f6a48208888ff1024c387dceae1e0dfbf0a0e17137442b33e35662a52e70e666deb017f6e622750a042
7
+ data.tar.gz: d743a08d17ebb58d7e906bca24300e0effb75e44004d40cebf5cdb5039fa0cfe6b63387a6b958748eb757dadc1522dd463eb0235e0c3631f43784c2112ae80a4
data/CHANGES.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changes
2
2
 
3
+ ## 2024-12-08 v0.0.2
4
+
5
+ * Added handling of `Interrupt` and `Errno::EPIPE` exceptions when using pager in `md` and `git-md` executables:
6
+ * Added require `'term/ansicolor'` to `Kramdown::ANSI::Pager`.
7
+ * Added rescue blocks in `Kramdown::ANSI::Pager.pager` to catch `Interrupt`, `Errno::EPIPE` exceptions.
8
+ * Added `pager_reset_screen` method to reset terminal screen by printing ANSI escape codes.
9
+ * Updated `spec/kramdown/ansi/pager_spec.rb` with tests for new functionality.
10
+
11
+ ## 2024-10-31 v0.0.1
12
+
13
+ * Strip CSI and OSC sequences in `Terminal::Table`:
14
+ + Fix size calculations
15
+
3
16
  ## 2024-10-31 v0.0.0
4
17
 
5
18
  * Start
data/README.md CHANGED
@@ -39,8 +39,8 @@ puts Kramdown::ANSI.parse(markdown)
39
39
 
40
40
  | Method | Description |
41
41
  | :----- | :---------- |
42
- | `md` executable | Outputs Markdown files with ANSI escape sequences in the terminal |
43
- | `git-md` executable | A Git plugin that outputs Markdown formatted git commit messages into the terminal |
42
+ | `md` executable | Outputs [Markdown](https://spec.commonmark.org/current/) files with ANSI escape sequences in the terminal |
43
+ | `git-md` executable | A Git plugin that outputs [Markdown](https://spec.commonmark.org/current/) formatted git commit messages into the terminal |
44
44
 
45
45
  ### The md executable
46
46
 
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: kramdown-ansi 0.0.0 ruby lib
2
+ # stub: kramdown-ansi 0.0.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "kramdown-ansi".freeze
6
- s.version = "0.0.0".freeze
6
+ s.version = "0.0.2".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2024-10-31"
11
+ s.date = "2024-12-08"
12
12
  s.description = "Kramdown::ANSI: A library for rendering Markdown(ish) documents with\nbeautiful ANSI escape sequences in the terminal.\n".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["md".freeze, "git-md".freeze]
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.licenses = ["MIT".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "Kramdown-ansi - Output markdown in the terminal with ANSI escape sequences".freeze, "--main".freeze, "README.md".freeze]
20
20
  s.required_ruby_version = Gem::Requirement.new("~> 3.1".freeze)
21
- s.rubygems_version = "3.5.22".freeze
21
+ s.rubygems_version = "3.5.23".freeze
22
22
  s.summary = "Output markdown in the terminal with ANSI escape sequences".freeze
23
23
  s.test_files = ["spec/kramdown/ansi/pager_spec.rb".freeze, "spec/kramdown/ansi/width_spec.rb".freeze, "spec/kramdown/ansi_spec.rb".freeze, "spec/spec_helper.rb".freeze]
24
24
 
@@ -1,4 +1,5 @@
1
1
  require 'tins/terminal'
2
+ require 'term/ansicolor'
2
3
 
3
4
  module Kramdown::ANSI::Pager
4
5
  module_function
@@ -18,10 +19,16 @@ module Kramdown::ANSI::Pager
18
19
  IO.popen(my_pager, 'w') do |output|
19
20
  output.sync = true
20
21
  yield output
22
+ rescue Interrupt, Errno::EPIPE
23
+ pager_reset_screen
24
+ return nil
25
+ ensure
21
26
  output.close
22
27
  end
28
+ my_pager
23
29
  else
24
30
  yield STDOUT
31
+ nil
25
32
  end
26
33
  else
27
34
  return unless STDOUT.tty?
@@ -34,4 +41,11 @@ module Kramdown::ANSI::Pager
34
41
  end
35
42
  end
36
43
  end
44
+
45
+ # Resets the terminal screen by printing ANSI escape codes for reset, clear
46
+ # screen, move home and show cursor.
47
+ def pager_reset_screen
48
+ c = Term::ANSIColor
49
+ STDOUT.print c.reset, c.clear_screen, c.move_home, c.show_cursor
50
+ end
37
51
  end
data/lib/kramdown/ansi.rb CHANGED
@@ -13,6 +13,12 @@ class Kramdown::ANSI < Kramdown::Converter::Base
13
13
  include Term::ANSIColor
14
14
  include Kramdown::ANSI::Width
15
15
 
16
+ module Terminal::Table::Util
17
+ def self.ansi_escape(line)
18
+ line.to_s.gsub(/\e\[.*?m|\e\].*?(\e|\a)\\?/, '')
19
+ end
20
+ end
21
+
16
22
  class ::Kramdown::Parser::Mygfm < ::Kramdown::Parser::GFM
17
23
  def initialize(source, options)
18
24
  options[:gfm_quirks] << :no_auto_typographic
@@ -1,6 +1,6 @@
1
1
  module Kramdown
2
2
  # Kramdown version
3
- VERSION = '0.0.0'
3
+ VERSION = '0.0.2'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -38,14 +38,42 @@ RSpec.describe Kramdown::ANSI::Pager do
38
38
  it 'can output to the command for paging if enough lines' do
39
39
  expect(Tins::Terminal).to receive(:lines).and_return 25
40
40
  block_called = false
41
- Kramdown::ANSI::Pager.pager(command: command, lines: 30) do |output|
41
+ result = Kramdown::ANSI::Pager.pager(command: command, lines: 30) do |output|
42
42
  expect(output).to be_a IO
43
43
  expect(output).not_to eq STDOUT
44
44
  block_called = true
45
45
  end
46
46
  expect(block_called).to eq true
47
+ expect(result).to eq command
47
48
  end
48
49
 
50
+ it 'closes output for Interrupt' do
51
+ expect(Tins::Terminal).to receive(:lines).and_return 25
52
+ block_called = false
53
+ expect_any_instance_of(IO).to receive(:sync=).and_raise Interrupt
54
+ expect_any_instance_of(IO).to receive(:close).and_call_original
55
+ expect(described_class).to receive(:pager_reset_screen)
56
+ result = Kramdown::ANSI::Pager.pager(command: command, lines: 30) do |output|
57
+ block_called = true
58
+ end
59
+ expect(block_called).to eq false
60
+ expect(result).to be_nil
61
+ end
62
+
63
+ it 'closes output for Errno::EPIPE' do
64
+ expect(Tins::Terminal).to receive(:lines).and_return 25
65
+ block_called = false
66
+ expect_any_instance_of(IO).to receive(:sync=).and_raise Errno::EPIPE
67
+ expect_any_instance_of(IO).to receive(:close).and_call_original
68
+ expect(described_class).to receive(:pager_reset_screen)
69
+ result = Kramdown::ANSI::Pager.pager(command: command, lines: 30) do |output|
70
+ block_called = true
71
+ end
72
+ expect(block_called).to eq false
73
+ expect(result).to be_nil
74
+ end
75
+
76
+
49
77
  it 'can output STDOUT if not enough lines' do
50
78
  expect(Tins::Terminal).to receive(:lines).and_return 25
51
79
  block_called = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-ansi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-31 00:00:00.000000000 Z
11
+ date: 2024-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
- rubygems_version: 3.5.22
181
+ rubygems_version: 3.5.23
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: Output markdown in the terminal with ANSI escape sequences