@iksdev/shard-cli 0.1.49 → 0.1.51

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/bin/shard.js +63 -30
  2. package/package.json +1 -1
package/bin/shard.js CHANGED
@@ -1155,7 +1155,8 @@ function strip(s) { return s.replace(/\x1b\[[0-9;]*m/g, ''); }
1155
1155
 
1156
1156
  // ─── Panel interactif ────────────────────────────────────────────────────────
1157
1157
 
1158
- const W = 58; // largeur intérieure (sans les bordures)
1158
+ function getW() { const cols = process.stdout.columns || 80; return Math.min(90, Math.max(60, cols - 4)); }
1159
+ const W = getW();
1159
1160
 
1160
1161
  function clearScreen() {
1161
1162
  process.stdout.write('\x1Bc');
@@ -1184,60 +1185,92 @@ function rowCentered(content, color = C.gray) {
1184
1185
 
1185
1186
  function printShareActiveScreen(share, fileName, limits, temps) {
1186
1187
  const GRN = '\x1b[32m';
1187
- const DGRN = '\x1b[90m'; // gris foncé pour les labels
1188
+ const DGRN = '\x1b[90m';
1188
1189
  const WHT = '\x1b[97m';
1189
1190
  const BWHT = '\x1b[1m\x1b[97m';
1190
1191
  const CYN = '\x1b[36m';
1191
1192
  const RST = '\x1b[0m';
1192
- const DIM = '\x1b[2m';
1193
1193
 
1194
- const LABEL_W = 10; // largeur des labels alignés
1195
-
1196
- // Tronque proprement une valeur si elle dépasse la largeur dispo
1197
- const valW = W - 2 - LABEL_W - 2; // bordure + label + espace
1198
- const trunc = (s) => s.length > valW ? s.slice(0, valW - 1) + '…' : s;
1194
+ // Recalcule W au moment de l'affichage pour coller à la taille réelle du terminal
1195
+ const WW = getW();
1196
+ const LABEL_W = 10;
1197
+ const valW = WW - 2 - LABEL_W - 2; // espace dispo pour la valeur
1198
+
1199
+ // Ligne simple label + valeur (valeur tronquée si elle dépasse)
1200
+ const rowShare = (label, value, valColor, border = GRN) => {
1201
+ const lbl = ` ${DGRN}${label.padEnd(LABEL_W)}${RST}`;
1202
+ const v = value.length > valW ? value.slice(0, valW - 1) + '…' : value;
1203
+ const val = `${valColor}${v}${RST}`;
1204
+ const vis = strip(lbl + val);
1205
+ const pad = WW - vis.length;
1206
+ return `${border}│${RST}${lbl}${val}${' '.repeat(Math.max(0, pad))}${border}│${RST}`;
1207
+ };
1199
1208
 
1200
- const rowShare = (label, value, valColor = WHT) => {
1201
- const lbl = ` ${DGRN}${label.padEnd(LABEL_W)}${RST}`;
1202
- const val = `${valColor}${trunc(value)}${RST}`;
1203
- const vis = strip(lbl + val);
1204
- const pad = W - vis.length;
1205
- return `${GRN}│${RST}${lbl}${val}${' '.repeat(Math.max(0, pad))}${GRN}│${RST}`;
1209
+ // Ligne URL sur 2 lignes si trop longue (jamais tronquée)
1210
+ const rowUrl = (label, value) => {
1211
+ const lines = [];
1212
+ const lbl = ` ${DGRN}${label.padEnd(LABEL_W)}${RST}`;
1213
+ const lblVis = strip(lbl);
1214
+ const available = WW - lblVis.length; // espace pour la valeur sur la 1ère ligne
1215
+ const available2 = WW - 2; // espace pour la continuation (indentée)
1216
+
1217
+ if (value.length <= available) {
1218
+ // Rentre sur une seule ligne
1219
+ const val = `${BWHT}${value}${RST}`;
1220
+ const vis = strip(lbl + val);
1221
+ const pad = WW - vis.length;
1222
+ lines.push(`${GRN}│${RST}${lbl}${val}${' '.repeat(Math.max(0, pad))}${GRN}│${RST}`);
1223
+ } else {
1224
+ // Première ligne : label + début de l'URL
1225
+ const part1 = value.slice(0, available);
1226
+ const val1 = `${BWHT}${part1}${RST}`;
1227
+ const vis1 = strip(lbl + val1);
1228
+ lines.push(`${GRN}│${RST}${lbl}${val1}${' '.repeat(Math.max(0, WW - vis1.length))}${GRN}│${RST}`);
1229
+ // Deuxième ligne : suite de l'URL indentée sous la valeur
1230
+ const indent = ' '.repeat(lblVis.length);
1231
+ let rest = value.slice(available);
1232
+ while (rest.length > 0) {
1233
+ const chunk = rest.slice(0, available2 - lblVis.length);
1234
+ rest = rest.slice(chunk.length);
1235
+ const val2 = `${BWHT}${chunk}${RST}`;
1236
+ const vis2 = strip(indent + val2);
1237
+ lines.push(`${GRN}│${RST}${indent}${val2}${' '.repeat(Math.max(0, WW - vis2.length))}${GRN}│${RST}`);
1238
+ }
1239
+ }
1240
+ return lines.join('\n');
1206
1241
  };
1207
1242
 
1208
1243
  const dlLabel = limits && limits > 0 ? `${limits} telechargement(s)` : 'illimite';
1209
1244
  const expLabel = temps && temps > 0 ? `dans ${temps} jour(s)` : 'jamais';
1210
- const dot = ` ${DIM}·${RST} `;
1211
1245
 
1212
1246
  clearScreen();
1213
1247
  console.log('');
1214
- // En-tête
1215
- console.log(`${GRN}┌${'─'.repeat(W)}┐${RST}`);
1216
1248
 
1217
- const badge = `${GRN}▸${RST} ${BWHT}PARTAGE ACTIF${RST}`;
1249
+ // ── Titre ─────────────────────────────────────────────────────────────────
1250
+ console.log(`${GRN}┌${'─'.repeat(WW)}┐${RST}`);
1251
+ const badge = `${GRN}▸${RST} ${BWHT}PARTAGE ACTIF${RST}`;
1218
1252
  const badgeVis = strip(badge);
1219
- const bL = Math.floor((W - badgeVis.length) / 2);
1220
- const bR = W - badgeVis.length - bL;
1253
+ const bL = Math.floor((WW - badgeVis.length) / 2);
1254
+ const bR = WW - badgeVis.length - bL;
1221
1255
  console.log(`${GRN}│${RST}${' '.repeat(bL)}${badge}${' '.repeat(bR)}${GRN}│${RST}`);
1256
+ console.log(`${GRN}├${'─'.repeat(WW)}┤${RST}`);
1222
1257
 
1223
- console.log(`${GRN}├${'─'.repeat(W)}┤${RST}`);
1224
-
1225
- // Infos
1226
- console.log(`${GRN}│${RST}${' '.repeat(W)}${GRN}│${RST}`);
1227
- if (share.url) console.log(rowShare('URL', share.url, BWHT));
1258
+ // ── Infos ─────────────────────────────────────────────────────────────────
1259
+ console.log(`${GRN}│${RST}${' '.repeat(WW)}${GRN}│${RST}`);
1260
+ if (share.url) console.log(rowUrl('URL', share.url));
1228
1261
  if (share.token) console.log(rowShare('Token', share.token, CYN));
1229
1262
  console.log(rowShare('Fichier', fileName, WHT));
1230
1263
  console.log(rowShare('Limite', dlLabel, WHT));
1231
1264
  console.log(rowShare('Expire', expLabel, WHT));
1232
- console.log(`${GRN}│${RST}${' '.repeat(W)}${GRN}│${RST}`);
1265
+ console.log(`${GRN}│${RST}${' '.repeat(WW)}${GRN}│${RST}`);
1233
1266
 
1234
- // Footer
1235
- console.log(`${DGRN}├${'─'.repeat(W)}┤${RST}`);
1267
+ // ── Footer ────────────────────────────────────────────────────────────────
1268
+ console.log(`${DGRN}├${'─'.repeat(WW)}┤${RST}`);
1236
1269
  const hint = ` Tape ${BWHT}q${RST}${DGRN} + Entree pour cloture et revenir au menu${RST}`;
1237
1270
  const hintVis = strip(hint);
1238
- const hPad = W - hintVis.length;
1271
+ const hPad = WW - hintVis.length;
1239
1272
  console.log(`${DGRN}│${RST}${hint}${' '.repeat(Math.max(0, hPad))}${DGRN}│${RST}`);
1240
- console.log(`${DGRN}└${'─'.repeat(W)}┘${RST}`);
1273
+ console.log(`${DGRN}└${'─'.repeat(WW)}┘${RST}`);
1241
1274
  console.log('');
1242
1275
  }
1243
1276
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iksdev/shard-cli",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "description": "CLI pour synchroniser un dossier local avec Shard",
5
5
  "bin": {
6
6
  "shard": "bin/shard.js"