pppt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1e80ca92eff95dbc7b56f6d44499f28ddc1729f
4
+ data.tar.gz: 0dd55ef56f991d77124a263ee28ece9d763273c8
5
+ SHA512:
6
+ metadata.gz: 6795fbbb55691b03b9c6ca3aa00a69c7bb23bbb17c3f34130e806966f22ad89c7505c36d1b229f7c6d065f289942182375de75131f523a97a1e6d9e9381dfb0b
7
+ data.tar.gz: 3079cda4dfedb58ea8d2e38f5859c759da0ec2343f2fbd85983cf6285bac183e82252373dba8bc77b6b0e3cdf40b5ebd8ccbc171a2569511ea29730e20abd4b3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ # 自動生成されるものはチェック対象から除外する
2
+ AllCops:
3
+ Exclude:
4
+ - "vendor/**/*" # rubocop config/default.yml
5
+ - "db/schema.rb"
6
+ - "pppt.gemspec"
7
+ DisplayCopNames: true
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pppt.gemspec
4
+ gemspec
5
+
6
+ gem 'rubocop'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ma2saka
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,30 @@
1
+ # Pppt (Poor Point Presentation Tool)
2
+
3
+ Simple presentation tool on console.
4
+
5
+ ## Installation
6
+
7
+ install it yourself as:
8
+
9
+ $ gem install pppt
10
+
11
+ ## Usage
12
+
13
+ Default presentation file is "presentation.yml"
14
+
15
+ $ pppt init
16
+ $ pppt show
17
+
18
+ You can specify for presentation file.
19
+
20
+ $ pppt init my.yml
21
+ $ pppt show my.yml
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ma2saka/pppt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
30
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pppt'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/pppt ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ #-*- coding:utf-8 -*-
3
+ require 'yaml'
4
+ require 'pppt'
5
+ require 'thor'
6
+
7
+ # Pppt Command Line Application
8
+ class App < Thor
9
+ desc 'show', 'show presentaion (default input: presentaion.yml)'
10
+ def show(file = 'presentaion.yml')
11
+ unless File.exist?(file)
12
+ STDERR.puts "pppt: #{file}: No such file"
13
+ exit 1
14
+ end
15
+
16
+ data = YAML.load(open(file))
17
+ ::Presentation.new(data).run
18
+ end
19
+
20
+ desc 'init', 'create presentation template'
21
+ def init(filename = 'presentaion.yml')
22
+ if File.exist?(filename)
23
+ STDERR.puts "pppt: #{filename}: File Already Exists."
24
+ exit 1
25
+ end
26
+ content = <<EOF
27
+ - action: logo
28
+
29
+ - action: Jacket
30
+ h1: Sample Presentation
31
+ h2: #{Date.today} < Your Name >
32
+
33
+ - h3: Sub Title
34
+
35
+ - title: Hello Sample Presentation
36
+ body:
37
+ - Operation Arrow keys, Spacebar, Enter, and BS.
38
+ - '"l" : show page list.'
39
+ - '":q" : quit.'
40
+
41
+ - title: Nested List Style
42
+ body:
43
+ - level 1
44
+ -
45
+ - level 2 -1
46
+ - level 2 -2
47
+ - level 2 -3
48
+ -
49
+ -
50
+ - level 3 -1
51
+ - level 3 -3
52
+
53
+ - title: Multiline text
54
+ body:
55
+ - multi line string support.
56
+ - |
57
+ """fibo
58
+ """
59
+ def fibo(n):
60
+ if n == 0 or n == 1: return 1
61
+ return fibo(n - 1) + fibo(n - 2)
62
+
63
+ - h3: Thank you!
64
+
65
+ EOF
66
+ File.write(filename, content)
67
+ STDOUT.puts "pppt: #{filename}: Created"
68
+ end
69
+ end
70
+
71
+ App.start
data/lib/pppt.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'pppt/version'
2
+ require 'pppt/presentation'
@@ -0,0 +1,30 @@
1
+ class Helpers
2
+ def self.truncate_screen_width(str, width, suffix = '...')
3
+ i = 0
4
+ str.each_char.inject(0) do |c, x|
5
+ c += x.ascii_only? ? 1 : 2
6
+ i += 1
7
+ next c if c < width
8
+ return str[0, i] + suffix
9
+ end
10
+ str
11
+ end
12
+
13
+ def self.split_screen_width(str, width = 40)
14
+ s = i = r = 0
15
+ str.each_char.inject([]) do |res, c|
16
+ i += c.ascii_only? ? 1 : 2
17
+ r += 1
18
+ next res if i < width
19
+ res << str[s, r]
20
+ s += r
21
+ i = r = 0
22
+ res
23
+ end << str[s, r]
24
+ end
25
+
26
+ def self.screen_width(str)
27
+ hankaku_len = str.each_char.count(&:ascii_only?)
28
+ hankaku_len + (str.size - hankaku_len) * 2
29
+ end
30
+ end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/ruby
2
+ require 'curses'
3
+ require 'pppt/helpers'
4
+ require 'pppt/presentation_pages'
5
+ require 'pppt/presentation_window'
6
+ include Curses
7
+
8
+ class Presentation
9
+ def initialize(pages)
10
+ @window = PresentationWindow.new(pages)
11
+ @prev_ch = nil
12
+ Curses.stdscr.keypad(true)
13
+ Curses.noecho
14
+ Curses.curs_set(0)
15
+ Curses.timeout = 1000
16
+ end
17
+
18
+ def run
19
+ loop do
20
+ @window.show
21
+ c = getch
22
+ case c
23
+ when 'l'
24
+ @window.index
25
+ when ':'
26
+ cmd = input
27
+ case cmd
28
+ when 'list', 'l'
29
+ @window.index
30
+ when 'q', 'exit'
31
+ exit
32
+ end
33
+ next
34
+ when 'k', Curses::KEY_UP, Curses::KEY_LEFT, 8
35
+ @window.prev
36
+ when ' ', 'j', Curses::KEY_RIGHT, Curses::KEY_DOWN, 10
37
+ @window.next
38
+ end
39
+ end
40
+ end
41
+
42
+ def getch
43
+ @prev_ch = Curses.stdscr.getch
44
+ end
45
+
46
+ def input
47
+ Curses.timeout = -1
48
+ setpos(Curses.stdscr.maxy - 1, 0)
49
+ Curses.stdscr.deleteln
50
+ Curses.stdscr.addstr(':')
51
+ Curses.echo
52
+ Curses.curs_set(2)
53
+ buf = Curses.stdscr.getstr
54
+ Curses.curs_set(0)
55
+ Curses.noecho
56
+ Curses.timeout = 1000
57
+ @prev_input = buf.chomp
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ class PresentationPages
2
+ attr_reader :data, :size
3
+ def initialize(pages)
4
+ @data = pages
5
+ i = 0
6
+ pages.each { |x| x['page'] = i += 1 unless x['action'] }
7
+ @size = i
8
+ end
9
+ end
@@ -0,0 +1,184 @@
1
+ class PresentationWindow
2
+ def initialize(data)
3
+ @pages = PresentationPages.new(data)
4
+ @current = 0
5
+ @max = @pages.size
6
+ init_screen
7
+ end
8
+
9
+ def next
10
+ @current += 1 if @pages.data.length - 1 > @current
11
+ end
12
+
13
+ def prev
14
+ @current -= 1 if @current > 0
15
+ end
16
+
17
+ def show(page = nil)
18
+ @current = page || @current
19
+ page_data = @pages.data[@current]
20
+ update_window(Curses.stdscr, page_data)
21
+ end
22
+
23
+ # 目次ページ
24
+ def index
25
+ w = Curses.stdscr
26
+ current = @current
27
+ start_point = current - w.maxy / 2
28
+ loop do
29
+ height = w.maxy - 5
30
+ w.clear
31
+ w.setpos(1, 0)
32
+ w.addstr(' -- index --'.center(w.maxx - 1))
33
+ vindex = 3
34
+ start_point = current if start_point > current
35
+ start_point = current - height if current - start_point >= height
36
+ start_point = 0 if start_point < 0
37
+ @pages.data.each_with_index do |page, i|
38
+ next if i < start_point
39
+ w.setpos(vindex, 0)
40
+ w.addstr(' ' * w.maxx)
41
+ w.setpos(vindex, 3)
42
+ w.standout if i == current
43
+ page_string = page_to_string(page)
44
+ w.addstr(page_string + (' ' * (w.maxx - Helpers.screen_width(page_string) - 4)))
45
+ vindex += 1
46
+ w.standend if i == current
47
+ break if i >= start_point + height
48
+ end
49
+ w.refresh
50
+ Curses.timeout = -1
51
+ c = w.getch
52
+ Curses.timeout = 1000
53
+ case c
54
+ when 27, 8
55
+ return current
56
+ when Curses::KEY_UP, 'k'
57
+ current -= 1 if current > 0
58
+ when Curses::KEY_DOWN, 'j'
59
+ current += 1 if current < @pages.data.length - 1
60
+ when 10, ' '
61
+ @current = current
62
+ return current
63
+ end
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ # window 全体を再描画
70
+ def update_window(w, page_data)
71
+ return unless page_data
72
+ w.clear
73
+ w.setpos(0, 0)
74
+ page_data.each do |k, v|
75
+ next unless v
76
+ write_element(w, k, v)
77
+ end
78
+ render_time(w)
79
+ w.refresh
80
+ end
81
+
82
+ # 画面右上の時刻表示
83
+ def render_time(w)
84
+ w.setpos(1, w.maxx - 10)
85
+ w.addstr(Time.now.strftime('%H:%M:%S'))
86
+ end
87
+
88
+ # 目次ページでのページ番号の整形
89
+ def page_to_string(page)
90
+ index = page['page'] || '-'
91
+ title = page['action'] || (page['title'] && " - #{page['title']}") || page['h1'] || page['h2'] || page['h3'] || (page['body'] && " #{Helpers.truncate_screen_width(page['body'].join(''), 15)}")
92
+ format('%02s %s', index, title)
93
+ end
94
+
95
+ # ページコンテンツを表示する
96
+ def write_element(w, k, v)
97
+ len = 1
98
+ len = Helpers.screen_width(v) if v.is_a? String
99
+ width = w.maxx - 1
100
+ pad = ' ' * ((width - len) / 2)
101
+ case k
102
+ when 'action'
103
+ if v == 'logo'
104
+ text = 'powered by POOR POINT 1.0'
105
+ w.setpos((w.maxy / 2) - 2, (w.maxx - text.length) / 2)
106
+ if !@started
107
+ text.each_char do |c|
108
+ w.addstr(c)
109
+ w.refresh
110
+ sleep 0.05
111
+ end
112
+ sleep 0.5
113
+ @started = true
114
+ else
115
+ w.addstr(text)
116
+ end
117
+ w.setpos(w.maxy - 5, 0)
118
+ w.attron(Curses::A_BLINK)
119
+ w.addstr('<< STAND BY >>'.center(w.maxx - 1))
120
+ w.attroff(Curses::A_BLINK)
121
+ end
122
+ when 'h1'
123
+ w.attron(Curses::A_BOLD)
124
+ w.setpos(w.maxy / 3, 0)
125
+ w.addstr("#{pad}#{v}#{pad}")
126
+ w.attroff(Curses::A_BOLD)
127
+ when 'h2'
128
+ w.attron(Curses::A_UNDERLINE)
129
+ w.setpos(w.maxy * 2 / 3, 0)
130
+ w.addstr("#{pad}#{v}#{pad}")
131
+ w.attroff(Curses::A_UNDERLINE)
132
+ when 'h3'
133
+ vindex = 0
134
+ v.split("\n").each do |x|
135
+ x.chomp!
136
+ w.setpos((w.maxy / 2) - 2 + vindex, 0)
137
+ len = Helpers.screen_width(x)
138
+ pad = ' ' * ((width - len) / 2)
139
+ w.addstr("#{pad}#{x}#{pad}")
140
+ vindex += 1
141
+ end
142
+ when 'title'
143
+ w.attron(Curses::A_BOLD)
144
+ w.setpos(1, 2)
145
+ w.addstr(v)
146
+ w.setpos(3, 0)
147
+ w.attroff(Curses::A_BOLD)
148
+ w.attron(Curses::A_REVERSE)
149
+ w.addstr(' ' * w.maxx)
150
+ w.attroff(Curses::A_REVERSE)
151
+ when 'body'
152
+ vindex = 5
153
+ w.setpos(vindex, 2)
154
+ v.each do |line|
155
+ vindex = render_line(w, line, vindex, 1)
156
+ end
157
+ when 'page'
158
+ w.setpos(w.maxy - 2, 0)
159
+ w.addstr("- #{v}/#{@max} -".center(w.maxx - 1))
160
+ end
161
+ end
162
+
163
+ def render_line(w, lines, vindex, level)
164
+ width = w.maxx - 4
165
+ vi = vindex + 1
166
+ if lines.is_a? Array
167
+ lines.each do |sub_line|
168
+ vi = render_line(w, sub_line, vi, level + 1)
169
+ end
170
+ else
171
+ sp = ['*', '-', '>'][level - 1]
172
+ indent = ' ' * (level * 2)
173
+ lines.split("\n").each do |x|
174
+ Helpers.split_screen_width(x, width - (4 + 4 * level)).each do |xl|
175
+ w.setpos(vi, 2)
176
+ w.addstr("#{indent}#{sp} #{xl}")
177
+ sp = ' '
178
+ vi += 1
179
+ end
180
+ end
181
+ end
182
+ vi
183
+ end
184
+ end
@@ -0,0 +1,3 @@
1
+ module Pppt
2
+ VERSION = '0.0.1'
3
+ end
data/pppt.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pppt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pppt'
8
+ spec.version = Pppt::VERSION
9
+ spec.authors = ['ma2saka']
10
+ spec.email = ['takashi.matsusaka@me.com']
11
+
12
+ spec.summary = 'Simple presentation tool on text console.'
13
+ spec.description = 'Simple presentation tool on text console. (Curses Based)'
14
+ spec.homepage = 'https://github.com/ma2saka/pppt'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.10'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_dependency 'curses'
33
+ spec.add_dependency 'thor'
34
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pppt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ma2saka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: curses
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Simple presentation tool on text console. (Curses Based)
70
+ email:
71
+ - takashi.matsusaka@me.com
72
+ executables:
73
+ - pppt
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/pppt
87
+ - lib/pppt.rb
88
+ - lib/pppt/helpers.rb
89
+ - lib/pppt/presentation.rb
90
+ - lib/pppt/presentation_pages.rb
91
+ - lib/pppt/presentation_window.rb
92
+ - lib/pppt/version.rb
93
+ - pppt.gemspec
94
+ homepage: https://github.com/ma2saka/pppt
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Simple presentation tool on text console.
118
+ test_files: []