przn 0.1.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b95e225303285a7367884694da54d91d95b0712be8100578411ae2b51581ee39
4
+ data.tar.gz: a2aea20a6be5dd25d7bd4cbd9af39e1440aebb7edc66c70071770b16ce1e352c
5
+ SHA512:
6
+ metadata.gz: 27846a7edb522887dc829610c2caf156a2793aaff8713aae1d12f6d1bbcb364942d3c3983aadf077a49d5929e8d269b16b6fedae5ad802aa1714ee2c35f0bde8
7
+ data.tar.gz: 4a9f75a34f60da321224fd41d7d2e3f527262a36f273b909d59a74154afb665e709cfaa9110ae1766394055e5889da98697e75a2a25677190e8a5dfec363ba31
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Akira Matsuda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # przn
2
+
3
+ A terminal-based presentation tool written in Ruby.
4
+ Renders Markdown slides with [Kitty text sizing protocol](https://sw.kovidgoyal.net/kitty/text-sizing-protocol/) support for beautifully scaled headings.
5
+
6
+ ## Installation
7
+
8
+ ```
9
+ gem install przn
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```
15
+ przn your_slides.md
16
+ ```
17
+
18
+ ### PDF export
19
+
20
+ ```
21
+ przn --export your_slides.md
22
+ przn --export pdf your_slides.md
23
+ przn --export pdf -o output.pdf your_slides.md
24
+ ```
25
+
26
+ Requires a TrueType font (with `glyf` outlines) for proper rendering. Prawn does not support CFF-based fonts (most `.otf` files). Fonts are auto-detected in this order: NotoSansJP TTF, HackGen, Arial Unicode.
27
+
28
+ ### Key bindings
29
+
30
+ | Key | Action |
31
+ |-----|--------|
32
+ | `→` `↓` `l` `j` `Space` | Next slide |
33
+ | `←` `↑` `h` `k` | Previous slide |
34
+ | `g` | First slide |
35
+ | `G` | Last slide |
36
+ | `q` `Ctrl-C` | Quit |
37
+
38
+ ## Markdown format
39
+
40
+ przn's Markdown format is compatible with [Rabbit](https://rabbit-shocker.org/)'s Markdown mode.
41
+
42
+ ### Slide splitting
43
+
44
+ Slides are separated by `#` (h1) headings.
45
+
46
+ ```markdown
47
+ # Slide 1
48
+
49
+ content
50
+
51
+ # Slide 2
52
+
53
+ more content
54
+ ```
55
+
56
+ ### Text formatting
57
+
58
+ ```markdown
59
+ *emphasis*
60
+ **bold**
61
+ ~~strikethrough~~
62
+ `inline code`
63
+ ```
64
+
65
+ ### Lists
66
+
67
+ ```markdown
68
+ * item 1
69
+ * item 2
70
+ * nested item
71
+
72
+ - also works as bullets
73
+
74
+ 1. ordered
75
+ 2. list
76
+ ```
77
+
78
+ ### Code blocks
79
+
80
+ Fenced code blocks:
81
+
82
+ ````markdown
83
+ ```ruby
84
+ puts "hello"
85
+ ```
86
+ ````
87
+
88
+ Indented code blocks (4 spaces) with optional kramdown IAL:
89
+
90
+ ```markdown
91
+ def hello
92
+ puts "world"
93
+ end
94
+ {: lang="ruby"}
95
+ ```
96
+
97
+ ### Block quotes
98
+
99
+ ```markdown
100
+ > quoted text
101
+ > continues here
102
+ ```
103
+
104
+ ### Tables
105
+
106
+ ```markdown
107
+ | Header 1 | Header 2 |
108
+ |----------|----------|
109
+ | cell 1 | cell 2 |
110
+ ```
111
+
112
+ ### Definition lists
113
+
114
+ ```markdown
115
+ term
116
+ : definition
117
+ ```
118
+
119
+ ### Text sizing
120
+
121
+ Uses Rabbit-compatible `{::tag}` notation. Supported size names: `xx-small`, `x-small`, `small`, `large`, `x-large`, `xx-large`, `xxx-large`, `xxxx-large`, and numeric `1`-`7`.
122
+
123
+ ```markdown
124
+ {::tag name="x-large"}Big text{:/tag}
125
+ {::tag name="7"}Maximum size{:/tag}
126
+ ```
127
+
128
+ On [Kitty](https://sw.kovidgoyal.net/kitty/)-compatible terminals, sized text is rendered using the OSC 66 text sizing protocol. On other terminals, the markup is silently ignored.
129
+
130
+ ### Alignment
131
+
132
+ ```markdown
133
+ {:.center}
134
+ centered text
135
+
136
+ {:.right}
137
+ right-aligned text
138
+ ```
139
+
140
+ ### Comments
141
+
142
+ ```markdown
143
+ {::comment}
144
+ This text is hidden from the presentation.
145
+ {:/comment}
146
+ ```
147
+
148
+ ### Notes
149
+
150
+ ```markdown
151
+ Visible text {::note}(speaker note){:/note}
152
+ ```
153
+
154
+ ## License
155
+
156
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/default_theme.yml ADDED
@@ -0,0 +1,16 @@
1
+ # Default przn theme
2
+ #
3
+ # Copy this file and pass your copy via --theme to customize.
4
+ # All keys are optional — unspecified values fall back to these defaults.
5
+
6
+ colors:
7
+ background: "000000"
8
+ foreground: "ffffff"
9
+ heading: # falls back to foreground
10
+ code_bg: "313244"
11
+ dim: "6c7086"
12
+ inline_code: "a6e3a1"
13
+
14
+ font:
15
+ family: # auto-detect
16
+ size: 18 # base font size in pt for PDF export
data/exe/przn ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/przn'
5
+
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: przn [options] <presentation.md>"
11
+ opts.on('--export [FORMAT]', 'Export to a format (default: pdf)') { |v|
12
+ if v && v.end_with?('.md')
13
+ ARGV.unshift(v)
14
+ options[:export] = 'pdf'
15
+ else
16
+ options[:export] = v || 'pdf'
17
+ end
18
+ }
19
+ opts.on('-o', '--output FILE', 'Output file path for export') { |v| options[:output] = v }
20
+ opts.on('--theme FILE', 'Theme file (YAML)') { |v| options[:theme] = v }
21
+ opts.on('--generate-theme', 'Generate theme.yml in current directory') { options[:generate_theme] = true }
22
+ end.parse!
23
+
24
+ if options[:generate_theme]
25
+ content = File.read(Przn::Theme::DEFAULT_PATH).sub(/\A(#[^\n]*\n)+\n/, '')
26
+ File.write('theme.yml', content)
27
+ puts "Generated: theme.yml"
28
+ exit
29
+ end
30
+
31
+ file = ARGV[0]
32
+ unless file
33
+ $stderr.puts "Usage: przn [options] <presentation.md>"
34
+ exit 1
35
+ end
36
+
37
+ theme = options[:theme] ? Przn::Theme.load(options[:theme]) : nil
38
+
39
+ if options[:export] == 'pdf'
40
+ output = options[:output] || File.basename(file, File.extname(file)) + '.pdf'
41
+ Przn.export_pdf(file, output, theme: theme)
42
+ else
43
+ Przn.start(file, theme: theme).run
44
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Przn
4
+ class Controller
5
+ def initialize(presentation, terminal, renderer)
6
+ @presentation = presentation
7
+ @terminal = terminal
8
+ @renderer = renderer
9
+ end
10
+
11
+ def run
12
+ @terminal.enter_alt_screen
13
+ @terminal.hide_cursor
14
+ render_current
15
+
16
+ @terminal.raw do
17
+ loop do
18
+ case read_key
19
+ when :right, :down, 'l', 'j', ' '
20
+ @presentation.next_slide
21
+ render_current
22
+ when :left, :up, 'h', 'k'
23
+ @presentation.prev_slide
24
+ render_current
25
+ when 'g'
26
+ @presentation.first_slide!
27
+ render_current
28
+ when 'G'
29
+ @presentation.last_slide!
30
+ render_current
31
+ when 'q', "\x03"
32
+ break
33
+ end
34
+ end
35
+ end
36
+ ensure
37
+ @terminal.show_cursor
38
+ @terminal.leave_alt_screen
39
+ end
40
+
41
+ private
42
+
43
+ def render_current
44
+ @renderer.render(
45
+ @presentation.current_slide,
46
+ current: @presentation.current,
47
+ total: @presentation.total
48
+ )
49
+ end
50
+
51
+ def read_key
52
+ c = $stdin.getc
53
+ return nil unless c
54
+
55
+ if c == "\e"
56
+ seq = $stdin.read_nonblock(2)
57
+ case seq
58
+ when '[A' then :up
59
+ when '[B' then :down
60
+ when '[C' then :right
61
+ when '[D' then :left
62
+ when '[H' then :home
63
+ when '[F' then :end
64
+ else :escape
65
+ end
66
+ else
67
+ c
68
+ end
69
+ rescue IO::WaitReadable
70
+ :escape
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Przn
4
+ module ImageUtil
5
+ module_function
6
+
7
+ def image_size(path)
8
+ return nil unless File.exist?(path)
9
+
10
+ File.open(path, 'rb') do |f|
11
+ header = f.read(8)
12
+ return nil unless header && header.size >= 4
13
+
14
+ # PNG
15
+ if header.b == "\x89PNG\r\n\x1a\n".b
16
+ f.seek(16)
17
+ w = f.read(4)&.unpack1('N')
18
+ h = f.read(4)&.unpack1('N')
19
+ return [w, h] if w && h
20
+ end
21
+
22
+ # JPEG
23
+ f.seek(0)
24
+ if header.b[0..1] == "\xFF\xD8".b
25
+ f.seek(2)
26
+ loop do
27
+ marker = f.read(2)
28
+ break unless marker && marker.size == 2 && marker.getbyte(0) == 0xFF
29
+ type = marker.getbyte(1)
30
+ if [0xC0, 0xC1, 0xC2].include?(type)
31
+ f.read(3)
32
+ h = f.read(2)&.unpack1('n')
33
+ w = f.read(2)&.unpack1('n')
34
+ return [w, h] if w && h
35
+ end
36
+ len = f.read(2)&.unpack1('n')
37
+ break unless len && len >= 2
38
+ f.seek(len - 2, IO::SEEK_CUR)
39
+ end
40
+ end
41
+
42
+ # GIF
43
+ f.seek(0)
44
+ sig = f.read(6)
45
+ if sig&.start_with?("GIF8")
46
+ w = f.read(2)&.unpack1('v')
47
+ h = f.read(2)&.unpack1('v')
48
+ return [w, h] if w && h
49
+ end
50
+ end
51
+ nil
52
+ rescue
53
+ nil
54
+ end
55
+
56
+ # Display image using kitten icat with --place for positioning
57
+ def kitty_icat(path, cols:, rows:, x:, y:)
58
+ args = ['kitten', 'icat', '--transfer-mode', 'stream',
59
+ '--place', "#{cols}x#{rows}@#{x}x#{y}",
60
+ File.expand_path(path)]
61
+ IO.popen(args, 'r', err: File::NULL) { |io| io.read }
62
+ end
63
+
64
+ def kitty_terminal?
65
+ ENV['TERM'] == 'xterm-kitty' || ENV['TERM_PROGRAM'] == 'kitty'
66
+ end
67
+
68
+ # Sixel via img2sixel
69
+ def sixel_available?
70
+ @sixel_available = system('command -v img2sixel > /dev/null 2>&1') if @sixel_available.nil?
71
+ @sixel_available
72
+ end
73
+
74
+ def sixel_encode(path, width: nil, height: nil)
75
+ return nil unless sixel_available?
76
+ return nil unless File.exist?(path)
77
+
78
+ args = ['img2sixel']
79
+ args += ['-w', width.to_s] if width
80
+ args += ['-h', height.to_s] if height
81
+ args << path
82
+ IO.popen(args, 'r', err: File::NULL) { |io| io.read }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Przn
4
+ module KittyText
5
+ HEADING_SCALES = {
6
+ 1 => 4,
7
+ 2 => 3,
8
+ 3 => 2,
9
+ }.freeze
10
+
11
+ module_function
12
+
13
+ def sized(text, s:, h: nil, v: nil)
14
+ params = +"s=#{s}"
15
+ params << ":h=#{h}" if h
16
+ params << ":v=#{v}" if v
17
+ "\e]66;#{params};#{text}\a"
18
+ end
19
+
20
+ def heading(text, level:)
21
+ scale = HEADING_SCALES[level]
22
+ return text unless scale
23
+
24
+ sized(text, s: scale, h: 1)
25
+ end
26
+ end
27
+ end