@commte/mdbrowse 0.3.0 → 0.3.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/assets/head.html CHANGED
@@ -351,6 +351,6 @@
351
351
  if (printing || (hoverable && bar.matches(':hover'))) return;
352
352
  if (Date.now() - lastScroll < 900) return;
353
353
  checkStamp();
354
- }, 1000);
354
+ }, 250);
355
355
  });
356
356
  </script>
package/bin/mdbrowse CHANGED
@@ -3,7 +3,7 @@
3
3
  # browser tab can stay open and just swap its contents.
4
4
  set -euo pipefail
5
5
 
6
- VERSION="0.3.0"
6
+ VERSION="0.3.1"
7
7
  PROG="$(basename "$0")"
8
8
  OUT="${MDBROWSE_OUT:-/tmp/mdbrowse.html}"
9
9
  case "$OUT" in
@@ -459,16 +459,18 @@ if [ "$daemon" -eq 1 ]; then
459
459
  # 変換の失敗は画面に出ないので、ログに残す
460
460
  log() { printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$1" >> "$LOGFILE"; }
461
461
 
462
- # Spotlight を使えない場合は木を歩く。大きな木では間隔を伸ばす
463
- scan_gap=2
462
+ # 表示中のファイルは 0.25 秒ごとに見る。1周 = 0.25 秒
463
+ TICK=0.25
464
+ # Spotlight への問い合わせは 2 秒ごと(8周に1回)
465
+ scan_gap=8
464
466
  if [ "$use_spotlight" -eq 0 ]; then
465
467
  t0="$(perl -MTime::HiRes=time -e 'printf "%d", time*1000')"
466
468
  newest_md "$root" >/dev/null
467
469
  t1="$(perl -MTime::HiRes=time -e 'printf "%d", time*1000')"
468
- scan_gap=$(( ( (t1 - t0) * 5 + 999) / 1000 ))
469
- [ "$scan_gap" -lt 2 ] && scan_gap=2
470
- [ "$scan_gap" -gt 10 ] && scan_gap=10
471
- log "watching $root every ${scan_gap}s (no Spotlight)"
470
+ scan_gap=$(( ( (t1 - t0) * 5 + 249) / 250 ))
471
+ [ "$scan_gap" -lt 8 ] && scan_gap=8
472
+ [ "$scan_gap" -gt 40 ] && scan_gap=40
473
+ log "watching $root every $(( scan_gap / 4 ))s (no Spotlight)"
472
474
  fi
473
475
 
474
476
  src="$(pick)"
@@ -476,7 +478,7 @@ if [ "$daemon" -eq 1 ]; then
476
478
  last="$src $(fingerprint "$src") $(fingerprint "$HEAD")"
477
479
  # 開いているファイルの保存は毎秒見る。別ファイルへの切り替えの検出は2秒ごと
478
480
  tick=0
479
- while sleep 1; do
481
+ while sleep "$TICK"; do
480
482
  tick=$(( tick + 1 ))
481
483
  if [ $(( tick % scan_gap )) -eq 0 ]; then
482
484
  cand="$(pick)"
@@ -508,7 +510,7 @@ render
508
510
  if [ "$watch" -eq 1 ]; then
509
511
  # ディレクトリを見る場合、木が大きいと走査が重い。1回の走査時間から
510
512
  # 待ち時間を決めて、CPU を食い潰さないようにする
511
- interval=1
513
+ interval=0.25
512
514
  if [ -n "$root" ]; then
513
515
  t0="$(perl -MTime::HiRes=time -e 'printf "%d", time*1000')"
514
516
  newest_md "$root" >/dev/null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commte/mdbrowse",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Preview the Markdown file you are editing in a real browser, with your own CSS, from any editor that can run a shell command. No server, no port.",
5
5
  "bin": {
6
6
  "mdbrowse": "bin/mdbrowse",