@bhanulabs/desical 0.0.0-stage → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +97 -2
- package/bin/desical.js +256 -0
- package/package.json +42 -4
- package/src/app.js +252 -0
- package/src/astro.js +91 -0
- package/src/festivals.js +322 -0
- package/src/locations.js +61 -0
- package/src/names.js +122 -0
- package/src/panchang.js +246 -0
- package/src/parse.js +60 -0
- package/src/render.js +273 -0
- package/src/time.js +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bhanulabs
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,98 @@
|
|
|
1
|
-
#
|
|
1
|
+
# desical — Telugu calendar (panchangam) for the terminal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Telugu panchangam calendar in your terminal: Gregorian and Telugu dates side by side, tithi,
|
|
4
|
+
nakshatra, yoga, karana, full and new moons, Rahu kalam, and Indian and international festivals.
|
|
5
|
+
All of it is calculated from astronomy for your location. Nothing comes from a lookup table, so
|
|
6
|
+
any year from 1600 to 2400 works.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm install -g @bhanulabs/desical
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or run it without installing: `npx @bhanulabs/desical`.
|
|
13
|
+
|
|
14
|
+
From a clone of this repo:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm install
|
|
18
|
+
npm link # optional: makes the `desical` command available everywhere
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
desical this month: grid with tithi, nakshatra, festivals
|
|
25
|
+
desical jan 2027 any month (also: 2027-01, next, prev)
|
|
26
|
+
desical today today's full panchangam
|
|
27
|
+
desical day 2027-01-15 panchangam for a date (also: tomorrow, "dec 25", 25-12-2026)
|
|
28
|
+
desical year 2027 festivals & holidays for a year (--all adds vratas etc.)
|
|
29
|
+
desical next 15 upcoming festivals
|
|
30
|
+
desical find diwali 2027 find a festival (aliases work: dasara, rakhi, ganesh...)
|
|
31
|
+
desical cities preset cities
|
|
32
|
+
desical config --city vijayawada save a default location
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Interactive mode
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
desical --app opens this month and stays open
|
|
39
|
+
desical day 2027-01-15 --app can also start in the day or year view
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Key | Month view | Day view | Year view |
|
|
43
|
+
|---|---|---|---|
|
|
44
|
+
| ← / → | previous / next month | previous / next day | previous / next year |
|
|
45
|
+
| PgUp / PgDn | previous / next year | previous / next month | previous / next year |
|
|
46
|
+
| ↑ / ↓, Home / End | scroll | scroll | scroll |
|
|
47
|
+
|
|
48
|
+
Anywhere: `m` month, `d` day, `y` year, `t` today, `g` go to a date / month / year
|
|
49
|
+
(`2027-01-15`, `jan 2030`, `2028`), `l` Telugu script on/off, `a` minor events on/off,
|
|
50
|
+
`?` help, `q` quit (`Esc` returns to the month view). The full month grid needs a window
|
|
51
|
+
at least 108 columns wide.
|
|
52
|
+
|
|
53
|
+
Options: `--city`, `--lat/--lon/--tz/--name` (any place, IANA time zone), `--all`,
|
|
54
|
+
`--telugu` (also show Telugu script), `--no-color`, `--json` (for day / year / next / find).
|
|
55
|
+
Output is English by default; `desical config --telugu` makes Telugu script the default
|
|
56
|
+
(`desical config --no-telugu` turns it off again).
|
|
57
|
+
|
|
58
|
+
## What is shown
|
|
59
|
+
|
|
60
|
+
- **Telugu calendar**: samvatsara (60-year cycle), ayanam, ruthuvu, masam (amanta, with
|
|
61
|
+
**Adhika masam**), paksham, vaaram
|
|
62
|
+
- **Panchangam**: tithi, nakshatra, yoga and karana, each with its end time; sunrise, sunset,
|
|
63
|
+
moonrise and moonset; Rahu kalam, Yamagandam, Gulika, Durmuhurtam and Varjyam;
|
|
64
|
+
Abhijit muhurtam and Amrita kalam
|
|
65
|
+
- **Moon & sky**: Pournami and Amavasya, with the exact time; the 12 sankrantis; solar and lunar
|
|
66
|
+
eclipses (grahanam), with whether each one can be seen from your location
|
|
67
|
+
- **Festivals**: Ugadi, Sri Rama Navami, Vinayaka Chavithi, Dasara, Bathukamma, Atla Taddi,
|
|
68
|
+
Deepavali, Nagula Chavithi, Karthika Pournami, Mukkoti Ekadashi, Bhogi, Sankranti, Kanuma,
|
|
69
|
+
Maha Shivaratri, Holi, Varalakshmi Vratam and many more. Also monthly Ekadashi (with names),
|
|
70
|
+
Pradosham, Masa Shivaratri, Sankashti Chaturthi and Karthika Somavaram.
|
|
71
|
+
- **Holidays**: national days, Telangana and AP formation days, Ramzan, Bakrid, Muharram,
|
|
72
|
+
Milad-un-Nabi, Good Friday, Easter, Christmas, New Year, Mother's/Father's Day, Thanksgiving,
|
|
73
|
+
Chinese New Year and more
|
|
74
|
+
|
|
75
|
+
## How it is calculated
|
|
76
|
+
|
|
77
|
+
- Sun and Moon positions come from [astronomy-engine](https://github.com/cosinekitty/astronomy).
|
|
78
|
+
Sidereal positions use the Lahiri (Chitrapaksha) ayanamsa.
|
|
79
|
+
- Months are **amanta**, as in the Telugu calendar. A month is named after the sankranti that
|
|
80
|
+
falls in it. A month with no sankranti is an Adhika masam.
|
|
81
|
+
- The tithi and nakshatra shown for a day are the ones in effect at **local sunrise**.
|
|
82
|
+
- Each festival uses its traditional time of day:
|
|
83
|
+
- sunrise: most festivals
|
|
84
|
+
- madhyahna: Rama Navami, Vinayaka Chavithi
|
|
85
|
+
- aparahna: Vijayadashami
|
|
86
|
+
- pradosha: Deepavali, Narasimha Jayanti
|
|
87
|
+
- nishita: Maha Shivaratri
|
|
88
|
+
- moonrise: Atla Taddi, Sankashti
|
|
89
|
+
|
|
90
|
+
If a tithi never covers that time on any day (a kshaya tithi), the festival goes on the day the
|
|
91
|
+
tithi begins.
|
|
92
|
+
- A sankranti that happens after sunset is observed the next day.
|
|
93
|
+
- Islamic dates are estimated by checking whether the new crescent can be seen. The real dates
|
|
94
|
+
depend on the moon actually being sighted, so they can be off by a day.
|
|
95
|
+
|
|
96
|
+
`npm test` checks the results against published calendar dates for 2025–2027.
|
|
97
|
+
Different panchangams sometimes differ by a day on a few festivals. When that happens, it is
|
|
98
|
+
because they use different timing rules (Smarta or Vaishnava, and so on).
|
package/bin/desical.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { Calendar } = require('../src/panchang');
|
|
7
|
+
const { CITIES, findCity, DEFAULT_CITY } = require('../src/locations');
|
|
8
|
+
const T = require('../src/time');
|
|
9
|
+
const R = require('../src/render');
|
|
10
|
+
const { UsageError, checkYear, parseDate, parseMonth } = require('../src/parse');
|
|
11
|
+
|
|
12
|
+
const CONFIG_FILE = path.join(os.homedir(), '.desicalrc.json');
|
|
13
|
+
|
|
14
|
+
const HELP = `
|
|
15
|
+
desical — Telugu panchangam calendar in your terminal
|
|
16
|
+
|
|
17
|
+
Usage
|
|
18
|
+
desical this month (grid with tithi, nakshatra, festivals)
|
|
19
|
+
desical month [when] a month: 2027-01 | jan 2027 | jan | next | prev
|
|
20
|
+
desical today today's full panchangam
|
|
21
|
+
desical day [date] panchangam for a date: 2026-12-25 | 25-12-2026 | dec 25 | tomorrow
|
|
22
|
+
desical year [YYYY] festivals & holidays of a year (add --all for vratas etc.)
|
|
23
|
+
desical next [N] the next N festivals/holidays (default 10)
|
|
24
|
+
desical find <name> [YYYY] find a festival: desical find diwali 2027
|
|
25
|
+
desical cities list preset cities
|
|
26
|
+
desical config [options] save default location / preferences
|
|
27
|
+
desical --app interactive mode: stays open, ←/→ to change months (? for keys)
|
|
28
|
+
|
|
29
|
+
Options
|
|
30
|
+
--city <name> e.g. hyderabad, vijayawada, tirupati, dallas, london
|
|
31
|
+
--lat <deg> --lon <deg> --tz <IANA zone> [--name <label>]
|
|
32
|
+
--all include minor events (Ekadashi, Pradosham, observances...)
|
|
33
|
+
--telugu also show Telugu script (తెలుగు)
|
|
34
|
+
--no-color plain output
|
|
35
|
+
--json machine-readable output (day, year, next, find)
|
|
36
|
+
--app open interactively (works with month / day / year commands)
|
|
37
|
+
-h, --help this help
|
|
38
|
+
|
|
39
|
+
Notes
|
|
40
|
+
Telugu calendar = amanta lunar months, Lahiri ayanamsa, tithi/nakshatra at local sunrise.
|
|
41
|
+
Islamic dates are astronomical estimates; actual dates depend on moon sighting.
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
function parseArgs(argv) {
|
|
45
|
+
const opts = {}, pos = [];
|
|
46
|
+
for (let i = 0; i < argv.length; i++) {
|
|
47
|
+
const a = argv[i];
|
|
48
|
+
if (a === '-h' || a === '--help') opts.help = true;
|
|
49
|
+
else if (a.startsWith('--no-')) opts[a.slice(5)] = false;
|
|
50
|
+
else if (a.startsWith('--')) {
|
|
51
|
+
const [k, v] = a.slice(2).split('=');
|
|
52
|
+
if (v !== undefined) opts[k] = v;
|
|
53
|
+
else if (['city', 'lat', 'lon', 'tz', 'name'].includes(k)) opts[k] = argv[++i];
|
|
54
|
+
else opts[k] = true;
|
|
55
|
+
} else pos.push(a);
|
|
56
|
+
}
|
|
57
|
+
recoverNpmFlags(opts);
|
|
58
|
+
return { opts, pos };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* `npm start today --json` hands "--json" to npm, not to us; npm exposes such flags as
|
|
63
|
+
* npm_config_* environment variables. Recover the on/off ones; the value options (--city X)
|
|
64
|
+
* cannot be recovered because npm separates the value from its flag.
|
|
65
|
+
*/
|
|
66
|
+
function recoverNpmFlags(opts) {
|
|
67
|
+
const env = process.env;
|
|
68
|
+
if (!env.npm_lifecycle_event) return; // not started by an npm script
|
|
69
|
+
const flag = (name) => env[`npm_config_${name}`];
|
|
70
|
+
if (opts.json === undefined && flag('json') === 'true') opts.json = true;
|
|
71
|
+
if (opts.all === undefined && flag('all') === 'true') opts.all = true;
|
|
72
|
+
if (opts.app === undefined && flag('app') === 'true') opts.app = true;
|
|
73
|
+
if (opts.help === undefined && flag('help') === 'true') opts.help = true;
|
|
74
|
+
if (opts.reset === undefined && flag('reset') === 'true') opts.reset = true;
|
|
75
|
+
for (const name of ['telugu', 'color']) {
|
|
76
|
+
const v = flag(name);
|
|
77
|
+
if (opts[name] === undefined && v !== undefined) opts[name] = !(v === '' || v === 'false');
|
|
78
|
+
}
|
|
79
|
+
const lost = ['city', 'lat', 'lon', 'tz', 'name'].filter((k) => opts[k] === undefined && flag(k) !== undefined);
|
|
80
|
+
if (lost.length) {
|
|
81
|
+
fail(`npm swallowed ${lost.map((k) => '--' + k).join(', ')}. Put "--" before desical's options:\n` +
|
|
82
|
+
` npm start -- today --${lost[0]} <value>\n` +
|
|
83
|
+
`or run "npm link" once and then use "desical today --${lost[0]} <value>" directly.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function loadConfig() {
|
|
88
|
+
try { return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8')); } catch { return {}; }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function resolveLocation(opts, cfg) {
|
|
92
|
+
if (opts.lat !== undefined || opts.lon !== undefined) {
|
|
93
|
+
const lat = parseFloat(opts.lat), lon = parseFloat(opts.lon);
|
|
94
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lon)) fail('Both --lat and --lon are required numbers.');
|
|
95
|
+
const tz = opts.tz || 'Asia/Kolkata';
|
|
96
|
+
checkTz(tz);
|
|
97
|
+
return { name: opts.name || `${lat}, ${lon}`, lat, lon, tz };
|
|
98
|
+
}
|
|
99
|
+
const name = opts.city || cfg.city;
|
|
100
|
+
if (name) {
|
|
101
|
+
const c = findCity(name);
|
|
102
|
+
if (!c) fail(`Unknown city "${name}". Run "desical cities", or use --lat/--lon/--tz.`);
|
|
103
|
+
return c;
|
|
104
|
+
}
|
|
105
|
+
if (cfg.lat !== undefined) return { name: cfg.name || `${cfg.lat}, ${cfg.lon}`, lat: cfg.lat, lon: cfg.lon, tz: cfg.tz || 'Asia/Kolkata' };
|
|
106
|
+
return CITIES[DEFAULT_CITY];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function checkTz(tz) {
|
|
110
|
+
try { new Intl.DateTimeFormat('en-US', { timeZone: tz }); } catch { fail(`Unknown time zone "${tz}" (use an IANA name like Asia/Kolkata).`); }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function fail(msg) {
|
|
114
|
+
process.stderr.write(`desical: ${msg}\n`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function main() {
|
|
119
|
+
const { opts, pos } = parseArgs(process.argv.slice(2));
|
|
120
|
+
if (opts.help) { process.stdout.write(HELP); return; }
|
|
121
|
+
const cfg = loadConfig();
|
|
122
|
+
const telugu = opts.telugu !== undefined ? opts.telugu !== false : cfg.telugu === true;
|
|
123
|
+
const color = opts.color !== false && !process.env.NO_COLOR && process.stdout.isTTY && cfg.color !== false;
|
|
124
|
+
R.setColor(!!color);
|
|
125
|
+
const view = { telugu, all: !!opts.all };
|
|
126
|
+
|
|
127
|
+
let cmd = (pos[0] || '').toLowerCase();
|
|
128
|
+
let rest = pos.slice(1);
|
|
129
|
+
|
|
130
|
+
if (cmd === 'help') { process.stdout.write(HELP); return; }
|
|
131
|
+
|
|
132
|
+
if (cmd === 'cities') {
|
|
133
|
+
for (const [k, c] of Object.entries(CITIES)) {
|
|
134
|
+
console.log(` ${k.padEnd(15)} ${c.name.padEnd(24)} ${c.lat.toFixed(2).padStart(7)} ${c.lon.toFixed(2).padStart(8)} ${c.tz}`);
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (cmd === 'config') {
|
|
140
|
+
if (opts.reset) { try { fs.unlinkSync(CONFIG_FILE); } catch { /* none */ } console.log('Config reset.'); return; }
|
|
141
|
+
const next = { ...cfg };
|
|
142
|
+
if (opts.city) {
|
|
143
|
+
if (!findCity(opts.city)) fail(`Unknown city "${opts.city}".`);
|
|
144
|
+
next.city = opts.city; delete next.lat; delete next.lon; delete next.tz; delete next.name;
|
|
145
|
+
}
|
|
146
|
+
if (opts.lat !== undefined) {
|
|
147
|
+
const loc = resolveLocation(opts, {});
|
|
148
|
+
Object.assign(next, { lat: loc.lat, lon: loc.lon, tz: loc.tz, name: loc.name });
|
|
149
|
+
delete next.city;
|
|
150
|
+
}
|
|
151
|
+
if (opts.telugu !== undefined) next.telugu = opts.telugu !== false;
|
|
152
|
+
if (opts.color !== undefined) next.color = opts.color !== false;
|
|
153
|
+
if (JSON.stringify(next) !== JSON.stringify(cfg)) {
|
|
154
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(next, null, 2) + '\n');
|
|
155
|
+
console.log(`Saved ${CONFIG_FILE}`);
|
|
156
|
+
}
|
|
157
|
+
const loc = resolveLocation({}, next);
|
|
158
|
+
console.log(`Location: ${loc.name} (${loc.lat}, ${loc.lon}, ${loc.tz})`);
|
|
159
|
+
console.log(`Telugu script: ${next.telugu ? 'on' : 'off'} · Colors: ${next.color === false ? 'off' : 'on'}`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const loc = resolveLocation(opts, cfg);
|
|
164
|
+
const cal = new Calendar(loc);
|
|
165
|
+
const idx = R.makeEventIndex(cal);
|
|
166
|
+
const today = cal.dayOf(new Date());
|
|
167
|
+
const out = (s) => process.stdout.write(s + '\n');
|
|
168
|
+
const json = (o) => out(JSON.stringify(o, null, 2));
|
|
169
|
+
|
|
170
|
+
// "desical jan 2027" / "desical 2027-01" shortcut for month view; "desical 2027" for year.
|
|
171
|
+
if (cmd && !['month', 'today', 'day', 'year', 'next', 'find', 'festivals', 'app'].includes(cmd)) {
|
|
172
|
+
if (/^\d{4}$/.test(cmd) && rest.length === 0) { rest = [cmd]; cmd = 'year'; }
|
|
173
|
+
else if (parseMonth(pos, today)) { rest = pos; cmd = 'month'; }
|
|
174
|
+
else if (/\d/.test(cmd) || ['tomorrow', 'yesterday'].includes(cmd)) { rest = pos; cmd = 'day'; }
|
|
175
|
+
else fail(`Unknown command "${cmd}". See "desical --help".`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (opts.app || cmd === 'app') {
|
|
179
|
+
const start = {};
|
|
180
|
+
if (cmd === 'month') {
|
|
181
|
+
const ym = parseMonth(rest, today);
|
|
182
|
+
if (!ym || ym[1] < 1 || ym[1] > 12) fail(`Could not understand month "${rest.join(' ')}".`);
|
|
183
|
+
checkYear(ym[0]);
|
|
184
|
+
Object.assign(start, { mode: 'month', y: ym[0], m: ym[1] });
|
|
185
|
+
} else if (cmd === 'day' || cmd === 'today') {
|
|
186
|
+
Object.assign(start, { mode: 'day', dn: cmd === 'today' ? today : parseDate(rest, today) });
|
|
187
|
+
} else if (cmd === 'year' || cmd === 'festivals') {
|
|
188
|
+
const Y = rest[0] ? parseInt(rest[0], 10) : T.ymd(today).y;
|
|
189
|
+
if (!Number.isFinite(Y)) fail(`Bad year "${rest[0]}".`);
|
|
190
|
+
Object.assign(start, { mode: 'year', Y: checkYear(Y) });
|
|
191
|
+
} else if (cmd && cmd !== 'app') fail(`--app works with the month, day and year views, not "${cmd}".`);
|
|
192
|
+
const color = opts.color !== false && !process.env.NO_COLOR && cfg.color !== false;
|
|
193
|
+
R.setColor(color);
|
|
194
|
+
require('../src/app').runApp({ cal, idx, view, start });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
switch (cmd || 'month') {
|
|
199
|
+
case 'month': {
|
|
200
|
+
const ym = parseMonth(rest, today);
|
|
201
|
+
if (!ym || ym[1] < 1 || ym[1] > 12) fail(`Could not understand month "${rest.join(' ')}". Try 2027-01, "jan 2027", next.`);
|
|
202
|
+
checkYear(ym[0]);
|
|
203
|
+
out(R.renderMonth(cal, idx, ym[0], ym[1], view));
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case 'today':
|
|
207
|
+
case 'day': {
|
|
208
|
+
const dn = cmd === 'today' ? today : parseDate(rest, today);
|
|
209
|
+
if (opts.json) json(R.dayJson(cal, idx, dn));
|
|
210
|
+
else out(R.renderDay(cal, idx, dn, view));
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case 'year':
|
|
214
|
+
case 'festivals': {
|
|
215
|
+
const Y = rest[0] ? parseInt(rest[0], 10) : T.ymd(today).y;
|
|
216
|
+
if (!Number.isFinite(Y)) fail(`Bad year "${rest[0]}".`);
|
|
217
|
+
checkYear(Y);
|
|
218
|
+
let evs = idx.year(Y);
|
|
219
|
+
if (!view.all) evs = evs.filter(R.isMajor);
|
|
220
|
+
if (opts.json) json(evs.map(R.eventJson));
|
|
221
|
+
else out(R.renderList(cal, evs, `Festivals & holidays ${Y}`, { ...view, groupByMonth: true }));
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case 'next': {
|
|
225
|
+
const n = rest[0] ? parseInt(rest[0], 10) : 10;
|
|
226
|
+
let evs = idx.range(today, today + 400);
|
|
227
|
+
if (!view.all) evs = evs.filter(R.isMajor);
|
|
228
|
+
evs = evs.slice(0, n);
|
|
229
|
+
if (opts.json) json(evs.map(R.eventJson));
|
|
230
|
+
else out(R.renderList(cal, evs, 'Upcoming festivals & holidays', view));
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case 'find': {
|
|
234
|
+
let words = rest.slice();
|
|
235
|
+
let Y = T.ymd(today).y;
|
|
236
|
+
if (words.length && /^\d{4}$/.test(words[words.length - 1])) Y = parseInt(words.pop(), 10);
|
|
237
|
+
checkYear(Y);
|
|
238
|
+
const q = words.join(' ').toLowerCase().trim();
|
|
239
|
+
if (!q) fail('Usage: desical find <festival name> [year]');
|
|
240
|
+
const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
|
241
|
+
const nq = norm(q);
|
|
242
|
+
const evs = idx.year(Y).filter((e) => norm(e.en).includes(nq) || (e.te && e.te.includes(q)) ||
|
|
243
|
+
(e.aliases || []).some((a) => norm(a).includes(nq) || nq.includes(norm(a))));
|
|
244
|
+
if (opts.json) json(evs.map(R.eventJson));
|
|
245
|
+
else out(R.renderList(cal, evs, `"${q}" in ${Y}`, view));
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
main();
|
|
253
|
+
} catch (e) {
|
|
254
|
+
if (e instanceof UsageError) fail(e.message);
|
|
255
|
+
throw e;
|
|
256
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhanulabs/desical",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Telugu panchangam calendar CLI: English & Telugu dates, tithi, nakshatra, full/new moons, Indian & international festivals",
|
|
5
|
+
"main": "src/panchang.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"desical": "bin/desical.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"src/"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "node bin/desical.js",
|
|
15
|
+
"test": "node --test test/"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"telugu",
|
|
19
|
+
"calendar",
|
|
20
|
+
"panchangam",
|
|
21
|
+
"panchang",
|
|
22
|
+
"festivals",
|
|
23
|
+
"cli"
|
|
24
|
+
],
|
|
25
|
+
"author": "bhanulabs",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/bhanulabs/desical.git"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/bhanulabs/desical#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/bhanulabs/desical/issues"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"astronomy-engine": "^2.1.19"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/app.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Interactive full-screen mode (desical --app): stays open, navigate with the keyboard.
|
|
3
|
+
const readline = require('readline');
|
|
4
|
+
const T = require('./time');
|
|
5
|
+
const R = require('./render');
|
|
6
|
+
const P = require('./parse');
|
|
7
|
+
|
|
8
|
+
const CSI = '\x1b[';
|
|
9
|
+
const ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]/y;
|
|
10
|
+
const MARK_RE = /\p{M}/u; // combining marks (Telugu vowel signs) take no column of their own
|
|
11
|
+
|
|
12
|
+
/** Cut a line (which may contain ANSI colour codes) to at most `cols` visible columns. */
|
|
13
|
+
function clip(line, cols) {
|
|
14
|
+
let out = '', w = 0, i = 0;
|
|
15
|
+
while (i < line.length) {
|
|
16
|
+
ANSI_RE.lastIndex = i;
|
|
17
|
+
const m = ANSI_RE.exec(line);
|
|
18
|
+
if (m) { out += m[0]; i += m[0].length; continue; }
|
|
19
|
+
const ch = String.fromCodePoint(line.codePointAt(i));
|
|
20
|
+
const cw = MARK_RE.test(ch) ? 0 : 1;
|
|
21
|
+
if (w + cw > cols) break;
|
|
22
|
+
out += ch; w += cw; i += ch.length;
|
|
23
|
+
}
|
|
24
|
+
return out + CSI + '0m';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const KEYS = {
|
|
28
|
+
month: '←/→ month PgUp/PgDn year t today d day y year g go to l Telugu a all ? help q quit',
|
|
29
|
+
day: '←/→ day PgUp/PgDn month t today m month y year g go to l Telugu ? help q quit',
|
|
30
|
+
year: '←/→ year ↑/↓ scroll t this year m month d day g go to l Telugu a all ? help q quit',
|
|
31
|
+
help: 'any key: back',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const HELP_LINES = [
|
|
35
|
+
'',
|
|
36
|
+
' desical — keyboard shortcuts',
|
|
37
|
+
'',
|
|
38
|
+
' Everywhere',
|
|
39
|
+
' m month view (calendar grid)',
|
|
40
|
+
' d day view (full panchangam)',
|
|
41
|
+
' y year view (festivals & holidays)',
|
|
42
|
+
' t jump to today / this month / this year',
|
|
43
|
+
' g go to a date, month or year — e.g. 2027-01-15, jan 2027, 2028, tomorrow',
|
|
44
|
+
' ↑ / ↓ scroll when the page is taller than the window (also Home / End)',
|
|
45
|
+
' l show / hide Telugu script',
|
|
46
|
+
' a show / hide minor events (vratas, observances)',
|
|
47
|
+
' ? this help',
|
|
48
|
+
' q, Ctrl+C quit (Esc goes back to the month view, or quits from it)',
|
|
49
|
+
'',
|
|
50
|
+
' Month view ← / → previous / next month PgUp / PgDn previous / next year',
|
|
51
|
+
' Day view ← / → previous / next day PgUp / PgDn previous / next month',
|
|
52
|
+
' Year view ← / → previous / next year',
|
|
53
|
+
'',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
function runApp({ cal, idx, view, start }) {
|
|
57
|
+
const out = process.stdout, inp = process.stdin;
|
|
58
|
+
if (!out.isTTY || !inp.isTTY) throw new P.UsageError('--app needs an interactive terminal.');
|
|
59
|
+
|
|
60
|
+
const today = () => cal.dayOf(new Date());
|
|
61
|
+
const t0 = T.ymd(today());
|
|
62
|
+
const st = {
|
|
63
|
+
mode: 'month', y: t0.y, m: t0.m, dn: today(), Y: t0.y,
|
|
64
|
+
scroll: 0, lines: [], prompt: null, message: '', prevMode: 'month',
|
|
65
|
+
...start,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// ── content ──
|
|
69
|
+
function refresh(keepScroll = false) {
|
|
70
|
+
let text;
|
|
71
|
+
try {
|
|
72
|
+
if (st.mode === 'month') text = R.renderMonth(cal, idx, st.y, st.m, view);
|
|
73
|
+
else if (st.mode === 'day') text = R.renderDay(cal, idx, st.dn, view);
|
|
74
|
+
else if (st.mode === 'year') {
|
|
75
|
+
let evs = idx.year(st.Y);
|
|
76
|
+
if (!view.all) evs = evs.filter(R.isMajor);
|
|
77
|
+
text = R.renderList(cal, evs, `Festivals & holidays ${st.Y}`, { ...view, groupByMonth: true });
|
|
78
|
+
} else text = HELP_LINES.join('\n');
|
|
79
|
+
} catch (e) {
|
|
80
|
+
text = `\n Error: ${e.message}`;
|
|
81
|
+
}
|
|
82
|
+
st.lines = text.split('\n');
|
|
83
|
+
if (!keepScroll) st.scroll = 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ── painting ──
|
|
87
|
+
function draw() {
|
|
88
|
+
const rows = out.rows || 24, cols = out.columns || 80;
|
|
89
|
+
const bodyH = Math.max(1, rows - 1);
|
|
90
|
+
const maxScroll = Math.max(0, st.lines.length - bodyH);
|
|
91
|
+
st.scroll = Math.min(Math.max(0, st.scroll), maxScroll);
|
|
92
|
+
|
|
93
|
+
let buf = CSI + 'H';
|
|
94
|
+
for (let i = 0; i < bodyH; i++) {
|
|
95
|
+
buf += clip(st.lines[st.scroll + i] || '', cols - 1) + CSI + 'K' + (i < bodyH - 1 ? '\r\n' : '');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let footer;
|
|
99
|
+
if (st.prompt !== null) {
|
|
100
|
+
footer = ` Go to (date, month or year): ${st.prompt}`;
|
|
101
|
+
} else {
|
|
102
|
+
let info = KEYS[st.mode];
|
|
103
|
+
if (maxScroll > 0) info = `[${st.scroll + 1}-${Math.min(st.lines.length, st.scroll + bodyH)}/${st.lines.length} ↑↓] ` + info;
|
|
104
|
+
if (st.message) info = `${st.message} │ ${info}`;
|
|
105
|
+
else if (st.mode === 'month' && cols < 108) info = 'widen the window to 108 columns for the full grid │ ' + info;
|
|
106
|
+
footer = ' ' + info;
|
|
107
|
+
}
|
|
108
|
+
footer = clip(footer, cols - 1).replace(/\x1b\[0m$/, '');
|
|
109
|
+
const pad = ' '.repeat(Math.max(0, cols - 1 - [...footer.replace(/\x1b\[[0-9;]*m/g, '')].length));
|
|
110
|
+
buf += `${CSI}${rows};1H${CSI}7m${footer}${pad}${CSI}0m`;
|
|
111
|
+
if (st.prompt !== null) buf += `${CSI}${rows};${Math.min(cols, 32 + [...st.prompt].length)}H${CSI}?25h`;
|
|
112
|
+
else buf += `${CSI}?25l`;
|
|
113
|
+
out.write(buf);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ── navigation helpers ──
|
|
117
|
+
const setMonth = (y, m) => {
|
|
118
|
+
const t = y * 12 + (m - 1);
|
|
119
|
+
const ny = Math.floor(t / 12), nm = (t % 12) + 1;
|
|
120
|
+
P.checkYear(ny);
|
|
121
|
+
st.y = ny; st.m = nm;
|
|
122
|
+
};
|
|
123
|
+
const go = (mode) => {
|
|
124
|
+
if (mode === st.mode) return;
|
|
125
|
+
if (mode === 'help') st.prevMode = st.mode;
|
|
126
|
+
if (mode === 'day') {
|
|
127
|
+
if (st.mode === 'month') {
|
|
128
|
+
const td = today(), t = T.ymd(td);
|
|
129
|
+
st.dn = t.y === st.y && t.m === st.m ? td : T.dayNum(st.y, st.m, 1);
|
|
130
|
+
} else if (st.mode === 'year') st.dn = T.ymd(today()).y === st.Y ? today() : T.dayNum(st.Y, 1, 1);
|
|
131
|
+
}
|
|
132
|
+
if (mode === 'month') {
|
|
133
|
+
if (st.mode === 'day') { const d = T.ymd(st.dn); st.y = d.y; st.m = d.m; }
|
|
134
|
+
if (st.mode === 'year' && st.Y !== st.y) { st.y = st.Y; st.m = 1; }
|
|
135
|
+
}
|
|
136
|
+
if (mode === 'year') st.Y = st.mode === 'day' ? T.ymd(st.dn).y : st.y;
|
|
137
|
+
st.mode = mode;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
function submitPrompt(text) {
|
|
141
|
+
const s = text.trim();
|
|
142
|
+
if (!s) return;
|
|
143
|
+
const td = today();
|
|
144
|
+
if (/^\d{4}$/.test(s)) { st.Y = P.checkYear(+s); st.mode = 'year'; return; }
|
|
145
|
+
let dn = null, dateErr = null;
|
|
146
|
+
try { dn = P.parseDate([s], td); } catch (e) { dateErr = e; }
|
|
147
|
+
if (dn !== null) { st.dn = dn; st.mode = 'day'; return; }
|
|
148
|
+
const ym = P.parseMonth([s], td);
|
|
149
|
+
if (!ym || ym[1] < 1 || ym[1] > 12) throw dateErr;
|
|
150
|
+
setMonth(ym[0], ym[1]);
|
|
151
|
+
st.mode = 'month';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── keyboard ──
|
|
155
|
+
function onKey(str, key = {}) {
|
|
156
|
+
if (key.ctrl && key.name === 'c') return quit();
|
|
157
|
+
st.message = '';
|
|
158
|
+
|
|
159
|
+
if (st.prompt !== null) {
|
|
160
|
+
if (key.name === 'return' || key.name === 'enter') {
|
|
161
|
+
const text = st.prompt;
|
|
162
|
+
st.prompt = null;
|
|
163
|
+
try { submitPrompt(text); refresh(); } catch (e) { st.message = e.message; }
|
|
164
|
+
} else if (key.name === 'escape') st.prompt = null;
|
|
165
|
+
else if (key.name === 'backspace') st.prompt = st.prompt.slice(0, -1);
|
|
166
|
+
else if (str && !key.ctrl && !key.meta && str >= ' ') st.prompt += str;
|
|
167
|
+
return draw();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (st.mode === 'help') { st.mode = st.prevMode; refresh(); return draw(); }
|
|
171
|
+
|
|
172
|
+
const name = key.name || str;
|
|
173
|
+
let changed = true, keepScroll = false;
|
|
174
|
+
try {
|
|
175
|
+
switch (name) {
|
|
176
|
+
case 'q': return quit();
|
|
177
|
+
case 'escape':
|
|
178
|
+
if (st.mode === 'month') return quit();
|
|
179
|
+
go('month'); break;
|
|
180
|
+
case 'left': case 'right': {
|
|
181
|
+
const dir = name === 'left' ? -1 : 1;
|
|
182
|
+
if (st.mode === 'month') setMonth(st.y, st.m + dir);
|
|
183
|
+
else if (st.mode === 'day') { P.checkYear(T.ymd(st.dn + dir).y); st.dn += dir; }
|
|
184
|
+
else st.Y = P.checkYear(st.Y + dir);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case 'pageup': case 'pagedown': {
|
|
188
|
+
const dir = name === 'pageup' ? -1 : 1;
|
|
189
|
+
if (st.mode === 'month') setMonth(st.y + dir, st.m);
|
|
190
|
+
else if (st.mode === 'day') {
|
|
191
|
+
const d = T.ymd(st.dn);
|
|
192
|
+
const t = d.y * 12 + (d.m - 1) + dir, ny = Math.floor(t / 12), nm = (t % 12) + 1;
|
|
193
|
+
P.checkYear(ny);
|
|
194
|
+
const last = T.ymd(T.dayNum(ny, nm + 1, 1) - 1).d;
|
|
195
|
+
st.dn = T.dayNum(ny, nm, Math.min(d.d, last));
|
|
196
|
+
} else st.Y = P.checkYear(st.Y + dir);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case 'up': st.scroll -= 1; changed = false; break;
|
|
200
|
+
case 'down': st.scroll += 1; changed = false; break;
|
|
201
|
+
case 'home': st.scroll = 0; changed = false; break;
|
|
202
|
+
case 'end': st.scroll = Infinity; changed = false; break;
|
|
203
|
+
case 'space': st.scroll += (out.rows || 24) - 2; changed = false; break;
|
|
204
|
+
case 't': {
|
|
205
|
+
const td = today(), t = T.ymd(td);
|
|
206
|
+
st.y = t.y; st.m = t.m; st.dn = td; st.Y = t.y;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 'm': go('month'); break;
|
|
210
|
+
case 'd': case 'return': case 'enter': go('day'); break;
|
|
211
|
+
case 'y': go('year'); break;
|
|
212
|
+
case 'g': st.prompt = ''; changed = false; break;
|
|
213
|
+
case 'l': view.telugu = !view.telugu; keepScroll = true; st.message = `Telugu script ${view.telugu ? 'on' : 'off'}`; break;
|
|
214
|
+
case 'a': view.all = !view.all; keepScroll = true; st.message = `Minor events ${view.all ? 'shown' : 'hidden'}`; break;
|
|
215
|
+
case '?': case 'h': go('help'); break;
|
|
216
|
+
default: changed = false;
|
|
217
|
+
}
|
|
218
|
+
} catch (e) {
|
|
219
|
+
st.message = e.message;
|
|
220
|
+
changed = false;
|
|
221
|
+
}
|
|
222
|
+
if (changed) refresh(keepScroll);
|
|
223
|
+
draw();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ── lifecycle ──
|
|
227
|
+
let done = false;
|
|
228
|
+
function cleanup() {
|
|
229
|
+
if (done) return;
|
|
230
|
+
done = true;
|
|
231
|
+
try { inp.setRawMode(false); } catch { /* already closed */ }
|
|
232
|
+
out.write(`${CSI}0m${CSI}?25h${CSI}?1049l`);
|
|
233
|
+
}
|
|
234
|
+
function quit() {
|
|
235
|
+
cleanup();
|
|
236
|
+
process.exit(0);
|
|
237
|
+
}
|
|
238
|
+
process.on('exit', cleanup);
|
|
239
|
+
process.on('uncaughtException', (e) => { cleanup(); console.error(e); process.exit(1); });
|
|
240
|
+
|
|
241
|
+
out.write(`${CSI}?1049h${CSI}?25l${CSI}2J`);
|
|
242
|
+
readline.emitKeypressEvents(inp);
|
|
243
|
+
inp.setRawMode(true);
|
|
244
|
+
inp.resume();
|
|
245
|
+
inp.on('keypress', onKey);
|
|
246
|
+
out.on('resize', () => { out.write(CSI + '2J'); draw(); });
|
|
247
|
+
|
|
248
|
+
refresh();
|
|
249
|
+
draw();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
module.exports = { runApp, clip };
|