datepick 1.1.0 → 1.1.2

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 +29 -12
  4. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ceff8901a135cf452aa4495b5145971ec30e69419cbd9a51b698b7a8f7324eb3
4
- data.tar.gz: 6cc4d3696f07aa9f505242c3455555df3fabed9e21ef5a8860d18ad77189acb4
3
+ metadata.gz: 36cdf3d1d78d3ac572e1c6564502e48669d967e3236794517c9d1fb8d1df6bce
4
+ data.tar.gz: ad6b3fb22029f3a9fe6ab07a050385f9e48bf91a9d11ce183bf9e54dd8b1f51f
5
5
  SHA512:
6
- metadata.gz: 708291522000ccfb8fa01ed63244d3f9c35227fd1bf3542901d8bd5349ecb16411ff01bef9e32e07b6835a546a80d09b2b50818ab226ddc03987775a3ba6fa15
7
- data.tar.gz: ea6877a3c756f81a71c327456d6d471e1f207a712a84e22f89993e08f028342982fad25a172da23ffaef197002e0203e3d0faa6177bb1fde7d823d2e20635902
6
+ metadata.gz: ec1afd6f3b996517951a3d3e45631d8e7d50b4e9589ae6941cf00d761773ed004bc7360675ad99f2bffee59f135d5fbc4f79c2d105a5ee28514b9473f17430a1
7
+ data.tar.gz: 53a6ff7642a64a8400e1589f1068925ef177b5d0743468ab05eb772b4a2ca77657b8b267da0c947bcf40f09b6c8f43228eda92922258362b4e374ac06a53d564
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
@@ -168,7 +170,7 @@ class DatePicker
168
170
  month_str = month_date.strftime("%B %Y")
169
171
  # Highlight current month with bold and underline
170
172
  if month_date.year == Date.today.year && month_date.month == Date.today.month
171
- month_str = month_str.fg(@config['colors']['month']).b.u
173
+ month_str = month_str.fg(@config['colors']['month']).bd.ul
172
174
  else
173
175
  month_str = month_str.fg(@config['colors']['month'])
174
176
  end
@@ -182,9 +184,9 @@ class DatePicker
182
184
  days = @config['week_starts_monday'] ? %w[Mo Tu We Th Fr Sa Su] : %w[Su Mo Tu We Th Fr Sa]
183
185
  days.each_with_index do |day, idx|
184
186
  # Use darker colors for day headers and make them bold
185
- color = ((@config['week_starts_monday'] && idx >= 5) || (!@config['week_starts_monday'] && (idx == 0 || idx == 6))) ?
187
+ color = ((@config['week_starts_monday'] && idx >= 5) || (!@config['week_starts_monday'] && (idx == 0 || idx == 6))) ?
186
188
  88 : 244 # Dark red for weekends, dark gray for weekdays
187
- day_header_line += day.fg(color).b + " "
189
+ day_header_line += day.fg(color).bd + " "
188
190
  end
189
191
  day_header_line += " " # Extra space between months
190
192
  end
@@ -205,9 +207,9 @@ class DatePicker
205
207
 
206
208
  # Apply styling
207
209
  if date == @selected_date
208
- day_str = day_str.fb(@config['colors']['selected'], 236).b
210
+ day_str = day_str.fb(@config['colors']['selected'], 236).bd
209
211
  elsif date == Date.today
210
- day_str = day_str.fg(@config['colors']['today']).b
212
+ day_str = day_str.fg(@config['colors']['today']).bd
211
213
  elsif date.saturday? || date.sunday?
212
214
  day_str = day_str.fg(@config['colors']['weekend'])
213
215
  else
@@ -278,7 +280,7 @@ class DatePicker
278
280
 
279
281
  lines = []
280
282
  lines << ""
281
- lines << "Configuration".fg(@config['colors']['year']).b
283
+ lines << "Configuration".fg(@config['colors']['year']).bd
282
284
  lines << ""
283
285
 
284
286
  config_items.each_with_index do |(label, value), idx|
@@ -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.1.0
4
+ version: 1.1.2
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-08-15 00:00:00.000000000 Z
11
+ date: 2026-04-11 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: '6.0'
19
+ version: '7.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: '6.0'
26
+ version: '7.0'
27
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. Version 1.1.0: Updated for rcurses 6.0.0 compatibility.'
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