MCPcopy Index your code
hub / github.com/ChinaSiro/claude-code-sourcemap / render

Method render

package/cli.js:5202–5203  ·  view source on GitHub ↗
(q,K,_,z,Y)

Source from the content-addressed store, hash-verified

5200`,await U77(Y,O,{encoding:"utf-8"}),`${h7("success",q)("Installed Alacritty Shift+Enter key binding")}${Cz}${h7("success",q)("You may need to restart Alacritty for changes to take effect")}${Cz}${$8.dim(`See ${xb(Y)}`)}${Cz}`}catch(O){throw H6(O),Error("Failed to install Alacritty Shift+Enter key binding")}}async function $AY(q){let K=Ad(Q77(),".config","zed"),_=Ad(K,"keymap.json");try{await g77(K,{recursive:!0});let z="[]",Y=!1;try{z=await F77(_,{encoding:"utf-8"}),Y=!0}catch(A){if(!e3(A))throw A}if(Y){if(z.includes("shift-enter"))return`${h7("warning",q)("Found existing Zed Shift+Enter key binding. Remove it to continue.")}${Cz}${$8.dim(`See ${xb(_)}`)}${Cz}`;let A=p77(4).toString("hex"),O=`${_}.${A}.bak`;try{await B77(_,O)}catch{return`${h7("warning",q)("Error backing up existing Zed keymap. Bailing out.")}${Cz}${$8.dim(`See ${xb(_)}`)}${Cz}${$8.dim(`Backup path: ${xb(O)}`)}${Cz}`}}let $;try{if($=r8(z),!Array.isArray($))$=[]}catch{$=[]}return $.push({context:"Terminal",bindings:{"shift-enter":["terminal::SendText","\x1B\r"]}}),await U77(_,g6($,null,2)+`
5201`,{encoding:"utf-8"}),`${h7("success",q)("Installed Zed Shift+Enter key binding")}${Cz}${$8.dim(`See ${xb(_)}`)}${Cz}`}catch(z){throw H6(z),Error("Failed to install Zed Shift+Enter key binding")}}var Cz=`
5202`,FB8;var SH6=y(()=>{x3();Ui();s6();t18();x77();u77();V1();y_();y8();XK();vO();E8();vK();l8();FB8={ghostty:"Ghostty",kitty:"Kitty","iTerm.app":"iTerm2",WezTerm:"WezTerm",WarpTerminal:"Warp"}});import{createHash as AAY}from"crypto";import{mkdir as OAY,readdir as wAY,readFile as jAY,stat as HAY,unlink as JAY,writeFile as MAY}from"fs/promises";import{join as i77}from"path";function r77(){return i77(c1(),XAY)}function sZK(q){return AAY("sha256").update(q).digest("hex").slice(0,16)}function tZK(q){return i77(r77(),`${q}.txt`)}async function eZK(q,K){try{let _=r77();await OAY(_,{recursive:!0});let z=tZK(q);await MAY(z,K,{encoding:"utf8",mode:384}),N(`Stored paste ${q} to ${z}`)}catch(_){N(`Failed to store paste: ${_}`)}}async function qGK(q){try{let K=tZK(q);return await jAY(K,{encoding:"utf8"})}catch(K){if(!_7(K))N(`Failed to retrieve paste ${q}: ${K}`);return null}}async function KGK(q){let K=r77(),_;try{_=await wAY(K)}catch{return}let z=q.getTime();for(let Y of _){if(!Y.endsWith(".txt"))continue;let $=i77(K,Y);try{if((await HAY($)).mtimeMs<z)await JAY($),N(`Cleaned up old paste: ${$}`)}catch{}}}var XAY="paste-cache";var o77=y(()=>{_8();m8();y8()});import{appendFile as PAY,writeFile as WAY}from"fs/promises";import{join as YGK}from"path";function Sh6(q){return(q.match(/\r\n|\r|\n/g)||[]).length}function cB8(q,K){if(K===0)return`[Pasted text #${q}]`;return`[Pasted text #${q} +${K} lines]`}function $GK(q){return`[Image #${q}]`}function Od(q){let K=/\[(Pasted text|Image|\.\.\.Truncated text) #(\d+)(?: \+\d+ lines)?(\.)*\]/g;return[...q.matchAll(K)].map((z)=>({id:parseInt(z[2]||"0"),match:z[0],index:z.index})).filter((z)=>z.id>0)}function Ch6(q,K){let _=Od(q),z=q;for(let Y=_.length-1;Y>=0;Y--){let $=_[Y],A=K[$.id];if(A?.type!=="text")continue;z=z.slice(0,$.index)+A.content+z.slice($.index+$.match.length)}return z}function fAY(q){return r8(q)}async function*AGK(){let q=N8();for(let _=Zp.length-1;_>=0;_--)yield Zp[_];let K=YGK(c1(),"history.jsonl");try{for await(let _ of uJ7(K))try{let z=fAY(_);if(z.sessionId===q&&OGK.has(z.timestamp))continue;yield z}catch(z){N(`Failed to parse history line: ${z}`)}}catch(_){if(s1(_)==="ENOENT")return;throw _}}async function*t77(){for await(let q of AGK())yield await s77(q)}async function*lB8(){let q=Fz(),K=N8(),_=[],z=0;for await(let Y of AGK()){if(!Y||typeof Y.project!=="string")continue;if(Y.project!==q)continue;if(Y.sessionId===K)yield await s77(Y),z++;else _.push(Y);if(z+_.length>=_GK)break}for(let Y of _){if(z>=_GK)return;yield await s77(Y),z++}}async function ZAY(q){if(q.content)return{id:q.id,type:q.type,content:q.content,mediaType:q.mediaType,filename:q.filename};if(q.contentHash){let K=await qGK(q.contentHash);if(K)return{id:q.id,type:q.type,content:K,mediaType:q.mediaType,filename:q.filename}}return null}async function s77(q){let K={};for(let[_,z]of Object.entries(q.pastedContents||{})){let Y=await ZAY(z);if(Y)K[Number(_)]=Y}return{display:q.display,pastedContents:K}}async function wGK(){if(Zp.length===0)return;let q;try{let K=YGK(c1(),"history.jsonl");await WAY(K,"",{encoding:"utf8",mode:384,flag:"a"}),q=await PJ(K,{stale:1e4,retries:{retries:3,minTimeout:50}});let _=Zp.map((z)=>g6(z)+`
5203`);Zp=[],await PAY(K,_.join(""),{mode:384})}catch(K){N(`Failed to write prompt history: ${K}`)}finally{if(q)await q()}}async function jGK(q){if(a77||Zp.length===0)return;if(q>5)return;a77=!0;try{await wGK()}finally{if(a77=!1,Zp.length>0)await R7(500),jGK(q+1)}}async function GAY(q){let K=typeof q==="string"?{display:q,pastedContents:{}}:q,_={};if(K.pastedContents)for(let[Y,$]of Object.entries(K.pastedContents)){if($.type==="image")continue;if($.content.length<=DAY)_[Number(Y)]={id:$.id,type:$.type,content:$.content,mediaType:$.mediaType,filename:$.filename};else{let A=sZK($.content);_[Number(Y)]={id:$.id,type:$.type,contentHash:A,mediaType:$.mediaType,filename:$.filename},eZK(A,$.content)}}let z={...K,pastedContents:_,timestamp:Date.now(),project:Fz(),sessionId:N8()};Zp.push(z),QB8=z,dB8=jGK(0)}function bh6(q){if(i6(process.env.CLAUDE_CODE_SKIP_PROMPT_HISTORY))return;if(!zGK)zGK=!0,pq(async()=>{if(dB8)await dB8;if(Zp.length>0)await wGK()});GAY(q)}function HGK(){if(!QB8)return;let q=QB8;QB8=null;let K=Zp.lastIndexOf(q);if(K!==-1)Zp.splice(K,1);else OGK.add(q.timestamp)}var _GK=100,DAY=1024,Zp,a77=!1,dB8=null,zGK=!1,QB8=null,OGK;var Ib=y(()=>{v8();c9();_8();m8();y8();e7();o77();l8();Zp=[],OGK=new Set});function ra(q,K="append"){if(q.length>0){if(e77&&ub.length>0)if(K==="prepend")ub[0]=q+ub[0];else ub[0]=ub[0]+q;else if(ub.unshift(q),ub.length>TAY)ub.pop();e77=!0,rB8=!1}}function oB8(){return ub[0]??""}function q78(){e77=!1}function aB8(q,K){JGK=q,qq7=K,rB8=!0,nB8=0}function sB8(){if(!rB8||ub.length<=1)return null;return nB8=(nB8+1)%ub.length,{text:ub[nB8]??"",start:JGK,length:qq7}}function tB8(q){qq7=q}function K78(){rB8=!1}class k5{measuredText;selection;offset;constructor(q,K=0,_=0){this.measuredText=q;this.selection=_;this.offset=Math.max(0,Math.min(this.text.length,K))}static fromText(q,K,_=0,z=0){return new k5(new MGK(q,K-1),_,z)}getViewportStartLine(q){if(q===void 0||q<=0)return 0;let{line:K}=this.getPosition(),_=this.measuredText.getWrappedText();if(_.length<=q)return 0;let z=Math.floor(q/2),Y=Math.max(0,K-z),$=Math.min(_.length,Y+q);if($-Y<q)Y=Math.max(0,$-q);return Y}getViewportCharOffset(q){let K=this.getViewportStartLine(q);if(K===0)return 0;return this.measuredText.getWrappedLines()[K]?.startOffset??0}getViewportCharEnd(q){let K=this.getViewportStartLine(q),_=this.measuredText.getWrappedLines();if(q===void 0||q<=0)return this.text.length;let z=Math.min(_.length,K+q);if(z>=_.length)return this.text.length;return _[z]?.startOffset??this.text.length}render(q,K,_,z,Y){let{line:$,column:A}=this.getPosition(),O=this.measuredText.getWrappedText(),w=this.getViewportStartLine(Y),j=Y!==void 0&&Y>0?Math.min(O.length,w+Y):O.length;return O.slice(w,j).map((H,J)=>{let M=J+w,X=H;if(K){let v=Array.from(YH().segment(H));if(M===O.length-1){let V=Math.min(6,v.length),E=v.length-V,S=v.length>V?v[E].index:0;X=K.repeat(E)+H.slice(S)}else X=K.repeat(v.length)}if($!==M)return X.trimEnd();let P="",W=q,D="",f=0,G=!1;for(let{segment:v}of YH().segment(X)){if(G){D+=v;continue}let V=f+O1(v);if(V>A)W=v,G=!0;else f=V,P+=v}let Z,T="";if(z&&M===O.length-1&&this.isAtEnd()&&z.text.length>0){let v=ox6(z.text)||z.text[0];Z=q?_(v):v;let V=z.text.slice(v.length);if(V.length>0)T=z.dim(V)}else Z=q?_(W):W;return P+Z+T+D.trimEnd()}).join(`
5204`)}left(){if(this.offset===0)return this;let q=this.imageRefEndingAt(this.offset);if(q)return new k5(this.measuredText,q.start);let K=this.measuredText.prevOffset(this.offset);return new k5(this.measuredText,K)}right(){if(this.offset>=this.text.length)return this;let q=this.imageRefStartingAt(this.offset);if(q)return new k5(this.measuredText,q.end);let K=this.measuredText.nextOffset(this.offset);return new k5(this.measuredText,Math.min(K,this.text.length))}imageRefEndingAt(q){let K=this.text.slice(0,q).match(/\[Image #\d+\]$/);return K?{start:q-K[0].length,end:q}:null}imageRefStartingAt(q){let K=this.text.slice(q).match(/^\[Image #\d+\]/);return K?{start:q,end:q+K[0].length}:null}snapOutOfImageRef(q,K){let _=/\[Image #\d+\]/g,z;while((z=_.exec(this.text))!==null){let Y=z.index,$=Y+z[0].length;if(q>Y&&q<$)return K==="start"?Y:$}return q}up(){let{line:q,column:K}=this.getPosition();if(q===0)return this;let _=this.measuredText.getWrappedText()[q-1];if(_===void 0)return this;let z=O1(_);if(K>z){let $=this.getOffset({line:q-1,column:z});return new k5(this.measuredText,$,0)}let Y=this.getOffset({line:q-1,column:K});return new k5(this.measuredText,Y,0)}down(){let{line:q,column:K}=this.getPosition();if(q>=this.measuredText.lineCount-1)return this;let _=this.measuredText.getWrappedText()[q+1];if(_===void 0)return this;let z=O1(_);if(K>z){let $=this.getOffset({line:q+1,column:z});return new k5(this.measuredText,$,0)}let Y=this.getOffset({line:q+1,column:K});return new k5(this.measuredText,Y,0)}startOfCurrentLine(){let{line:q}=this.getPosition();return new k5(this.measuredText,this.getOffset({line:q,column:0}),0)}startOfLine(){let{line:q,column:K}=this.getPosition();if(K===0&&q>0)return new k5(this.measuredText,this.getOffset({line:q-1,column:0}),0);return this.startOfCurrentLine()}firstNonBlankInLine(){let{line:q}=this.getPosition(),_=(this.measuredText.getWrappedText()[q]||"").match(/^\s*\S/),z=_?.index?_.index+_[0].length-1:0,Y=this.getOffset({line:q,column:z});return new k5(this.measuredText,Y,0)}endOfLine(){let{line:q}=this.getPosition(),K=this.measuredText.getLineLength(q),_=this.getOffset({line:q,column:K});return new k5(this.measuredText,_,0)}findLogicalLineStart(q=this.offset){let K=this.text.lastIndexOf(`
5205`,q-1);return K===-1?0:K+1}findLogicalLineEnd(q=this.offset){let K=this.text.indexOf(`
5206`,q);return K===-1?this.text.length:K}getLogicalLineBounds(){return{start:this.findLogicalLineStart(),end:this.findLogicalLineEnd()}}createCursorWithColumn(q,K,_){let z=K-q,Y=Math.min(_,z),$=q+Y,A=this.measuredText.snapToGraphemeBoundary($);return new k5(this.measuredText,A,0)}endOfLogicalLine(){return new k5(this.measuredText,this.findLogicalLineEnd(),0)}startOfLogicalLine(){return new k5(this.measuredText,this.findLogicalLineStart(),0)}firstNonBlankInLogicalLine(){let{start:q,end:K}=this.getLogicalLineBounds(),z=this.text.slice(q,K).match(/\S/),Y=q+(z?.index??0);return new k5(this.measuredText,Y,0)}upLogicalLine(){let{start:q}=this.getLogicalLineBounds();if(q===0)return new k5(this.measuredText,0,0);let K=this.offset-q,_=q-1,z=this.findLogicalLineStart(_);return this.createCursorWithColumn(z,_,K)}downLogicalLine(){let{start:q,end:K}=this.getLogicalLineBounds();if(K>=this.text.length)return new k5(this.measuredText,this.text.length,0);let _=this.offset-q,z=K+1,Y=this.findLogicalLineEnd(z);return this.createCursorWithColumn(z,Y,_)}nextWord(){if(this.isAtEnd())return this;let q=this.measuredText.getWordBoundaries();for(let K of q)if(K.isWordLike&&K.start>this.offset)return new k5(this.measuredText,K.start);return new k5(this.measuredText,this.text.length)}endOfWord(){if(this.isAtEnd())return this;let q=this.measuredText.getWordBoundaries();for(let K of q){if(!K.isWordLike)continue;if(this.offset>=K.start&&this.offset<K.end-1)return new k5(this.measuredText,K.end-1);if(this.offset===K.end-1){for(let _ of q)if(_.isWordLike&&_.start>this.offset)return new k5(this.measuredText,_.end-1);return this}}for(let K of q)if(K.isWordLike&&K.start>this.offset)return new k5(this.measuredText,K.end-1);return this}prevWord(){if(this.isAtStart())return this;let q=this.measuredText.getWordBoundaries(),K=null;for(let _ of q){if(!_.isWordLike)continue;if(_.start<this.offset){if(this.offset>_.start&&this.offset<=_.end)return new k5(this.measuredText,_.start);K=_.start}}if(K!==null)return new k5(this.measuredText,K);return new k5(this.measuredText,0)}nextVimWord(){if(this.isAtEnd())return this;let q=this.offset,K=(z)=>this.measuredText.nextOffset(z),_=this.graphemeAt(q);if(!_)return this;if(ia(_))while(q<this.text.length&&ia(this.graphemeAt(q)))q=K(q);else if(w56(_))while(q<this.text.length&&w56(this.graphemeAt(q)))q=K(q);while(q<this.text.length&&e18.test(this.graphemeAt(q)))q=K(q);return new k5(this.measuredText,q)}endOfVimWord(){if(this.isAtEnd())return this;let q=this.text,K=this.offset,_=(Y)=>this.measuredText.nextOffset(Y);if(this.graphemeAt(K)==="")return this;K=_(K);while(K<q.length&&e18.test(this.graphemeAt(K)))K=_(K);if(K>=q.length)return new k5(this.measuredText,q.length);let z=this.graphemeAt(K);if(ia(z))while(K<q.length){let Y=_(K);if(Y>=q.length||!ia(this.graphemeAt(Y)))break;K=Y}else if(w56(z))while(K<q.length){let Y=_(K);if(Y>=q.length||!w56(this.graphemeAt(Y)))break;K=Y}return new k5(this.measuredText,K)}prevVimWord(){if(this.isAtStart())return this;let q=this.offset,K=(z)=>this.measuredText.prevOffset(z);q=K(q);while(q>0&&e18.test(this.graphemeAt(q)))q=K(q);if(q===0&&e18.test(this.graphemeAt(0)))return new k5(this.measuredText,0);let _=this.graphemeAt(q);if(ia(_))while(q>0){let z=K(q);if(!ia(this.graphemeAt(z)))break;q=z}else if(w56(_))while(q>0){let z=K(q);if(!w56(this.graphemeAt(z)))break;q=z}return new k5(this.measuredText,q)}nextWORD(){let q=this;while(!q.isOverWhitespace()&&!q.isAtEnd())q=q.right();while(q.isOverWhitespace()&&!q.isAtEnd())q=q.right();return q}endOfWORD(){if(this.isAtEnd())return this;let q=this;if(!q.isOverWhitespace()&&(q.right().isOverWhitespace()||q.right().isAtEnd()))return q=q.right(),q.endOfWORD();if(q.isOverWhitespace())q=q.nextWORD();while(!q.right().isOverWhitespace()&&!q.isAtEnd())q=q.right();return q}prevWORD(){let q=this;if(q.left().isOverWhitespace())q=q.left();while(q.isOverWhitespace()&&!q.isAtStart())q=q.left();if(!q.isOverWhitespace())while(!q.left().isOverWhitespace()&&!q.isAtStart())q=q.left();return q}modifyText(q,K=""){let _=this.offset,z=q.offset,Y=this.text.slice(0,_)+K+this.text.slice(z);return k5.fromText(Y,this.columns,_+K.normalize("NFC").length)}insert(q){return this.modifyText(this,q)}del(){if(this.isAtEnd())return this;return this.modifyText(this.right())}backspace(){if(this.isAtStart())return this;return this.left().modifyText(this)}deleteToLineStart(){if(this.offset>0&&this.text[this.offset-1]===`

Callers

nothing calls this directly

Calls 12

getPositionMethod · 0.95
getViewportStartLineMethod · 0.95
isAtEndMethod · 0.95
YHFunction · 0.85
ox6Function · 0.85
_Class · 0.70
getWrappedTextMethod · 0.45
minMethod · 0.45
joinMethod · 0.45
sliceMethod · 0.45
fromMethod · 0.45
segmentMethod · 0.45

Tested by

no test coverage detected