fullscreen_tui 0.1.0

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
+ SHA256:
3
+ metadata.gz: e18910035ac6cba870a3a6e75c5b1a2d44a711481c4af6de6da68ab151e0a801
4
+ data.tar.gz: 5876fb56e1136f720eaca08841cb61c90625949d6e9677b7fac659be9a0527ac
5
+ SHA512:
6
+ metadata.gz: 8b50cf1d96d88510c4a6d0702fcf6e366abbbaa847cf227acc86c72987e0d8eab1c2c348d7deb5f93297acf714e547c0402439654e21f769c9fa29861849d94a
7
+ data.tar.gz: c5b5c1ffe1325d60bb535c6c2c3f5245e1a4830fb2c8ca6b40472f9833c3ba01d46b344560d78882c478cf3e3b9dcbd5e4bbf6ee9f54f3a31b9fb18a4d74b9f8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /vendor/bundle
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,11 @@
1
+ image: ruby:2.5.1
2
+
3
+ before_script:
4
+ - bundle install --path /cache
5
+
6
+ cache:
7
+ paths:
8
+ - /cache
9
+
10
+ rubocop:
11
+ script: bundle exec rubocop
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ ThunderKey-rubocop: rubocop.yml
@@ -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 nicolas@keltec.ch. 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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in fullscreen_tui.gemspec
8
+ gemspec
9
+
10
+ gem 'ThunderKey-rubocop'
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fullscreen_tui (0.1.0)
5
+ colorize (~> 0.8)
6
+ ruby-terminfo (~> 0.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ThunderKey-rubocop (0.0.9)
12
+ rubocop (~> 0.59)
13
+ rubocop-rspec (~> 1.30)
14
+ ast (2.4.0)
15
+ colorize (0.8.1)
16
+ jaro_winkler (1.5.1)
17
+ parallel (1.12.1)
18
+ parser (2.5.3.0)
19
+ ast (~> 2.4.0)
20
+ powerpack (0.1.2)
21
+ rainbow (3.0.0)
22
+ rake (10.5.0)
23
+ rubocop (0.61.1)
24
+ jaro_winkler (~> 1.5.1)
25
+ parallel (~> 1.10)
26
+ parser (>= 2.5, != 2.5.1.1)
27
+ powerpack (~> 0.1)
28
+ rainbow (>= 2.2.2, < 4.0)
29
+ ruby-progressbar (~> 1.7)
30
+ unicode-display_width (~> 1.4.0)
31
+ rubocop-rspec (1.30.1)
32
+ rubocop (>= 0.60.0)
33
+ ruby-progressbar (1.10.0)
34
+ ruby-terminfo (0.1.1)
35
+ unicode-display_width (1.4.1)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ ThunderKey-rubocop
42
+ bundler (~> 1.16)
43
+ fullscreen_tui!
44
+ rake (~> 10.0)
45
+
46
+ BUNDLED WITH
47
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Nicolas Ganz
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,43 @@
1
+ # FullscreenTui
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fullscreen_tui`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fullscreen_tui'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fullscreen_tui
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fullscreen_tui. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the FullscreenTui project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fullscreen_tui/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'fullscreen_tui'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require 'pry'
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/example ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'fullscreen_tui'
6
+
7
+ class Example < FullscreenTui
8
+ def initialize
9
+ @lines = (1..40).map {|i| "some test #{i} " * 10 }
10
+ super headers: [] # ['Example', 'For FullscreenTui']
11
+ end
12
+
13
+ def key_press key
14
+ case key
15
+ when 'a' then @footer.message += "you've pressed a"
16
+ else super
17
+ end
18
+ end
19
+ end
20
+
21
+ Example.new.run
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'fullscreen_tui/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'fullscreen_tui'
9
+ spec.version = FullscreenTui::VERSION
10
+ spec.authors = ['Nicolas Ganz']
11
+ spec.email = ['nicolas@keltec.ch']
12
+
13
+ spec.summary = 'A simple fullscreen wrapper for terminal uis'
14
+ spec.homepage = 'https://gitlab.com/ThunderKey/fullscreen_tui'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'colorize', '~> 0.8'
25
+ spec.add_dependency 'ruby-terminfo', '~> 0.1'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.16'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'terminfo'
4
+ require 'io/console'
5
+ require 'English'
6
+ require_relative 'fullscreen_tui/header'
7
+ require_relative 'fullscreen_tui/footer'
8
+ require_relative 'fullscreen_tui/renderer'
9
+
10
+ class FullscreenTui
11
+ def initialize headers:, renderer: nil
12
+ @header = Header.new headers
13
+ @footer = Footer.new
14
+ @selection = 0
15
+ @renderer = renderer || Renderer.new
16
+ end
17
+
18
+ def run
19
+ catch :quit do
20
+ loop do
21
+ print_screen
22
+ react
23
+ end
24
+ end
25
+ end
26
+
27
+ def print_screen
28
+ clear
29
+
30
+ lines, columns = TermInfo.screen_size
31
+
32
+ header = @header.output
33
+ lines -= required_lines header, columns
34
+ footer = @footer.output width: columns, lines: @lines.size, current_line: @selection
35
+ lines -= required_lines footer, columns
36
+
37
+ @renderer.header header unless header.empty?
38
+
39
+ print_lines lines, columns
40
+
41
+ @renderer.footer footer
42
+ end
43
+
44
+ def key_press key
45
+ case key
46
+ when :arrow_up then go_up
47
+ when :arrow_down then go_down
48
+ when 'q', "\u0004" then throw :quit # ctrl-d
49
+ else @footer.message = "Unknown key: #{key.inspect}"
50
+ end
51
+ end
52
+
53
+ def selected_line
54
+ @lines[@selection]
55
+ end
56
+
57
+ ARROWS = {
58
+ 'A' => :arrow_up,
59
+ 'B' => :arrow_down,
60
+ 'C' => :arrow_right,
61
+ 'D' => :arrow_left,
62
+ }.freeze
63
+
64
+ def react
65
+ key = case char = STDIN.getch
66
+ when "\u0003" then exit 1
67
+ when "\e"
68
+ case subchar = STDIN.getch
69
+ when '['
70
+ ARROWS.fetch(STDIN.getch) {|k| "\e[#{k}" }
71
+ else "\e#{subchar}"
72
+ end
73
+ else char
74
+ end
75
+ key_press key
76
+ end
77
+
78
+ def go_up
79
+ @footer.message = ''
80
+ return if @selection.zero?
81
+
82
+ @selection -= 1
83
+ end
84
+
85
+ def go_down
86
+ @footer.message = ''
87
+ return if @selection >= @lines.size - 1
88
+
89
+ @selection += 1
90
+ end
91
+
92
+ def read_full_line message
93
+ puts message
94
+ gets
95
+ end
96
+
97
+ private
98
+
99
+ def print_lines lines, columns
100
+ used_lines = 0
101
+ offset = [@selection - 5, 0].max
102
+ @lines[offset..-1].each.with_index do |l, i|
103
+ selected = i + offset == @selection
104
+ line = l.to_s
105
+ used_lines += (line.size.to_f / columns).ceil
106
+ if used_lines > lines
107
+ @renderer.line '...', selected: selected
108
+ break
109
+ end
110
+
111
+ @renderer.line line, selected: selected
112
+ break if used_lines == lines
113
+ end
114
+
115
+ (lines - used_lines).times { @renderer.line '~', selected: false }
116
+ end
117
+
118
+ def required_lines text, columns
119
+ text.split($INPUT_RECORD_SEPARATOR)
120
+ .inject(0) {|sum, line| sum + (line.size.to_f / columns).ceil }
121
+ end
122
+
123
+ def clear
124
+ system(Gem.win_platform? ? 'cls' : 'clear')
125
+ end
126
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FullscreenTui
4
+ class Footer
5
+ attr_accessor :message
6
+ SEPERATOR = ' | '
7
+
8
+ def initialize
9
+ self.message = ''
10
+ end
11
+
12
+ def output width:, lines:, current_line:
13
+ parts = [
14
+ message,
15
+ "#{(current_line + 1).to_s.rjust lines.to_s.size}/#{lines}",
16
+ ]
17
+ part_width = width - parts[1].size - SEPERATOR.size
18
+ parts[0] = if parts[0].size > part_width
19
+ "#{parts[0][0...part_width - 3]}..."
20
+ else
21
+ parts[0].ljust part_width
22
+ end
23
+ parts.join SEPERATOR
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FullscreenTui
4
+ class Header
5
+ attr_accessor :parts
6
+ SEPERATOR = $INPUT_RECORD_SEPARATOR
7
+
8
+ def initialize parts = nil
9
+ self.parts = parts.nil? ? [] : parts
10
+ end
11
+
12
+ def output
13
+ parts.join SEPERATOR
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+
5
+ class FullscreenTui
6
+ class Renderer
7
+ def header line
8
+ puts line
9
+ end
10
+
11
+ def line line, selected:
12
+ puts(selected ? line.underline : line)
13
+ end
14
+
15
+ def footer line
16
+ print line
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FullscreenTui
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fullscreen_tui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Ganz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-terminfo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - nicolas@keltec.ch
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".gitlab-ci.yml"
78
+ - ".rubocop.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/example
87
+ - bin/setup
88
+ - fullscreen_tui.gemspec
89
+ - lib/fullscreen_tui.rb
90
+ - lib/fullscreen_tui/footer.rb
91
+ - lib/fullscreen_tui/header.rb
92
+ - lib/fullscreen_tui/renderer.rb
93
+ - lib/fullscreen_tui/version.rb
94
+ homepage: https://gitlab.com/ThunderKey/fullscreen_tui
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.7.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A simple fullscreen wrapper for terminal uis
118
+ test_files: []