terminal_calendar 0.1.0

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.
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+ require 'tty-prompt'
3
+
4
+ module TTY
5
+ class Prompt
6
+ class Carousel
7
+ extend Forwardable
8
+ attr_accessor :option_style
9
+
10
+ DEFAULT_KEY_MAP = {
11
+ left: :left,
12
+ right: :right,
13
+ end_keys: [:return]
14
+ }.freeze
15
+
16
+ # rubocop:disable Metrics/MethodLength
17
+ def initialize(options, start_at: 0, key_map: DEFAULT_KEY_MAP,
18
+ input: $stdin, output: $stdout, env: ENV, interrupt: :error,
19
+ track_history: true, option_style: nil, margin: 0, padding: 2)
20
+ @reader = TTY::Reader.new(
21
+ input: input,
22
+ output: output,
23
+ interrupt: interrupt,
24
+ track_history: track_history,
25
+ env: env
26
+ )
27
+ @key_map = DEFAULT_KEY_MAP.merge(key_map)
28
+ @output = output
29
+ @options = options
30
+ @max_option_length = @options.map(&:length).max
31
+ @padding = padding
32
+ @content_size = @padding + @max_option_length + @padding
33
+ @current_index = start_at
34
+ @cursor = TTY::Cursor
35
+ @pastel = Pastel.new
36
+ @option_style = option_style
37
+ @margin = margin
38
+ end
39
+ # rubocop:enable Metrics/MethodLength
40
+
41
+ def select
42
+ render
43
+ capture_keys
44
+ end
45
+
46
+ def render
47
+ output.print("#{' ' * margin}#{left_arrow}#{content}#{right_arrow}")
48
+ end
49
+
50
+ def content
51
+ padding = content_size - selected_option.length
52
+ padding_left = padding / 2
53
+ padding_right = padding - padding_left
54
+ (' ' * padding_left) + style_option + (' ' * padding_right)
55
+ end
56
+
57
+ def move_left
58
+ @current_index -= 1
59
+ @current_index = @options.length - 1 if current_index.negative?
60
+ end
61
+
62
+ def move_right
63
+ @current_index += 1
64
+ @current_index = 0 if current_index >= options.length
65
+ end
66
+
67
+ def redraw
68
+ output.print(clear_lines(1))
69
+ render
70
+ end
71
+
72
+ def selected_option
73
+ options[current_index]
74
+ end
75
+
76
+ private
77
+
78
+ def capture_keys
79
+ loop do
80
+ press = reader.read_keypress
81
+ kp = TTY::Reader::Keys.keys.fetch(press) { press }
82
+ case kp
83
+ when key_map[:left]
84
+ move_left
85
+ redraw
86
+ when key_map[:right]
87
+ move_right
88
+ redraw
89
+ when *key_map[:end_keys]
90
+ @output.puts
91
+ break
92
+ end
93
+ end
94
+ end
95
+
96
+ def left_arrow
97
+ TTY::Prompt::Symbols::KEYS.fetch(:arrow_left)
98
+ end
99
+
100
+ def right_arrow
101
+ TTY::Prompt::Symbols::KEYS.fetch(:arrow_right)
102
+ end
103
+
104
+ def style_option
105
+ return selected_option unless option_style
106
+
107
+ pastel.decorate(selected_option, *option_style)
108
+ end
109
+
110
+ attr_reader :reader, :key_map, :options, :pastel, :current_index, :output, :content_size, :margin
111
+
112
+ def_delegator :@cursor, :clear_lines
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,4 @@
1
+ class TerminalCalendar
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/terminal_calendar/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'terminal_calendar'
7
+ spec.version = TerminalCalendar::VERSION
8
+ spec.authors = ['Michael Cordell']
9
+ spec.email = ['mike@mikecordell.com']
10
+
11
+ spec.summary = 'Terminal Calendar'
12
+ spec.description = 'Utility for manipulating a calendar in the command line'
13
+ spec.homepage = 'https://github.com/mcordell/terminal_calendar'
14
+ spec.required_ruby_version = '>= 2.5.0'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/mcordell/terminal_calendar'
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (File.expand_path(f) == __FILE__) ||
24
+ f.start_with?(*%w(bin/ test/ spec/ features/ .git .circleci appveyor Gemfile))
25
+ end
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ spec.add_dependency 'tty-box', '~> 0.7', '>= 0.7.0'
33
+ spec.add_dependency 'tty-cursor', '~> 0.7', '>= 0.7.0'
34
+ spec.add_dependency 'tty-prompt', '~> 0.23', '>= 0.23.1'
35
+ spec.add_dependency 'tty-reader', '~> 0.9', '>= 0.9.0'
36
+ spec.cert_chain = ['certs/mcordell.pem']
37
+ spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
38
+
39
+ # For more information and examples about making a new gem, check out our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ spec.metadata['rubygems_mfa_required'] = 'true'
42
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terminal_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Cordell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEeDCCAuCgAwIBAgIBATANBgkqhkiG9w0BAQsFADBBMQ0wCwYDVQQDDARtaWtl
14
+ MRswGQYKCZImiZPyLGQBGRYLbWlrZWNvcmRlbGwxEzARBgoJkiaJk/IsZAEZFgNj
15
+ b20wHhcNMjMwODI2MjMzMjA0WhcNMjQwODI1MjMzMjA0WjBBMQ0wCwYDVQQDDARt
16
+ aWtlMRswGQYKCZImiZPyLGQBGRYLbWlrZWNvcmRlbGwxEzARBgoJkiaJk/IsZAEZ
17
+ FgNjb20wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAw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MavH70GYYej3HdahEu8CjuwGMykA/jww0F+p60QvoGZOcg3hkQRUdT
34
+ oD3LQJLiK+oNexJ0i/rh1pbCMAq1sjGFGyv2ACBn+KEmmLzkDgldJfDyyOtOgomB
35
+ sHCLzDW9qhsvbL8U+XYT0o7iwdtzH6ql3vTd5mxENXSOC9rVMI2amNAJkuwpJvCA
36
+ ZDG8uvZdWY9MZGDjweK0/9rt/PItld9RW4EQJxwgyu/yU1giVs/0wZib+Uw=
37
+ -----END CERTIFICATE-----
38
+ date: 2023-08-26 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: tty-box
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.7'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.7.0
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.7'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.7.0
60
+ - !ruby/object:Gem::Dependency
61
+ name: tty-cursor
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.7'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.7.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.7'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 0.7.0
80
+ - !ruby/object:Gem::Dependency
81
+ name: tty-prompt
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '0.23'
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.23.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.23'
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.23.1
100
+ - !ruby/object:Gem::Dependency
101
+ name: tty-reader
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '0.9'
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.0
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.9'
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 0.9.0
120
+ description: Utility for manipulating a calendar in the command line
121
+ email:
122
+ - mike@mikecordell.com
123
+ executables: []
124
+ extensions: []
125
+ extra_rdoc_files: []
126
+ files:
127
+ - ".rspec"
128
+ - ".ruby-version"
129
+ - LICENSE
130
+ - README.md
131
+ - Rakefile
132
+ - _doc/cal-screenshot.png
133
+ - _doc/date-picker.gif
134
+ - certs/mcordell.pem
135
+ - lib/date_extensions.rb
136
+ - lib/terminal_calendar.rb
137
+ - lib/terminal_calendar/date_picker.rb
138
+ - lib/terminal_calendar/month.rb
139
+ - lib/terminal_calendar/month/calendar_day.rb
140
+ - lib/terminal_calendar/selection/cell.rb
141
+ - lib/terminal_calendar/selection/grid.rb
142
+ - lib/terminal_calendar/selection/month_page.rb
143
+ - lib/terminal_calendar/selection/month_year_dialog.rb
144
+ - lib/terminal_calendar/selection/null_cell.rb
145
+ - lib/terminal_calendar/selection/selector.rb
146
+ - lib/terminal_calendar/version.rb
147
+ - lib/tty/prompt/carousel.rb
148
+ - sig/terminal_calendar.rbs
149
+ - terminal_calendar.gemspec
150
+ homepage: https://github.com/mcordell/terminal_calendar
151
+ licenses:
152
+ - MIT
153
+ metadata:
154
+ homepage_uri: https://github.com/mcordell/terminal_calendar
155
+ source_code_uri: https://github.com/mcordell/terminal_calendar
156
+ rubygems_mfa_required: 'true'
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: 2.5.0
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubygems_version: 3.4.17
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Terminal Calendar
176
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ l�y�����l~�R0��[�.������n�m�ۥ��,��y�6k0D�T�c�L�j�^�ia[4�(`�CA�o��/�ϱEq���4�S�5���2$ �?^&�t��]� ��w�o� �r~�r+�Z�%�A�6����(��J
2
+ +��*�ۯ�t��#Tz[���@ǟ�,+{�.Qk�]�� দ5�