pause_output 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83c19923ca0b37435ae429d19333cee7ecf30e5a
4
+ data.tar.gz: f86703967f428ca682930f17988ac0464f4fe07b
5
+ SHA512:
6
+ metadata.gz: cfa242aa5ca571b682089ca88522e6262cfc7bd11d48d545f4a6ec475d74ee8516c6cd7fab1868acabdca8f54443b5bd0d1fc4539eec1bf3c4eca8a914b854e1
7
+ data.tar.gz: 65a06d93e70e33d4ddb032225608ed9f6162c75c0fc4edcd0ea07862690d6b202e849d14711540b4a17fd324005969d11281bfc7a979fb64384365752844c20a
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at peter.c.camilleri@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pause_output.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 PeterCamilleri
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.
@@ -0,0 +1,89 @@
1
+ # PauseOutput
2
+
3
+ The pause_output gem provides a facility like the classic more (or less) utility
4
+ within Ruby programs. This little bit of code started out as a feature of the
5
+ mysh (my shell) program but was spun off as it was felt that this capability
6
+ had use on a larger scale.
7
+
8
+ Also included is a simple demo program called pom (Pause Output More) This
9
+ simple demo accepts a list of files and displays them, pausing as needed.
10
+ It is as easy to use as this:
11
+
12
+ pom README.md
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'pause_output'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install pause_output
29
+
30
+ ## Usage
31
+
32
+ The pause_output gem works through the more command. This simple command
33
+ accepts optional hash arguments and a block. For example:
34
+
35
+ ```ruby
36
+ more do
37
+ 100.times do |i|
38
+ puts "#{'%5d' % i}, #{'%6d' % (i*i)}, #{'%8d' % (i*i*i)}"
39
+ end
40
+ end
41
+ ```
42
+
43
+ #### Options
44
+
45
+ The following options are available for use in the optional options hash
46
+ parameter of the global Object#more method:
47
+
48
+ Option | Values | Default | Description
49
+ ------------|---------|---------------|----------------
50
+ :page_pause | boolean | true | Is page pause enabled?
51
+ :page_height| integer | console height| The height of the page.
52
+ :page_width | integer | console width | The width of the page.
53
+ :page_msg | string | "Press enter, space or q:" | The paused prompt message.
54
+
55
+ The default value is used if the option is absent from the hash. Unsupported
56
+ option values are ignored and have no effect.
57
+
58
+ Notes:
59
+ * Setting page_pause to false can allow a block of code to run without pausing
60
+ at page breaks, if that is desired.
61
+ * If the :page_height and :page_width values are not valid, the default values
62
+ will be used instead.
63
+ * Nesting of "more" blocks is allowed. However, only the options of the outermost
64
+ block are active. The options passed into "inner" blocks are ignored.
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
73
+
74
+ OR...
75
+
76
+ * Make a suggestion by raising an
77
+ [issue](https://github.com/PeterCamilleri/pause_output/issues)
78
+ . All ideas and comments are welcome.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the
83
+ [MIT License](./LICENSE.txt).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the pause_output project’s codebases, issue trackers,
88
+ chat rooms and mailing lists is expected to follow the
89
+ [code of conduct](./CODE_OF_CONDUCT.md).
data/exe/pom ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The Ruby inspired, ego based, My Shell command line processor.
4
+ #
5
+
6
+ require_relative '..\lib\pause_output'
7
+
8
+ MiniTerm.open(quiet: true, strict: true) unless MiniTerm.term_open?
9
+
10
+ if ARGV[0] == '-h'
11
+ puts "The paused output more gem demo. Version: #{::PauseOutput::VERSION}"
12
+ exit
13
+ end
14
+
15
+ more do
16
+ ARGV.each do |file_name|
17
+ puts "**** File: #{file_name} ****"," "
18
+ puts IO.read(file_name), " "
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+
3
+ require "mini_term"
4
+
5
+ require_relative "pause_output/exceptions"
6
+ require_relative "pause_output/output_pager"
7
+ require_relative "pause_output/globalize"
8
+ require_relative "pause_output/version"
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+
3
+ # The stop output exception.
4
+ class PauseOutputStop < StandardError; end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ #Monkey patches for pause output global entities.
4
+ class Object
5
+
6
+ private
7
+
8
+ # Execute a block with page paused output.
9
+ def more(options={})
10
+ saved = $stdout
11
+
12
+ disabled = options[:page_pause]
13
+ disabled = disabled.downcase if disabled.is_a?(String)
14
+
15
+ unless [false, 'false', 'off', 'no'].include?(disabled)
16
+ outer = $stdout.equal?($pause_output_out)
17
+ $stdout = ::PauseOutput::OutputPager.new(options) if outer
18
+ end
19
+
20
+ yield
21
+
22
+ rescue PauseOutputStop
23
+ raise unless outer
24
+ return
25
+
26
+ ensure
27
+ $stdout = saved
28
+ end
29
+
30
+ end
@@ -0,0 +1,112 @@
1
+ # coding: utf-8
2
+
3
+ $pause_output_out = $stdout # Keep a copy of the real $stdout.
4
+
5
+ module PauseOutput
6
+
7
+ # A class to manage paged output.
8
+ class OutputPager
9
+
10
+ # Set up the initial values.
11
+ def initialize(options={})
12
+ @options = options
13
+ @lines = 0
14
+ @chars = 0
15
+ end
16
+
17
+ # Write out a general string with page pauses.
18
+ def write(str)
19
+ while !str.empty?
20
+ pre,mid,str = str.partition("\n")
21
+ write_str(pre) unless pre.empty?
22
+ writeln unless mid.empty?
23
+ end
24
+ end
25
+
26
+ # Write out an object as a string.
27
+ def <<(obj)
28
+ write(obj.to_s)
29
+ end
30
+
31
+ private
32
+
33
+ # Write out a simple string with no embedded new-lines.
34
+ def write_str(str)
35
+ loop do
36
+ len = str.length
37
+
38
+ if @chars + len < chars_per_line
39
+ $pause_output_out.write(str)
40
+ @chars += len
41
+ return
42
+ else
43
+ tilt = chars_per_line - @chars
44
+ $pause_output_out.write(str[0, tilt])
45
+ count_lines
46
+
47
+ str = (str[tilt..-1])
48
+ end
49
+ end
50
+ end
51
+
52
+ # Write out a new-line.
53
+ def writeln
54
+ $pause_output_out.write("\n")
55
+ count_lines
56
+ end
57
+
58
+ # A new line is out, count it!
59
+ def count_lines
60
+ @chars = 0
61
+ @lines += 1
62
+
63
+ if @lines >= (lines_per_page - 1)
64
+ case pause.downcase
65
+ when " "
66
+ @lines -= 1
67
+ when "q"
68
+ @lines = 0
69
+ raise PauseOutputStop
70
+ else
71
+ @lines = 0
72
+ end
73
+ end
74
+ end
75
+
76
+ # Pause waiting for the user.
77
+ def pause
78
+ msg = pause_message
79
+ $pause_output_out.write(msg)
80
+
81
+ MiniTerm.raw do |term|
82
+ result = term.get_raw_char
83
+ term.flush
84
+ result
85
+ end
86
+
87
+ ensure
88
+ $pause_output_out.write("\r" + " " * msg.length + "\r")
89
+ end
90
+
91
+ # How many lines fit on a page?
92
+ def lines_per_page
93
+ result = @options[:page_height].to_i
94
+ result = MiniTerm.height if result < 2
95
+ result
96
+ end
97
+
98
+ # How many characters fit on a line?
99
+ def chars_per_line
100
+ result = @options[:page_width].to_i
101
+ result = MiniTerm.width if result < 20
102
+ result
103
+ end
104
+
105
+ # Get the text of the pause message.
106
+ def pause_message
107
+ @options.key?(:page_msg) ? @options[:page_msg] : "Press enter, space or q:"
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+
3
+ # Pause console output so that it can be read before scrolling off the screen.
4
+ module PauseOutput
5
+ VERSION = "0.1.0".freeze
6
+
7
+ DESCRIPTION = "pause_output: A simple facility to pause output on the console terminal.".freeze
8
+ end
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "pause_output/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "pause_output"
7
+ spec.version = PauseOutput::VERSION
8
+ spec.authors = ["PeterCamilleri"]
9
+ spec.email = ["peter.c.camilleri@gmail.com"]
10
+
11
+ spec.summary = %q{Pause lengthy console output.}
12
+ spec.description = %q{pause_output: A simple facility to pause output on the console terminal.}
13
+ spec.homepage = "https://github.com/PeterCamilleri/pause_output"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|docs)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec
21
+ .files
22
+ .reject { |f| f.downcase == 'exe/readme.md'}
23
+ .grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency 'minitest_visible', "~> 0.1"
30
+ spec.add_development_dependency 'reek', "~> 5.0.2"
31
+
32
+ spec.add_runtime_dependency 'mini_term', "~> 0.1.0"
33
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env rake
2
+ # coding: utf-8
3
+
4
+ require "bundler/gem_tasks"
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["test/**/*_test.rb"]
11
+ end
12
+
13
+ task :default => :test
14
+
15
+ desc "Run a scan for smelly code!"
16
+ task :reek do |t|
17
+ `reek --no-color lib > reek.txt`
18
+ end
19
+
20
+ desc "What version of pause_output is this?"
21
+ task :vers do |t|
22
+ puts
23
+ puts "pause_output version = #{::PauseOutput::VERSION}"
24
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pause_output
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - PeterCamilleri
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-15 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest_visible
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: reek
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.0.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.0.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: mini_term
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
97
+ description: 'pause_output: A simple facility to pause output on the console terminal.'
98
+ email:
99
+ - peter.c.camilleri@gmail.com
100
+ executables:
101
+ - pom
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - exe/pom
111
+ - lib/pause_output.rb
112
+ - lib/pause_output/exceptions.rb
113
+ - lib/pause_output/globalize.rb
114
+ - lib/pause_output/output_pager.rb
115
+ - lib/pause_output/version.rb
116
+ - pause_output.gemspec
117
+ - rakefile.rb
118
+ homepage: https://github.com/PeterCamilleri/pause_output
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Pause lengthy console output.
142
+ test_files: []