free-coding-models 0.5.11 → 0.5.14

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.
@@ -31,6 +31,8 @@
31
31
  * - `calculateViewport`: Compute visible slice of model rows
32
32
  * - `sortResultsWithPinnedFavorites`: Sort with pinned items at top
33
33
  * - `adjustScrollOffset`: Clamp scrollOffset so cursor stays visible
34
+ * - `fadedRow`: Multiply every 24-bit RGB channel by a factor to fade an
35
+ * entire ANSI-colored line uniformly — used for "unusable" rows.
34
36
  *
35
37
  * 📦 Dependencies:
36
38
  * - chalk: Terminal colors and formatting
@@ -56,6 +58,39 @@ export function stripAnsi(input) {
56
58
  return String(input).replace(/\x1b\[[0-9;]*m/g, '').replace(/\x1b\][^\x1b]*\x1b\\/g, '')
57
59
  }
58
60
 
61
+ // 📖 fadedRow: Multiply every 24-bit RGB channel inside an ANSI-colored string by `factor`
62
+ // 📖 (default 0.8 = 80% opacity, i.e. 20% less opaque) so the whole line reads as
63
+ // 📖 uniformly faded. Only foreground/background 24-bit SGR codes (38;2;R;G;B and
64
+ // 📖 48;2;R;G;B) are touched — bold, dim, reset codes, hyperlinks, and cursor SGRs
65
+ // 📖 pass through unchanged so the structural styling stays intact.
66
+ // 📖 Used to make "unusable" rows (NO KEY / AUTH FAIL) visually de-emphasized at
67
+ // 📖 the row level rather than dimming a single cell, which is easier to miss at
68
+ // 📖 a glance when scanning the table.
69
+ // 📖 Channels are clamped to 0–255 and rounded to integers so terminal parsers
70
+ // 📖 never receive an out-of-range byte. When `factor >= 1` the input is returned
71
+ // 📖 untouched (identity fast path) so callers can wire this in without paying
72
+ // 📖 the cost on every row.
73
+ export function fadedRow(input, factor = 0.8) {
74
+ const text = String(input)
75
+ if (factor >= 1) return text
76
+ // 📖 Pre-clamp factor to [0, 1] to avoid negative channel values that would
77
+ // 📖 confuse downstream regex replacements; we still respect very small values
78
+ // 📖 so a caller can pass e.g. 0.1 to almost black-out a row.
79
+ const safeFactor = Math.max(0, Math.min(1, factor))
80
+ return text.replace(
81
+ /\x1b\[(38|48);2;(\d+);(\d+);(\d+)m/g,
82
+ (_match, kind, rStr, gStr, bStr) => {
83
+ const r = parseInt(rStr, 10)
84
+ const g = parseInt(gStr, 10)
85
+ const b = parseInt(bStr, 10)
86
+ const nr = Math.max(0, Math.min(255, Math.round(r * safeFactor)))
87
+ const ng = Math.max(0, Math.min(255, Math.round(g * safeFactor)))
88
+ const nb = Math.max(0, Math.min(255, Math.round(b * safeFactor)))
89
+ return `\x1b[${kind};2;${nr};${ng};${nb}m`
90
+ }
91
+ )
92
+ }
93
+
59
94
  // 📖 maskApiKey: Mask all but first 4 and last 3 characters of an API key.
60
95
  // 📖 Prevents accidental disclosure of secrets in TUI display.
61
96
  export function maskApiKey(key) {
@@ -17,6 +17,8 @@
17
17
  * - High-visibility active text-filter banner with one-key clear action (`X`)
18
18
  * - Full-width red outdated-version banner when a newer npm release is known
19
19
  * - Distinct auth-failure vs missing-key health labels so configured providers stay honest
20
+ * - 80%-opacity row fade for "unusable" models (NO KEY / AUTH FAIL) so the user can spot at a glance
21
+ * which rows are not actually reachable, even when the cursor is parked elsewhere
20
22
  *
21
23
  * → Functions:
22
24
  * - `renderTable` — Render the full TUI table as a string (no side effects)
@@ -27,7 +29,7 @@
27
29
  * - ../src/tier-colors.js: TIER_COLOR
28
30
  * - ../src/utils.js: getAvg, getVerdict, getUptime, getStabilityScore
29
31
  * - ../src/ping.js: usagePlaceholderForProvider
30
- * - ../src/render-helpers.js: calculateViewport, sortResultsWithPinnedFavorites, padEndDisplay
32
+ * - ../src/render-helpers.js: calculateViewport, sortResultsWithPinnedFavorites, padEndDisplay, fadedRow
31
33
  *
32
34
  * @see bin/free-coding-models.js — main entry point that calls renderTable
33
35
  */
@@ -50,7 +52,7 @@ import { TIER_COLOR } from './tier-colors.js'
50
52
  import { getAvg, getVerdict, getUptime, getStabilityScore, getVersionStatusInfo } from '../core/utils.js'
51
53
  import { usagePlaceholderForProvider } from '../core/ping.js'
52
54
  import { formatBenchmarkLatency, formatBenchmarkTps } from '../core/benchmark.js'
53
- import { calculateViewport, sortResultsWithPinnedFavorites, padEndDisplay, displayWidth, stripAnsi } from './render-helpers.js'
55
+ import { calculateViewport, sortResultsWithPinnedFavorites, padEndDisplay, displayWidth, stripAnsi, fadedRow } from './render-helpers.js'
54
56
  import { getToolMeta, TOOL_METADATA, TOOL_MODE_ORDER, isModelCompatibleWithTool } from '../core/tool-metadata.js'
55
57
  import { getColumnSpacing } from './ui-config.js'
56
58
  import { detectPackageManager, getManualInstallCmd } from '../core/updater.js'
@@ -946,20 +948,33 @@ export function renderTable({
946
948
  if (showBenchmarkColumns) rowParts.push(latencyCell, tpsCell)
947
949
  const row = ' ' + rowParts.join(COL_SEP)
948
950
 
951
+ // 📖 "Unusable" models (no key / bad key) are visually de-emphasized at the
952
+ // 📖 row level. The user cannot actually send a request to these models, so
953
+ // 📖 we drop the whole line to 80% opacity (20% less opaque) so it stands
954
+ // 📖 out from working rows at a glance, even if the cursor is parked on a
955
+ // 📖 different model. The cursor always wins so the user never loses track
956
+ // 📖 of their active selection. fadedRow multiplies every 24-bit RGB
957
+ // 📖 channel by 0.8 so the result works on every terminal that supports
958
+ // 📖 truecolor (no reliance on the SGR 2 "faint" code, which is ignored by
959
+ // 📖 some terminals).
960
+ const isUnusable = r.status === 'noauth' || r.status === 'auth_error'
961
+
962
+ let renderedRow
949
963
  if (isCursor) {
950
- lines.push(themeColors.bgModelCursor(row))
964
+ renderedRow = themeColors.bgModelCursor(row)
951
965
  } else if (isIncompatible) {
952
966
  // 📖 Dark red background for models incompatible with the active tool mode.
953
967
  // 📖 This visually warns the user that selecting this model won't work with their current tool.
954
- lines.push(chalk.bgRgb(60, 15, 15).rgb(180, 130, 130)(row))
968
+ renderedRow = chalk.bgRgb(60, 15, 15).rgb(180, 130, 130)(row)
955
969
  } else if (r.isRecommended) {
956
970
  // 📖 Medium green background for recommended models (distinguishable from favorites)
957
- lines.push(themeColors.bgModelRecommended(row))
971
+ renderedRow = themeColors.bgModelRecommended(row)
958
972
  } else if (r.isFavorite) {
959
- lines.push(themeColors.bgModelFavorite(row))
973
+ renderedRow = themeColors.bgModelFavorite(row)
960
974
  } else {
961
- lines.push(row)
975
+ renderedRow = row
962
976
  }
977
+ lines.push(isUnusable ? fadedRow(renderedRow, 0.8) : renderedRow)
963
978
  }
964
979
 
965
980
  // 📖 Mouse support: record the 1-based terminal row range of model data rows.