sugarcraft/sugar-calendar

PHP port of EthanEFung/bubble-datepicker — interactive date picker component for terminal UIs. Supports month/year navigation, keyboard navigation, date selection with visual cursor, and customizable styling.

Maintainers

Package info

github.com/sugarcraft/sugar-calendar

pkg:composer/sugarcraft/sugar-calendar

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-05-07 01:29 UTC

This package is not auto-updated.

Last update: 2026-05-07 15:02:44 UTC


README

sugar-calendar

CI codecov Packagist Version License PHP

SugarCalendar

PHP port of EthanEFung/bubble-datepicker — interactive date picker component for terminal UIs. Inspired by the jQuery Datepicker widget.

Features

  • Month/year navigation — prev/next buttons, year select
  • Keyboard navigation — arrow keys, Enter to select, Esc to close
  • Date selection — select/clear a date, visual cursor
  • Today highlight — show current date distinctly
  • Selected date styling — clear visual indicator
  • Pure renderer — outputs ANSI strings, no external TUI framework needed

Install

composer require sugarcraft/sugar-calendar

Quick Start

use SugarCraft\Calendar\Model;
use SugarCraft\Calendar\DatePicker;

$picker = DatePicker::new(new \DateTimeImmutable('2026-05-01'));
$picker = $picker->SelectDate();  // enter "select mode"

echo $picker->View();  // render calendar

Navigation

// Month navigation
$picker = $picker->GoToPreviousMonth();
$picker = $picker->GoToNextMonth();
$picker = $picker->GoToPreviousYear();
$picker = $picker->GoToNextYear();
$picker = $picker->GoToToday();

// Set arbitrary month
$picker = $picker->SetTime(new \DateTimeImmutable('2025-12-01'));

// Selection
$picker = $picker->SelectDate();   // confirm selection
$picker = $picker->ClearDate();    // clear selection

Keyboard Handling

Handle keyboard input by calling the appropriate move methods:

if ($key === 'left')  $picker = $picker->MoveCursorLeft();
if ($key === 'right') $picker = $picker->MoveCursorRight();
if ($key === 'up')    $picker = $picker->MoveCursorUp();
if ($key === 'down')  $picker = $picker->MoveCursorDown();
if ($key === 'enter') $picker = $picker->SelectDate();
if ($key === 'esc')   $picker = $picker->ClearDate();

License

MIT