marvi 0.1.1 → 0.1.3

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: 41854d878cdc8137d35b7c54ff30ffb13b90206869828a6db31bd53b8d279f1b
4
- data.tar.gz: 396301e10a2d99ffd4c27526b1e792495c286450ae3e4c213ace369ea2b96706
3
+ metadata.gz: 38191038ed0255015b0184643cc52e36bc35b8973803c75f3f5636e227fddba6
4
+ data.tar.gz: 83a3fe56615300c99bcc9858750926d5afab8a4e7a78c279e7b74ceef81ff074
5
5
  SHA512:
6
- metadata.gz: f7493dd561c802f8db70acf7f87fdc62f49aec9b74f9681197598e4781885598ce5a5ccf1acfad2975ab22a669556ada2282363b9d4342047ece848334686072
7
- data.tar.gz: 2c3e48d560413d982c451a9c3a562c102ac06da98900cf1441f73c05077f9dfa8682c6d6d4ea3e44a43ef7387cbeefe67d949b651a9e1d65808a5634348ff17d
6
+ metadata.gz: 0dce42f6d88ceac30fa7cd2a75ad9318ab383f71164ad383ea1a95835601129ac8df125c403e634b5882a68802d24e05b4db9dd57496b4b91ab3a9a3bc176cca
7
+ data.tar.gz: 4f41145dc7639d8034cdff69b750dd0c92856b23b830b3e25542de48685e11f70a610cca7130a4ca54b04e829d5bd79bdcc5322f94fea939c6e6c64db81bbb08
@@ -24,7 +24,7 @@ module Marvi
24
24
  @lines = ASTWalker.new.walk(markdown)
25
25
  @scroll = 0
26
26
 
27
- ::Curses.init_screen
27
+ with_safe_term { ::Curses.init_screen }
28
28
  ::Curses.start_color
29
29
  ::Curses.use_default_colors
30
30
  ::Curses.noecho
@@ -42,6 +42,48 @@ module Marvi
42
42
 
43
43
  private
44
44
 
45
+ # ncurses uses the terminfo `rep` capability ("ESC[Nb") to compress runs of
46
+ # identical glyphs, but ghostty mishandles it and drops the run from the
47
+ # screen — table borders and long padding go missing. The bug surfaces both
48
+ # under xterm-ghostty directly and inside multiplexers like cmux that ship a
49
+ # terminfo whose xterm-256color entry advertises `rep`. Detect `rep` in the
50
+ # active terminfo and swap to a known no-rep alternative around initscr only.
51
+ REP_SAFE_TERMS = %w[screen-256color tmux-256color xterm-color xterm].freeze
52
+
53
+ def with_safe_term
54
+ original = ENV["TERM"]
55
+ replacement = rep_safe_term_for(original)
56
+ ENV["TERM"] = replacement if replacement
57
+ yield
58
+ ensure
59
+ ENV["TERM"] = original
60
+ end
61
+
62
+ def rep_safe_term_for(term)
63
+ return nil if term.nil? || term.empty?
64
+ return nil unless terminfo_has_rep?(term)
65
+
66
+ REP_SAFE_TERMS.find { |candidate| candidate != term && terminfo_exists?(candidate) && !terminfo_has_rep?(candidate) }
67
+ end
68
+
69
+ def terminfo_has_rep?(term)
70
+ infocmp(term)&.include?("rep=") || false
71
+ end
72
+
73
+ def terminfo_exists?(term)
74
+ !infocmp(term).nil?
75
+ end
76
+
77
+ def infocmp(term)
78
+ @infocmp_cache ||= {}
79
+ return @infocmp_cache[term] if @infocmp_cache.key?(term)
80
+
81
+ output = IO.popen(["infocmp", "-1", term, err: File::NULL], &:read)
82
+ @infocmp_cache[term] = $?.success? ? output : nil
83
+ rescue StandardError
84
+ @infocmp_cache[term] = nil
85
+ end
86
+
45
87
  def setup_colors
46
88
  ::Curses.init_pair(COLOR_PAIRS[:cyan], ::Curses::COLOR_CYAN, -1)
47
89
  ::Curses.init_pair(COLOR_PAIRS[:green], ::Curses::COLOR_GREEN, -1)
@@ -86,7 +128,7 @@ module Marvi
86
128
  end
87
129
 
88
130
  def reinit_curses
89
- ::Curses.init_screen
131
+ with_safe_term { ::Curses.init_screen }
90
132
  ::Curses.start_color
91
133
  ::Curses.use_default_colors
92
134
  ::Curses.noecho
data/lib/marvi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Marvi
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marvi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitsutaka Mimura