kramdown-ansi 0.0.1 → 0.0.2

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: dd37ac254127e9b4654a9a7621159894bee90193506f2b30fad07e3db7978663
4
- data.tar.gz: 9cf0fa562dd8e274b7fba315c85c9148082ba71afdaf5a9f11a4e2ba201787b9
3
+ metadata.gz: abe5c3ac6431c1a6f2997c3c1414aa57fbfdb1c8eb2938b0bb9b7c59273c33ce
4
+ data.tar.gz: c1baef27fc70c8b613f911e5d7c945d9b8739faa0ef3b95e1cf771d705606a0e
5
5
  SHA512:
6
- metadata.gz: 8e72c1899f5338ed596bd4dc6a367e9ed32d9eb3a1cdcbc9ec9c4b1476557934de5ac5706d63f85a77f73880ad6a0316a26a5b58f4768cf77aebcf0d9076cc1b
7
- data.tar.gz: 7cdd5cde26c6e8a15975d75c867fa57b78fe07794b6a785802c6c5098fc6004a2b1a6b95d78eca4ad58df3c0ef214ffc5e2d4d4b27502d436a40db10b5711229
6
+ metadata.gz: 46da2186b55e0974b27ee06bbc5432b98e3dc2df22077f6a48208888ff1024c387dceae1e0dfbf0a0e17137442b33e35662a52e70e666deb017f6e622750a042
7
+ data.tar.gz: d743a08d17ebb58d7e906bca24300e0effb75e44004d40cebf5cdb5039fa0cfe6b63387a6b958748eb757dadc1522dd463eb0235e0c3631f43784c2112ae80a4
data/CHANGES.md CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 2024-10-31 v0.0.1
4
12
 
5
13
  * Strip CSI and OSC sequences in `Terminal::Table`:
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: kramdown-ansi 0.0.1 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.1".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
@@ -1,6 +1,6 @@
1
1
  module Kramdown
2
2
  # Kramdown version
3
- VERSION = '0.0.1'
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.1
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