textbringer-presentation 0.1.1 → 0.1.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
- SHA1:
3
- metadata.gz: 46e7f2d5bc20a3ac9b87ef487883c1ca9a666e35
4
- data.tar.gz: 55c6fd520e3cacf510ef29a700e984d13dda94b2
2
+ SHA256:
3
+ metadata.gz: c79839a7bba5c9edf03480908e01d39cf58f25c16682ad405a8b5bc7e6668f5c
4
+ data.tar.gz: 5354a10987d944e84480c436d8aa9f736415f995fb5b0d44e02c3dd461e2ea04
5
5
  SHA512:
6
- metadata.gz: '0810b703bf1865e6648294e596d307b02bc1aca4788d8da6f2b31dd1f1fb8bb15383f4b51be8485721b4c05658b3b53510d279a911011087065c428518d91149'
7
- data.tar.gz: 61675634c9c3fbefea071b87a5352a0a45c5e734dbceb7377c8ad2a75f71b8946755537a85888c177e39c9d15335ff219c43ab6ccd897a8262a10498da56a3a7
6
+ metadata.gz: 9064b8dd688e91ba0d862fb7e42df1decf74d2c8fb8a8a5adcf2d3719eb3a1e97d500b46e3b7bef2aaac5f0d290569da8d39165928b966fbef9421d7022af148
7
+ data.tar.gz: c9a4a947b982ab3b5b0006bba3708745905e5cf8b4a4ddc78b2266e7e95cd898b1d0d98b69526037d6f06fd53b01031a4eab7a59479c7a67bbf95db26d1b550a
@@ -21,6 +21,8 @@ module Textbringer
21
21
  PRESENTATION_MODE_MAP = Keymap.new
22
22
  PRESENTATION_MODE_MAP.define_key(:right, :forward_slide_command)
23
23
  PRESENTATION_MODE_MAP.define_key(:left, :backward_slide_command)
24
+ PRESENTATION_MODE_MAP.define_key("j", :forward_slide_command)
25
+ PRESENTATION_MODE_MAP.define_key("k", :backward_slide_command)
24
26
  PRESENTATION_MODE_MAP.define_key("q", :quit_presentation_command)
25
27
  PRESENTATION_MODE_MAP.define_key("\C-l", :show_current_slide_command)
26
28
 
@@ -84,7 +86,12 @@ module Textbringer
84
86
  if buffer
85
87
  buffer.kill
86
88
  end
89
+ src_buffer = @buffer[:source_buffer]
90
+ pos = @buffer[:slide_list].current.start_pos
87
91
  kill_buffer(@buffer)
92
+ switch_to_buffer(src_buffer)
93
+ src_buffer.goto_char(pos)
94
+ Window.current.recenter
88
95
  Window.redraw
89
96
  end
90
97
 
@@ -92,9 +99,13 @@ module Textbringer
92
99
 
93
100
  def show_image(img, body)
94
101
  Window.redisplay
95
- wininfo = `xwininfo -id $WINDOWID`
96
- width = wininfo.slice(/Width: (\d+)/, 1).to_i
97
- height = wininfo.slice(/Height: (\d+)/, 1).to_i
102
+ width = CONFIG[:presentation_window_width]
103
+ height = CONFIG[:presentation_window_height]
104
+ if width.nil? || height.nil?
105
+ wininfo = `xwininfo -id $WINDOWID`
106
+ width = wininfo.slice(/Width: (\d+)/, 1).to_i
107
+ height = wininfo.slice(/Height: (\d+)/, 1).to_i
108
+ end
98
109
  lines = Window.lines
99
110
  columns = Window.columns
100
111
  y = @buffer[:presentation_top_margin] +
@@ -105,7 +116,8 @@ module Textbringer
105
116
  STDOUT.printf("\e[%d;%dH", y, left_margin + 1)
106
117
  img_size = "#{img_width}x#{img_height}"
107
118
  img_bg = @buffer[:presentation_image_background]
108
- STDOUT.print(`convert -resize #{img_size} -gravity center -background '#{img_bg}' -extent #{img_size} '#{img}' - | img2sixel`)
119
+ options = CONFIG.fetch(:presentation_img2sixel_options, "")
120
+ STDOUT.print(`convert -resize #{img_size} -gravity center -background '#{img_bg}' -extent #{img_size} '#{img}' - | img2sixel #{options}`)
109
121
  STDOUT.flush
110
122
  end
111
123
 
@@ -2,19 +2,5 @@
2
2
 
3
3
  require_relative "presentation/version"
4
4
  require_relative "presentation/slide_list"
5
+ require_relative "presentation/commands"
5
6
  require_relative "modes/presentation_mode"
6
-
7
- module Textbringer
8
- module Presentation
9
- end
10
-
11
- include Commands
12
-
13
- define_command(:presentation) do
14
- slide_list = Presentation::SlideList.new(Buffer.current.to_s)
15
- buffer = Buffer.find_or_new("*Presentaion*", undo_limit: 0)
16
- switch_to_buffer(buffer)
17
- buffer[:slide_list] = slide_list
18
- presentation_mode
19
- end
20
- end
@@ -0,0 +1,9 @@
1
+ define_command(:presentation) do
2
+ src_buffer = Buffer.current
3
+ slide_list = Presentation::SlideList.new(src_buffer)
4
+ buffer = Buffer.find_or_new("*Presentaion*", undo_limit: 0)
5
+ switch_to_buffer(buffer)
6
+ buffer[:source_buffer] = src_buffer
7
+ buffer[:slide_list] = slide_list
8
+ presentation_mode
9
+ end
@@ -1,24 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "commonmarker"
4
+
3
5
  module Textbringer
4
6
  module Presentation
5
7
  class Slide
6
- attr_reader :number, :title, :body
8
+ attr_reader :number, :title
9
+ attr_accessor :start_pos, :end_pos
7
10
 
8
- def initialize(number, title, body)
11
+ def initialize(buffer, number, title)
12
+ @buffer = buffer
9
13
  @number = number
10
14
  @title = title
11
- @body = body
15
+ @start_pos = nil
16
+ @end_pos = nil
17
+ end
18
+
19
+ def body
20
+ @buffer.substring(@start_pos, @end_pos).sub(/\A.*\n/, "").strip
12
21
  end
13
22
  end
14
23
 
15
24
  class SlideList
16
- def initialize(s)
17
- @list = s.scan(/^#+ *(.*?)\n(.*?)(?:(?=^#)|\z)/m).map.with_index {
18
- |(title, body), i|
19
- Slide.new(i + 1, title.strip, body.strip)
20
- }
21
- @index = 0
25
+ def initialize(buffer)
26
+ @buffer = buffer
27
+ doc = CommonMarker.render_doc(buffer.to_s)
28
+ @list = []
29
+ slide = nil
30
+ i = 1
31
+ @buffer.save_excursion do
32
+ doc.each do |node|
33
+ if node.type == :header
34
+ @buffer.goto_line(node.sourcepos[:start_line])
35
+ slide.end_pos = @buffer.point - 1 if slide
36
+ title = node.to_plaintext.strip
37
+ slide = Slide.new(buffer, i, title)
38
+ slide.start_pos = @buffer.point
39
+ @list.push(slide)
40
+ i += 1
41
+ end
42
+ end
43
+ slide.end_pos = @buffer.point_max if slide
44
+ end
45
+ @index = @list.index { |slide|
46
+ slide.start_pos <= @buffer.point && @buffer.point <= slide.end_pos
47
+ } || 0
22
48
  end
23
49
 
24
50
  def size
@@ -29,6 +55,17 @@ module Textbringer
29
55
  @list[@index]
30
56
  end
31
57
 
58
+ def current_page
59
+ @index + 1
60
+ end
61
+
62
+ def goto_page(no)
63
+ if no < 1 || no > @list.size
64
+ raise ArgumentError, "Invalid page number: #{no}"
65
+ end
66
+ @index = no - 1
67
+ end
68
+
32
69
  def forward_slide
33
70
  if @index < @list.size - 1
34
71
  @index += 1
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Textbringer
4
4
  module Presentation
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_runtime_dependency "textbringer"
25
+ spec.add_runtime_dependency "commonmarker"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.14"
27
28
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textbringer-presentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-19 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textbringer
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: commonmarker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +180,7 @@ files:
166
180
  - bin/setup
167
181
  - lib/textbringer/modes/presentation_mode.rb
168
182
  - lib/textbringer/presentation.rb
183
+ - lib/textbringer/presentation/commands.rb
169
184
  - lib/textbringer/presentation/slide_list.rb
170
185
  - lib/textbringer/presentation/version.rb
171
186
  - lib/textbringer_plugin.rb
@@ -189,10 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
204
  - !ruby/object:Gem::Version
190
205
  version: '0'
191
206
  requirements: []
192
- rubyforge_project:
193
- rubygems_version: 2.6.10
207
+ rubygems_version: 3.1.0.pre1
194
208
  signing_key:
195
209
  specification_version: 4
196
210
  summary: Presentation mode for Textbringer.
197
211
  test_files: []
198
- has_rdoc: