@mihairo/cmt 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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Conventional Commits CLI — zero dependencies, one bash script.
4
4
 
5
- [![npm](https://img.shields.io/npm/v/cmt-cli?label=npm)](https://npmjs.com/package/cmt-cli)
5
+ [![npm](https://img.shields.io/npm/v/@mihairo/cmt?label=npm)](https://npmjs.com/package/@mihairo/cmt)
6
6
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-fe5196?logo=conventionalcommits)](https://conventionalcommits.org)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
8
8
 
@@ -13,7 +13,7 @@
13
13
  **npm (any project — no Node required at runtime)**
14
14
 
15
15
  ```bash
16
- npm install -g cmt-cli
16
+ npm install -g @mihairo/cmt
17
17
  ```
18
18
 
19
19
  **Homebrew**
@@ -124,7 +124,7 @@ validate it automatically — no extension needed.
124
124
  ```json
125
125
  {
126
126
  "$schema": "https://raw.githubusercontent.com/mihai-ro/cmt/main/schema/cmt.schema.json",
127
- "version": "1.0.0",
127
+ "version": "1.1.0",
128
128
  "customTypes": [
129
129
  {
130
130
  "type": "wip",
package/cmt CHANGED
@@ -6,7 +6,7 @@
6
6
  # =============================================================================
7
7
  set -euo pipefail
8
8
 
9
- CC_VERSION="1.0.0"
9
+ CC_VERSION="1.1.0"
10
10
  CC_CONFIG_FILE=".cmt.json"
11
11
  CC_SCHEMA_URL="https://raw.githubusercontent.com/mihai-ro/cmt/main/schema/cmt.schema.json"
12
12
 
@@ -227,7 +227,7 @@ load_config() {
227
227
  _pick() {
228
228
  local _var="$1" _prompt="$2"; shift 2
229
229
  local -a _items=("$@")
230
- local _n=${#_items[@]} _cur=0 _top=0 _view=7 _k1 _k2 _k3
230
+ local _n=${#_items[@]} _cur=0 _top=0 _view=7 _k1 _k2 _k3 _last_dl=0
231
231
 
232
232
  exec 9<>/dev/tty
233
233
 
@@ -259,17 +259,17 @@ _pick() {
259
259
  }
260
260
 
261
261
  # draw the visible window of _view items starting at _top
262
+ # updates _last_dl with the number of lines actually drawn
262
263
  _draw() {
264
+ _last_dl=0
263
265
  local _i _end
264
266
  _end=$(( _top + _view ))
265
267
  [[ $_end -gt $_n ]] && _end=$_n
266
- local _visible=$(( _end - _top ))
267
268
 
268
- # scroll hint above
269
+ # scroll hint above — only when items are hidden above
269
270
  if [[ $_top -gt 0 ]]; then
270
271
  printf " ${MUTED}↑ %d more${RESET}\033[K\n" "$_top" >&9
271
- else
272
- printf "\033[K\n" >&9
272
+ _last_dl=$(( _last_dl + 1 ))
273
273
  fi
274
274
 
275
275
  for (( _i=_top; _i<_end; _i++ )); do
@@ -278,6 +278,7 @@ _pick() {
278
278
  else
279
279
  printf " ${MUTED}·${RESET} ${MUTED}%s${RESET}\033[K\n" "${_items[$_i]}" >&9
280
280
  fi
281
+ _last_dl=$(( _last_dl + 1 ))
281
282
  done
282
283
 
283
284
  # scroll hint below
@@ -287,11 +288,9 @@ _pick() {
287
288
  else
288
289
  printf "\033[K\n" >&9
289
290
  fi
291
+ _last_dl=$(( _last_dl + 1 ))
290
292
  }
291
293
 
292
- # total drawn lines = _view items + 2 hint lines — fixed for this pick session
293
- local _dl=$(( _view < _n ? _view + 2 : _n + 2 ))
294
-
295
294
  printf "\033[?25l" >&9
296
295
  printf "\n ${ACCENT_BOLD}%s${RESET}\n\n" "$_prompt" >&9
297
296
  _draw
@@ -314,12 +313,13 @@ _pick() {
314
313
  j) _pick_move_down ;;
315
314
  q|$'\003') stty "$_old" <&9 2>/dev/null; trap - EXIT INT TERM; exec 9>&-; exit 1 ;;
316
315
  esac
317
- printf "\033[%dA" "$_dl" >&9
316
+ printf "\033[%dA" "$_last_dl" >&9
317
+ printf "\033[J" >&9
318
318
  _draw
319
319
  done
320
320
 
321
321
  # collapse to just the selected line
322
- printf "\033[%dA" "$_dl" >&9
322
+ printf "\033[%dA" "$_last_dl" >&9
323
323
  printf "\033[J" >&9
324
324
  printf " ${ACCENT_BOLD}❯${RESET} ${BOLD}%s${RESET}\n" "${_items[$_cur]}" >&9
325
325
 
@@ -335,7 +335,7 @@ _pick() {
335
335
  _pick_fallback() {
336
336
  local _var="$1" _prompt="$2"; shift 2
337
337
  local -a _items=("$@") _i=1 _choice
338
- printf "\n\033[1m%s\033[0m\n\n" "$_prompt" >/dev/tty
338
+ printf "\n\033[1m%s\033[0m\n" "$_prompt" >/dev/tty
339
339
  for _item in "${_items[@]}"; do
340
340
  printf " %2d) %s\n" "$_i" "$_item" >/dev/tty
341
341
  _i=$(( _i + 1 ))
@@ -492,13 +492,42 @@ assemble_message() {
492
492
  COMMIT_MESSAGE="$msg"
493
493
  }
494
494
 
495
+ _print_commit_box() {
496
+ local msg="$1" _max=0 _line _W _content_w _bar _bottom _max_W
497
+
498
+ _max_W=$(( ${COLUMNS:-$(tput cols 2>/dev/null || echo 80)} - 2 ))
499
+ [[ $_max_W -lt 50 ]] && _max_W=50
500
+
501
+ while IFS= read -r _line; do
502
+ [[ ${#_line} -gt $_max ]] && _max=${#_line}
503
+ done <<< "$msg"
504
+
505
+ _W=$(( _max + 6 ))
506
+ [[ $_W -lt 50 ]] && _W=50
507
+ [[ $_W -gt $_max_W ]] && _W=$_max_W
508
+ _content_w=$(( _W - 6 ))
509
+
510
+ printf -v _bar '%*s' $(( _W - 19 )) ''; _bar=${_bar// /─}
511
+ printf "\n ${MUTED}╭─ commit message %s╮${RESET}\n" "$_bar" >/dev/tty
512
+ while IFS= read -r _line; do
513
+ printf " ${MUTED}│${RESET} ${BOLD}%-${_content_w}s${RESET} ${MUTED}│${RESET}\n" "$_line" >/dev/tty
514
+ done <<< "$(printf '%s\n' "$msg" | awk -v w="$_content_w" '{
515
+ if (length($0) <= w) { print; next }
516
+ line = ""
517
+ for (i = 1; i <= NF; i++) {
518
+ if (line == "") { line = $i }
519
+ else if (length(line) + 1 + length($i) <= w) { line = line " " $i }
520
+ else { print line; line = $i }
521
+ }
522
+ if (line != "") print line
523
+ }')"
524
+ printf -v _bottom '%*s' $(( _W - 2 )) ''; _bottom=${_bottom// /─}
525
+ printf " ${MUTED}╰%s╯${RESET}\n" "$_bottom" >/dev/tty
526
+ }
527
+
495
528
  # confirm and commit
496
529
  confirm_and_commit() {
497
- printf "\n ${MUTED}╭─ commit message ──────────────────────────────╮${RESET}\n" >/dev/tty
498
- while IFS= read -r _line; do
499
- printf " ${MUTED}│${RESET} ${BOLD}%s${RESET}\n" "$_line" >/dev/tty
500
- done <<< "$COMMIT_MESSAGE"
501
- printf " ${MUTED}╰───────────────────────────────────────────────╯${RESET}\n" >/dev/tty
530
+ _print_commit_box "$COMMIT_MESSAGE"
502
531
 
503
532
  printf "\n ${ACCENT_BOLD}commit?${RESET} ${MUTED}[Y/n/e]${RESET} ${ACCENT}›${RESET} " >/dev/tty
504
533
  read -r ans </dev/tty
@@ -558,11 +587,8 @@ cmd_commit() {
558
587
 
559
588
  if [[ $write_only -eq 1 ]]; then
560
589
  # show preview on /dev/tty (git won't capture it — only stdout goes to the msg file)
561
- printf "\n ${MUTED}╭─ commit message ──────────────────────────────╮${RESET}\n" >/dev/tty
562
- while IFS= read -r _line; do
563
- printf " ${MUTED}│${RESET} ${BOLD}%s${RESET}\n" "$_line" >/dev/tty
564
- done <<< "$COMMIT_MESSAGE"
565
- printf " ${MUTED}╰───────────────────────────────────────────────╯${RESET}\n\n" >/dev/tty
590
+ _print_commit_box "$COMMIT_MESSAGE"
591
+ printf "\n" >/dev/tty
566
592
  printf '%s' "$COMMIT_MESSAGE"
567
593
  return 0
568
594
  fi
@@ -651,7 +677,7 @@ lint_message() {
651
677
 
652
678
  # report
653
679
  local exit_code=0
654
- printf "\n ${ACCENT_BOLD}lint${RESET} ${MUTED}%s${RESET}\n\n" "$header"
680
+ printf "\n ${ACCENT_BOLD}lint${RESET} ${MUTED}%s${RESET}\n" "$header"
655
681
 
656
682
  if [[ ${#errors[@]} -gt 0 ]]; then
657
683
  for e in "${errors[@]}"; do
@@ -738,7 +764,7 @@ cmd_log() {
738
764
  load_config
739
765
 
740
766
  local limit="${1:-20}"
741
- printf "\n ${ACCENT_BOLD}log${RESET} ${MUTED}last %s commits${RESET}\n\n" "$limit"
767
+ printf "\n ${ACCENT_BOLD}log${RESET} ${MUTED}last %s commits${RESET}\n" "$limit"
742
768
 
743
769
  local _p_log_type='^([a-z][a-z0-9_-]*)[(:!]'
744
770
  while IFS='|' read -r hash short_hash date author subject; do
@@ -772,7 +798,7 @@ cmd_log() {
772
798
  # cmd: types
773
799
  cmd_types() {
774
800
  load_config
775
- printf "\n ${ACCENT_BOLD}commit types${RESET}\n\n"
801
+ printf "\n ${ACCENT_BOLD}commit types${RESET}\n"
776
802
  for entry in "${TYPES[@]}"; do
777
803
  local t e s d badge
778
804
  IFS='|' read -r t e s d <<< "$entry"
@@ -805,7 +831,7 @@ cmd_init() {
805
831
  cat > "${git_root}/${CC_CONFIG_FILE}" << JSONEOF
806
832
  {
807
833
  "\$schema": "${CC_SCHEMA_URL}",
808
- "version": "1.0.0",
834
+ "version": "${CC_VERSION}",
809
835
  "customTypes": [
810
836
  { "type": "wip", "emoji": "🚧", "semver": "none", "description": "Work in progress" }
811
837
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mihairo/cmt",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Zero-dependency conventional commits CLI — interactive picker, linter, and git hook installer. One bash script, works in any repo.",
5
5
  "keywords": [
6
6
  "conventional-commits",
@@ -14,10 +14,10 @@
14
14
 
15
15
  "version": {
16
16
  "type": "string",
17
- "description": "Config schema version. Currently '1.0.0'.",
17
+ "description": "Config schema version. Currently '1.1.0'.",
18
18
  "pattern": "^\\d+\\.\\d+\\.\\d+$",
19
- "default": "1.0.0",
20
- "examples": ["1.0.0"]
19
+ "default": "1.1.0",
20
+ "examples": ["1.1.0"]
21
21
  },
22
22
 
23
23
  "customTypes": {
@@ -124,7 +124,7 @@
124
124
  "examples": [
125
125
  {
126
126
  "$schema": "https://raw.githubusercontent.com/mihai-ro/cmt/main/schema/cc.schema.json",
127
- "version": "1.0.0",
127
+ "version": "1.1.0",
128
128
  "customTypes": [
129
129
  {
130
130
  "type": "wip",