Lines 13-68javascript
13Segment length: ${X.text.length}, maxWidth: ${J}
14Segment: "${X.text.slice(0,50)}${X.text.length>50?"...":""}"`)}if(q.length>0&&q[0].isContinuation)throw Error("[LineBreaking] First segment incorrectly marked as continuation!");for(let Q=1;Q<q.length;Q++)if(!q[Q].isContinuation)throw Error(`[LineBreaking] Segment ${Q} should be marked as continuation but isn't!`)}function H0($,J){if(J<=0)return 1;if($.length<=J)return 1;return Math.ceil($.length/J)}import o from"fast-diff";function Q$($,J){if(!$||!J)return!1;let q=o($,J),K=0,Q=0;for(let[Z,Y]of q)if(Q+=Y.length,Z===o.EQUAL)K+=Y.length;if(Q===0)return!1;return K/Q>=0.5}function X$($,J){let q=o( ...
15`);return $1.highlight(J,q).value.replace(/\x1b\[0m/g,z$).split(`
16`)}catch{return $}}function _$($){if($.type==="addition"||$.type==="deletion")return $.content.slice(1);if($.type==="context"&&$.content.startsWith(" "))return $.content.slice(1);return $.content}function b($){return _$($).replace(/[\x00-\x08\x0a-\x1f\x7f]/g,"").replace(/\t/g," ")}function M$($){switch($.type){case"header":return{type:"diff-header",content:$.content};case"hunk":return{type:"diff-hunk",content:$.content,editedAt:$.editedAt};case"addition":return{type:"diff-add",lineNum:$.newLineNum,content:b($)};case"deletion":return{type:"diff-del",lineNum:$.oldLineNum,content:b($)};case"co ...
17`))q.push({type:"commit-message",content:` ${K}`});q.push({type:"spacer"})}return q.push(...k0(J)),q}function R0($){let J=0;for
18`),totalRows:A,hunkCount:O,hunkBoundaries:M}}function T$($,J,q,K=0,Q,X="dark",Z=!1){let Y=A$($,J);if(Y.length===0)return{content:"{gray-fg}No commit selected{/gray-fg}",totalRows:0,hunkCount:0,hunkBoundaries:[]};let z=W0(X),V=R0(Y),G=q-V-5,B=q-2,U=F0(Y,G,Z),j=U.length;return{content:(Q?U.slice(K,K+Q):U.slice(K)).map((A)=>Q1(A,V,G,B,z,Z)).join(`
19`),totalRows:j,hunkCount:0,hunkBoundaries:[]}}function E$($,J,q,K=0,Q,X="dark",Z=!1,Y){let{rows:z,hunkMapping:V}=N$($,J);if(z.length===0)return{content:"{gray-fg}No diff to display{/gray-fg}",totalRows:0,hunkCount:0,hunkBoundaries:[],hunkMapping:[]};let G=Y!==void 0&&Y>=0,B=W0(X),U=R0(z),j=G?1:0,D=q-U-5-j,_=q-2,A=F0(z,D,Z),M=A.length,O=J1(A),N=O.length,v=Math.min(Y??0,N-1),R=new Map;if(G)for(let I=0;I<O.length;I++){let u=O[I];for(let P=u.startRow;P<u.endRow;P++)R.set(P,I)}let y=K;return{content:(Q?A.slice(y,y+Q):A.slice(y)).map((I,u)=>{let P=y+u,m=Q1(I,U,D,_,B,Z);if(!G)return m;let z0=R.get(P) ...
20`),totalRows:M,hunkCount:N,hunkBoundaries:O,hunkMapping:V}}var K0=4;function k$($){let{state:J,stagedCount:q,
21`):[];if(G.length===0&&!J.inputFocused)G.push("Press i or Enter to edit...");let B=J.message?"":"{gray-fg}",U=J.message?
23`)}function Z1($,J,q){if(!$)return[];let K=$.split(`
24`),Q=[],X=J?E0(J):null;for(let Z=0;Z<K.length;Z++){let Y=K[Z],z=X?B$(Y,X):void 0;Q.push({type:"code",lineNum:Z+1,content:Y,highlighted:z})}if(q)Q.push({type:"truncation",content:"(file truncated)"});return Q}function L$($,J,q){if(!q)return $;let Q=Math.max(10,J),X=[];for(let Z of $)if(Z.type==="code"){let Y=Z.content;if(!Y||Y.length<=Q){X.push(Z);continue}let z=v0(Y,Q);for(let V=0;V<z.length;V++){let G=z[V];X.push({type:"code",lineNum:G.isContinuation?0:Z.lineNum,content:G.text,highlighted:void 0,isContinuation:G.isContinuation})}}else X.push(Z);return X}function y$($,J,q){if(!q)return $.lengt ...
25`)}function P$($,J,q,K,Q){if(!$)return 0;let X=Z1($,J,q),Z=Y1(X
26`),K=[],Q=-1;for(let V=0;V<q.length;V++){if(q[V].startsWith("@@")){Q=V;break}K.push(q[V])}if(Q===-1)return null;let X=-1,Z=-1;for(let V=Q;V<q.length;V++)if(q[V].startsWith("@@")){if(X++,X===J){Z=V;break}}if(Z===-1)return null;let Y=[q[Z]];for(let V=Z+1;V<q.length;V++){if(q[V].startsWith("@@")||q[V].startsWith("diff --git"))break;Y.push(q[V])}while(Y.length>1&&Y[Y.length-1]==="")Y.pop();return[...K,...Y].join(`
28`}class B1{ctx;pendingSelectionAnchor=null;pendingFlatSelectionPath=null;pendingHunkIndex=null;constructor($){this.ctx=$}consumePendingSelectionAnchor(){let $=this.pendingSelectionAnchor;return this.pendingSelectionAnchor=null,$}consumePendingFlatSelectionPath(){let $=this.pendingFlatSelectionPath;return this.pendingFlatSelectionPath=null,$}consumePendingHunkIndex(){let $=this.pendingHunkIndex;return this.pendingHunkIndex=null,$}async stageSelected(){let $=this.ctx.getSession(),J=$?.shared.status?.files??[],q=this.ctx.uiState.state.selectedIndex;if(this.ctx.uiState.state.flatViewMode){let K=S( ...
29`)),this.screen.render()}destroy(){this.box.destroy()}focus(){this.box.focus()}}import N2 from"neo-blessed";var u$={name:"diffstalker",version:"0.5.1",description:"Interactive terminal UI for git staging, committing, and live diff review",author:"yogh-io"
30`)),this.screen.render()}renderGroups($,J){let q=[];for(let K of $){q.push(`{bold}{gray-fg}${K.title}{/gray-fg}{/bold}`);for(let Q of K.entries)q.push(` {cyan-fg}${Q.key.padEnd(10)}{/cyan-fg} ${Q.description}`);q.push("")}return q}destroy(){if(this.screenClickHandler)this.screen.removeListener("click",this.screenClickHandler),this.screenClickHandler=null;this.box.destroy()}focus(){this.box.focus()}}import v2 from"neo-blessed";class M1{box;screen;branches;selectedIndex;currentBranch;onSelect;onCancel;constructor($,J,q,K,Q){if(this.screen=$,this.branches=J,this.currentBranch=q,this.onSelect=K,t ...
31`)),this.screen.render()}destroy(){this.box.destroy()}focus(){this.box.focus()}}import H2 from"neo-blessed";class D1{box;screen;filePath;untracked;onConfirm;onCancel;constructor($,J,q,
32`)),this.screen.render()}destroy(){this.box.destroy()}focus(){this.box.focus()}}import m$ from"neo-blessed";import{Fzf as T2}from"fzf";var S0=15,E2
33`)),this.screen.render()}destroy(){if(this.debounceTimer)clearTimeout(this.debounceTimer);this.textbox.destroy(),this.box.destroy()}focus(){this.textbox.focus()}}import R2 from"neo-blessed";class C0{box;screen;onConfirm;onCancel;constructor($,J,q,K,Q){this.screen=$,this.onConfirm=K,this.onCancel=Q;let X=Math.min(60,$.width-6),Z=8;this.box=R2.box({parent:$,top:"center",left:"center",width:X,height:Z,border:{type:"line"},style:{border:{fg:"yellow"}},tags:!0,keys:!0}),this.setupKeyHandlers(),this.renderContent(J,q,X)}setupKeyHandlers(){this.box.key(["y","Y"],()=>{this.destroy(),this.onConfirm()}) ...
34`)),this.screen.render()}destroy(){this.box.destroy()}focus(){this.box.focus()}}import y2 from"neo-blessed";import*as k from"node:fs";import*as X0 from"node:path";import*as d$ from"node:os";import*as A1 from"node:os"
35`)}function a$($,J){if(J!==void 0)return J;if($.watcherEnabled&&$.targetFile!==l$.targetFile)return $.targetFile;return}function d($){let J=d$.homedir();if($.startsWith(J))return"~"+$.slice(J.length);return $}function N1($){return $.length>1&&$.endsWith("/")?$.slice(0,-1):$}function o$($,J=10){let q=N1($),K=[];if(k.existsSync(w))try{let X=JSON.parse(k.readFileSync(w,"utf-8"));if(Array.isArray(X.recentRepos))K=X.recentRepos}catch{}let Q=K.filter((X)=>N1(X)!==q);Z0({recentRepos:[q,...Q.map(N1)].slice(0,J)})}class W1{box;screen;repos;selectedIndex;currentRepo;onSelect;onCancel;constructor($,J,q,K ...
36`)),this.screen.render()}destroy(){this.box.destroy()}focus(){this.box.focus()}}import*as b0 from"node:path";import I2 from"neo-blessed";var s$="j/k: navigate | Enter: select | Esc: cancel";function P2($){if($.length===0
37`)),this.screen.render()}destroy(){this.box.destroy()}focus(){this.box.focus()}}var S2=!1;function n$($){S2=$}function T1($){process.stderr.write(`[diffstalker warn] ${$}
38`)}function C2($){if($ instanceof Error)return $.message;if($)return String($);return""}function i$($,J){let q=J?`: ${C2(J)}`:"";process.stderr.write(`[diffstalker error] ${$}${q}
39`)}class E1{ctx;activeModal=null;activeModalType=null;constructor($){this.ctx=$}hasActiveModal(){return this.activeModal!==null}getActiveModalType(){return this.activeModalType}closeActiveModal(){if(this.activeModal)this.activeModal.destroy(),this.activeModal=null,this.activeModalType=null,this.ctx.render()}clearModal(){this.activeModal=null,this.activeModalType=null}openThemePicker(){this.activeModalType="theme",this.activeModal=new j1(this.ctx.screen,this.ctx.getCurrentTheme(),($)=>{this.ctx.setCurrentTheme($),Z0({theme:$}),this.clearModal(),this.ctx.render()},()=>{this.clearModal()}),this.a ...
41`);while(q!==-1){let K=this.buffer.slice(0,q);this.buffer=this.buffer.slice(q+2);let Q="",X=""
42`))if(Z.startsWith("event: "))Q=Z.slice(7);else if(Z.startsWith("data: "))X=Z.slice(6);
44`)}}close(){if(this.closed)return;this.closed=!0,this.request.destroy()}}class F1{target;constructor($){this.target=$}request($,J,q){let K=q===void 0?null:JSON.stringify(q);return new Promise((Q,X)=>{let Z=R1.request({...q3(this.target),method:$,path:J,headers:{accept:"application/json",...K===null?{}:{"content-type":"application/json","content-length":Buffer.byteLength(K)}}},(Y)=>{let z=[];Y.on("data",(V)=>z.push(V)),Y.on("end",()=>{let V=Y.statusCode??0,G=Buffer.concat(z).toString("utf-8"),B=null;if(G.length>0)try{B=JSON.parse(G)}catch{X(new x(V,`Daemon sent invalid JSON (HTTP ${V}): ${G.sli ...
45Maximum size: ${u2/1024/1024} MB`,truncated:!0}});return}if(J.binary){this.updateState({selectedFile:{path:$,content:"Binary file - cannot display"}});return}let q=J.content;if(J.truncated)q+=`
47... (truncated, ${J.totalLines-m2} more lines)`;if(J.size>f2)q=`Warning: Large file (${(J.size/1024).toFixed(1)} KB)
49`+q;this.updateState({selectedFile:{path:$,content:q,truncated:J.truncated}})}catch(J){let q;if(E(J))q="daemon connection lost — reconnecting…";else if(J instanceof Error)q=`Error: ${J.message}`;else q="Failed to read file";this.updateState({selectedFile:{path:$,content:q}})}}async selectIndex($){let J=this._state.displayRows;if($<0||$>=J.length)return;let q=J[$];if(this.updateState({selectedIndex:$}),q&&!q.node.isDirectory)await this.loadFile(q.node.path);else this.updateState({selectedFile:null})}navigateUp($){let J=Math.max(0,this._state.selectedIndex-1);if(J===this._state.selectedIndex)ret ...
50Pass --socket PATH or set DIFFSTALKER_SOCKET.`);return F.join(K,K7)}async function N3($,J){let q=null,K=new Promise((X)=>{q=setTimeout
51Omit the path to use the daemon's target, or restart the daemon with --follow-file ${J}.`)}async function b1($){let J=Z7($.socketPath),q=new g0({socketPath:J});if(await N3(q,A3)){if($.followFile!==void 0)await U7(q,$.followFile);return{client:q,socketPath:J,spawned:!1}}let K=G7();L.mkdirSync(F.dirname(J),{recursive:!0,mode:448});let Q=["--socket",J];if($.followFile!==void 0)Q.push("--follow-file",$.followFile);let X=null,Z=$7(K,Q,{detached:!0,stdio:"ignore"});Z.on("error",(z)=>{X=z}),Z.unref();let Y=Date.now()+X7;while(Date.now()<Y){if(X!==null)throw Error(`Failed to spawn diffstalkerd (${K}): ...
52diffstalker - Terminal git diff/status viewer
54Usage: diffstalker [options] [path]
57 -f, --follow [FILE] Follow hook file for dynamic repo switching
58 (default: ~/.cache/diffstalker/target)
59 -s, --socket PATH diffstalkerd socket to attach to or spawn on
60 (default: $DIFFSTALKER_SOCKET, then
61 $XDG_RUNTIME_DIR/diffstalker/diffstalkerd.sock)
62 -d, --debug Log path changes to stderr for debugging
63 -h, --help Show this help message
66 [path] Path to a git repository (fixed, no watching)
Long lines were clipped for display.