visualizar-rate-limit 0.1.2 → 0.1.3

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.
@@ -119,6 +119,9 @@ launch_login() {
119
119
  --user-data-dir="$PROFILE_DIR" \
120
120
  --remote-debugging-port="$DEBUG_PORT" \
121
121
  --remote-allow-origins='*' \
122
+ --disable-background-timer-throttling \
123
+ --disable-backgrounding-occluded-windows \
124
+ --disable-renderer-backgrounding \
122
125
  --new-window \
123
126
  "$URL" \
124
127
  >>"$LOG_FILE" 2>&1 < /dev/null &
@@ -215,11 +218,23 @@ run_once() {
215
218
  }
216
219
 
217
220
  watch_mode() {
221
+ local first_render=1
222
+ local frame=""
223
+ export VRL_FORCE_COLOR=1
224
+
225
+ trap 'printf "\033[?25h"' EXIT INT TERM
226
+
218
227
  while true; do
219
- clear
220
- if ! run_once; then
228
+ if frame="$(run_once 2>&1)"; then
229
+ if [[ "$first_render" -eq 1 ]]; then
230
+ first_render=0
231
+ printf '\033[?25l\033[2J\033[H%s' "$frame"
232
+ else
233
+ printf '\033[H\033[J%s' "$frame"
234
+ fi
235
+ else
221
236
  exit_code=$?
222
- printf '\nReintentando en %ss...\n' "$REFRESH_SECONDS" >&2
237
+ printf '\033[H\033[J%s\n\nReintentando en %ss...\n' "$frame" "$REFRESH_SECONDS" >&2
223
238
  sleep "$REFRESH_SECONDS"
224
239
  continue
225
240
  fi
package/example.png CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visualizar-rate-limit",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "TUI para ver el rate limit de Codex desde chatgpt.com/codex/settings/usage",
5
5
  "type": "module",
6
6
  "bin": {
@@ -5,6 +5,7 @@ import puppeteer from 'puppeteer-core';
5
5
 
6
6
  const mode = process.argv[2] || 'render';
7
7
  const debug = process.argv.includes('--debug') || process.env.VRL_DEBUG === '1';
8
+ const forceColor = process.env.VRL_FORCE_COLOR === '1';
8
9
  const url = process.env.VRL_URL || 'https://chatgpt.com/codex/settings/usage';
9
10
  const browserPath = process.env.CHROME_BIN;
10
11
  const userDataDir = process.env.VRL_PROFILE_DIR;
@@ -97,13 +98,21 @@ function fallbackWindows(text) {
97
98
  }
98
99
 
99
100
  function colorize(percent, value) {
100
- if (!process.stdout.isTTY) return value;
101
+ if (!process.stdout.isTTY && !forceColor) return value;
101
102
  if (percent < 20) return `\x1b[31m${value}\x1b[0m`;
102
103
  if (percent <= 50) return `\x1b[33m${value}\x1b[0m`;
103
104
  return `\x1b[32m${value}\x1b[0m`;
104
105
  }
105
106
 
106
- function renderBar(percent, width = 38) {
107
+ function getBarWidth() {
108
+ if (!process.stdout.isTTY) return 38;
109
+
110
+ const columns = process.stdout.columns || 80;
111
+ const reservedWidth = 24;
112
+ return clamp(columns - reservedWidth, 10, 60);
113
+ }
114
+
115
+ function renderBar(percent, width = getBarWidth()) {
107
116
  const filled = Math.round((percent / 100) * width);
108
117
  const empty = Math.max(0, width - filled);
109
118
  const bar = `${'█'.repeat(filled)}${'░'.repeat(empty)}`;
@@ -173,11 +182,13 @@ async function ensureUsagePage(page) {
173
182
  const currentUrl = page.url();
174
183
 
175
184
  if (currentUrl === url) {
185
+ logDebug('Recargando pestaña de usage para obtener valores frescos');
186
+ await page.reload({ waitUntil: 'domcontentloaded', timeout: 20000 }).catch(() => null);
187
+ await page.waitForFunction(() => document.body && document.body.innerText.length > 50, { timeout: 5000 }).catch(() => {});
188
+ await page.waitForNetworkIdle({ idleTime: 350, timeout: 2500 }).catch(() => {});
189
+
176
190
  const payload = await readPagePayload(page);
177
- if (looksUsablePayload(payload)) {
178
- logDebug('Reutilizando pestaña existente ya cargada');
179
- return payload;
180
- }
191
+ if (looksUsablePayload(payload)) return payload;
181
192
  }
182
193
 
183
194
  logDebug(`Abriendo ${url}`);