tokmon 0.8.0 → 0.8.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 (2) hide show
  1. package/dist/cli.js +42 -16
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/cli.tsx
4
4
  import { render } from "ink";
5
- import { MouseProvider as MouseProvider2 } from "@zenobius/ink-mouse";
5
+ import { MouseProvider } from "@zenobius/ink-mouse";
6
6
 
7
7
  // src/config.ts
8
8
  import { readFile, writeFile, mkdir } from "fs/promises";
@@ -37,7 +37,7 @@ async function saveConfig(config2) {
37
37
  // src/app.tsx
38
38
  import { useState, useEffect, useCallback, useRef } from "react";
39
39
  import { Box, Text, useInput, useStdout, useApp } from "ink";
40
- import { useMouse } from "@zenobius/ink-mouse";
40
+ import { useMouse, useOnMouseClick } from "@zenobius/ink-mouse";
41
41
 
42
42
  // src/data.ts
43
43
  import { readdir, stat as fsStat } from "fs/promises";
@@ -585,7 +585,7 @@ function App({ interval: cliInterval }) {
585
585
  if (!dashboard) return /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: "Loading..." }) });
586
586
  const rawTableData = table ? [table.daily, table.weekly, table.monthly][view] : [];
587
587
  const tableData = sortRows(rawTableData, sort);
588
- return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, minHeight: rows, children: [
588
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, height: rows, children: [
589
589
  /* @__PURE__ */ jsxs(Box, { justifyContent: "space-between", children: [
590
590
  /* @__PURE__ */ jsxs(Box, { children: [
591
591
  /* @__PURE__ */ jsxs(Text, { bold: true, color: "greenBright", children: [
@@ -593,7 +593,7 @@ function App({ interval: cliInterval }) {
593
593
  " tokmon"
594
594
  ] }),
595
595
  /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
596
- " \xB7 ",
596
+ " \xB7 every ",
597
597
  cliInterval ? cliInterval / 1e3 : cfg.interval,
598
598
  "s"
599
599
  ] })
@@ -602,15 +602,34 @@ function App({ interval: cliInterval }) {
602
602
  ] }),
603
603
  showSettings ? /* @__PURE__ */ jsx(SettingsView, { config: cfg, cursor: settingsCursor }) : /* @__PURE__ */ jsxs(Fragment, { children: [
604
604
  /* @__PURE__ */ jsxs(Box, { marginTop: 1, children: [
605
- /* @__PURE__ */ jsx(TabBar, { tabs: TABS, active: tab }),
605
+ /* @__PURE__ */ jsx(TabBar, { tabs: TABS, active: tab, onSelect: (i) => {
606
+ setTab(i);
607
+ resetView();
608
+ } }),
606
609
  /* @__PURE__ */ jsx(Text, { dimColor: true, children: " Tab/\u2190\u2192" })
607
610
  ] }),
608
611
  /* @__PURE__ */ jsx(Box, { height: 1 }),
609
612
  tab === 0 && /* @__PURE__ */ jsx(DashboardView, { data: dashboard, billing }),
610
613
  tab === 1 && /* @__PURE__ */ jsxs(Fragment, { children: [
611
- /* @__PURE__ */ jsx(ViewBar, { views: VIEWS, active: view, sort: SORTS[sort] }),
614
+ /* @__PURE__ */ jsx(ViewBar, { views: VIEWS, active: view, sort: SORTS[sort], onSelect: (i) => {
615
+ setView(i);
616
+ resetView();
617
+ } }),
612
618
  /* @__PURE__ */ jsx(Box, { height: 1 }),
613
- tableLoading && !table ? /* @__PURE__ */ jsx(Spinner, { label: "Loading 6 months of history" }) : /* @__PURE__ */ jsx(TableView, { rows: tableData, cursor, expanded, maxRows: rows - 12, wide: cols > 90 })
619
+ tableLoading && !table ? /* @__PURE__ */ jsx(Spinner, { label: "Loading 6 months of history" }) : /* @__PURE__ */ jsx(
620
+ TableView,
621
+ {
622
+ rows: tableData,
623
+ cursor,
624
+ expanded,
625
+ maxRows: rows - 12,
626
+ wide: cols > 90,
627
+ onRowClick: (idx) => {
628
+ if (idx === cursor) setExpanded((e) => e === idx ? -1 : idx);
629
+ else setCursor(idx);
630
+ }
631
+ }
632
+ )
614
633
  ] })
615
634
  ] }),
616
635
  (tab === 0 || showSettings) && /* @__PURE__ */ jsx(Footer, {})
@@ -625,8 +644,8 @@ function Footer() {
625
644
  /* @__PURE__ */ jsx(Text, { dimColor: true, children: ") \xB7 s=settings q=quit" })
626
645
  ] });
627
646
  }
628
- function TabBar({ tabs, active }) {
629
- return /* @__PURE__ */ jsx(Box, { children: tabs.map((t, i) => /* @__PURE__ */ jsx(Box, { marginRight: 1, children: i === active ? /* @__PURE__ */ jsxs(Text, { bold: true, inverse: true, children: [
647
+ function TabBar({ tabs, active, onSelect }) {
648
+ return /* @__PURE__ */ jsx(Box, { children: tabs.map((t, i) => /* @__PURE__ */ jsx(ClickableBox, { onClick: () => onSelect(i), marginRight: 1, children: i === active ? /* @__PURE__ */ jsxs(Text, { bold: true, inverse: true, children: [
630
649
  " ",
631
650
  t,
632
651
  " "
@@ -636,14 +655,14 @@ function TabBar({ tabs, active }) {
636
655
  " "
637
656
  ] }) }, t)) });
638
657
  }
639
- function ViewBar({ views, active, sort }) {
658
+ function ViewBar({ views, active, sort, onSelect }) {
640
659
  return /* @__PURE__ */ jsxs(Box, { children: [
641
- views.map((v, i) => /* @__PURE__ */ jsx(Box, { marginRight: 2, children: i === active ? /* @__PURE__ */ jsxs(Text, { bold: true, color: "cyan", children: [
660
+ views.map((v, i) => /* @__PURE__ */ jsx(ClickableBox, { onClick: () => onSelect(i), marginRight: 2, children: i === active ? /* @__PURE__ */ jsxs(Text, { bold: true, color: "cyan", children: [
642
661
  "[",
643
662
  v,
644
663
  "]"
645
664
  ] }) : /* @__PURE__ */ jsx(Text, { dimColor: true, children: v }) }, v)),
646
- /* @__PURE__ */ jsx(Text, { dimColor: true, children: " d/w/m \xB7 sort: " }),
665
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: " sort: " }),
647
666
  /* @__PURE__ */ jsx(Text, { bold: true, color: "magenta", children: sort }),
648
667
  /* @__PURE__ */ jsx(Text, { dimColor: true, children: " o=cycle" })
649
668
  ] });
@@ -794,7 +813,7 @@ function SummaryRow({ label, summary }) {
794
813
  ] }) })
795
814
  ] });
796
815
  }
797
- function TableView({ rows: allRows, cursor, expanded, maxRows, wide }) {
816
+ function TableView({ rows: allRows, cursor, expanded, maxRows, wide, onRowClick }) {
798
817
  const W = wide ? { label: 10, models: 18, input: 8, output: 8, cc: 8, cr: 9, total: 9, cost: 10 } : { label: 8, models: 14, input: 7, output: 7, cc: 7, cr: 8, total: 0, cost: 9 };
799
818
  const lineW = W.label + W.models + W.input + W.output + W.cc + W.cr + W.total + W.cost;
800
819
  const totals = { input: 0, output: 0, cacheCreate: 0, cacheRead: 0, cost: 0 };
@@ -828,7 +847,7 @@ function TableView({ rows: allRows, cursor, expanded, maxRows, wide }) {
828
847
  const selected = idx === clampedCursor;
829
848
  const isExpanded = idx === expanded;
830
849
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
831
- /* @__PURE__ */ jsxs(Text, { inverse: selected, children: [
850
+ /* @__PURE__ */ jsx(ClickableBox, { onClick: () => onRowClick(idx), children: /* @__PURE__ */ jsxs(Text, { inverse: selected, children: [
832
851
  /* @__PURE__ */ jsxs(Text, { color: selected ? void 0 : "cyan", children: [
833
852
  selected ? "\u25B8 " : " ",
834
853
  col(fmtLabel(r.label), W.label, "left")
@@ -840,7 +859,7 @@ function TableView({ rows: allRows, cursor, expanded, maxRows, wide }) {
840
859
  /* @__PURE__ */ jsx(Text, { children: col(tokens(r.cacheRead), W.cr) }),
841
860
  W.total > 0 && /* @__PURE__ */ jsx(Text, { children: col(tokens(r.total), W.total) }),
842
861
  /* @__PURE__ */ jsx(Text, { bold: true, color: selected ? void 0 : "yellow", children: col(currency(r.cost), W.cost) })
843
- ] }),
862
+ ] }) }),
844
863
  isExpanded && /* @__PURE__ */ jsx(RowDetail, { row: r, indent: W.label + 2 })
845
864
  ] }, r.label);
846
865
  }),
@@ -920,6 +939,13 @@ function fmtLabel(label) {
920
939
  }
921
940
  return shortDate(label);
922
941
  }
942
+ function ClickableBox({ onClick, children, ...props }) {
943
+ const ref = useRef(null);
944
+ useOnMouseClick(ref, (clicked) => {
945
+ if (clicked) onClick();
946
+ });
947
+ return /* @__PURE__ */ jsx(Box, { ref, ...props, children });
948
+ }
923
949
 
924
950
  // src/cli.tsx
925
951
  import { jsx as jsx2 } from "react/jsx-runtime";
@@ -949,5 +975,5 @@ var config = await loadConfig();
949
975
  if (config.clearScreen && process.stdout.isTTY) {
950
976
  process.stdout.write("\x1B[2J\x1B[H");
951
977
  }
952
- var { waitUntilExit } = render(/* @__PURE__ */ jsx2(MouseProvider2, { children: /* @__PURE__ */ jsx2(App, { interval }) }));
978
+ var { waitUntilExit } = render(/* @__PURE__ */ jsx2(MouseProvider, { children: /* @__PURE__ */ jsx2(App, { interval }) }));
953
979
  await waitUntilExit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmon",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Terminal dashboard for Claude Code usage and costs",
5
5
  "type": "module",
6
6
  "bin": {