datepick 1.0.0 → 1.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -2
  3. data/lib/datepick.rb +23 -6
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42e1650fbe65ad40a8bab0a5629d85aa2b43a6b5be8087058058d1f826a05a03
4
- data.tar.gz: eb804269ae096c685567eb409c5c40f158bf0ca4b71ee0c1567f02a1f8caf8af
3
+ metadata.gz: edc0a93673e9ac3916ec8e31ac1cbd6c886dd72699337fe077c5ee59911d3849
4
+ data.tar.gz: 4d2878ff16f75622a85461a5bef192a34ec9cafba94ef9fe59039879afce9467
5
5
  SHA512:
6
- metadata.gz: 924025949e01cb91dd1542542334007883646c5bbb51c6a373b28ff9f58df24eb49b19c5b5534d52fdf39145d64d73937fec5e2bf1b5843c101636bbf088baba
7
- data.tar.gz: 1470fe30803a6860d468c86f1afbbbe1557ebb3a674f7b9ba7c08f964df7320c0e1cc67af57e2f16f271f9e3c741a81bb495970180870c25a8467a8bf5566f1b
6
+ metadata.gz: cea2c7637686272e5a39113b19f572c393a8fb33dbd007a69f4ad5aac26ed1aba36d17c53ad8b1b8697baf3faf055e9e71d940e1a7f23fb83db5649e5219dfff
7
+ data.tar.gz: 56f64ce009db0560b87eef26811dec8ac6f68e3c10761d4b392271d7108d658309db6c4243c3889ffb3ab5e44a2f834a14a109f7d120c561834cfc1b3eb9eca1
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Datepick - Interactive Terminal Date Picker
2
2
 
3
- A powerful, interactive terminal date picker built with Ruby and rcurses. Features vim-style navigation, configurable date formats, multiple month views, and extensive keyboard shortcuts. Perfect for shell scripts and command-line workflows that need date selection.
3
+ [![Gem Version](https://badge.fury.io/rb/datepick.svg)](https://badge.fury.io/rb/datepick)
4
+ [![Ruby](https://img.shields.io/badge/Ruby-CC342D?style=flat&logo=ruby&logoColor=white)](https://www.ruby-lang.org/)
5
+ [![License](https://img.shields.io/badge/License-Public%20Domain-brightgreen.svg)](https://unlicense.org/)
6
+ [![GitHub stars](https://img.shields.io/github/stars/isene/datepick.svg)](https://github.com/isene/datepick/stargazers)
7
+ [![Stay Amazing](https://img.shields.io/badge/Stay-Amazing-blue.svg)](https://isene.org)
8
+
9
+ <img src="img/datepick_logo.svg" align="left" width="150" height="150"> A powerful, interactive terminal date picker built with Ruby and rcurses. Features vim-style navigation, configurable date formats, multiple month views, and extensive keyboard shortcuts. Perfect for shell scripts and command-line workflows that need date selection.
10
+ <br clear="left"/>
4
11
 
5
12
  ## Features
6
13
 
@@ -179,4 +186,4 @@ Created by [Geir Isene](https://isene.com/)
179
186
 
180
187
  - **Homepage**: https://isene.com/
181
188
  - **Source Code**: https://github.com/isene/datepick
182
- - **RubyGems**: https://rubygems.org/gems/datepick
189
+ - **RubyGems**: https://rubygems.org/gems/datepick
data/lib/datepick.rb CHANGED
@@ -41,8 +41,10 @@ class DatePicker
41
41
  @current_month = Date.today
42
42
  @config_mode = false
43
43
  @config_selected = 0
44
- @screen_w = `tput cols`.to_i
45
- @screen_h = `tput lines`.to_i
44
+ @screen_w = (`tput cols`.to_i rescue 0)
45
+ @screen_h = (`tput lines`.to_i rescue 0)
46
+ @screen_w = 80 if @screen_w < 1
47
+ @screen_h = 24 if @screen_h < 1
46
48
 
47
49
  # Initialize panes
48
50
  @main_pane = Rcurses::Pane.new(1, 1, @screen_w, @screen_h - 4, nil, nil)
@@ -115,7 +117,7 @@ class DatePicker
115
117
  @help_pane.refresh
116
118
 
117
119
  # Update status
118
- status_text = "Selected: #{@selected_date.strftime(@config['date_format'])}".fg(@config['colors']['selected'])
120
+ status_text = "Selected: #{safe_strftime(@selected_date, @config['date_format'])}".fg(@config['colors']['selected'])
119
121
  @status_pane.text = status_text
120
122
  @status_pane.refresh
121
123
  end
@@ -323,7 +325,7 @@ class DatePicker
323
325
  @prev_content = "" # Force refresh
324
326
  when 'ENTER'
325
327
  Rcurses.cleanup!
326
- puts @selected_date.strftime(@config['date_format'])
328
+ puts safe_strftime(@selected_date, @config['date_format'])
327
329
  exit
328
330
  when 'LEFT', 'h', 'H'
329
331
  @selected_date = @selected_date.prev_day
@@ -421,13 +423,22 @@ class DatePicker
421
423
  def handle_config_edit
422
424
  case @config_selected
423
425
  when 0 # Date format
424
- format_help = DATE_FORMATS.map { |k, v| "#{k}: #{Date.today.strftime(v)}" }.join(" | ")
426
+ format_help = DATE_FORMATS.map { |k, v| "#{k}: #{safe_strftime(Date.today, v)}" }.join(" | ")
425
427
  new_format = get_input_with_help("Date format", @config['date_format'], format_help)
426
428
  # Check if user entered a number for quick format selection
427
429
  if new_format && DATE_FORMATS[new_format]
428
430
  @config['date_format'] = DATE_FORMATS[new_format]
429
431
  elsif new_format && !new_format.empty?
430
- @config['date_format'] = new_format
432
+ # Validate the custom format string before accepting it
433
+ begin
434
+ result = Date.today.strftime(new_format)
435
+ # Must produce at least one digit (any useful date format does)
436
+ if result.match?(/\d/)
437
+ @config['date_format'] = new_format
438
+ end
439
+ rescue ArgumentError
440
+ # Invalid format string; keep the old one
441
+ end
431
442
  end
432
443
  @prev_content = "" # Force refresh to show new value
433
444
  when 1 # Months before
@@ -495,6 +506,12 @@ class DatePicker
495
506
  result.strip
496
507
  end
497
508
 
509
+ def safe_strftime(date, fmt)
510
+ date.strftime(fmt)
511
+ rescue ArgumentError
512
+ date.strftime('%Y-%m-%d') + ' [invalid format]'
513
+ end
514
+
498
515
  def update_current_month
499
516
  @current_month = Date.new(@selected_date.year, @selected_date.month, 1)
500
517
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datepick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-01 00:00:00.000000000 Z
11
+ date: 2026-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rcurses
@@ -16,18 +16,18 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.8'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.8'
27
- description: A powerful interactive terminal date picker built with rcurses. Features
26
+ version: '6.0'
27
+ description: 'A powerful interactive terminal date picker built with rcurses. Features
28
28
  vim-style navigation, configurable date formats, multiple month views, and extensive
29
29
  keyboard shortcuts. Perfect for shell scripts and command-line workflows that need
30
- date selection.
30
+ date selection. Version 1.1.1: Add date format validation and terminal size fallback.'
31
31
  email: g@isene.com
32
32
  executables:
33
33
  - datepick