index.js 255 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Terminal = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. var CircularList_1 = require("./utils/CircularList");
  5. exports.CHAR_DATA_ATTR_INDEX = 0;
  6. exports.CHAR_DATA_CHAR_INDEX = 1;
  7. exports.CHAR_DATA_WIDTH_INDEX = 2;
  8. exports.CHAR_DATA_CODE_INDEX = 3;
  9. exports.MAX_BUFFER_SIZE = 4294967295;
  10. var Buffer = (function () {
  11. function Buffer(_terminal, _hasScrollback) {
  12. this._terminal = _terminal;
  13. this._hasScrollback = _hasScrollback;
  14. this.clear();
  15. }
  16. Object.defineProperty(Buffer.prototype, "lines", {
  17. get: function () {
  18. return this._lines;
  19. },
  20. enumerable: true,
  21. configurable: true
  22. });
  23. Object.defineProperty(Buffer.prototype, "hasScrollback", {
  24. get: function () {
  25. return this._hasScrollback && this.lines.maxLength > this._terminal.rows;
  26. },
  27. enumerable: true,
  28. configurable: true
  29. });
  30. Object.defineProperty(Buffer.prototype, "isCursorInViewport", {
  31. get: function () {
  32. var absoluteY = this.ybase + this.y;
  33. var relativeY = absoluteY - this.ydisp;
  34. return (relativeY >= 0 && relativeY < this._terminal.rows);
  35. },
  36. enumerable: true,
  37. configurable: true
  38. });
  39. Buffer.prototype._getCorrectBufferLength = function (rows) {
  40. if (!this._hasScrollback) {
  41. return rows;
  42. }
  43. var correctBufferLength = rows + this._terminal.options.scrollback;
  44. return correctBufferLength > exports.MAX_BUFFER_SIZE ? exports.MAX_BUFFER_SIZE : correctBufferLength;
  45. };
  46. Buffer.prototype.fillViewportRows = function () {
  47. if (this._lines.length === 0) {
  48. var i = this._terminal.rows;
  49. while (i--) {
  50. this.lines.push(this._terminal.blankLine());
  51. }
  52. }
  53. };
  54. Buffer.prototype.clear = function () {
  55. this.ydisp = 0;
  56. this.ybase = 0;
  57. this.y = 0;
  58. this.x = 0;
  59. this._lines = new CircularList_1.CircularList(this._getCorrectBufferLength(this._terminal.rows));
  60. this.scrollTop = 0;
  61. this.scrollBottom = this._terminal.rows - 1;
  62. this.setupTabStops();
  63. };
  64. Buffer.prototype.resize = function (newCols, newRows) {
  65. var newMaxLength = this._getCorrectBufferLength(newRows);
  66. if (newMaxLength > this._lines.maxLength) {
  67. this._lines.maxLength = newMaxLength;
  68. }
  69. if (this._lines.length > 0) {
  70. if (this._terminal.cols < newCols) {
  71. var ch = [this._terminal.defAttr, ' ', 1, 32];
  72. for (var i = 0; i < this._lines.length; i++) {
  73. while (this._lines.get(i).length < newCols) {
  74. this._lines.get(i).push(ch);
  75. }
  76. }
  77. }
  78. var addToY = 0;
  79. if (this._terminal.rows < newRows) {
  80. for (var y = this._terminal.rows; y < newRows; y++) {
  81. if (this._lines.length < newRows + this.ybase) {
  82. if (this.ybase > 0 && this._lines.length <= this.ybase + this.y + addToY + 1) {
  83. this.ybase--;
  84. addToY++;
  85. if (this.ydisp > 0) {
  86. this.ydisp--;
  87. }
  88. }
  89. else {
  90. this._lines.push(this._terminal.blankLine(undefined, undefined, newCols));
  91. }
  92. }
  93. }
  94. }
  95. else {
  96. for (var y = this._terminal.rows; y > newRows; y--) {
  97. if (this._lines.length > newRows + this.ybase) {
  98. if (this._lines.length > this.ybase + this.y + 1) {
  99. this._lines.pop();
  100. }
  101. else {
  102. this.ybase++;
  103. this.ydisp++;
  104. }
  105. }
  106. }
  107. }
  108. if (newMaxLength < this._lines.maxLength) {
  109. var amountToTrim = this._lines.length - newMaxLength;
  110. if (amountToTrim > 0) {
  111. this._lines.trimStart(amountToTrim);
  112. this.ybase = Math.max(this.ybase - amountToTrim, 0);
  113. this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
  114. }
  115. this._lines.maxLength = newMaxLength;
  116. }
  117. this.x = Math.min(this.x, newCols - 1);
  118. this.y = Math.min(this.y, newRows - 1);
  119. if (addToY) {
  120. this.y += addToY;
  121. }
  122. this.savedY = Math.min(this.savedY, newRows - 1);
  123. this.savedX = Math.min(this.savedX, newCols - 1);
  124. this.scrollTop = 0;
  125. }
  126. this.scrollBottom = newRows - 1;
  127. };
  128. Buffer.prototype.translateBufferLineToString = function (lineIndex, trimRight, startCol, endCol) {
  129. if (startCol === void 0) { startCol = 0; }
  130. if (endCol === void 0) { endCol = null; }
  131. var lineString = '';
  132. var line = this.lines.get(lineIndex);
  133. if (!line) {
  134. return '';
  135. }
  136. var startIndex = startCol;
  137. if (endCol === null) {
  138. endCol = line.length;
  139. }
  140. var endIndex = endCol;
  141. for (var i = 0; i < line.length; i++) {
  142. var char = line[i];
  143. lineString += char[exports.CHAR_DATA_CHAR_INDEX];
  144. if (char[exports.CHAR_DATA_WIDTH_INDEX] === 0) {
  145. if (startCol >= i) {
  146. startIndex--;
  147. }
  148. if (endCol >= i) {
  149. endIndex--;
  150. }
  151. }
  152. else {
  153. if (char[exports.CHAR_DATA_CHAR_INDEX].length > 1) {
  154. if (startCol > i) {
  155. startIndex += char[exports.CHAR_DATA_CHAR_INDEX].length - 1;
  156. }
  157. if (endCol > i) {
  158. endIndex += char[exports.CHAR_DATA_CHAR_INDEX].length - 1;
  159. }
  160. }
  161. }
  162. }
  163. if (trimRight) {
  164. var rightWhitespaceIndex = lineString.search(/\s+$/);
  165. if (rightWhitespaceIndex !== -1) {
  166. endIndex = Math.min(endIndex, rightWhitespaceIndex);
  167. }
  168. if (endIndex <= startIndex) {
  169. return '';
  170. }
  171. }
  172. return lineString.substring(startIndex, endIndex);
  173. };
  174. Buffer.prototype.setupTabStops = function (i) {
  175. if (i != null) {
  176. if (!this.tabs[i]) {
  177. i = this.prevStop(i);
  178. }
  179. }
  180. else {
  181. this.tabs = {};
  182. i = 0;
  183. }
  184. for (; i < this._terminal.cols; i += this._terminal.options.tabStopWidth) {
  185. this.tabs[i] = true;
  186. }
  187. };
  188. Buffer.prototype.prevStop = function (x) {
  189. if (x == null) {
  190. x = this.x;
  191. }
  192. while (!this.tabs[--x] && x > 0)
  193. ;
  194. return x >= this._terminal.cols ? this._terminal.cols - 1 : x < 0 ? 0 : x;
  195. };
  196. Buffer.prototype.nextStop = function (x) {
  197. if (x == null) {
  198. x = this.x;
  199. }
  200. while (!this.tabs[++x] && x < this._terminal.cols)
  201. ;
  202. return x >= this._terminal.cols ? this._terminal.cols - 1 : x < 0 ? 0 : x;
  203. };
  204. return Buffer;
  205. }());
  206. exports.Buffer = Buffer;
  207. },{"./utils/CircularList":32}],2:[function(require,module,exports){
  208. "use strict";
  209. var __extends = (this && this.__extends) || (function () {
  210. var extendStatics = Object.setPrototypeOf ||
  211. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  212. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  213. return function (d, b) {
  214. extendStatics(d, b);
  215. function __() { this.constructor = d; }
  216. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  217. };
  218. })();
  219. Object.defineProperty(exports, "__esModule", { value: true });
  220. var Buffer_1 = require("./Buffer");
  221. var EventEmitter_1 = require("./EventEmitter");
  222. var BufferSet = (function (_super) {
  223. __extends(BufferSet, _super);
  224. function BufferSet(_terminal) {
  225. var _this = _super.call(this) || this;
  226. _this._terminal = _terminal;
  227. _this._normal = new Buffer_1.Buffer(_this._terminal, true);
  228. _this._normal.fillViewportRows();
  229. _this._alt = new Buffer_1.Buffer(_this._terminal, false);
  230. _this._activeBuffer = _this._normal;
  231. _this.setupTabStops();
  232. return _this;
  233. }
  234. Object.defineProperty(BufferSet.prototype, "alt", {
  235. get: function () {
  236. return this._alt;
  237. },
  238. enumerable: true,
  239. configurable: true
  240. });
  241. Object.defineProperty(BufferSet.prototype, "active", {
  242. get: function () {
  243. return this._activeBuffer;
  244. },
  245. enumerable: true,
  246. configurable: true
  247. });
  248. Object.defineProperty(BufferSet.prototype, "normal", {
  249. get: function () {
  250. return this._normal;
  251. },
  252. enumerable: true,
  253. configurable: true
  254. });
  255. BufferSet.prototype.activateNormalBuffer = function () {
  256. if (this._activeBuffer === this._normal) {
  257. return;
  258. }
  259. this._alt.clear();
  260. this._activeBuffer = this._normal;
  261. this.emit('activate', {
  262. activeBuffer: this._normal,
  263. inactiveBuffer: this._alt
  264. });
  265. };
  266. BufferSet.prototype.activateAltBuffer = function () {
  267. if (this._activeBuffer === this._alt) {
  268. return;
  269. }
  270. this._alt.fillViewportRows();
  271. this._activeBuffer = this._alt;
  272. this.emit('activate', {
  273. activeBuffer: this._alt,
  274. inactiveBuffer: this._normal
  275. });
  276. };
  277. BufferSet.prototype.resize = function (newCols, newRows) {
  278. this._normal.resize(newCols, newRows);
  279. this._alt.resize(newCols, newRows);
  280. };
  281. BufferSet.prototype.setupTabStops = function (i) {
  282. this._normal.setupTabStops(i);
  283. this._alt.setupTabStops(i);
  284. };
  285. return BufferSet;
  286. }(EventEmitter_1.EventEmitter));
  287. exports.BufferSet = BufferSet;
  288. },{"./Buffer":1,"./EventEmitter":7}],3:[function(require,module,exports){
  289. "use strict";
  290. Object.defineProperty(exports, "__esModule", { value: true });
  291. exports.wcwidth = (function (opts) {
  292. var COMBINING_BMP = [
  293. [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
  294. [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
  295. [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
  296. [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
  297. [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
  298. [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
  299. [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
  300. [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
  301. [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
  302. [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
  303. [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
  304. [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
  305. [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
  306. [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
  307. [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
  308. [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
  309. [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
  310. [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
  311. [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
  312. [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
  313. [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
  314. [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
  315. [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
  316. [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
  317. [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
  318. [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
  319. [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
  320. [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
  321. [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
  322. [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
  323. [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
  324. [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
  325. [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
  326. [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
  327. [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
  328. [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
  329. [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
  330. [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
  331. [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
  332. [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
  333. [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
  334. [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
  335. [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
  336. ];
  337. var COMBINING_HIGH = [
  338. [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
  339. [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
  340. [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
  341. [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
  342. [0xE0100, 0xE01EF]
  343. ];
  344. function bisearch(ucs, data) {
  345. var min = 0;
  346. var max = data.length - 1;
  347. var mid;
  348. if (ucs < data[0][0] || ucs > data[max][1]) {
  349. return false;
  350. }
  351. while (max >= min) {
  352. mid = (min + max) >> 1;
  353. if (ucs > data[mid][1]) {
  354. min = mid + 1;
  355. }
  356. else if (ucs < data[mid][0]) {
  357. max = mid - 1;
  358. }
  359. else {
  360. return true;
  361. }
  362. }
  363. return false;
  364. }
  365. function wcwidthBMP(ucs) {
  366. if (ucs === 0) {
  367. return opts.nul;
  368. }
  369. if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) {
  370. return opts.control;
  371. }
  372. if (bisearch(ucs, COMBINING_BMP)) {
  373. return 0;
  374. }
  375. if (isWideBMP(ucs)) {
  376. return 2;
  377. }
  378. return 1;
  379. }
  380. function isWideBMP(ucs) {
  381. return (ucs >= 0x1100 && (ucs <= 0x115f ||
  382. ucs === 0x2329 ||
  383. ucs === 0x232a ||
  384. (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs !== 0x303f) ||
  385. (ucs >= 0xac00 && ucs <= 0xd7a3) ||
  386. (ucs >= 0xf900 && ucs <= 0xfaff) ||
  387. (ucs >= 0xfe10 && ucs <= 0xfe19) ||
  388. (ucs >= 0xfe30 && ucs <= 0xfe6f) ||
  389. (ucs >= 0xff00 && ucs <= 0xff60) ||
  390. (ucs >= 0xffe0 && ucs <= 0xffe6)));
  391. }
  392. function wcwidthHigh(ucs) {
  393. if (bisearch(ucs, COMBINING_HIGH)) {
  394. return 0;
  395. }
  396. if ((ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x30000 && ucs <= 0x3fffd)) {
  397. return 2;
  398. }
  399. return 1;
  400. }
  401. var control = opts.control | 0;
  402. var table = null;
  403. function init_table() {
  404. var CODEPOINTS = 65536;
  405. var BITWIDTH = 2;
  406. var ITEMSIZE = 32;
  407. var CONTAINERSIZE = CODEPOINTS * BITWIDTH / ITEMSIZE;
  408. var CODEPOINTS_PER_ITEM = ITEMSIZE / BITWIDTH;
  409. table = (typeof Uint32Array === 'undefined')
  410. ? new Array(CONTAINERSIZE)
  411. : new Uint32Array(CONTAINERSIZE);
  412. for (var i = 0; i < CONTAINERSIZE; ++i) {
  413. var num = 0;
  414. var pos = CODEPOINTS_PER_ITEM;
  415. while (pos--) {
  416. num = (num << 2) | wcwidthBMP(CODEPOINTS_PER_ITEM * i + pos);
  417. }
  418. table[i] = num;
  419. }
  420. return table;
  421. }
  422. return function (num) {
  423. num = num | 0;
  424. if (num < 32) {
  425. return control | 0;
  426. }
  427. if (num < 127) {
  428. return 1;
  429. }
  430. var t = table || init_table();
  431. if (num < 65536) {
  432. return t[num >> 4] >> ((num & 15) << 1) & 3;
  433. }
  434. return wcwidthHigh(num);
  435. };
  436. })({ nul: 0, control: 0 });
  437. },{}],4:[function(require,module,exports){
  438. "use strict";
  439. Object.defineProperty(exports, "__esModule", { value: true });
  440. exports.CHARSETS = {};
  441. exports.DEFAULT_CHARSET = exports.CHARSETS['B'];
  442. exports.CHARSETS['0'] = {
  443. '`': '\u25c6',
  444. 'a': '\u2592',
  445. 'b': '\u0009',
  446. 'c': '\u000c',
  447. 'd': '\u000d',
  448. 'e': '\u000a',
  449. 'f': '\u00b0',
  450. 'g': '\u00b1',
  451. 'h': '\u2424',
  452. 'i': '\u000b',
  453. 'j': '\u2518',
  454. 'k': '\u2510',
  455. 'l': '\u250c',
  456. 'm': '\u2514',
  457. 'n': '\u253c',
  458. 'o': '\u23ba',
  459. 'p': '\u23bb',
  460. 'q': '\u2500',
  461. 'r': '\u23bc',
  462. 's': '\u23bd',
  463. 't': '\u251c',
  464. 'u': '\u2524',
  465. 'v': '\u2534',
  466. 'w': '\u252c',
  467. 'x': '\u2502',
  468. 'y': '\u2264',
  469. 'z': '\u2265',
  470. '{': '\u03c0',
  471. '|': '\u2260',
  472. '}': '\u00a3',
  473. '~': '\u00b7'
  474. };
  475. exports.CHARSETS['A'] = {
  476. '#': '£'
  477. };
  478. exports.CHARSETS['B'] = null;
  479. exports.CHARSETS['4'] = {
  480. '#': '£',
  481. '@': '¾',
  482. '[': 'ij',
  483. '\\': '½',
  484. ']': '|',
  485. '{': '¨',
  486. '|': 'f',
  487. '}': '¼',
  488. '~': '´'
  489. };
  490. exports.CHARSETS['C'] =
  491. exports.CHARSETS['5'] = {
  492. '[': 'Ä',
  493. '\\': 'Ö',
  494. ']': 'Å',
  495. '^': 'Ü',
  496. '`': 'é',
  497. '{': 'ä',
  498. '|': 'ö',
  499. '}': 'å',
  500. '~': 'ü'
  501. };
  502. exports.CHARSETS['R'] = {
  503. '#': '£',
  504. '@': 'à',
  505. '[': '°',
  506. '\\': 'ç',
  507. ']': '§',
  508. '{': 'é',
  509. '|': 'ù',
  510. '}': 'è',
  511. '~': '¨'
  512. };
  513. exports.CHARSETS['Q'] = {
  514. '@': 'à',
  515. '[': 'â',
  516. '\\': 'ç',
  517. ']': 'ê',
  518. '^': 'î',
  519. '`': 'ô',
  520. '{': 'é',
  521. '|': 'ù',
  522. '}': 'è',
  523. '~': 'û'
  524. };
  525. exports.CHARSETS['K'] = {
  526. '@': '§',
  527. '[': 'Ä',
  528. '\\': 'Ö',
  529. ']': 'Ü',
  530. '{': 'ä',
  531. '|': 'ö',
  532. '}': 'ü',
  533. '~': 'ß'
  534. };
  535. exports.CHARSETS['Y'] = {
  536. '#': '£',
  537. '@': '§',
  538. '[': '°',
  539. '\\': 'ç',
  540. ']': 'é',
  541. '`': 'ù',
  542. '{': 'à',
  543. '|': 'ò',
  544. '}': 'è',
  545. '~': 'ì'
  546. };
  547. exports.CHARSETS['E'] =
  548. exports.CHARSETS['6'] = {
  549. '@': 'Ä',
  550. '[': 'Æ',
  551. '\\': 'Ø',
  552. ']': 'Å',
  553. '^': 'Ü',
  554. '`': 'ä',
  555. '{': 'æ',
  556. '|': 'ø',
  557. '}': 'å',
  558. '~': 'ü'
  559. };
  560. exports.CHARSETS['Z'] = {
  561. '#': '£',
  562. '@': '§',
  563. '[': '¡',
  564. '\\': 'Ñ',
  565. ']': '¿',
  566. '{': '°',
  567. '|': 'ñ',
  568. '}': 'ç'
  569. };
  570. exports.CHARSETS['H'] =
  571. exports.CHARSETS['7'] = {
  572. '@': 'É',
  573. '[': 'Ä',
  574. '\\': 'Ö',
  575. ']': 'Å',
  576. '^': 'Ü',
  577. '`': 'é',
  578. '{': 'ä',
  579. '|': 'ö',
  580. '}': 'å',
  581. '~': 'ü'
  582. };
  583. exports.CHARSETS['='] = {
  584. '#': 'ù',
  585. '@': 'à',
  586. '[': 'é',
  587. '\\': 'ç',
  588. ']': 'ê',
  589. '^': 'î',
  590. '_': 'è',
  591. '`': 'ô',
  592. '{': 'ä',
  593. '|': 'ö',
  594. '}': 'ü',
  595. '~': 'û'
  596. };
  597. },{}],5:[function(require,module,exports){
  598. "use strict";
  599. Object.defineProperty(exports, "__esModule", { value: true });
  600. var CompositionHelper = (function () {
  601. function CompositionHelper(textarea, compositionView, terminal) {
  602. this.textarea = textarea;
  603. this.compositionView = compositionView;
  604. this.terminal = terminal;
  605. this.isComposing = false;
  606. this.isSendingComposition = false;
  607. this.compositionPosition = { start: null, end: null };
  608. }
  609. CompositionHelper.prototype.compositionstart = function () {
  610. this.isComposing = true;
  611. this.compositionPosition.start = this.textarea.value.length;
  612. this.compositionView.textContent = '';
  613. this.compositionView.classList.add('active');
  614. };
  615. CompositionHelper.prototype.compositionupdate = function (ev) {
  616. var _this = this;
  617. this.compositionView.textContent = ev.data;
  618. this.updateCompositionElements();
  619. setTimeout(function () {
  620. _this.compositionPosition.end = _this.textarea.value.length;
  621. }, 0);
  622. };
  623. CompositionHelper.prototype.compositionend = function () {
  624. this.finalizeComposition(true);
  625. };
  626. CompositionHelper.prototype.keydown = function (ev) {
  627. if (this.isComposing || this.isSendingComposition) {
  628. if (ev.keyCode === 229) {
  629. return false;
  630. }
  631. else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
  632. return false;
  633. }
  634. else {
  635. this.finalizeComposition(false);
  636. }
  637. }
  638. if (ev.keyCode === 229) {
  639. this.handleAnyTextareaChanges();
  640. return false;
  641. }
  642. return true;
  643. };
  644. CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) {
  645. var _this = this;
  646. this.compositionView.classList.remove('active');
  647. this.isComposing = false;
  648. this.clearTextareaPosition();
  649. if (!waitForPropogation) {
  650. this.isSendingComposition = false;
  651. var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end);
  652. this.terminal.handler(input);
  653. }
  654. else {
  655. var currentCompositionPosition_1 = {
  656. start: this.compositionPosition.start,
  657. end: this.compositionPosition.end,
  658. };
  659. this.isSendingComposition = true;
  660. setTimeout(function () {
  661. if (_this.isSendingComposition) {
  662. _this.isSendingComposition = false;
  663. var input = void 0;
  664. if (_this.isComposing) {
  665. input = _this.textarea.value.substring(currentCompositionPosition_1.start, currentCompositionPosition_1.end);
  666. }
  667. else {
  668. input = _this.textarea.value.substring(currentCompositionPosition_1.start);
  669. }
  670. _this.terminal.handler(input);
  671. }
  672. }, 0);
  673. }
  674. };
  675. CompositionHelper.prototype.handleAnyTextareaChanges = function () {
  676. var _this = this;
  677. var oldValue = this.textarea.value;
  678. setTimeout(function () {
  679. if (!_this.isComposing) {
  680. var newValue = _this.textarea.value;
  681. var diff = newValue.replace(oldValue, '');
  682. if (diff.length > 0) {
  683. _this.terminal.handler(diff);
  684. }
  685. }
  686. }, 0);
  687. };
  688. CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) {
  689. var _this = this;
  690. if (!this.isComposing) {
  691. return;
  692. }
  693. if (this.terminal.buffer.isCursorInViewport) {
  694. var cellHeight = Math.ceil(this.terminal.charMeasure.height * this.terminal.options.lineHeight);
  695. var cursorTop = this.terminal.buffer.y * cellHeight;
  696. var cursorLeft = this.terminal.buffer.x * this.terminal.charMeasure.width;
  697. this.compositionView.style.left = cursorLeft + 'px';
  698. this.compositionView.style.top = cursorTop + 'px';
  699. this.compositionView.style.height = cellHeight + 'px';
  700. this.compositionView.style.lineHeight = cellHeight + 'px';
  701. var compositionViewBounds = this.compositionView.getBoundingClientRect();
  702. this.textarea.style.left = cursorLeft + 'px';
  703. this.textarea.style.top = cursorTop + 'px';
  704. this.textarea.style.width = compositionViewBounds.width + 'px';
  705. this.textarea.style.height = compositionViewBounds.height + 'px';
  706. this.textarea.style.lineHeight = compositionViewBounds.height + 'px';
  707. }
  708. if (!dontRecurse) {
  709. setTimeout(function () { return _this.updateCompositionElements(true); }, 0);
  710. }
  711. };
  712. CompositionHelper.prototype.clearTextareaPosition = function () {
  713. this.textarea.style.left = '';
  714. this.textarea.style.top = '';
  715. };
  716. return CompositionHelper;
  717. }());
  718. exports.CompositionHelper = CompositionHelper;
  719. },{}],6:[function(require,module,exports){
  720. "use strict";
  721. Object.defineProperty(exports, "__esModule", { value: true });
  722. var C0;
  723. (function (C0) {
  724. C0.NUL = '\x00';
  725. C0.SOH = '\x01';
  726. C0.STX = '\x02';
  727. C0.ETX = '\x03';
  728. C0.EOT = '\x04';
  729. C0.ENQ = '\x05';
  730. C0.ACK = '\x06';
  731. C0.BEL = '\x07';
  732. C0.BS = '\x08';
  733. C0.HT = '\x09';
  734. C0.LF = '\x0a';
  735. C0.VT = '\x0b';
  736. C0.FF = '\x0c';
  737. C0.CR = '\x0d';
  738. C0.SO = '\x0e';
  739. C0.SI = '\x0f';
  740. C0.DLE = '\x10';
  741. C0.DC1 = '\x11';
  742. C0.DC2 = '\x12';
  743. C0.DC3 = '\x13';
  744. C0.DC4 = '\x14';
  745. C0.NAK = '\x15';
  746. C0.SYN = '\x16';
  747. C0.ETB = '\x17';
  748. C0.CAN = '\x18';
  749. C0.EM = '\x19';
  750. C0.SUB = '\x1a';
  751. C0.ESC = '\x1b';
  752. C0.FS = '\x1c';
  753. C0.GS = '\x1d';
  754. C0.RS = '\x1e';
  755. C0.US = '\x1f';
  756. C0.SP = '\x20';
  757. C0.DEL = '\x7f';
  758. })(C0 = exports.C0 || (exports.C0 = {}));
  759. },{}],7:[function(require,module,exports){
  760. "use strict";
  761. Object.defineProperty(exports, "__esModule", { value: true });
  762. var EventEmitter = (function () {
  763. function EventEmitter() {
  764. this._events = this._events || {};
  765. }
  766. EventEmitter.prototype.on = function (type, listener) {
  767. this._events[type] = this._events[type] || [];
  768. this._events[type].push(listener);
  769. };
  770. EventEmitter.prototype.off = function (type, listener) {
  771. if (!this._events[type]) {
  772. return;
  773. }
  774. var obj = this._events[type];
  775. var i = obj.length;
  776. while (i--) {
  777. if (obj[i] === listener) {
  778. obj.splice(i, 1);
  779. return;
  780. }
  781. }
  782. };
  783. EventEmitter.prototype.removeAllListeners = function (type) {
  784. if (this._events[type]) {
  785. delete this._events[type];
  786. }
  787. };
  788. EventEmitter.prototype.emit = function (type) {
  789. var args = [];
  790. for (var _i = 1; _i < arguments.length; _i++) {
  791. args[_i - 1] = arguments[_i];
  792. }
  793. if (!this._events[type]) {
  794. return;
  795. }
  796. var obj = this._events[type];
  797. for (var i = 0; i < obj.length; i++) {
  798. obj[i].apply(this, args);
  799. }
  800. };
  801. EventEmitter.prototype.listeners = function (type) {
  802. return this._events[type] || [];
  803. };
  804. EventEmitter.prototype.destroy = function () {
  805. this._events = {};
  806. };
  807. return EventEmitter;
  808. }());
  809. exports.EventEmitter = EventEmitter;
  810. },{}],8:[function(require,module,exports){
  811. "use strict";
  812. Object.defineProperty(exports, "__esModule", { value: true });
  813. var EscapeSequences_1 = require("./EscapeSequences");
  814. var Charsets_1 = require("./Charsets");
  815. var Buffer_1 = require("./Buffer");
  816. var Types_1 = require("./renderer/Types");
  817. var CharWidth_1 = require("./CharWidth");
  818. var InputHandler = (function () {
  819. function InputHandler(_terminal) {
  820. this._terminal = _terminal;
  821. }
  822. InputHandler.prototype.addChar = function (char, code) {
  823. if (char >= ' ') {
  824. var chWidth = CharWidth_1.wcwidth(code);
  825. if (this._terminal.charset && this._terminal.charset[char]) {
  826. char = this._terminal.charset[char];
  827. }
  828. var row = this._terminal.buffer.y + this._terminal.buffer.ybase;
  829. if (!chWidth && this._terminal.buffer.x) {
  830. if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1]) {
  831. if (!this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][Buffer_1.CHAR_DATA_WIDTH_INDEX]) {
  832. if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2]) {
  833. this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2][Buffer_1.CHAR_DATA_CHAR_INDEX] += char;
  834. this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2][3] = char.charCodeAt(0);
  835. }
  836. }
  837. else {
  838. this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][Buffer_1.CHAR_DATA_CHAR_INDEX] += char;
  839. this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][3] = char.charCodeAt(0);
  840. }
  841. this._terminal.updateRange(this._terminal.buffer.y);
  842. }
  843. return;
  844. }
  845. if (this._terminal.buffer.x + chWidth - 1 >= this._terminal.cols) {
  846. if (this._terminal.wraparoundMode) {
  847. this._terminal.buffer.x = 0;
  848. this._terminal.buffer.y++;
  849. if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
  850. this._terminal.buffer.y--;
  851. this._terminal.scroll(true);
  852. }
  853. else {
  854. this._terminal.buffer.lines.get(this._terminal.buffer.y).isWrapped = true;
  855. }
  856. }
  857. else {
  858. if (chWidth === 2) {
  859. return;
  860. }
  861. }
  862. }
  863. row = this._terminal.buffer.y + this._terminal.buffer.ybase;
  864. if (this._terminal.insertMode) {
  865. for (var moves = 0; moves < chWidth; ++moves) {
  866. var removed = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).pop();
  867. if (removed[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 0
  868. && this._terminal.buffer.lines.get(row)[this._terminal.cols - 2]
  869. && this._terminal.buffer.lines.get(row)[this._terminal.cols - 2][Buffer_1.CHAR_DATA_WIDTH_INDEX] === 2) {
  870. this._terminal.buffer.lines.get(row)[this._terminal.cols - 2] = [this._terminal.curAttr, ' ', 1, ' '.charCodeAt(0)];
  871. }
  872. this._terminal.buffer.lines.get(row).splice(this._terminal.buffer.x, 0, [this._terminal.curAttr, ' ', 1, ' '.charCodeAt(0)]);
  873. }
  874. }
  875. this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, char, chWidth, char.charCodeAt(0)];
  876. this._terminal.buffer.x++;
  877. this._terminal.updateRange(this._terminal.buffer.y);
  878. if (chWidth === 2) {
  879. this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, '', 0, undefined];
  880. this._terminal.buffer.x++;
  881. }
  882. }
  883. };
  884. InputHandler.prototype.bell = function () {
  885. this._terminal.bell();
  886. };
  887. InputHandler.prototype.lineFeed = function () {
  888. if (this._terminal.convertEol) {
  889. this._terminal.buffer.x = 0;
  890. }
  891. this._terminal.buffer.y++;
  892. if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
  893. this._terminal.buffer.y--;
  894. this._terminal.scroll();
  895. }
  896. if (this._terminal.buffer.x >= this._terminal.cols) {
  897. this._terminal.buffer.x--;
  898. }
  899. this._terminal.emit('linefeed');
  900. };
  901. InputHandler.prototype.carriageReturn = function () {
  902. this._terminal.buffer.x = 0;
  903. };
  904. InputHandler.prototype.backspace = function () {
  905. if (this._terminal.buffer.x > 0) {
  906. this._terminal.buffer.x--;
  907. }
  908. };
  909. InputHandler.prototype.tab = function () {
  910. this._terminal.buffer.x = this._terminal.buffer.nextStop();
  911. };
  912. InputHandler.prototype.shiftOut = function () {
  913. this._terminal.setgLevel(1);
  914. };
  915. InputHandler.prototype.shiftIn = function () {
  916. this._terminal.setgLevel(0);
  917. };
  918. InputHandler.prototype.insertChars = function (params) {
  919. var param = params[0];
  920. if (param < 1)
  921. param = 1;
  922. var row = this._terminal.buffer.y + this._terminal.buffer.ybase;
  923. var j = this._terminal.buffer.x;
  924. var ch = [this._terminal.eraseAttr(), ' ', 1, 32];
  925. while (param-- && j < this._terminal.cols) {
  926. this._terminal.buffer.lines.get(row).splice(j++, 0, ch);
  927. this._terminal.buffer.lines.get(row).pop();
  928. }
  929. };
  930. InputHandler.prototype.cursorUp = function (params) {
  931. var param = params[0];
  932. if (param < 1) {
  933. param = 1;
  934. }
  935. this._terminal.buffer.y -= param;
  936. if (this._terminal.buffer.y < 0) {
  937. this._terminal.buffer.y = 0;
  938. }
  939. };
  940. InputHandler.prototype.cursorDown = function (params) {
  941. var param = params[0];
  942. if (param < 1) {
  943. param = 1;
  944. }
  945. this._terminal.buffer.y += param;
  946. if (this._terminal.buffer.y >= this._terminal.rows) {
  947. this._terminal.buffer.y = this._terminal.rows - 1;
  948. }
  949. if (this._terminal.buffer.x >= this._terminal.cols) {
  950. this._terminal.buffer.x--;
  951. }
  952. };
  953. InputHandler.prototype.cursorForward = function (params) {
  954. var param = params[0];
  955. if (param < 1) {
  956. param = 1;
  957. }
  958. this._terminal.buffer.x += param;
  959. if (this._terminal.buffer.x >= this._terminal.cols) {
  960. this._terminal.buffer.x = this._terminal.cols - 1;
  961. }
  962. };
  963. InputHandler.prototype.cursorBackward = function (params) {
  964. var param = params[0];
  965. if (param < 1) {
  966. param = 1;
  967. }
  968. if (this._terminal.buffer.x >= this._terminal.cols) {
  969. this._terminal.buffer.x--;
  970. }
  971. this._terminal.buffer.x -= param;
  972. if (this._terminal.buffer.x < 0) {
  973. this._terminal.buffer.x = 0;
  974. }
  975. };
  976. InputHandler.prototype.cursorNextLine = function (params) {
  977. var param = params[0];
  978. if (param < 1) {
  979. param = 1;
  980. }
  981. this._terminal.buffer.y += param;
  982. if (this._terminal.buffer.y >= this._terminal.rows) {
  983. this._terminal.buffer.y = this._terminal.rows - 1;
  984. }
  985. this._terminal.buffer.x = 0;
  986. };
  987. InputHandler.prototype.cursorPrecedingLine = function (params) {
  988. var param = params[0];
  989. if (param < 1) {
  990. param = 1;
  991. }
  992. this._terminal.buffer.y -= param;
  993. if (this._terminal.buffer.y < 0) {
  994. this._terminal.buffer.y = 0;
  995. }
  996. this._terminal.buffer.x = 0;
  997. };
  998. InputHandler.prototype.cursorCharAbsolute = function (params) {
  999. var param = params[0];
  1000. if (param < 1) {
  1001. param = 1;
  1002. }
  1003. this._terminal.buffer.x = param - 1;
  1004. };
  1005. InputHandler.prototype.cursorPosition = function (params) {
  1006. var col;
  1007. var row = params[0] - 1;
  1008. if (params.length >= 2) {
  1009. col = params[1] - 1;
  1010. }
  1011. else {
  1012. col = 0;
  1013. }
  1014. if (row < 0) {
  1015. row = 0;
  1016. }
  1017. else if (row >= this._terminal.rows) {
  1018. row = this._terminal.rows - 1;
  1019. }
  1020. if (col < 0) {
  1021. col = 0;
  1022. }
  1023. else if (col >= this._terminal.cols) {
  1024. col = this._terminal.cols - 1;
  1025. }
  1026. this._terminal.buffer.x = col;
  1027. this._terminal.buffer.y = row;
  1028. };
  1029. InputHandler.prototype.cursorForwardTab = function (params) {
  1030. var param = params[0] || 1;
  1031. while (param--) {
  1032. this._terminal.buffer.x = this._terminal.buffer.nextStop();
  1033. }
  1034. };
  1035. InputHandler.prototype.eraseInDisplay = function (params) {
  1036. var j;
  1037. switch (params[0]) {
  1038. case 0:
  1039. this._terminal.eraseRight(this._terminal.buffer.x, this._terminal.buffer.y);
  1040. j = this._terminal.buffer.y + 1;
  1041. for (; j < this._terminal.rows; j++) {
  1042. this._terminal.eraseLine(j);
  1043. }
  1044. break;
  1045. case 1:
  1046. this._terminal.eraseLeft(this._terminal.buffer.x, this._terminal.buffer.y);
  1047. j = this._terminal.buffer.y;
  1048. while (j--) {
  1049. this._terminal.eraseLine(j);
  1050. }
  1051. break;
  1052. case 2:
  1053. j = this._terminal.rows;
  1054. while (j--)
  1055. this._terminal.eraseLine(j);
  1056. break;
  1057. case 3:
  1058. var scrollBackSize = this._terminal.buffer.lines.length - this._terminal.rows;
  1059. if (scrollBackSize > 0) {
  1060. this._terminal.buffer.lines.trimStart(scrollBackSize);
  1061. this._terminal.buffer.ybase = Math.max(this._terminal.buffer.ybase - scrollBackSize, 0);
  1062. this._terminal.buffer.ydisp = Math.max(this._terminal.buffer.ydisp - scrollBackSize, 0);
  1063. this._terminal.emit('scroll', 0);
  1064. }
  1065. break;
  1066. }
  1067. };
  1068. InputHandler.prototype.eraseInLine = function (params) {
  1069. switch (params[0]) {
  1070. case 0:
  1071. this._terminal.eraseRight(this._terminal.buffer.x, this._terminal.buffer.y);
  1072. break;
  1073. case 1:
  1074. this._terminal.eraseLeft(this._terminal.buffer.x, this._terminal.buffer.y);
  1075. break;
  1076. case 2:
  1077. this._terminal.eraseLine(this._terminal.buffer.y);
  1078. break;
  1079. }
  1080. };
  1081. InputHandler.prototype.insertLines = function (params) {
  1082. var param = params[0];
  1083. if (param < 1) {
  1084. param = 1;
  1085. }
  1086. var row = this._terminal.buffer.y + this._terminal.buffer.ybase;
  1087. var scrollBottomRowsOffset = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
  1088. var scrollBottomAbsolute = this._terminal.rows - 1 + this._terminal.buffer.ybase - scrollBottomRowsOffset + 1;
  1089. while (param--) {
  1090. this._terminal.buffer.lines.splice(scrollBottomAbsolute - 1, 1);
  1091. this._terminal.buffer.lines.splice(row, 0, this._terminal.blankLine(true));
  1092. }
  1093. this._terminal.updateRange(this._terminal.buffer.y);
  1094. this._terminal.updateRange(this._terminal.buffer.scrollBottom);
  1095. };
  1096. InputHandler.prototype.deleteLines = function (params) {
  1097. var param = params[0];
  1098. if (param < 1) {
  1099. param = 1;
  1100. }
  1101. var row = this._terminal.buffer.y + this._terminal.buffer.ybase;
  1102. var j;
  1103. j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
  1104. j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j;
  1105. while (param--) {
  1106. this._terminal.buffer.lines.splice(row, 1);
  1107. this._terminal.buffer.lines.splice(j, 0, this._terminal.blankLine(true));
  1108. }
  1109. this._terminal.updateRange(this._terminal.buffer.y);
  1110. this._terminal.updateRange(this._terminal.buffer.scrollBottom);
  1111. };
  1112. InputHandler.prototype.deleteChars = function (params) {
  1113. var param = params[0];
  1114. if (param < 1) {
  1115. param = 1;
  1116. }
  1117. var row = this._terminal.buffer.y + this._terminal.buffer.ybase;
  1118. var ch = [this._terminal.eraseAttr(), ' ', 1, 32];
  1119. while (param--) {
  1120. this._terminal.buffer.lines.get(row).splice(this._terminal.buffer.x, 1);
  1121. this._terminal.buffer.lines.get(row).push(ch);
  1122. }
  1123. this._terminal.updateRange(this._terminal.buffer.y);
  1124. };
  1125. InputHandler.prototype.scrollUp = function (params) {
  1126. var param = params[0] || 1;
  1127. while (param--) {
  1128. this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollTop, 1);
  1129. this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollBottom, 0, this._terminal.blankLine());
  1130. }
  1131. this._terminal.updateRange(this._terminal.buffer.scrollTop);
  1132. this._terminal.updateRange(this._terminal.buffer.scrollBottom);
  1133. };
  1134. InputHandler.prototype.scrollDown = function (params) {
  1135. var param = params[0] || 1;
  1136. while (param--) {
  1137. this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollBottom, 1);
  1138. this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollTop, 0, this._terminal.blankLine());
  1139. }
  1140. this._terminal.updateRange(this._terminal.buffer.scrollTop);
  1141. this._terminal.updateRange(this._terminal.buffer.scrollBottom);
  1142. };
  1143. InputHandler.prototype.eraseChars = function (params) {
  1144. var param = params[0];
  1145. if (param < 1) {
  1146. param = 1;
  1147. }
  1148. var row = this._terminal.buffer.y + this._terminal.buffer.ybase;
  1149. var j = this._terminal.buffer.x;
  1150. var ch = [this._terminal.eraseAttr(), ' ', 1, 32];
  1151. while (param-- && j < this._terminal.cols) {
  1152. this._terminal.buffer.lines.get(row)[j++] = ch;
  1153. }
  1154. };
  1155. InputHandler.prototype.cursorBackwardTab = function (params) {
  1156. var param = params[0] || 1;
  1157. while (param--) {
  1158. this._terminal.buffer.x = this._terminal.buffer.prevStop();
  1159. }
  1160. };
  1161. InputHandler.prototype.charPosAbsolute = function (params) {
  1162. var param = params[0];
  1163. if (param < 1) {
  1164. param = 1;
  1165. }
  1166. this._terminal.buffer.x = param - 1;
  1167. if (this._terminal.buffer.x >= this._terminal.cols) {
  1168. this._terminal.buffer.x = this._terminal.cols - 1;
  1169. }
  1170. };
  1171. InputHandler.prototype.HPositionRelative = function (params) {
  1172. var param = params[0];
  1173. if (param < 1) {
  1174. param = 1;
  1175. }
  1176. this._terminal.buffer.x += param;
  1177. if (this._terminal.buffer.x >= this._terminal.cols) {
  1178. this._terminal.buffer.x = this._terminal.cols - 1;
  1179. }
  1180. };
  1181. InputHandler.prototype.repeatPrecedingCharacter = function (params) {
  1182. var param = params[0] || 1;
  1183. var line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + this._terminal.buffer.y);
  1184. var ch = line[this._terminal.buffer.x - 1] || [this._terminal.defAttr, ' ', 1, 32];
  1185. while (param--) {
  1186. line[this._terminal.buffer.x++] = ch;
  1187. }
  1188. };
  1189. InputHandler.prototype.sendDeviceAttributes = function (params) {
  1190. if (params[0] > 0) {
  1191. return;
  1192. }
  1193. if (!this._terminal.prefix) {
  1194. if (this._terminal.is('xterm') || this._terminal.is('rxvt-unicode') || this._terminal.is('screen')) {
  1195. this._terminal.send(EscapeSequences_1.C0.ESC + '[?1;2c');
  1196. }
  1197. else if (this._terminal.is('linux')) {
  1198. this._terminal.send(EscapeSequences_1.C0.ESC + '[?6c');
  1199. }
  1200. }
  1201. else if (this._terminal.prefix === '>') {
  1202. if (this._terminal.is('xterm')) {
  1203. this._terminal.send(EscapeSequences_1.C0.ESC + '[>0;276;0c');
  1204. }
  1205. else if (this._terminal.is('rxvt-unicode')) {
  1206. this._terminal.send(EscapeSequences_1.C0.ESC + '[>85;95;0c');
  1207. }
  1208. else if (this._terminal.is('linux')) {
  1209. this._terminal.send(params[0] + 'c');
  1210. }
  1211. else if (this._terminal.is('screen')) {
  1212. this._terminal.send(EscapeSequences_1.C0.ESC + '[>83;40003;0c');
  1213. }
  1214. }
  1215. };
  1216. InputHandler.prototype.linePosAbsolute = function (params) {
  1217. var param = params[0];
  1218. if (param < 1) {
  1219. param = 1;
  1220. }
  1221. this._terminal.buffer.y = param - 1;
  1222. if (this._terminal.buffer.y >= this._terminal.rows) {
  1223. this._terminal.buffer.y = this._terminal.rows - 1;
  1224. }
  1225. };
  1226. InputHandler.prototype.VPositionRelative = function (params) {
  1227. var param = params[0];
  1228. if (param < 1) {
  1229. param = 1;
  1230. }
  1231. this._terminal.buffer.y += param;
  1232. if (this._terminal.buffer.y >= this._terminal.rows) {
  1233. this._terminal.buffer.y = this._terminal.rows - 1;
  1234. }
  1235. if (this._terminal.buffer.x >= this._terminal.cols) {
  1236. this._terminal.buffer.x--;
  1237. }
  1238. };
  1239. InputHandler.prototype.HVPosition = function (params) {
  1240. if (params[0] < 1)
  1241. params[0] = 1;
  1242. if (params[1] < 1)
  1243. params[1] = 1;
  1244. this._terminal.buffer.y = params[0] - 1;
  1245. if (this._terminal.buffer.y >= this._terminal.rows) {
  1246. this._terminal.buffer.y = this._terminal.rows - 1;
  1247. }
  1248. this._terminal.buffer.x = params[1] - 1;
  1249. if (this._terminal.buffer.x >= this._terminal.cols) {
  1250. this._terminal.buffer.x = this._terminal.cols - 1;
  1251. }
  1252. };
  1253. InputHandler.prototype.tabClear = function (params) {
  1254. var param = params[0];
  1255. if (param <= 0) {
  1256. delete this._terminal.buffer.tabs[this._terminal.buffer.x];
  1257. }
  1258. else if (param === 3) {
  1259. this._terminal.buffer.tabs = {};
  1260. }
  1261. };
  1262. InputHandler.prototype.setMode = function (params) {
  1263. if (params.length > 1) {
  1264. for (var i = 0; i < params.length; i++) {
  1265. this.setMode([params[i]]);
  1266. }
  1267. return;
  1268. }
  1269. if (!this._terminal.prefix) {
  1270. switch (params[0]) {
  1271. case 4:
  1272. this._terminal.insertMode = true;
  1273. break;
  1274. case 20:
  1275. break;
  1276. }
  1277. }
  1278. else if (this._terminal.prefix === '?') {
  1279. switch (params[0]) {
  1280. case 1:
  1281. this._terminal.applicationCursor = true;
  1282. break;
  1283. case 2:
  1284. this._terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
  1285. this._terminal.setgCharset(1, Charsets_1.DEFAULT_CHARSET);
  1286. this._terminal.setgCharset(2, Charsets_1.DEFAULT_CHARSET);
  1287. this._terminal.setgCharset(3, Charsets_1.DEFAULT_CHARSET);
  1288. break;
  1289. case 3:
  1290. this._terminal.savedCols = this._terminal.cols;
  1291. this._terminal.resize(132, this._terminal.rows);
  1292. break;
  1293. case 6:
  1294. this._terminal.originMode = true;
  1295. break;
  1296. case 7:
  1297. this._terminal.wraparoundMode = true;
  1298. break;
  1299. case 12:
  1300. break;
  1301. case 66:
  1302. this._terminal.log('Serial port requested application keypad.');
  1303. this._terminal.applicationKeypad = true;
  1304. this._terminal.viewport.syncScrollArea();
  1305. break;
  1306. case 9:
  1307. case 1000:
  1308. case 1002:
  1309. case 1003:
  1310. this._terminal.x10Mouse = params[0] === 9;
  1311. this._terminal.vt200Mouse = params[0] === 1000;
  1312. this._terminal.normalMouse = params[0] > 1000;
  1313. this._terminal.mouseEvents = true;
  1314. this._terminal.element.classList.add('enable-mouse-events');
  1315. this._terminal.selectionManager.disable();
  1316. this._terminal.log('Binding to mouse events.');
  1317. break;
  1318. case 1004:
  1319. this._terminal.sendFocus = true;
  1320. break;
  1321. case 1005:
  1322. this._terminal.utfMouse = true;
  1323. break;
  1324. case 1006:
  1325. this._terminal.sgrMouse = true;
  1326. break;
  1327. case 1015:
  1328. this._terminal.urxvtMouse = true;
  1329. break;
  1330. case 25:
  1331. this._terminal.cursorHidden = false;
  1332. break;
  1333. case 1049:
  1334. case 47:
  1335. case 1047:
  1336. this._terminal.buffers.activateAltBuffer();
  1337. this._terminal.viewport.syncScrollArea();
  1338. this._terminal.showCursor();
  1339. break;
  1340. case 2004:
  1341. this._terminal.bracketedPasteMode = true;
  1342. break;
  1343. }
  1344. }
  1345. };
  1346. InputHandler.prototype.resetMode = function (params) {
  1347. if (params.length > 1) {
  1348. for (var i = 0; i < params.length; i++) {
  1349. this.resetMode([params[i]]);
  1350. }
  1351. return;
  1352. }
  1353. if (!this._terminal.prefix) {
  1354. switch (params[0]) {
  1355. case 4:
  1356. this._terminal.insertMode = false;
  1357. break;
  1358. case 20:
  1359. break;
  1360. }
  1361. }
  1362. else if (this._terminal.prefix === '?') {
  1363. switch (params[0]) {
  1364. case 1:
  1365. this._terminal.applicationCursor = false;
  1366. break;
  1367. case 3:
  1368. if (this._terminal.cols === 132 && this._terminal.savedCols) {
  1369. this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
  1370. }
  1371. delete this._terminal.savedCols;
  1372. break;
  1373. case 6:
  1374. this._terminal.originMode = false;
  1375. break;
  1376. case 7:
  1377. this._terminal.wraparoundMode = false;
  1378. break;
  1379. case 12:
  1380. break;
  1381. case 66:
  1382. this._terminal.log('Switching back to normal keypad.');
  1383. this._terminal.applicationKeypad = false;
  1384. this._terminal.viewport.syncScrollArea();
  1385. break;
  1386. case 9:
  1387. case 1000:
  1388. case 1002:
  1389. case 1003:
  1390. this._terminal.x10Mouse = false;
  1391. this._terminal.vt200Mouse = false;
  1392. this._terminal.normalMouse = false;
  1393. this._terminal.mouseEvents = false;
  1394. this._terminal.element.classList.remove('enable-mouse-events');
  1395. this._terminal.selectionManager.enable();
  1396. break;
  1397. case 1004:
  1398. this._terminal.sendFocus = false;
  1399. break;
  1400. case 1005:
  1401. this._terminal.utfMouse = false;
  1402. break;
  1403. case 1006:
  1404. this._terminal.sgrMouse = false;
  1405. break;
  1406. case 1015:
  1407. this._terminal.urxvtMouse = false;
  1408. break;
  1409. case 25:
  1410. this._terminal.cursorHidden = true;
  1411. break;
  1412. case 1049:
  1413. case 47:
  1414. case 1047:
  1415. this._terminal.buffers.activateNormalBuffer();
  1416. this._terminal.refresh(0, this._terminal.rows - 1);
  1417. this._terminal.viewport.syncScrollArea();
  1418. this._terminal.showCursor();
  1419. break;
  1420. case 2004:
  1421. this._terminal.bracketedPasteMode = false;
  1422. break;
  1423. }
  1424. }
  1425. };
  1426. InputHandler.prototype.charAttributes = function (params) {
  1427. if (params.length === 1 && params[0] === 0) {
  1428. this._terminal.curAttr = this._terminal.defAttr;
  1429. return;
  1430. }
  1431. var l = params.length;
  1432. var flags = this._terminal.curAttr >> 18;
  1433. var fg = (this._terminal.curAttr >> 9) & 0x1ff;
  1434. var bg = this._terminal.curAttr & 0x1ff;
  1435. var p;
  1436. for (var i = 0; i < l; i++) {
  1437. p = params[i];
  1438. if (p >= 30 && p <= 37) {
  1439. fg = p - 30;
  1440. }
  1441. else if (p >= 40 && p <= 47) {
  1442. bg = p - 40;
  1443. }
  1444. else if (p >= 90 && p <= 97) {
  1445. p += 8;
  1446. fg = p - 90;
  1447. }
  1448. else if (p >= 100 && p <= 107) {
  1449. p += 8;
  1450. bg = p - 100;
  1451. }
  1452. else if (p === 0) {
  1453. flags = this._terminal.defAttr >> 18;
  1454. fg = (this._terminal.defAttr >> 9) & 0x1ff;
  1455. bg = this._terminal.defAttr & 0x1ff;
  1456. }
  1457. else if (p === 1) {
  1458. flags |= Types_1.FLAGS.BOLD;
  1459. }
  1460. else if (p === 4) {
  1461. flags |= Types_1.FLAGS.UNDERLINE;
  1462. }
  1463. else if (p === 5) {
  1464. flags |= Types_1.FLAGS.BLINK;
  1465. }
  1466. else if (p === 7) {
  1467. flags |= Types_1.FLAGS.INVERSE;
  1468. }
  1469. else if (p === 8) {
  1470. flags |= Types_1.FLAGS.INVISIBLE;
  1471. }
  1472. else if (p === 2) {
  1473. flags |= Types_1.FLAGS.DIM;
  1474. }
  1475. else if (p === 22) {
  1476. flags &= ~Types_1.FLAGS.BOLD;
  1477. flags &= ~Types_1.FLAGS.DIM;
  1478. }
  1479. else if (p === 24) {
  1480. flags &= ~Types_1.FLAGS.UNDERLINE;
  1481. }
  1482. else if (p === 25) {
  1483. flags &= ~Types_1.FLAGS.BLINK;
  1484. }
  1485. else if (p === 27) {
  1486. flags &= ~Types_1.FLAGS.INVERSE;
  1487. }
  1488. else if (p === 28) {
  1489. flags &= ~Types_1.FLAGS.INVISIBLE;
  1490. }
  1491. else if (p === 39) {
  1492. fg = (this._terminal.defAttr >> 9) & 0x1ff;
  1493. }
  1494. else if (p === 49) {
  1495. bg = this._terminal.defAttr & 0x1ff;
  1496. }
  1497. else if (p === 38) {
  1498. if (params[i + 1] === 2) {
  1499. i += 2;
  1500. fg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
  1501. if (fg === -1)
  1502. fg = 0x1ff;
  1503. i += 2;
  1504. }
  1505. else if (params[i + 1] === 5) {
  1506. i += 2;
  1507. p = params[i] & 0xff;
  1508. fg = p;
  1509. }
  1510. }
  1511. else if (p === 48) {
  1512. if (params[i + 1] === 2) {
  1513. i += 2;
  1514. bg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
  1515. if (bg === -1)
  1516. bg = 0x1ff;
  1517. i += 2;
  1518. }
  1519. else if (params[i + 1] === 5) {
  1520. i += 2;
  1521. p = params[i] & 0xff;
  1522. bg = p;
  1523. }
  1524. }
  1525. else if (p === 100) {
  1526. fg = (this._terminal.defAttr >> 9) & 0x1ff;
  1527. bg = this._terminal.defAttr & 0x1ff;
  1528. }
  1529. else {
  1530. this._terminal.error('Unknown SGR attribute: %d.', p);
  1531. }
  1532. }
  1533. this._terminal.curAttr = (flags << 18) | (fg << 9) | bg;
  1534. };
  1535. InputHandler.prototype.deviceStatus = function (params) {
  1536. if (!this._terminal.prefix) {
  1537. switch (params[0]) {
  1538. case 5:
  1539. this._terminal.send(EscapeSequences_1.C0.ESC + '[0n');
  1540. break;
  1541. case 6:
  1542. this._terminal.send(EscapeSequences_1.C0.ESC + '['
  1543. + (this._terminal.buffer.y + 1)
  1544. + ';'
  1545. + (this._terminal.buffer.x + 1)
  1546. + 'R');
  1547. break;
  1548. }
  1549. }
  1550. else if (this._terminal.prefix === '?') {
  1551. switch (params[0]) {
  1552. case 6:
  1553. this._terminal.send(EscapeSequences_1.C0.ESC + '[?'
  1554. + (this._terminal.buffer.y + 1)
  1555. + ';'
  1556. + (this._terminal.buffer.x + 1)
  1557. + 'R');
  1558. break;
  1559. case 15:
  1560. break;
  1561. case 25:
  1562. break;
  1563. case 26:
  1564. break;
  1565. case 53:
  1566. break;
  1567. }
  1568. }
  1569. };
  1570. InputHandler.prototype.softReset = function (params) {
  1571. this._terminal.cursorHidden = false;
  1572. this._terminal.insertMode = false;
  1573. this._terminal.originMode = false;
  1574. this._terminal.wraparoundMode = true;
  1575. this._terminal.applicationKeypad = false;
  1576. this._terminal.viewport.syncScrollArea();
  1577. this._terminal.applicationCursor = false;
  1578. this._terminal.buffer.scrollTop = 0;
  1579. this._terminal.buffer.scrollBottom = this._terminal.rows - 1;
  1580. this._terminal.curAttr = this._terminal.defAttr;
  1581. this._terminal.buffer.x = this._terminal.buffer.y = 0;
  1582. this._terminal.charset = null;
  1583. this._terminal.glevel = 0;
  1584. this._terminal.charsets = [null];
  1585. };
  1586. InputHandler.prototype.setCursorStyle = function (params) {
  1587. var param = params[0] < 1 ? 1 : params[0];
  1588. switch (param) {
  1589. case 1:
  1590. case 2:
  1591. this._terminal.setOption('cursorStyle', 'block');
  1592. break;
  1593. case 3:
  1594. case 4:
  1595. this._terminal.setOption('cursorStyle', 'underline');
  1596. break;
  1597. case 5:
  1598. case 6:
  1599. this._terminal.setOption('cursorStyle', 'bar');
  1600. break;
  1601. }
  1602. var isBlinking = param % 2 === 1;
  1603. this._terminal.setOption('cursorBlink', isBlinking);
  1604. };
  1605. InputHandler.prototype.setScrollRegion = function (params) {
  1606. if (this._terminal.prefix)
  1607. return;
  1608. this._terminal.buffer.scrollTop = (params[0] || 1) - 1;
  1609. this._terminal.buffer.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
  1610. this._terminal.buffer.x = 0;
  1611. this._terminal.buffer.y = 0;
  1612. };
  1613. InputHandler.prototype.saveCursor = function (params) {
  1614. this._terminal.buffer.savedX = this._terminal.buffer.x;
  1615. this._terminal.buffer.savedY = this._terminal.buffer.y;
  1616. };
  1617. InputHandler.prototype.restoreCursor = function (params) {
  1618. this._terminal.buffer.x = this._terminal.buffer.savedX || 0;
  1619. this._terminal.buffer.y = this._terminal.buffer.savedY || 0;
  1620. };
  1621. return InputHandler;
  1622. }());
  1623. exports.InputHandler = InputHandler;
  1624. },{"./Buffer":1,"./CharWidth":3,"./Charsets":4,"./EscapeSequences":6,"./renderer/Types":28}],9:[function(require,module,exports){
  1625. "use strict";
  1626. var __extends = (this && this.__extends) || (function () {
  1627. var extendStatics = Object.setPrototypeOf ||
  1628. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1629. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1630. return function (d, b) {
  1631. extendStatics(d, b);
  1632. function __() { this.constructor = d; }
  1633. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1634. };
  1635. })();
  1636. Object.defineProperty(exports, "__esModule", { value: true });
  1637. var Types_1 = require("./Types");
  1638. var MouseZoneManager_1 = require("./input/MouseZoneManager");
  1639. var EventEmitter_1 = require("./EventEmitter");
  1640. var protocolClause = '(https?:\\/\\/)';
  1641. var domainCharacterSet = '[\\da-z\\.-]+';
  1642. var negatedDomainCharacterSet = '[^\\da-z\\.-]+';
  1643. var domainBodyClause = '(' + domainCharacterSet + ')';
  1644. var tldClause = '([a-z\\.]{2,6})';
  1645. var ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
  1646. var localHostClause = '(localhost)';
  1647. var portClause = '(:\\d{1,5})';
  1648. var hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
  1649. var pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
  1650. var queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
  1651. var queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
  1652. var hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';
  1653. var negatedPathCharacterSet = '[^\\/\\w\\.\\-%]+';
  1654. var bodyClause = hostClause + pathClause + queryStringClause + hashFragmentClause;
  1655. var start = '(?:^|' + negatedDomainCharacterSet + ')(';
  1656. var end = ')($|' + negatedPathCharacterSet + ')';
  1657. var strictUrlRegex = new RegExp(start + protocolClause + bodyClause + end);
  1658. var HYPERTEXT_LINK_MATCHER_ID = 0;
  1659. var Linkifier = (function (_super) {
  1660. __extends(Linkifier, _super);
  1661. function Linkifier(_terminal) {
  1662. var _this = _super.call(this) || this;
  1663. _this._terminal = _terminal;
  1664. _this._linkMatchers = [];
  1665. _this._nextLinkMatcherId = HYPERTEXT_LINK_MATCHER_ID;
  1666. _this._rowsToLinkify = {
  1667. start: null,
  1668. end: null
  1669. };
  1670. _this.registerLinkMatcher(strictUrlRegex, null, { matchIndex: 1 });
  1671. return _this;
  1672. }
  1673. Linkifier.prototype.attachToDom = function (mouseZoneManager) {
  1674. this._mouseZoneManager = mouseZoneManager;
  1675. };
  1676. Linkifier.prototype.linkifyRows = function (start, end) {
  1677. var _this = this;
  1678. if (!this._mouseZoneManager) {
  1679. return;
  1680. }
  1681. if (this._rowsToLinkify.start === null) {
  1682. this._rowsToLinkify.start = start;
  1683. this._rowsToLinkify.end = end;
  1684. }
  1685. else {
  1686. this._rowsToLinkify.start = Math.min(this._rowsToLinkify.start, start);
  1687. this._rowsToLinkify.end = Math.max(this._rowsToLinkify.end, end);
  1688. }
  1689. this._mouseZoneManager.clearAll(start, end);
  1690. if (this._rowsTimeoutId) {
  1691. clearTimeout(this._rowsTimeoutId);
  1692. }
  1693. this._rowsTimeoutId = setTimeout(function () { return _this._linkifyRows(); }, Linkifier.TIME_BEFORE_LINKIFY);
  1694. };
  1695. Linkifier.prototype._linkifyRows = function () {
  1696. this._rowsTimeoutId = null;
  1697. for (var i = this._rowsToLinkify.start; i <= this._rowsToLinkify.end; i++) {
  1698. this._linkifyRow(i);
  1699. }
  1700. this._rowsToLinkify.start = null;
  1701. this._rowsToLinkify.end = null;
  1702. };
  1703. Linkifier.prototype.setHypertextLinkHandler = function (handler) {
  1704. this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].handler = handler;
  1705. };
  1706. Linkifier.prototype.setHypertextValidationCallback = function (callback) {
  1707. this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].validationCallback = callback;
  1708. };
  1709. Linkifier.prototype.registerLinkMatcher = function (regex, handler, options) {
  1710. if (options === void 0) { options = {}; }
  1711. if (this._nextLinkMatcherId !== HYPERTEXT_LINK_MATCHER_ID && !handler) {
  1712. throw new Error('handler must be defined');
  1713. }
  1714. var matcher = {
  1715. id: this._nextLinkMatcherId++,
  1716. regex: regex,
  1717. handler: handler,
  1718. matchIndex: options.matchIndex,
  1719. validationCallback: options.validationCallback,
  1720. hoverTooltipCallback: options.tooltipCallback,
  1721. hoverLeaveCallback: options.leaveCallback,
  1722. willLinkActivate: options.willLinkActivate,
  1723. priority: options.priority || 0
  1724. };
  1725. this._addLinkMatcherToList(matcher);
  1726. return matcher.id;
  1727. };
  1728. Linkifier.prototype._addLinkMatcherToList = function (matcher) {
  1729. if (this._linkMatchers.length === 0) {
  1730. this._linkMatchers.push(matcher);
  1731. return;
  1732. }
  1733. for (var i = this._linkMatchers.length - 1; i >= 0; i--) {
  1734. if (matcher.priority <= this._linkMatchers[i].priority) {
  1735. this._linkMatchers.splice(i + 1, 0, matcher);
  1736. return;
  1737. }
  1738. }
  1739. this._linkMatchers.splice(0, 0, matcher);
  1740. };
  1741. Linkifier.prototype.deregisterLinkMatcher = function (matcherId) {
  1742. for (var i = 1; i < this._linkMatchers.length; i++) {
  1743. if (this._linkMatchers[i].id === matcherId) {
  1744. this._linkMatchers.splice(i, 1);
  1745. return true;
  1746. }
  1747. }
  1748. return false;
  1749. };
  1750. Linkifier.prototype._linkifyRow = function (rowIndex) {
  1751. var absoluteRowIndex = this._terminal.buffer.ydisp + rowIndex;
  1752. if (absoluteRowIndex >= this._terminal.buffer.lines.length) {
  1753. return;
  1754. }
  1755. var text = this._terminal.buffer.translateBufferLineToString(absoluteRowIndex, false);
  1756. for (var i = 0; i < this._linkMatchers.length; i++) {
  1757. this._doLinkifyRow(rowIndex, text, this._linkMatchers[i]);
  1758. }
  1759. };
  1760. Linkifier.prototype._doLinkifyRow = function (rowIndex, text, matcher, offset) {
  1761. var _this = this;
  1762. if (offset === void 0) { offset = 0; }
  1763. var result = [];
  1764. var isHttpLinkMatcher = matcher.id === HYPERTEXT_LINK_MATCHER_ID;
  1765. var match = text.match(matcher.regex);
  1766. if (!match || match.length === 0) {
  1767. return;
  1768. }
  1769. var uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
  1770. var index = text.indexOf(uri);
  1771. if (matcher.validationCallback) {
  1772. matcher.validationCallback(uri, function (isValid) {
  1773. if (_this._rowsTimeoutId) {
  1774. return;
  1775. }
  1776. if (isValid) {
  1777. _this._addLink(offset + index, rowIndex, uri, matcher);
  1778. }
  1779. });
  1780. }
  1781. else {
  1782. this._addLink(offset + index, rowIndex, uri, matcher);
  1783. }
  1784. var remainingStartIndex = index + uri.length;
  1785. var remainingText = text.substr(remainingStartIndex);
  1786. if (remainingText.length > 0) {
  1787. this._doLinkifyRow(rowIndex, remainingText, matcher, offset + remainingStartIndex);
  1788. }
  1789. };
  1790. Linkifier.prototype._addLink = function (x, y, uri, matcher) {
  1791. var _this = this;
  1792. this._mouseZoneManager.add(new MouseZoneManager_1.MouseZone(x + 1, x + 1 + uri.length, y + 1, function (e) {
  1793. if (matcher.handler) {
  1794. return matcher.handler(e, uri);
  1795. }
  1796. window.open(uri, '_blank');
  1797. }, function (e) {
  1798. _this.emit(Types_1.LinkHoverEventTypes.HOVER, { x: x, y: y, length: uri.length });
  1799. _this._terminal.element.style.cursor = 'pointer';
  1800. }, function (e) {
  1801. _this.emit(Types_1.LinkHoverEventTypes.TOOLTIP, { x: x, y: y, length: uri.length });
  1802. if (matcher.hoverTooltipCallback) {
  1803. matcher.hoverTooltipCallback(e, uri);
  1804. }
  1805. }, function () {
  1806. _this.emit(Types_1.LinkHoverEventTypes.LEAVE, { x: x, y: y, length: uri.length });
  1807. _this._terminal.element.style.cursor = '';
  1808. if (matcher.hoverLeaveCallback) {
  1809. matcher.hoverLeaveCallback();
  1810. }
  1811. }, function (e) {
  1812. if (matcher.willLinkActivate) {
  1813. return matcher.willLinkActivate(e, uri);
  1814. }
  1815. return true;
  1816. }));
  1817. };
  1818. Linkifier.TIME_BEFORE_LINKIFY = 200;
  1819. return Linkifier;
  1820. }(EventEmitter_1.EventEmitter));
  1821. exports.Linkifier = Linkifier;
  1822. },{"./EventEmitter":7,"./Types":14,"./input/MouseZoneManager":18}],10:[function(require,module,exports){
  1823. "use strict";
  1824. Object.defineProperty(exports, "__esModule", { value: true });
  1825. var EscapeSequences_1 = require("./EscapeSequences");
  1826. var Charsets_1 = require("./Charsets");
  1827. var normalStateHandler = {};
  1828. normalStateHandler[EscapeSequences_1.C0.BEL] = function (parser, handler) { return handler.bell(); };
  1829. normalStateHandler[EscapeSequences_1.C0.LF] = function (parser, handler) { return handler.lineFeed(); };
  1830. normalStateHandler[EscapeSequences_1.C0.VT] = normalStateHandler[EscapeSequences_1.C0.LF];
  1831. normalStateHandler[EscapeSequences_1.C0.FF] = normalStateHandler[EscapeSequences_1.C0.LF];
  1832. normalStateHandler[EscapeSequences_1.C0.CR] = function (parser, handler) { return handler.carriageReturn(); };
  1833. normalStateHandler[EscapeSequences_1.C0.BS] = function (parser, handler) { return handler.backspace(); };
  1834. normalStateHandler[EscapeSequences_1.C0.HT] = function (parser, handler) { return handler.tab(); };
  1835. normalStateHandler[EscapeSequences_1.C0.SO] = function (parser, handler) { return handler.shiftOut(); };
  1836. normalStateHandler[EscapeSequences_1.C0.SI] = function (parser, handler) { return handler.shiftIn(); };
  1837. normalStateHandler[EscapeSequences_1.C0.ESC] = function (parser, handler) { return parser.setState(ParserState.ESCAPED); };
  1838. var escapedStateHandler = {};
  1839. escapedStateHandler['['] = function (parser, terminal) {
  1840. terminal.params = [];
  1841. terminal.currentParam = 0;
  1842. parser.setState(ParserState.CSI_PARAM);
  1843. };
  1844. escapedStateHandler[']'] = function (parser, terminal) {
  1845. terminal.params = [];
  1846. terminal.currentParam = 0;
  1847. parser.setState(ParserState.OSC);
  1848. };
  1849. escapedStateHandler['P'] = function (parser, terminal) {
  1850. terminal.params = [];
  1851. terminal.currentParam = 0;
  1852. parser.setState(ParserState.DCS);
  1853. };
  1854. escapedStateHandler['_'] = function (parser, terminal) {
  1855. parser.setState(ParserState.IGNORE);
  1856. };
  1857. escapedStateHandler['^'] = function (parser, terminal) {
  1858. parser.setState(ParserState.IGNORE);
  1859. };
  1860. escapedStateHandler['c'] = function (parser, terminal) {
  1861. terminal.reset();
  1862. };
  1863. escapedStateHandler['E'] = function (parser, terminal) {
  1864. terminal.buffer.x = 0;
  1865. terminal.index();
  1866. parser.setState(ParserState.NORMAL);
  1867. };
  1868. escapedStateHandler['D'] = function (parser, terminal) {
  1869. terminal.index();
  1870. parser.setState(ParserState.NORMAL);
  1871. };
  1872. escapedStateHandler['M'] = function (parser, terminal) {
  1873. terminal.reverseIndex();
  1874. parser.setState(ParserState.NORMAL);
  1875. };
  1876. escapedStateHandler['%'] = function (parser, terminal) {
  1877. terminal.setgLevel(0);
  1878. terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
  1879. parser.setState(ParserState.NORMAL);
  1880. parser.skipNextChar();
  1881. };
  1882. escapedStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
  1883. var csiParamStateHandler = {};
  1884. csiParamStateHandler['?'] = function (parser) { return parser.setPrefix('?'); };
  1885. csiParamStateHandler['>'] = function (parser) { return parser.setPrefix('>'); };
  1886. csiParamStateHandler['!'] = function (parser) { return parser.setPrefix('!'); };
  1887. csiParamStateHandler['0'] = function (parser) { return parser.setParam(parser.getParam() * 10); };
  1888. csiParamStateHandler['1'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 1); };
  1889. csiParamStateHandler['2'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 2); };
  1890. csiParamStateHandler['3'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 3); };
  1891. csiParamStateHandler['4'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 4); };
  1892. csiParamStateHandler['5'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 5); };
  1893. csiParamStateHandler['6'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 6); };
  1894. csiParamStateHandler['7'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 7); };
  1895. csiParamStateHandler['8'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 8); };
  1896. csiParamStateHandler['9'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 9); };
  1897. csiParamStateHandler['$'] = function (parser) { return parser.setPostfix('$'); };
  1898. csiParamStateHandler['"'] = function (parser) { return parser.setPostfix('"'); };
  1899. csiParamStateHandler[' '] = function (parser) { return parser.setPostfix(' '); };
  1900. csiParamStateHandler['\''] = function (parser) { return parser.setPostfix('\''); };
  1901. csiParamStateHandler[';'] = function (parser) { return parser.finalizeParam(); };
  1902. csiParamStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
  1903. var csiStateHandler = {};
  1904. csiStateHandler['@'] = function (handler, params, prefix) { return handler.insertChars(params); };
  1905. csiStateHandler['A'] = function (handler, params, prefix) { return handler.cursorUp(params); };
  1906. csiStateHandler['B'] = function (handler, params, prefix) { return handler.cursorDown(params); };
  1907. csiStateHandler['C'] = function (handler, params, prefix) { return handler.cursorForward(params); };
  1908. csiStateHandler['D'] = function (handler, params, prefix) { return handler.cursorBackward(params); };
  1909. csiStateHandler['E'] = function (handler, params, prefix) { return handler.cursorNextLine(params); };
  1910. csiStateHandler['F'] = function (handler, params, prefix) { return handler.cursorPrecedingLine(params); };
  1911. csiStateHandler['G'] = function (handler, params, prefix) { return handler.cursorCharAbsolute(params); };
  1912. csiStateHandler['H'] = function (handler, params, prefix) { return handler.cursorPosition(params); };
  1913. csiStateHandler['I'] = function (handler, params, prefix) { return handler.cursorForwardTab(params); };
  1914. csiStateHandler['J'] = function (handler, params, prefix) { return handler.eraseInDisplay(params); };
  1915. csiStateHandler['K'] = function (handler, params, prefix) { return handler.eraseInLine(params); };
  1916. csiStateHandler['L'] = function (handler, params, prefix) { return handler.insertLines(params); };
  1917. csiStateHandler['M'] = function (handler, params, prefix) { return handler.deleteLines(params); };
  1918. csiStateHandler['P'] = function (handler, params, prefix) { return handler.deleteChars(params); };
  1919. csiStateHandler['S'] = function (handler, params, prefix) { return handler.scrollUp(params); };
  1920. csiStateHandler['T'] = function (handler, params, prefix) {
  1921. if (params.length < 2 && !prefix) {
  1922. handler.scrollDown(params);
  1923. }
  1924. };
  1925. csiStateHandler['X'] = function (handler, params, prefix) { return handler.eraseChars(params); };
  1926. csiStateHandler['Z'] = function (handler, params, prefix) { return handler.cursorBackwardTab(params); };
  1927. csiStateHandler['`'] = function (handler, params, prefix) { return handler.charPosAbsolute(params); };
  1928. csiStateHandler['a'] = function (handler, params, prefix) { return handler.HPositionRelative(params); };
  1929. csiStateHandler['b'] = function (handler, params, prefix) { return handler.repeatPrecedingCharacter(params); };
  1930. csiStateHandler['c'] = function (handler, params, prefix) { return handler.sendDeviceAttributes(params); };
  1931. csiStateHandler['d'] = function (handler, params, prefix) { return handler.linePosAbsolute(params); };
  1932. csiStateHandler['e'] = function (handler, params, prefix) { return handler.VPositionRelative(params); };
  1933. csiStateHandler['f'] = function (handler, params, prefix) { return handler.HVPosition(params); };
  1934. csiStateHandler['g'] = function (handler, params, prefix) { return handler.tabClear(params); };
  1935. csiStateHandler['h'] = function (handler, params, prefix) { return handler.setMode(params); };
  1936. csiStateHandler['l'] = function (handler, params, prefix) { return handler.resetMode(params); };
  1937. csiStateHandler['m'] = function (handler, params, prefix) { return handler.charAttributes(params); };
  1938. csiStateHandler['n'] = function (handler, params, prefix) { return handler.deviceStatus(params); };
  1939. csiStateHandler['p'] = function (handler, params, prefix) {
  1940. switch (prefix) {
  1941. case '!':
  1942. handler.softReset(params);
  1943. break;
  1944. }
  1945. };
  1946. csiStateHandler['q'] = function (handler, params, prefix, postfix) {
  1947. if (postfix === ' ') {
  1948. handler.setCursorStyle(params);
  1949. }
  1950. };
  1951. csiStateHandler['r'] = function (handler, params) { return handler.setScrollRegion(params); };
  1952. csiStateHandler['s'] = function (handler, params) { return handler.saveCursor(params); };
  1953. csiStateHandler['u'] = function (handler, params) { return handler.restoreCursor(params); };
  1954. csiStateHandler[EscapeSequences_1.C0.CAN] = function (handler, params, prefix, postfix, parser) { return parser.setState(ParserState.NORMAL); };
  1955. var ParserState;
  1956. (function (ParserState) {
  1957. ParserState[ParserState["NORMAL"] = 0] = "NORMAL";
  1958. ParserState[ParserState["ESCAPED"] = 1] = "ESCAPED";
  1959. ParserState[ParserState["CSI_PARAM"] = 2] = "CSI_PARAM";
  1960. ParserState[ParserState["CSI"] = 3] = "CSI";
  1961. ParserState[ParserState["OSC"] = 4] = "OSC";
  1962. ParserState[ParserState["CHARSET"] = 5] = "CHARSET";
  1963. ParserState[ParserState["DCS"] = 6] = "DCS";
  1964. ParserState[ParserState["IGNORE"] = 7] = "IGNORE";
  1965. })(ParserState = exports.ParserState || (exports.ParserState = {}));
  1966. var Parser = (function () {
  1967. function Parser(_inputHandler, _terminal) {
  1968. this._inputHandler = _inputHandler;
  1969. this._terminal = _terminal;
  1970. this._state = ParserState.NORMAL;
  1971. }
  1972. Parser.prototype.parse = function (data) {
  1973. var l = data.length;
  1974. var j;
  1975. var cs;
  1976. var ch;
  1977. var code;
  1978. var low;
  1979. var cursorStartX = this._terminal.buffer.x;
  1980. var cursorStartY = this._terminal.buffer.y;
  1981. if (this._terminal.debug) {
  1982. this._terminal.log('data: ' + data);
  1983. }
  1984. this._position = 0;
  1985. if (this._terminal.surrogate_high) {
  1986. data = this._terminal.surrogate_high + data;
  1987. this._terminal.surrogate_high = '';
  1988. }
  1989. for (; this._position < l; this._position++) {
  1990. ch = data[this._position];
  1991. code = data.charCodeAt(this._position);
  1992. if (0xD800 <= code && code <= 0xDBFF) {
  1993. low = data.charCodeAt(this._position + 1);
  1994. if (isNaN(low)) {
  1995. this._terminal.surrogate_high = ch;
  1996. continue;
  1997. }
  1998. code = ((code - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
  1999. ch += data.charAt(this._position + 1);
  2000. }
  2001. if (0xDC00 <= code && code <= 0xDFFF) {
  2002. continue;
  2003. }
  2004. switch (this._state) {
  2005. case ParserState.NORMAL:
  2006. if (ch in normalStateHandler) {
  2007. normalStateHandler[ch](this, this._inputHandler);
  2008. }
  2009. else {
  2010. this._inputHandler.addChar(ch, code);
  2011. }
  2012. break;
  2013. case ParserState.ESCAPED:
  2014. if (ch in escapedStateHandler) {
  2015. escapedStateHandler[ch](this, this._terminal);
  2016. break;
  2017. }
  2018. switch (ch) {
  2019. case '(':
  2020. case ')':
  2021. case '*':
  2022. case '+':
  2023. case '-':
  2024. case '.':
  2025. switch (ch) {
  2026. case '(':
  2027. this._terminal.gcharset = 0;
  2028. break;
  2029. case ')':
  2030. this._terminal.gcharset = 1;
  2031. break;
  2032. case '*':
  2033. this._terminal.gcharset = 2;
  2034. break;
  2035. case '+':
  2036. this._terminal.gcharset = 3;
  2037. break;
  2038. case '-':
  2039. this._terminal.gcharset = 1;
  2040. break;
  2041. case '.':
  2042. this._terminal.gcharset = 2;
  2043. break;
  2044. }
  2045. this._state = ParserState.CHARSET;
  2046. break;
  2047. case '/':
  2048. this._terminal.gcharset = 3;
  2049. this._state = ParserState.CHARSET;
  2050. this._position--;
  2051. break;
  2052. case 'N':
  2053. this._state = ParserState.NORMAL;
  2054. break;
  2055. case 'O':
  2056. this._state = ParserState.NORMAL;
  2057. break;
  2058. case 'n':
  2059. this._terminal.setgLevel(2);
  2060. this._state = ParserState.NORMAL;
  2061. break;
  2062. case 'o':
  2063. this._terminal.setgLevel(3);
  2064. this._state = ParserState.NORMAL;
  2065. break;
  2066. case '|':
  2067. this._terminal.setgLevel(3);
  2068. this._state = ParserState.NORMAL;
  2069. break;
  2070. case '}':
  2071. this._terminal.setgLevel(2);
  2072. this._state = ParserState.NORMAL;
  2073. break;
  2074. case '~':
  2075. this._terminal.setgLevel(1);
  2076. this._state = ParserState.NORMAL;
  2077. break;
  2078. case '7':
  2079. this._inputHandler.saveCursor();
  2080. this._state = ParserState.NORMAL;
  2081. break;
  2082. case '8':
  2083. this._inputHandler.restoreCursor();
  2084. this._state = ParserState.NORMAL;
  2085. break;
  2086. case '#':
  2087. this._state = ParserState.NORMAL;
  2088. this._position++;
  2089. break;
  2090. case 'H':
  2091. this._terminal.tabSet();
  2092. this._state = ParserState.NORMAL;
  2093. break;
  2094. case '=':
  2095. this._terminal.log('Serial port requested application keypad.');
  2096. this._terminal.applicationKeypad = true;
  2097. if (this._terminal.viewport) {
  2098. this._terminal.viewport.syncScrollArea();
  2099. }
  2100. this._state = ParserState.NORMAL;
  2101. break;
  2102. case '>':
  2103. this._terminal.log('Switching back to normal keypad.');
  2104. this._terminal.applicationKeypad = false;
  2105. if (this._terminal.viewport) {
  2106. this._terminal.viewport.syncScrollArea();
  2107. }
  2108. this._state = ParserState.NORMAL;
  2109. break;
  2110. default:
  2111. this._state = ParserState.NORMAL;
  2112. this._terminal.error('Unknown ESC control: %s.', ch);
  2113. break;
  2114. }
  2115. break;
  2116. case ParserState.CHARSET:
  2117. if (ch in Charsets_1.CHARSETS) {
  2118. cs = Charsets_1.CHARSETS[ch];
  2119. if (ch === '/') {
  2120. this.skipNextChar();
  2121. }
  2122. }
  2123. else {
  2124. cs = Charsets_1.DEFAULT_CHARSET;
  2125. }
  2126. this._terminal.setgCharset(this._terminal.gcharset, cs);
  2127. this._terminal.gcharset = null;
  2128. this._state = ParserState.NORMAL;
  2129. break;
  2130. case ParserState.OSC:
  2131. if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
  2132. if (ch === EscapeSequences_1.C0.ESC)
  2133. this._position++;
  2134. this._terminal.params.push(this._terminal.currentParam);
  2135. switch (this._terminal.params[0]) {
  2136. case 0:
  2137. case 1:
  2138. case 2:
  2139. if (this._terminal.params[1]) {
  2140. this._terminal.title = this._terminal.params[1];
  2141. this._terminal.handleTitle(this._terminal.title);
  2142. }
  2143. break;
  2144. case 3:
  2145. break;
  2146. case 4:
  2147. case 5:
  2148. break;
  2149. case 10:
  2150. case 11:
  2151. case 12:
  2152. case 13:
  2153. case 14:
  2154. case 15:
  2155. case 16:
  2156. case 17:
  2157. case 18:
  2158. case 19:
  2159. break;
  2160. case 46:
  2161. break;
  2162. case 50:
  2163. break;
  2164. case 51:
  2165. break;
  2166. case 52:
  2167. break;
  2168. case 104:
  2169. case 105:
  2170. case 110:
  2171. case 111:
  2172. case 112:
  2173. case 113:
  2174. case 114:
  2175. case 115:
  2176. case 116:
  2177. case 117:
  2178. case 118:
  2179. break;
  2180. }
  2181. this._terminal.params = [];
  2182. this._terminal.currentParam = 0;
  2183. this._state = ParserState.NORMAL;
  2184. }
  2185. else {
  2186. if (!this._terminal.params.length) {
  2187. if (ch >= '0' && ch <= '9') {
  2188. this._terminal.currentParam =
  2189. this._terminal.currentParam * 10 + ch.charCodeAt(0) - 48;
  2190. }
  2191. else if (ch === ';') {
  2192. this._terminal.params.push(this._terminal.currentParam);
  2193. this._terminal.currentParam = '';
  2194. }
  2195. }
  2196. else {
  2197. this._terminal.currentParam += ch;
  2198. }
  2199. }
  2200. break;
  2201. case ParserState.CSI_PARAM:
  2202. if (ch in csiParamStateHandler) {
  2203. csiParamStateHandler[ch](this);
  2204. break;
  2205. }
  2206. this.finalizeParam();
  2207. this._state = ParserState.CSI;
  2208. case ParserState.CSI:
  2209. if (ch in csiStateHandler) {
  2210. if (this._terminal.debug) {
  2211. this._terminal.log("CSI " + (this._terminal.prefix ? this._terminal.prefix : '') + " " + (this._terminal.params ? this._terminal.params.join(';') : '') + " " + (this._terminal.postfix ? this._terminal.postfix : '') + " " + ch);
  2212. }
  2213. csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
  2214. }
  2215. else {
  2216. this._terminal.error('Unknown CSI code: %s.', ch);
  2217. }
  2218. this._state = ParserState.NORMAL;
  2219. this._terminal.prefix = '';
  2220. this._terminal.postfix = '';
  2221. break;
  2222. case ParserState.DCS:
  2223. if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
  2224. if (ch === EscapeSequences_1.C0.ESC)
  2225. this._position++;
  2226. var pt = void 0;
  2227. var valid = void 0;
  2228. switch (this._terminal.prefix) {
  2229. case '':
  2230. break;
  2231. case '$q':
  2232. pt = this._terminal.currentParam;
  2233. valid = false;
  2234. switch (pt) {
  2235. case '"q':
  2236. pt = '0"q';
  2237. break;
  2238. case '"p':
  2239. pt = '61"p';
  2240. break;
  2241. case 'r':
  2242. pt = ''
  2243. + (this._terminal.buffer.scrollTop + 1)
  2244. + ';'
  2245. + (this._terminal.buffer.scrollBottom + 1)
  2246. + 'r';
  2247. break;
  2248. case 'm':
  2249. pt = '0m';
  2250. break;
  2251. default:
  2252. this._terminal.error('Unknown DCS Pt: %s.', pt);
  2253. pt = '';
  2254. break;
  2255. }
  2256. this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '$r' + pt + EscapeSequences_1.C0.ESC + '\\');
  2257. break;
  2258. case '+p':
  2259. break;
  2260. case '+q':
  2261. pt = this._terminal.currentParam;
  2262. valid = false;
  2263. this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '+r' + pt + EscapeSequences_1.C0.ESC + '\\');
  2264. break;
  2265. default:
  2266. this._terminal.error('Unknown DCS prefix: %s.', this._terminal.prefix);
  2267. break;
  2268. }
  2269. this._terminal.currentParam = 0;
  2270. this._terminal.prefix = '';
  2271. this._state = ParserState.NORMAL;
  2272. }
  2273. else if (!this._terminal.currentParam) {
  2274. if (!this._terminal.prefix && ch !== '$' && ch !== '+') {
  2275. this._terminal.currentParam = ch;
  2276. }
  2277. else if (this._terminal.prefix.length === 2) {
  2278. this._terminal.currentParam = ch;
  2279. }
  2280. else {
  2281. this._terminal.prefix += ch;
  2282. }
  2283. }
  2284. else {
  2285. this._terminal.currentParam += ch;
  2286. }
  2287. break;
  2288. case ParserState.IGNORE:
  2289. if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
  2290. if (ch === EscapeSequences_1.C0.ESC)
  2291. this._position++;
  2292. this._state = ParserState.NORMAL;
  2293. }
  2294. break;
  2295. }
  2296. }
  2297. if (this._terminal.buffer.x !== cursorStartX || this._terminal.buffer.y !== cursorStartY) {
  2298. this._terminal.emit('cursormove');
  2299. }
  2300. return this._state;
  2301. };
  2302. Parser.prototype.setState = function (state) {
  2303. this._state = state;
  2304. };
  2305. Parser.prototype.setPrefix = function (prefix) {
  2306. this._terminal.prefix = prefix;
  2307. };
  2308. Parser.prototype.setPostfix = function (postfix) {
  2309. this._terminal.postfix = postfix;
  2310. };
  2311. Parser.prototype.setParam = function (param) {
  2312. this._terminal.currentParam = param;
  2313. };
  2314. Parser.prototype.getParam = function () {
  2315. return this._terminal.currentParam;
  2316. };
  2317. Parser.prototype.finalizeParam = function () {
  2318. this._terminal.params.push(this._terminal.currentParam);
  2319. this._terminal.currentParam = 0;
  2320. };
  2321. Parser.prototype.skipNextChar = function () {
  2322. this._position++;
  2323. };
  2324. return Parser;
  2325. }());
  2326. exports.Parser = Parser;
  2327. },{"./Charsets":4,"./EscapeSequences":6}],11:[function(require,module,exports){
  2328. "use strict";
  2329. var __extends = (this && this.__extends) || (function () {
  2330. var extendStatics = Object.setPrototypeOf ||
  2331. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2332. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2333. return function (d, b) {
  2334. extendStatics(d, b);
  2335. function __() { this.constructor = d; }
  2336. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2337. };
  2338. })();
  2339. Object.defineProperty(exports, "__esModule", { value: true });
  2340. var MouseHelper_1 = require("./utils/MouseHelper");
  2341. var Browser = require("./shared/utils/Browser");
  2342. var EventEmitter_1 = require("./EventEmitter");
  2343. var SelectionModel_1 = require("./SelectionModel");
  2344. var Buffer_1 = require("./Buffer");
  2345. var AltClickHandler_1 = require("./handlers/AltClickHandler");
  2346. var DRAG_SCROLL_MAX_THRESHOLD = 50;
  2347. var DRAG_SCROLL_MAX_SPEED = 15;
  2348. var DRAG_SCROLL_INTERVAL = 50;
  2349. var ALT_CLICK_MOVE_CURSOR_TIME = 500;
  2350. var WORD_SEPARATORS = ' ()[]{}\'"';
  2351. var NON_BREAKING_SPACE_CHAR = String.fromCharCode(160);
  2352. var ALL_NON_BREAKING_SPACE_REGEX = new RegExp(NON_BREAKING_SPACE_CHAR, 'g');
  2353. var SelectionMode;
  2354. (function (SelectionMode) {
  2355. SelectionMode[SelectionMode["NORMAL"] = 0] = "NORMAL";
  2356. SelectionMode[SelectionMode["WORD"] = 1] = "WORD";
  2357. SelectionMode[SelectionMode["LINE"] = 2] = "LINE";
  2358. })(SelectionMode || (SelectionMode = {}));
  2359. var SelectionManager = (function (_super) {
  2360. __extends(SelectionManager, _super);
  2361. function SelectionManager(_terminal, _charMeasure) {
  2362. var _this = _super.call(this) || this;
  2363. _this._terminal = _terminal;
  2364. _this._charMeasure = _charMeasure;
  2365. _this._enabled = true;
  2366. _this._initListeners();
  2367. _this.enable();
  2368. _this._model = new SelectionModel_1.SelectionModel(_terminal);
  2369. _this._activeSelectionMode = SelectionMode.NORMAL;
  2370. return _this;
  2371. }
  2372. Object.defineProperty(SelectionManager.prototype, "_buffer", {
  2373. get: function () {
  2374. return this._terminal.buffers.active;
  2375. },
  2376. enumerable: true,
  2377. configurable: true
  2378. });
  2379. SelectionManager.prototype._initListeners = function () {
  2380. var _this = this;
  2381. this._mouseMoveListener = function (event) { return _this._onMouseMove(event); };
  2382. this._mouseUpListener = function (event) { return _this._onMouseUp(event); };
  2383. this._trimListener = function (amount) { return _this._onTrim(amount); };
  2384. this.initBuffersListeners();
  2385. };
  2386. SelectionManager.prototype.initBuffersListeners = function () {
  2387. var _this = this;
  2388. this._terminal.buffer.lines.on('trim', this._trimListener);
  2389. this._terminal.buffers.on('activate', function (e) { return _this._onBufferActivate(e); });
  2390. };
  2391. SelectionManager.prototype.disable = function () {
  2392. this.clearSelection();
  2393. this._enabled = false;
  2394. };
  2395. SelectionManager.prototype.enable = function () {
  2396. this._enabled = true;
  2397. };
  2398. Object.defineProperty(SelectionManager.prototype, "selectionStart", {
  2399. get: function () { return this._model.finalSelectionStart; },
  2400. enumerable: true,
  2401. configurable: true
  2402. });
  2403. Object.defineProperty(SelectionManager.prototype, "selectionEnd", {
  2404. get: function () { return this._model.finalSelectionEnd; },
  2405. enumerable: true,
  2406. configurable: true
  2407. });
  2408. Object.defineProperty(SelectionManager.prototype, "hasSelection", {
  2409. get: function () {
  2410. var start = this._model.finalSelectionStart;
  2411. var end = this._model.finalSelectionEnd;
  2412. if (!start || !end) {
  2413. return false;
  2414. }
  2415. return start[0] !== end[0] || start[1] !== end[1];
  2416. },
  2417. enumerable: true,
  2418. configurable: true
  2419. });
  2420. Object.defineProperty(SelectionManager.prototype, "selectionText", {
  2421. get: function () {
  2422. var start = this._model.finalSelectionStart;
  2423. var end = this._model.finalSelectionEnd;
  2424. if (!start || !end) {
  2425. return '';
  2426. }
  2427. var startRowEndCol = start[1] === end[1] ? end[0] : null;
  2428. var result = [];
  2429. result.push(this._buffer.translateBufferLineToString(start[1], true, start[0], startRowEndCol));
  2430. for (var i = start[1] + 1; i <= end[1] - 1; i++) {
  2431. var bufferLine = this._buffer.lines.get(i);
  2432. var lineText = this._buffer.translateBufferLineToString(i, true);
  2433. if (bufferLine.isWrapped) {
  2434. result[result.length - 1] += lineText;
  2435. }
  2436. else {
  2437. result.push(lineText);
  2438. }
  2439. }
  2440. if (start[1] !== end[1]) {
  2441. var bufferLine = this._buffer.lines.get(end[1]);
  2442. var lineText = this._buffer.translateBufferLineToString(end[1], true, 0, end[0]);
  2443. if (bufferLine.isWrapped) {
  2444. result[result.length - 1] += lineText;
  2445. }
  2446. else {
  2447. result.push(lineText);
  2448. }
  2449. }
  2450. var formattedResult = result.map(function (line) {
  2451. return line.replace(ALL_NON_BREAKING_SPACE_REGEX, ' ');
  2452. }).join(Browser.isMSWindows ? '\r\n' : '\n');
  2453. return formattedResult;
  2454. },
  2455. enumerable: true,
  2456. configurable: true
  2457. });
  2458. SelectionManager.prototype.clearSelection = function () {
  2459. this._model.clearSelection();
  2460. this._removeMouseDownListeners();
  2461. this.refresh();
  2462. };
  2463. SelectionManager.prototype.refresh = function (isNewSelection) {
  2464. var _this = this;
  2465. if (!this._refreshAnimationFrame) {
  2466. this._refreshAnimationFrame = window.requestAnimationFrame(function () { return _this._refresh(); });
  2467. }
  2468. if (Browser.isLinux && isNewSelection) {
  2469. var selectionText = this.selectionText;
  2470. if (selectionText.length) {
  2471. this.emit('newselection', this.selectionText);
  2472. }
  2473. }
  2474. };
  2475. SelectionManager.prototype._refresh = function () {
  2476. this._refreshAnimationFrame = null;
  2477. this.emit('refresh', { start: this._model.finalSelectionStart, end: this._model.finalSelectionEnd });
  2478. };
  2479. SelectionManager.prototype.isClickInSelection = function (event) {
  2480. var coords = this._getMouseBufferCoords(event);
  2481. var start = this._model.finalSelectionStart;
  2482. var end = this._model.finalSelectionEnd;
  2483. if (!start || !end) {
  2484. return false;
  2485. }
  2486. return (coords[1] > start[1] && coords[1] < end[1]) ||
  2487. (start[1] === end[1] && coords[1] === start[1] && coords[0] > start[0] && coords[0] < end[0]) ||
  2488. (start[1] < end[1] && coords[1] === end[1] && coords[0] < end[0]);
  2489. };
  2490. SelectionManager.prototype.selectWordAtCursor = function (event) {
  2491. var coords = this._getMouseBufferCoords(event);
  2492. if (coords) {
  2493. this._selectWordAt(coords, false);
  2494. this._model.selectionEnd = null;
  2495. this.refresh(true);
  2496. }
  2497. };
  2498. SelectionManager.prototype.selectAll = function () {
  2499. this._model.isSelectAllActive = true;
  2500. this.refresh();
  2501. this._terminal.emit('selection');
  2502. };
  2503. SelectionManager.prototype._onTrim = function (amount) {
  2504. var needsRefresh = this._model.onTrim(amount);
  2505. if (needsRefresh) {
  2506. this.refresh();
  2507. }
  2508. };
  2509. SelectionManager.prototype._getMouseBufferCoords = function (event) {
  2510. var coords = this._terminal.mouseHelper.getCoords(event, this._terminal.screenElement, this._charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows, true);
  2511. if (!coords) {
  2512. return null;
  2513. }
  2514. coords[0]--;
  2515. coords[1]--;
  2516. coords[1] += this._terminal.buffer.ydisp;
  2517. return coords;
  2518. };
  2519. SelectionManager.prototype._getMouseEventScrollAmount = function (event) {
  2520. var offset = MouseHelper_1.MouseHelper.getCoordsRelativeToElement(event, this._terminal.screenElement)[1];
  2521. var terminalHeight = this._terminal.rows * Math.ceil(this._charMeasure.height * this._terminal.options.lineHeight);
  2522. if (offset >= 0 && offset <= terminalHeight) {
  2523. return 0;
  2524. }
  2525. if (offset > terminalHeight) {
  2526. offset -= terminalHeight;
  2527. }
  2528. offset = Math.min(Math.max(offset, -DRAG_SCROLL_MAX_THRESHOLD), DRAG_SCROLL_MAX_THRESHOLD);
  2529. offset /= DRAG_SCROLL_MAX_THRESHOLD;
  2530. return (offset / Math.abs(offset)) + Math.round(offset * (DRAG_SCROLL_MAX_SPEED - 1));
  2531. };
  2532. SelectionManager.prototype.shouldForceSelection = function (event) {
  2533. return Browser.isMac ? event.altKey : event.shiftKey;
  2534. };
  2535. SelectionManager.prototype.onMouseDown = function (event) {
  2536. this._mouseDownTimeStamp = event.timeStamp;
  2537. if (event.button === 2 && this.hasSelection) {
  2538. return;
  2539. }
  2540. if (event.button !== 0) {
  2541. return;
  2542. }
  2543. if (!this._enabled) {
  2544. if (!this.shouldForceSelection(event)) {
  2545. return;
  2546. }
  2547. event.stopPropagation();
  2548. }
  2549. event.preventDefault();
  2550. this._dragScrollAmount = 0;
  2551. if (this._enabled && event.shiftKey) {
  2552. this._onIncrementalClick(event);
  2553. }
  2554. else {
  2555. if (event.detail === 1) {
  2556. this._onSingleClick(event);
  2557. }
  2558. else if (event.detail === 2) {
  2559. this._onDoubleClick(event);
  2560. }
  2561. else if (event.detail === 3) {
  2562. this._onTripleClick(event);
  2563. }
  2564. }
  2565. this._addMouseDownListeners();
  2566. this.refresh(true);
  2567. };
  2568. SelectionManager.prototype._addMouseDownListeners = function () {
  2569. var _this = this;
  2570. this._terminal.element.ownerDocument.addEventListener('mousemove', this._mouseMoveListener);
  2571. this._terminal.element.ownerDocument.addEventListener('mouseup', this._mouseUpListener);
  2572. this._dragScrollIntervalTimer = setInterval(function () { return _this._dragScroll(); }, DRAG_SCROLL_INTERVAL);
  2573. };
  2574. SelectionManager.prototype._removeMouseDownListeners = function () {
  2575. this._terminal.element.ownerDocument.removeEventListener('mousemove', this._mouseMoveListener);
  2576. this._terminal.element.ownerDocument.removeEventListener('mouseup', this._mouseUpListener);
  2577. clearInterval(this._dragScrollIntervalTimer);
  2578. this._dragScrollIntervalTimer = null;
  2579. };
  2580. SelectionManager.prototype._onIncrementalClick = function (event) {
  2581. if (this._model.selectionStart) {
  2582. this._model.selectionEnd = this._getMouseBufferCoords(event);
  2583. }
  2584. };
  2585. SelectionManager.prototype._onSingleClick = function (event) {
  2586. this._model.selectionStartLength = 0;
  2587. this._model.isSelectAllActive = false;
  2588. this._activeSelectionMode = SelectionMode.NORMAL;
  2589. this._model.selectionStart = this._getMouseBufferCoords(event);
  2590. if (!this._model.selectionStart) {
  2591. return;
  2592. }
  2593. this._model.selectionEnd = null;
  2594. var line = this._buffer.lines.get(this._model.selectionStart[1]);
  2595. if (!line) {
  2596. return;
  2597. }
  2598. if (line.length >= this._model.selectionStart[0]) {
  2599. return;
  2600. }
  2601. var char = line[this._model.selectionStart[0]];
  2602. if (char[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 0) {
  2603. this._model.selectionStart[0]++;
  2604. }
  2605. };
  2606. SelectionManager.prototype._onDoubleClick = function (event) {
  2607. var coords = this._getMouseBufferCoords(event);
  2608. if (coords) {
  2609. this._activeSelectionMode = SelectionMode.WORD;
  2610. this._selectWordAt(coords, true);
  2611. }
  2612. };
  2613. SelectionManager.prototype._onTripleClick = function (event) {
  2614. var coords = this._getMouseBufferCoords(event);
  2615. if (coords) {
  2616. this._activeSelectionMode = SelectionMode.LINE;
  2617. this._selectLineAt(coords[1]);
  2618. }
  2619. };
  2620. SelectionManager.prototype._onMouseMove = function (event) {
  2621. event.stopImmediatePropagation();
  2622. var previousSelectionEnd = this._model.selectionEnd ? [this._model.selectionEnd[0], this._model.selectionEnd[1]] : null;
  2623. this._model.selectionEnd = this._getMouseBufferCoords(event);
  2624. if (!this._model.selectionEnd) {
  2625. this.refresh(true);
  2626. return;
  2627. }
  2628. if (this._activeSelectionMode === SelectionMode.LINE) {
  2629. if (this._model.selectionEnd[1] < this._model.selectionStart[1]) {
  2630. this._model.selectionEnd[0] = 0;
  2631. }
  2632. else {
  2633. this._model.selectionEnd[0] = this._terminal.cols;
  2634. }
  2635. }
  2636. else if (this._activeSelectionMode === SelectionMode.WORD) {
  2637. this._selectToWordAt(this._model.selectionEnd);
  2638. }
  2639. this._dragScrollAmount = this._getMouseEventScrollAmount(event);
  2640. if (this._dragScrollAmount > 0) {
  2641. this._model.selectionEnd[0] = this._terminal.cols;
  2642. }
  2643. else if (this._dragScrollAmount < 0) {
  2644. this._model.selectionEnd[0] = 0;
  2645. }
  2646. if (this._model.selectionEnd[1] < this._buffer.lines.length) {
  2647. var char = this._buffer.lines.get(this._model.selectionEnd[1])[this._model.selectionEnd[0]];
  2648. if (char && char[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 0) {
  2649. this._model.selectionEnd[0]++;
  2650. }
  2651. }
  2652. if (!previousSelectionEnd ||
  2653. previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
  2654. previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
  2655. this.refresh(true);
  2656. }
  2657. };
  2658. SelectionManager.prototype._dragScroll = function () {
  2659. if (this._dragScrollAmount) {
  2660. this._terminal.scrollLines(this._dragScrollAmount, false);
  2661. if (this._dragScrollAmount > 0) {
  2662. this._model.selectionEnd = [this._terminal.cols - 1, Math.min(this._terminal.buffer.ydisp + this._terminal.rows, this._terminal.buffer.lines.length - 1)];
  2663. }
  2664. else {
  2665. this._model.selectionEnd = [0, this._terminal.buffer.ydisp];
  2666. }
  2667. this.refresh();
  2668. }
  2669. };
  2670. SelectionManager.prototype._onMouseUp = function (event) {
  2671. var timeElapsed = event.timeStamp - this._mouseDownTimeStamp;
  2672. this._removeMouseDownListeners();
  2673. if (this.selectionText.length <= 1 && timeElapsed < ALT_CLICK_MOVE_CURSOR_TIME) {
  2674. (new AltClickHandler_1.AltClickHandler(event, this._terminal)).move();
  2675. }
  2676. else if (this.hasSelection) {
  2677. this._terminal.emit('selection');
  2678. }
  2679. };
  2680. SelectionManager.prototype._onBufferActivate = function (e) {
  2681. this.clearSelection();
  2682. e.inactiveBuffer.lines.off('trim', this._trimListener);
  2683. e.activeBuffer.lines.on('trim', this._trimListener);
  2684. };
  2685. SelectionManager.prototype._convertViewportColToCharacterIndex = function (bufferLine, coords) {
  2686. var charIndex = coords[0];
  2687. for (var i = 0; coords[0] >= i; i++) {
  2688. var char = bufferLine[i];
  2689. if (char[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 0) {
  2690. charIndex--;
  2691. }
  2692. else if (char[Buffer_1.CHAR_DATA_CHAR_INDEX].length > 1 && coords[0] !== i) {
  2693. charIndex += char[Buffer_1.CHAR_DATA_CHAR_INDEX].length - 1;
  2694. }
  2695. }
  2696. return charIndex;
  2697. };
  2698. SelectionManager.prototype.setSelection = function (col, row, length) {
  2699. this._model.clearSelection();
  2700. this._removeMouseDownListeners();
  2701. this._model.selectionStart = [col, row];
  2702. this._model.selectionStartLength = length;
  2703. this.refresh();
  2704. };
  2705. SelectionManager.prototype._getWordAt = function (coords, allowWhitespaceOnlySelection) {
  2706. var bufferLine = this._buffer.lines.get(coords[1]);
  2707. if (!bufferLine) {
  2708. return null;
  2709. }
  2710. var line = this._buffer.translateBufferLineToString(coords[1], false);
  2711. var startIndex = this._convertViewportColToCharacterIndex(bufferLine, coords);
  2712. var endIndex = startIndex;
  2713. var charOffset = coords[0] - startIndex;
  2714. var leftWideCharCount = 0;
  2715. var rightWideCharCount = 0;
  2716. var leftLongCharOffset = 0;
  2717. var rightLongCharOffset = 0;
  2718. if (line.charAt(startIndex) === ' ') {
  2719. while (startIndex > 0 && line.charAt(startIndex - 1) === ' ') {
  2720. startIndex--;
  2721. }
  2722. while (endIndex < line.length && line.charAt(endIndex + 1) === ' ') {
  2723. endIndex++;
  2724. }
  2725. }
  2726. else {
  2727. var startCol = coords[0];
  2728. var endCol = coords[0];
  2729. if (bufferLine[startCol][Buffer_1.CHAR_DATA_WIDTH_INDEX] === 0) {
  2730. leftWideCharCount++;
  2731. startCol--;
  2732. }
  2733. if (bufferLine[endCol][Buffer_1.CHAR_DATA_WIDTH_INDEX] === 2) {
  2734. rightWideCharCount++;
  2735. endCol++;
  2736. }
  2737. if (bufferLine[endCol][Buffer_1.CHAR_DATA_CHAR_INDEX].length > 1) {
  2738. rightLongCharOffset += bufferLine[endCol][Buffer_1.CHAR_DATA_CHAR_INDEX].length - 1;
  2739. endIndex += bufferLine[endCol][Buffer_1.CHAR_DATA_CHAR_INDEX].length - 1;
  2740. }
  2741. while (startCol > 0 && startIndex > 0 && !this._isCharWordSeparator(bufferLine[startCol - 1])) {
  2742. var char = bufferLine[startCol - 1];
  2743. if (char[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 0) {
  2744. leftWideCharCount++;
  2745. startCol--;
  2746. }
  2747. else if (char[Buffer_1.CHAR_DATA_CHAR_INDEX].length > 1) {
  2748. leftLongCharOffset += char[Buffer_1.CHAR_DATA_CHAR_INDEX].length - 1;
  2749. startIndex -= char[Buffer_1.CHAR_DATA_CHAR_INDEX].length - 1;
  2750. }
  2751. startIndex--;
  2752. startCol--;
  2753. }
  2754. while (endCol < bufferLine.length && endIndex + 1 < line.length && !this._isCharWordSeparator(bufferLine[endCol + 1])) {
  2755. var char = bufferLine[endCol + 1];
  2756. if (char[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 2) {
  2757. rightWideCharCount++;
  2758. endCol++;
  2759. }
  2760. else if (char[Buffer_1.CHAR_DATA_CHAR_INDEX].length > 1) {
  2761. rightLongCharOffset += char[Buffer_1.CHAR_DATA_CHAR_INDEX].length - 1;
  2762. endIndex += char[Buffer_1.CHAR_DATA_CHAR_INDEX].length - 1;
  2763. }
  2764. endIndex++;
  2765. endCol++;
  2766. }
  2767. }
  2768. endIndex++;
  2769. var start = startIndex
  2770. + charOffset
  2771. - leftWideCharCount
  2772. + leftLongCharOffset;
  2773. var length = Math.min(this._terminal.cols, endIndex
  2774. - startIndex
  2775. + leftWideCharCount
  2776. + rightWideCharCount
  2777. - leftLongCharOffset
  2778. - rightLongCharOffset);
  2779. if (!allowWhitespaceOnlySelection && line.slice(startIndex, endIndex).trim() === '') {
  2780. return null;
  2781. }
  2782. return { start: start, length: length };
  2783. };
  2784. SelectionManager.prototype._selectWordAt = function (coords, allowWhitespaceOnlySelection) {
  2785. var wordPosition = this._getWordAt(coords, allowWhitespaceOnlySelection);
  2786. if (wordPosition) {
  2787. this._model.selectionStart = [wordPosition.start, coords[1]];
  2788. this._model.selectionStartLength = wordPosition.length;
  2789. }
  2790. };
  2791. SelectionManager.prototype._selectToWordAt = function (coords) {
  2792. var wordPosition = this._getWordAt(coords, true);
  2793. if (wordPosition) {
  2794. this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : (wordPosition.start + wordPosition.length), coords[1]];
  2795. }
  2796. };
  2797. SelectionManager.prototype._isCharWordSeparator = function (charData) {
  2798. if (charData[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 0) {
  2799. return false;
  2800. }
  2801. return WORD_SEPARATORS.indexOf(charData[Buffer_1.CHAR_DATA_CHAR_INDEX]) >= 0;
  2802. };
  2803. SelectionManager.prototype._selectLineAt = function (line) {
  2804. this._model.selectionStart = [0, line];
  2805. this._model.selectionStartLength = this._terminal.cols;
  2806. };
  2807. return SelectionManager;
  2808. }(EventEmitter_1.EventEmitter));
  2809. exports.SelectionManager = SelectionManager;
  2810. },{"./Buffer":1,"./EventEmitter":7,"./SelectionModel":12,"./handlers/AltClickHandler":16,"./shared/utils/Browser":30,"./utils/MouseHelper":33}],12:[function(require,module,exports){
  2811. "use strict";
  2812. Object.defineProperty(exports, "__esModule", { value: true });
  2813. var SelectionModel = (function () {
  2814. function SelectionModel(_terminal) {
  2815. this._terminal = _terminal;
  2816. this.clearSelection();
  2817. }
  2818. SelectionModel.prototype.clearSelection = function () {
  2819. this.selectionStart = null;
  2820. this.selectionEnd = null;
  2821. this.isSelectAllActive = false;
  2822. this.selectionStartLength = 0;
  2823. };
  2824. Object.defineProperty(SelectionModel.prototype, "finalSelectionStart", {
  2825. get: function () {
  2826. if (this.isSelectAllActive) {
  2827. return [0, 0];
  2828. }
  2829. if (!this.selectionEnd || !this.selectionStart) {
  2830. return this.selectionStart;
  2831. }
  2832. return this.areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
  2833. },
  2834. enumerable: true,
  2835. configurable: true
  2836. });
  2837. Object.defineProperty(SelectionModel.prototype, "finalSelectionEnd", {
  2838. get: function () {
  2839. if (this.isSelectAllActive) {
  2840. return [this._terminal.cols, this._terminal.buffer.ybase + this._terminal.rows - 1];
  2841. }
  2842. if (!this.selectionStart) {
  2843. return null;
  2844. }
  2845. if (!this.selectionEnd || this.areSelectionValuesReversed()) {
  2846. return [this.selectionStart[0] + this.selectionStartLength, this.selectionStart[1]];
  2847. }
  2848. if (this.selectionStartLength) {
  2849. if (this.selectionEnd[1] === this.selectionStart[1]) {
  2850. return [Math.max(this.selectionStart[0] + this.selectionStartLength, this.selectionEnd[0]), this.selectionEnd[1]];
  2851. }
  2852. }
  2853. return this.selectionEnd;
  2854. },
  2855. enumerable: true,
  2856. configurable: true
  2857. });
  2858. SelectionModel.prototype.areSelectionValuesReversed = function () {
  2859. var start = this.selectionStart;
  2860. var end = this.selectionEnd;
  2861. if (!start || !end) {
  2862. return false;
  2863. }
  2864. return start[1] > end[1] || (start[1] === end[1] && start[0] > end[0]);
  2865. };
  2866. SelectionModel.prototype.onTrim = function (amount) {
  2867. if (this.selectionStart) {
  2868. this.selectionStart[1] -= amount;
  2869. }
  2870. if (this.selectionEnd) {
  2871. this.selectionEnd[1] -= amount;
  2872. }
  2873. if (this.selectionEnd && this.selectionEnd[1] < 0) {
  2874. this.clearSelection();
  2875. return true;
  2876. }
  2877. if (this.selectionStart && this.selectionStart[1] < 0) {
  2878. this.selectionStart[1] = 0;
  2879. }
  2880. return false;
  2881. };
  2882. return SelectionModel;
  2883. }());
  2884. exports.SelectionModel = SelectionModel;
  2885. },{}],13:[function(require,module,exports){
  2886. "use strict";
  2887. var __extends = (this && this.__extends) || (function () {
  2888. var extendStatics = Object.setPrototypeOf ||
  2889. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2890. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2891. return function (d, b) {
  2892. extendStatics(d, b);
  2893. function __() { this.constructor = d; }
  2894. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2895. };
  2896. })();
  2897. Object.defineProperty(exports, "__esModule", { value: true });
  2898. var BufferSet_1 = require("./BufferSet");
  2899. var Buffer_1 = require("./Buffer");
  2900. var CompositionHelper_1 = require("./CompositionHelper");
  2901. var EventEmitter_1 = require("./EventEmitter");
  2902. var Viewport_1 = require("./Viewport");
  2903. var Clipboard_1 = require("./handlers/Clipboard");
  2904. var EscapeSequences_1 = require("./EscapeSequences");
  2905. var InputHandler_1 = require("./InputHandler");
  2906. var Parser_1 = require("./Parser");
  2907. var Renderer_1 = require("./renderer/Renderer");
  2908. var Linkifier_1 = require("./Linkifier");
  2909. var SelectionManager_1 = require("./SelectionManager");
  2910. var CharMeasure_1 = require("./utils/CharMeasure");
  2911. var Browser = require("./shared/utils/Browser");
  2912. var MouseHelper_1 = require("./utils/MouseHelper");
  2913. var Sounds_1 = require("./utils/Sounds");
  2914. var ColorManager_1 = require("./renderer/ColorManager");
  2915. var MouseZoneManager_1 = require("./input/MouseZoneManager");
  2916. var document = (typeof window !== 'undefined') ? window.document : null;
  2917. var WRITE_BUFFER_PAUSE_THRESHOLD = 5;
  2918. var WRITE_BATCH_SIZE = 300;
  2919. var DEFAULT_OPTIONS = {
  2920. cols: 80,
  2921. rows: 24,
  2922. convertEol: false,
  2923. termName: 'xterm',
  2924. cursorBlink: false,
  2925. cursorStyle: 'block',
  2926. bellSound: Sounds_1.BELL_SOUND,
  2927. bellStyle: 'none',
  2928. enableBold: true,
  2929. fontFamily: 'courier-new, courier, monospace',
  2930. fontSize: 15,
  2931. fontWeight: 'normal',
  2932. fontWeightBold: 'bold',
  2933. lineHeight: 1.0,
  2934. letterSpacing: 0,
  2935. scrollback: 1000,
  2936. screenKeys: false,
  2937. debug: false,
  2938. macOptionIsMeta: false,
  2939. cancelEvents: false,
  2940. disableStdin: false,
  2941. useFlowControl: false,
  2942. allowTransparency: false,
  2943. tabStopWidth: 8,
  2944. theme: null,
  2945. rightClickSelectsWord: Browser.isMac
  2946. };
  2947. var Terminal = (function (_super) {
  2948. __extends(Terminal, _super);
  2949. function Terminal(options) {
  2950. if (options === void 0) { options = {}; }
  2951. var _this = _super.call(this) || this;
  2952. _this.browser = Browser;
  2953. _this.options = options;
  2954. _this.setup();
  2955. return _this;
  2956. }
  2957. Terminal.prototype.setup = function () {
  2958. var _this = this;
  2959. Object.keys(DEFAULT_OPTIONS).forEach(function (key) {
  2960. if (_this.options[key] == null) {
  2961. _this.options[key] = DEFAULT_OPTIONS[key];
  2962. }
  2963. _this[key] = _this.options[key];
  2964. });
  2965. this.parent = document ? document.body : null;
  2966. this.cols = this.options.cols;
  2967. this.rows = this.options.rows;
  2968. if (this.options.handler) {
  2969. this.on('data', this.options.handler);
  2970. }
  2971. this.cursorState = 0;
  2972. this.cursorHidden = false;
  2973. this.sendDataQueue = '';
  2974. this.customKeyEventHandler = null;
  2975. this.applicationKeypad = false;
  2976. this.applicationCursor = false;
  2977. this.originMode = false;
  2978. this.insertMode = false;
  2979. this.wraparoundMode = true;
  2980. this.bracketedPasteMode = false;
  2981. this.charset = null;
  2982. this.gcharset = null;
  2983. this.glevel = 0;
  2984. this.charsets = [null];
  2985. this.readable = true;
  2986. this.writable = true;
  2987. this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
  2988. this.curAttr = (0 << 18) | (257 << 9) | (256 << 0);
  2989. this.params = [];
  2990. this.currentParam = 0;
  2991. this.prefix = '';
  2992. this.postfix = '';
  2993. this.writeBuffer = [];
  2994. this.writeInProgress = false;
  2995. this.xoffSentToCatchUp = false;
  2996. this.writeStopped = false;
  2997. this.surrogateHigh = '';
  2998. this.userScrolling = false;
  2999. this.inputHandler = new InputHandler_1.InputHandler(this);
  3000. this.parser = new Parser_1.Parser(this.inputHandler, this);
  3001. this.renderer = this.renderer || null;
  3002. this.selectionManager = this.selectionManager || null;
  3003. this.linkifier = this.linkifier || new Linkifier_1.Linkifier(this);
  3004. this._mouseZoneManager = this._mouseZoneManager || null;
  3005. this.buffers = new BufferSet_1.BufferSet(this);
  3006. if (this.selectionManager) {
  3007. this.selectionManager.clearSelection();
  3008. this.selectionManager.initBuffersListeners();
  3009. }
  3010. };
  3011. Object.defineProperty(Terminal.prototype, "buffer", {
  3012. get: function () {
  3013. return this.buffers.active;
  3014. },
  3015. enumerable: true,
  3016. configurable: true
  3017. });
  3018. Terminal.prototype.eraseAttr = function () {
  3019. return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
  3020. };
  3021. Terminal.prototype.focus = function () {
  3022. if (this.textarea) {
  3023. this.textarea.focus();
  3024. }
  3025. };
  3026. Object.defineProperty(Terminal.prototype, "isFocused", {
  3027. get: function () {
  3028. return document.activeElement === this.textarea;
  3029. },
  3030. enumerable: true,
  3031. configurable: true
  3032. });
  3033. Terminal.prototype.getOption = function (key) {
  3034. if (!(key in DEFAULT_OPTIONS)) {
  3035. throw new Error('No option with key "' + key + '"');
  3036. }
  3037. if (typeof this.options[key] !== 'undefined') {
  3038. return this.options[key];
  3039. }
  3040. return this[key];
  3041. };
  3042. Terminal.prototype.setOption = function (key, value) {
  3043. if (!(key in DEFAULT_OPTIONS)) {
  3044. throw new Error('No option with key "' + key + '"');
  3045. }
  3046. switch (key) {
  3047. case 'bellStyle':
  3048. if (!value) {
  3049. value = 'none';
  3050. }
  3051. break;
  3052. case 'cursorStyle':
  3053. if (!value) {
  3054. value = 'block';
  3055. }
  3056. break;
  3057. case 'fontWeight':
  3058. if (!value) {
  3059. value = 'normal';
  3060. }
  3061. break;
  3062. case 'fontWeightBold':
  3063. if (!value) {
  3064. value = 'bold';
  3065. }
  3066. break;
  3067. case 'lineHeight':
  3068. if (value < 1) {
  3069. console.warn(key + " cannot be less than 1, value: " + value);
  3070. return;
  3071. }
  3072. case 'tabStopWidth':
  3073. if (value < 1) {
  3074. console.warn(key + " cannot be less than 1, value: " + value);
  3075. return;
  3076. }
  3077. break;
  3078. case 'theme':
  3079. if (this.renderer) {
  3080. this._setTheme(value);
  3081. return;
  3082. }
  3083. break;
  3084. case 'scrollback':
  3085. value = Math.min(value, Buffer_1.MAX_BUFFER_SIZE);
  3086. if (value < 0) {
  3087. console.warn(key + " cannot be less than 0, value: " + value);
  3088. return;
  3089. }
  3090. if (this.options[key] !== value) {
  3091. var newBufferLength = this.rows + value;
  3092. if (this.buffer.lines.length > newBufferLength) {
  3093. var amountToTrim = this.buffer.lines.length - newBufferLength;
  3094. var needsRefresh = (this.buffer.ydisp - amountToTrim < 0);
  3095. this.buffer.lines.trimStart(amountToTrim);
  3096. this.buffer.ybase = Math.max(this.buffer.ybase - amountToTrim, 0);
  3097. this.buffer.ydisp = Math.max(this.buffer.ydisp - amountToTrim, 0);
  3098. if (needsRefresh) {
  3099. this.refresh(0, this.rows - 1);
  3100. }
  3101. }
  3102. }
  3103. break;
  3104. }
  3105. this[key] = value;
  3106. this.options[key] = value;
  3107. switch (key) {
  3108. case 'fontFamily':
  3109. case 'fontSize':
  3110. this.renderer.clear();
  3111. this.charMeasure.measure(this.options);
  3112. break;
  3113. case 'enableBold':
  3114. case 'letterSpacing':
  3115. case 'lineHeight':
  3116. case 'fontWeight':
  3117. case 'fontWeightBold':
  3118. var didCharSizeChange = (key === 'fontWeight' || key === 'fontWeightBold' || key === 'enableBold');
  3119. this.renderer.clear();
  3120. this.renderer.onResize(this.cols, this.rows, didCharSizeChange);
  3121. this.refresh(0, this.rows - 1);
  3122. case 'scrollback':
  3123. this.buffers.resize(this.cols, this.rows);
  3124. this.viewport.syncScrollArea();
  3125. break;
  3126. case 'tabStopWidth':
  3127. this.buffers.setupTabStops();
  3128. break;
  3129. case 'bellSound':
  3130. case 'bellStyle':
  3131. this.syncBellSound();
  3132. break;
  3133. }
  3134. if (this.renderer) {
  3135. this.renderer.onOptionsChanged();
  3136. }
  3137. };
  3138. Terminal.prototype._onTextAreaFocus = function () {
  3139. if (this.sendFocus) {
  3140. this.send(EscapeSequences_1.C0.ESC + '[I');
  3141. }
  3142. this.element.classList.add('focus');
  3143. this.showCursor();
  3144. this.emit('focus');
  3145. };
  3146. Terminal.prototype.blur = function () {
  3147. return this.textarea.blur();
  3148. };
  3149. Terminal.prototype._onTextAreaBlur = function () {
  3150. this.refresh(this.buffer.y, this.buffer.y);
  3151. if (this.sendFocus) {
  3152. this.send(EscapeSequences_1.C0.ESC + '[O');
  3153. }
  3154. this.element.classList.remove('focus');
  3155. this.emit('blur');
  3156. };
  3157. Terminal.prototype.initGlobal = function () {
  3158. var _this = this;
  3159. this.bindKeys();
  3160. on(this.element, 'copy', function (event) {
  3161. if (!_this.hasSelection()) {
  3162. return;
  3163. }
  3164. Clipboard_1.copyHandler(event, _this, _this.selectionManager);
  3165. });
  3166. var pasteHandlerWrapper = function (event) { return Clipboard_1.pasteHandler(event, _this); };
  3167. on(this.textarea, 'paste', pasteHandlerWrapper);
  3168. on(this.element, 'paste', pasteHandlerWrapper);
  3169. if (Browser.isFirefox) {
  3170. on(this.element, 'mousedown', function (event) {
  3171. if (event.button === 2) {
  3172. Clipboard_1.rightClickHandler(event, _this.textarea, _this.selectionManager, _this.options.rightClickSelectsWord);
  3173. }
  3174. });
  3175. }
  3176. else {
  3177. on(this.element, 'contextmenu', function (event) {
  3178. Clipboard_1.rightClickHandler(event, _this.textarea, _this.selectionManager, _this.options.rightClickSelectsWord);
  3179. });
  3180. }
  3181. if (Browser.isLinux) {
  3182. on(this.element, 'auxclick', function (event) {
  3183. if (event.button === 1) {
  3184. Clipboard_1.moveTextAreaUnderMouseCursor(event, _this.textarea);
  3185. }
  3186. });
  3187. }
  3188. };
  3189. Terminal.prototype.bindKeys = function () {
  3190. var _this = this;
  3191. var self = this;
  3192. on(this.element, 'keydown', function (ev) {
  3193. if (document.activeElement !== this) {
  3194. return;
  3195. }
  3196. self._keyDown(ev);
  3197. }, true);
  3198. on(this.element, 'keypress', function (ev) {
  3199. if (document.activeElement !== this) {
  3200. return;
  3201. }
  3202. self._keyPress(ev);
  3203. }, true);
  3204. on(this.element, 'keyup', function (ev) {
  3205. if (!wasMondifierKeyOnlyEvent(ev)) {
  3206. _this.focus();
  3207. }
  3208. }, true);
  3209. on(this.textarea, 'keydown', function (ev) {
  3210. _this._keyDown(ev);
  3211. }, true);
  3212. on(this.textarea, 'keypress', function (ev) {
  3213. _this._keyPress(ev);
  3214. _this.textarea.value = '';
  3215. }, true);
  3216. on(this.textarea, 'compositionstart', function () { return _this.compositionHelper.compositionstart(); });
  3217. on(this.textarea, 'compositionupdate', function (e) { return _this.compositionHelper.compositionupdate(e); });
  3218. on(this.textarea, 'compositionend', function () { return _this.compositionHelper.compositionend(); });
  3219. this.on('refresh', function () { return _this.compositionHelper.updateCompositionElements(); });
  3220. this.on('refresh', function (data) { return _this.queueLinkification(data.start, data.end); });
  3221. };
  3222. Terminal.prototype.open = function (parent) {
  3223. var _this = this;
  3224. var i = 0;
  3225. var div;
  3226. this.parent = parent || this.parent;
  3227. if (!this.parent) {
  3228. throw new Error('Terminal requires a parent element.');
  3229. }
  3230. this.context = this.parent.ownerDocument.defaultView;
  3231. this.document = this.parent.ownerDocument;
  3232. this.body = this.document.body;
  3233. this.element = this.document.createElement('div');
  3234. this.element.classList.add('terminal');
  3235. this.element.classList.add('xterm');
  3236. this.element.setAttribute('tabindex', '0');
  3237. this.parent.appendChild(this.element);
  3238. var fragment = document.createDocumentFragment();
  3239. this.viewportElement = document.createElement('div');
  3240. this.viewportElement.classList.add('xterm-viewport');
  3241. fragment.appendChild(this.viewportElement);
  3242. this.viewportScrollArea = document.createElement('div');
  3243. this.viewportScrollArea.classList.add('xterm-scroll-area');
  3244. this.viewportElement.appendChild(this.viewportScrollArea);
  3245. this.screenElement = document.createElement('div');
  3246. this.screenElement.classList.add('xterm-screen');
  3247. this.helperContainer = document.createElement('div');
  3248. this.helperContainer.classList.add('xterm-helpers');
  3249. this.screenElement.appendChild(this.helperContainer);
  3250. fragment.appendChild(this.screenElement);
  3251. this._mouseZoneManager = new MouseZoneManager_1.MouseZoneManager(this);
  3252. this.on('scroll', function () { return _this._mouseZoneManager.clearAll(); });
  3253. this.linkifier.attachToDom(this._mouseZoneManager);
  3254. this.textarea = document.createElement('textarea');
  3255. this.textarea.classList.add('xterm-helper-textarea');
  3256. this.textarea.setAttribute('autocorrect', 'off');
  3257. this.textarea.setAttribute('autocapitalize', 'off');
  3258. this.textarea.setAttribute('spellcheck', 'false');
  3259. this.textarea.tabIndex = 0;
  3260. this.textarea.addEventListener('focus', function () { return _this._onTextAreaFocus(); });
  3261. this.textarea.addEventListener('blur', function () { return _this._onTextAreaBlur(); });
  3262. this.helperContainer.appendChild(this.textarea);
  3263. this.compositionView = document.createElement('div');
  3264. this.compositionView.classList.add('composition-view');
  3265. this.compositionHelper = new CompositionHelper_1.CompositionHelper(this.textarea, this.compositionView, this);
  3266. this.helperContainer.appendChild(this.compositionView);
  3267. this.charSizeStyleElement = document.createElement('style');
  3268. this.helperContainer.appendChild(this.charSizeStyleElement);
  3269. this.charMeasure = new CharMeasure_1.CharMeasure(document, this.helperContainer);
  3270. this.syncBellSound();
  3271. this.element.appendChild(fragment);
  3272. this.renderer = new Renderer_1.Renderer(this, this.options.theme);
  3273. this.options.theme = null;
  3274. this.viewport = new Viewport_1.Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
  3275. this.viewport.onThemeChanged(this.renderer.colorManager.colors);
  3276. this.on('cursormove', function () { return _this.renderer.onCursorMove(); });
  3277. this.on('resize', function () { return _this.renderer.onResize(_this.cols, _this.rows, false); });
  3278. this.on('blur', function () { return _this.renderer.onBlur(); });
  3279. this.on('focus', function () { return _this.renderer.onFocus(); });
  3280. this.charMeasure.on('charsizechanged', function () { return _this.renderer.onResize(_this.cols, _this.rows, true); });
  3281. this.renderer.on('resize', function (dimensions) { return _this.viewport.syncScrollArea(); });
  3282. this.selectionManager = new SelectionManager_1.SelectionManager(this, this.charMeasure);
  3283. this.element.addEventListener('mousedown', function (e) { return _this.selectionManager.onMouseDown(e); });
  3284. this.selectionManager.on('refresh', function (data) { return _this.renderer.onSelectionChanged(data.start, data.end); });
  3285. this.selectionManager.on('newselection', function (text) {
  3286. _this.textarea.value = text;
  3287. _this.textarea.focus();
  3288. _this.textarea.select();
  3289. });
  3290. this.on('scroll', function () {
  3291. _this.viewport.syncScrollArea();
  3292. _this.selectionManager.refresh();
  3293. });
  3294. this.viewportElement.addEventListener('scroll', function () { return _this.selectionManager.refresh(); });
  3295. this.mouseHelper = new MouseHelper_1.MouseHelper(this.renderer);
  3296. this.charMeasure.measure(this.options);
  3297. this.refresh(0, this.rows - 1);
  3298. this.initGlobal();
  3299. this.bindMouse();
  3300. };
  3301. Terminal.prototype._setTheme = function (theme) {
  3302. var colors = this.renderer.setTheme(theme);
  3303. if (this.viewport) {
  3304. this.viewport.onThemeChanged(colors);
  3305. }
  3306. };
  3307. Terminal.applyAddon = function (addon) {
  3308. addon.apply(Terminal);
  3309. };
  3310. Terminal.prototype.bindMouse = function () {
  3311. var _this = this;
  3312. var el = this.element;
  3313. var self = this;
  3314. var pressed = 32;
  3315. function sendButton(ev) {
  3316. var button;
  3317. var pos;
  3318. button = getButton(ev);
  3319. pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.options.lineHeight, self.cols, self.rows);
  3320. if (!pos)
  3321. return;
  3322. sendEvent(button, pos);
  3323. switch (ev.overrideType || ev.type) {
  3324. case 'mousedown':
  3325. pressed = button;
  3326. break;
  3327. case 'mouseup':
  3328. pressed = 32;
  3329. break;
  3330. case 'wheel':
  3331. break;
  3332. }
  3333. }
  3334. function sendMove(ev) {
  3335. var button = pressed;
  3336. var pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.options.lineHeight, self.cols, self.rows);
  3337. if (!pos)
  3338. return;
  3339. button += 32;
  3340. sendEvent(button, pos);
  3341. }
  3342. function encode(data, ch) {
  3343. if (!self.utfMouse) {
  3344. if (ch === 255) {
  3345. data.push(0);
  3346. return;
  3347. }
  3348. if (ch > 127)
  3349. ch = 127;
  3350. data.push(ch);
  3351. }
  3352. else {
  3353. if (ch === 2047) {
  3354. data.push(0);
  3355. return;
  3356. }
  3357. if (ch < 127) {
  3358. data.push(ch);
  3359. }
  3360. else {
  3361. if (ch > 2047)
  3362. ch = 2047;
  3363. data.push(0xC0 | (ch >> 6));
  3364. data.push(0x80 | (ch & 0x3F));
  3365. }
  3366. }
  3367. }
  3368. function sendEvent(button, pos) {
  3369. if (self.vt300Mouse) {
  3370. button &= 3;
  3371. pos.x -= 32;
  3372. pos.y -= 32;
  3373. var data_1 = EscapeSequences_1.C0.ESC + '[24';
  3374. if (button === 0)
  3375. data_1 += '1';
  3376. else if (button === 1)
  3377. data_1 += '3';
  3378. else if (button === 2)
  3379. data_1 += '5';
  3380. else if (button === 3)
  3381. return;
  3382. else
  3383. data_1 += '0';
  3384. data_1 += '~[' + pos.x + ',' + pos.y + ']\r';
  3385. self.send(data_1);
  3386. return;
  3387. }
  3388. if (self.decLocator) {
  3389. button &= 3;
  3390. pos.x -= 32;
  3391. pos.y -= 32;
  3392. if (button === 0)
  3393. button = 2;
  3394. else if (button === 1)
  3395. button = 4;
  3396. else if (button === 2)
  3397. button = 6;
  3398. else if (button === 3)
  3399. button = 3;
  3400. self.send(EscapeSequences_1.C0.ESC + '['
  3401. + button
  3402. + ';'
  3403. + (button === 3 ? 4 : 0)
  3404. + ';'
  3405. + pos.y
  3406. + ';'
  3407. + pos.x
  3408. + ';'
  3409. + pos.page || 0
  3410. + '&w');
  3411. return;
  3412. }
  3413. if (self.urxvtMouse) {
  3414. pos.x -= 32;
  3415. pos.y -= 32;
  3416. pos.x++;
  3417. pos.y++;
  3418. self.send(EscapeSequences_1.C0.ESC + '[' + button + ';' + pos.x + ';' + pos.y + 'M');
  3419. return;
  3420. }
  3421. if (self.sgrMouse) {
  3422. pos.x -= 32;
  3423. pos.y -= 32;
  3424. self.send(EscapeSequences_1.C0.ESC + '[<'
  3425. + (((button & 3) === 3 ? button & ~3 : button) - 32)
  3426. + ';'
  3427. + pos.x
  3428. + ';'
  3429. + pos.y
  3430. + ((button & 3) === 3 ? 'm' : 'M'));
  3431. return;
  3432. }
  3433. var data = [];
  3434. encode(data, button);
  3435. encode(data, pos.x);
  3436. encode(data, pos.y);
  3437. self.send(EscapeSequences_1.C0.ESC + '[M' + String.fromCharCode.apply(String, data));
  3438. }
  3439. function getButton(ev) {
  3440. var button;
  3441. var shift;
  3442. var meta;
  3443. var ctrl;
  3444. var mod;
  3445. switch (ev.overrideType || ev.type) {
  3446. case 'mousedown':
  3447. button = ev.button != null
  3448. ? +ev.button
  3449. : ev.which != null
  3450. ? ev.which - 1
  3451. : null;
  3452. if (Browser.isMSIE) {
  3453. button = button === 1 ? 0 : button === 4 ? 1 : button;
  3454. }
  3455. break;
  3456. case 'mouseup':
  3457. button = 3;
  3458. break;
  3459. case 'DOMMouseScroll':
  3460. button = ev.detail < 0
  3461. ? 64
  3462. : 65;
  3463. break;
  3464. case 'wheel':
  3465. button = ev.wheelDeltaY > 0
  3466. ? 64
  3467. : 65;
  3468. break;
  3469. }
  3470. shift = ev.shiftKey ? 4 : 0;
  3471. meta = ev.metaKey ? 8 : 0;
  3472. ctrl = ev.ctrlKey ? 16 : 0;
  3473. mod = shift | meta | ctrl;
  3474. if (self.vt200Mouse) {
  3475. mod &= ctrl;
  3476. }
  3477. else if (!self.normalMouse) {
  3478. mod = 0;
  3479. }
  3480. button = (32 + (mod << 2)) + button;
  3481. return button;
  3482. }
  3483. on(el, 'mousedown', function (ev) {
  3484. ev.preventDefault();
  3485. _this.focus();
  3486. if (!_this.mouseEvents || _this.selectionManager.shouldForceSelection(ev)) {
  3487. return;
  3488. }
  3489. sendButton(ev);
  3490. if (_this.vt200Mouse) {
  3491. ev.overrideType = 'mouseup';
  3492. sendButton(ev);
  3493. return _this.cancel(ev);
  3494. }
  3495. if (_this.normalMouse)
  3496. on(_this.document, 'mousemove', sendMove);
  3497. if (!_this.x10Mouse) {
  3498. var handler_1 = function (ev) {
  3499. sendButton(ev);
  3500. if (_this.normalMouse)
  3501. off(_this.document, 'mousemove', sendMove);
  3502. off(_this.document, 'mouseup', handler_1);
  3503. return _this.cancel(ev);
  3504. };
  3505. on(_this.document, 'mouseup', handler_1);
  3506. }
  3507. return _this.cancel(ev);
  3508. });
  3509. on(el, 'wheel', function (ev) {
  3510. if (!_this.mouseEvents)
  3511. return;
  3512. if (_this.x10Mouse || _this.vt300Mouse || _this.decLocator)
  3513. return;
  3514. sendButton(ev);
  3515. ev.preventDefault();
  3516. });
  3517. on(el, 'wheel', function (ev) {
  3518. if (_this.mouseEvents)
  3519. return;
  3520. _this.viewport.onWheel(ev);
  3521. return _this.cancel(ev);
  3522. });
  3523. on(el, 'touchstart', function (ev) {
  3524. if (_this.mouseEvents)
  3525. return;
  3526. _this.viewport.onTouchStart(ev);
  3527. return _this.cancel(ev);
  3528. });
  3529. on(el, 'touchmove', function (ev) {
  3530. if (_this.mouseEvents)
  3531. return;
  3532. _this.viewport.onTouchMove(ev);
  3533. return _this.cancel(ev);
  3534. });
  3535. };
  3536. Terminal.prototype.destroy = function () {
  3537. _super.prototype.destroy.call(this);
  3538. this.readable = false;
  3539. this.writable = false;
  3540. this.handler = function () { };
  3541. this.write = function () { };
  3542. if (this.element && this.element.parentNode) {
  3543. this.element.parentNode.removeChild(this.element);
  3544. }
  3545. };
  3546. Terminal.prototype.refresh = function (start, end) {
  3547. if (this.renderer) {
  3548. this.renderer.queueRefresh(start, end);
  3549. }
  3550. };
  3551. Terminal.prototype.queueLinkification = function (start, end) {
  3552. if (this.linkifier) {
  3553. this.linkifier.linkifyRows(start, end);
  3554. }
  3555. };
  3556. Terminal.prototype.showCursor = function () {
  3557. if (!this.cursorState) {
  3558. this.cursorState = 1;
  3559. this.refresh(this.buffer.y, this.buffer.y);
  3560. }
  3561. };
  3562. Terminal.prototype.scroll = function (isWrapped) {
  3563. var newLine = this.blankLine(undefined, isWrapped);
  3564. var topRow = this.buffer.ybase + this.buffer.scrollTop;
  3565. var bottomRow = this.buffer.ybase + this.buffer.scrollBottom;
  3566. if (this.buffer.scrollTop === 0) {
  3567. var willBufferBeTrimmed = this.buffer.lines.length === this.buffer.lines.maxLength;
  3568. if (bottomRow === this.buffer.lines.length - 1) {
  3569. this.buffer.lines.push(newLine);
  3570. }
  3571. else {
  3572. this.buffer.lines.splice(bottomRow + 1, 0, newLine);
  3573. }
  3574. if (!willBufferBeTrimmed) {
  3575. this.buffer.ybase++;
  3576. if (!this.userScrolling) {
  3577. this.buffer.ydisp++;
  3578. }
  3579. }
  3580. else {
  3581. if (this.userScrolling) {
  3582. this.buffer.ydisp = Math.max(this.buffer.ydisp - 1, 0);
  3583. }
  3584. }
  3585. }
  3586. else {
  3587. var scrollRegionHeight = bottomRow - topRow + 1;
  3588. this.buffer.lines.shiftElements(topRow + 1, scrollRegionHeight - 1, -1);
  3589. this.buffer.lines.set(bottomRow, newLine);
  3590. }
  3591. if (!this.userScrolling) {
  3592. this.buffer.ydisp = this.buffer.ybase;
  3593. }
  3594. this.updateRange(this.buffer.scrollTop);
  3595. this.updateRange(this.buffer.scrollBottom);
  3596. this.emit('scroll', this.buffer.ydisp);
  3597. };
  3598. Terminal.prototype.scrollLines = function (disp, suppressScrollEvent) {
  3599. if (disp < 0) {
  3600. if (this.buffer.ydisp === 0) {
  3601. return;
  3602. }
  3603. this.userScrolling = true;
  3604. }
  3605. else if (disp + this.buffer.ydisp >= this.buffer.ybase) {
  3606. this.userScrolling = false;
  3607. }
  3608. var oldYdisp = this.buffer.ydisp;
  3609. this.buffer.ydisp = Math.max(Math.min(this.buffer.ydisp + disp, this.buffer.ybase), 0);
  3610. if (oldYdisp === this.buffer.ydisp) {
  3611. return;
  3612. }
  3613. if (!suppressScrollEvent) {
  3614. this.emit('scroll', this.buffer.ydisp);
  3615. }
  3616. this.refresh(0, this.rows - 1);
  3617. };
  3618. Terminal.prototype.scrollPages = function (pageCount) {
  3619. this.scrollLines(pageCount * (this.rows - 1));
  3620. };
  3621. Terminal.prototype.scrollToTop = function () {
  3622. this.scrollLines(-this.buffer.ydisp);
  3623. };
  3624. Terminal.prototype.scrollToBottom = function () {
  3625. this.scrollLines(this.buffer.ybase - this.buffer.ydisp);
  3626. };
  3627. Terminal.prototype.write = function (data) {
  3628. var _this = this;
  3629. this.writeBuffer.push(data);
  3630. if (this.options.useFlowControl && !this.xoffSentToCatchUp && this.writeBuffer.length >= WRITE_BUFFER_PAUSE_THRESHOLD) {
  3631. this.send(EscapeSequences_1.C0.DC3);
  3632. this.xoffSentToCatchUp = true;
  3633. }
  3634. if (!this.writeInProgress && this.writeBuffer.length > 0) {
  3635. this.writeInProgress = true;
  3636. setTimeout(function () {
  3637. _this.innerWrite();
  3638. });
  3639. }
  3640. };
  3641. Terminal.prototype.innerWrite = function () {
  3642. var _this = this;
  3643. var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
  3644. while (writeBatch.length > 0) {
  3645. var data = writeBatch.shift();
  3646. if (this.xoffSentToCatchUp && writeBatch.length === 0 && this.writeBuffer.length === 0) {
  3647. this.send(EscapeSequences_1.C0.DC1);
  3648. this.xoffSentToCatchUp = false;
  3649. }
  3650. this.refreshStart = this.buffer.y;
  3651. this.refreshEnd = this.buffer.y;
  3652. var state = this.parser.parse(data);
  3653. this.parser.setState(state);
  3654. this.updateRange(this.buffer.y);
  3655. this.refresh(this.refreshStart, this.refreshEnd);
  3656. }
  3657. if (this.writeBuffer.length > 0) {
  3658. setTimeout(function () { return _this.innerWrite(); }, 0);
  3659. }
  3660. else {
  3661. this.writeInProgress = false;
  3662. }
  3663. };
  3664. Terminal.prototype.writeln = function (data) {
  3665. this.write(data + '\r\n');
  3666. };
  3667. Terminal.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler) {
  3668. this.customKeyEventHandler = customKeyEventHandler;
  3669. };
  3670. Terminal.prototype.setHypertextLinkHandler = function (handler) {
  3671. if (!this.linkifier) {
  3672. throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
  3673. }
  3674. this.linkifier.setHypertextLinkHandler(handler);
  3675. this.refresh(0, this.rows - 1);
  3676. };
  3677. Terminal.prototype.setHypertextValidationCallback = function (callback) {
  3678. if (!this.linkifier) {
  3679. throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
  3680. }
  3681. this.linkifier.setHypertextValidationCallback(callback);
  3682. this.refresh(0, this.rows - 1);
  3683. };
  3684. Terminal.prototype.registerLinkMatcher = function (regex, handler, options) {
  3685. if (this.linkifier) {
  3686. var matcherId = this.linkifier.registerLinkMatcher(regex, handler, options);
  3687. this.refresh(0, this.rows - 1);
  3688. return matcherId;
  3689. }
  3690. return 0;
  3691. };
  3692. Terminal.prototype.deregisterLinkMatcher = function (matcherId) {
  3693. if (this.linkifier) {
  3694. if (this.linkifier.deregisterLinkMatcher(matcherId)) {
  3695. this.refresh(0, this.rows - 1);
  3696. }
  3697. }
  3698. };
  3699. Terminal.prototype.hasSelection = function () {
  3700. return this.selectionManager ? this.selectionManager.hasSelection : false;
  3701. };
  3702. Terminal.prototype.getSelection = function () {
  3703. return this.selectionManager ? this.selectionManager.selectionText : '';
  3704. };
  3705. Terminal.prototype.clearSelection = function () {
  3706. if (this.selectionManager) {
  3707. this.selectionManager.clearSelection();
  3708. }
  3709. };
  3710. Terminal.prototype.selectAll = function () {
  3711. if (this.selectionManager) {
  3712. this.selectionManager.selectAll();
  3713. }
  3714. };
  3715. Terminal.prototype._keyDown = function (ev) {
  3716. if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
  3717. return false;
  3718. }
  3719. if (!this.compositionHelper.keydown(ev)) {
  3720. if (this.buffer.ybase !== this.buffer.ydisp) {
  3721. this.scrollToBottom();
  3722. }
  3723. return false;
  3724. }
  3725. var result = this._evaluateKeyEscapeSequence(ev);
  3726. if (result.key === EscapeSequences_1.C0.DC3) {
  3727. this.writeStopped = true;
  3728. }
  3729. else if (result.key === EscapeSequences_1.C0.DC1) {
  3730. this.writeStopped = false;
  3731. }
  3732. if (result.scrollLines) {
  3733. this.scrollLines(result.scrollLines);
  3734. return this.cancel(ev, true);
  3735. }
  3736. if (this._isThirdLevelShift(this.browser, ev)) {
  3737. return true;
  3738. }
  3739. if (result.cancel) {
  3740. this.cancel(ev, true);
  3741. }
  3742. if (!result.key) {
  3743. return true;
  3744. }
  3745. this.emit('keydown', ev);
  3746. this.emit('key', result.key, ev);
  3747. this.showCursor();
  3748. this.handler(result.key);
  3749. return this.cancel(ev, true);
  3750. };
  3751. Terminal.prototype._isThirdLevelShift = function (browser, ev) {
  3752. var thirdLevelKey = (browser.isMac && !this.options.macOptionIsMeta && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
  3753. (browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
  3754. if (ev.type === 'keypress') {
  3755. return thirdLevelKey;
  3756. }
  3757. return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47);
  3758. };
  3759. Terminal.prototype._evaluateKeyEscapeSequence = function (ev) {
  3760. var result = {
  3761. cancel: false,
  3762. key: undefined,
  3763. scrollLines: undefined
  3764. };
  3765. var modifiers = (ev.shiftKey ? 1 : 0) | (ev.altKey ? 2 : 0) | (ev.ctrlKey ? 4 : 0) | (ev.metaKey ? 8 : 0);
  3766. switch (ev.keyCode) {
  3767. case 0:
  3768. if (ev.key === 'UIKeyInputUpArrow') {
  3769. if (this.applicationCursor) {
  3770. result.key = EscapeSequences_1.C0.ESC + 'OA';
  3771. }
  3772. else {
  3773. result.key = EscapeSequences_1.C0.ESC + '[A';
  3774. }
  3775. }
  3776. else if (ev.key === 'UIKeyInputLeftArrow') {
  3777. if (this.applicationCursor) {
  3778. result.key = EscapeSequences_1.C0.ESC + 'OD';
  3779. }
  3780. else {
  3781. result.key = EscapeSequences_1.C0.ESC + '[D';
  3782. }
  3783. }
  3784. else if (ev.key === 'UIKeyInputRightArrow') {
  3785. if (this.applicationCursor) {
  3786. result.key = EscapeSequences_1.C0.ESC + 'OC';
  3787. }
  3788. else {
  3789. result.key = EscapeSequences_1.C0.ESC + '[C';
  3790. }
  3791. }
  3792. else if (ev.key === 'UIKeyInputDownArrow') {
  3793. if (this.applicationCursor) {
  3794. result.key = EscapeSequences_1.C0.ESC + 'OB';
  3795. }
  3796. else {
  3797. result.key = EscapeSequences_1.C0.ESC + '[B';
  3798. }
  3799. }
  3800. break;
  3801. case 8:
  3802. if (ev.shiftKey) {
  3803. result.key = EscapeSequences_1.C0.BS;
  3804. break;
  3805. }
  3806. else if (ev.altKey) {
  3807. result.key = EscapeSequences_1.C0.ESC + EscapeSequences_1.C0.DEL;
  3808. break;
  3809. }
  3810. result.key = EscapeSequences_1.C0.DEL;
  3811. break;
  3812. case 9:
  3813. if (ev.shiftKey) {
  3814. result.key = EscapeSequences_1.C0.ESC + '[Z';
  3815. break;
  3816. }
  3817. result.key = EscapeSequences_1.C0.HT;
  3818. result.cancel = true;
  3819. break;
  3820. case 13:
  3821. result.key = EscapeSequences_1.C0.CR;
  3822. result.cancel = true;
  3823. break;
  3824. case 27:
  3825. result.key = EscapeSequences_1.C0.ESC;
  3826. result.cancel = true;
  3827. break;
  3828. case 37:
  3829. if (modifiers) {
  3830. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'D';
  3831. if (result.key === EscapeSequences_1.C0.ESC + '[1;3D') {
  3832. result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'b' : EscapeSequences_1.C0.ESC + '[1;5D';
  3833. }
  3834. }
  3835. else if (this.applicationCursor) {
  3836. result.key = EscapeSequences_1.C0.ESC + 'OD';
  3837. }
  3838. else {
  3839. result.key = EscapeSequences_1.C0.ESC + '[D';
  3840. }
  3841. break;
  3842. case 39:
  3843. if (modifiers) {
  3844. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'C';
  3845. if (result.key === EscapeSequences_1.C0.ESC + '[1;3C') {
  3846. result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'f' : EscapeSequences_1.C0.ESC + '[1;5C';
  3847. }
  3848. }
  3849. else if (this.applicationCursor) {
  3850. result.key = EscapeSequences_1.C0.ESC + 'OC';
  3851. }
  3852. else {
  3853. result.key = EscapeSequences_1.C0.ESC + '[C';
  3854. }
  3855. break;
  3856. case 38:
  3857. if (modifiers) {
  3858. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'A';
  3859. if (result.key === EscapeSequences_1.C0.ESC + '[1;3A') {
  3860. result.key = EscapeSequences_1.C0.ESC + '[1;5A';
  3861. }
  3862. }
  3863. else if (this.applicationCursor) {
  3864. result.key = EscapeSequences_1.C0.ESC + 'OA';
  3865. }
  3866. else {
  3867. result.key = EscapeSequences_1.C0.ESC + '[A';
  3868. }
  3869. break;
  3870. case 40:
  3871. if (modifiers) {
  3872. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'B';
  3873. if (result.key === EscapeSequences_1.C0.ESC + '[1;3B') {
  3874. result.key = EscapeSequences_1.C0.ESC + '[1;5B';
  3875. }
  3876. }
  3877. else if (this.applicationCursor) {
  3878. result.key = EscapeSequences_1.C0.ESC + 'OB';
  3879. }
  3880. else {
  3881. result.key = EscapeSequences_1.C0.ESC + '[B';
  3882. }
  3883. break;
  3884. case 45:
  3885. if (!ev.shiftKey && !ev.ctrlKey) {
  3886. result.key = EscapeSequences_1.C0.ESC + '[2~';
  3887. }
  3888. break;
  3889. case 46:
  3890. if (modifiers) {
  3891. result.key = EscapeSequences_1.C0.ESC + '[3;' + (modifiers + 1) + '~';
  3892. }
  3893. else {
  3894. result.key = EscapeSequences_1.C0.ESC + '[3~';
  3895. }
  3896. break;
  3897. case 36:
  3898. if (modifiers) {
  3899. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'H';
  3900. }
  3901. else if (this.applicationCursor) {
  3902. result.key = EscapeSequences_1.C0.ESC + 'OH';
  3903. }
  3904. else {
  3905. result.key = EscapeSequences_1.C0.ESC + '[H';
  3906. }
  3907. break;
  3908. case 35:
  3909. if (modifiers) {
  3910. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'F';
  3911. }
  3912. else if (this.applicationCursor) {
  3913. result.key = EscapeSequences_1.C0.ESC + 'OF';
  3914. }
  3915. else {
  3916. result.key = EscapeSequences_1.C0.ESC + '[F';
  3917. }
  3918. break;
  3919. case 33:
  3920. if (ev.shiftKey) {
  3921. result.scrollLines = -(this.rows - 1);
  3922. }
  3923. else {
  3924. result.key = EscapeSequences_1.C0.ESC + '[5~';
  3925. }
  3926. break;
  3927. case 34:
  3928. if (ev.shiftKey) {
  3929. result.scrollLines = this.rows - 1;
  3930. }
  3931. else {
  3932. result.key = EscapeSequences_1.C0.ESC + '[6~';
  3933. }
  3934. break;
  3935. case 112:
  3936. if (modifiers) {
  3937. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'P';
  3938. }
  3939. else {
  3940. result.key = EscapeSequences_1.C0.ESC + 'OP';
  3941. }
  3942. break;
  3943. case 113:
  3944. if (modifiers) {
  3945. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'Q';
  3946. }
  3947. else {
  3948. result.key = EscapeSequences_1.C0.ESC + 'OQ';
  3949. }
  3950. break;
  3951. case 114:
  3952. if (modifiers) {
  3953. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'R';
  3954. }
  3955. else {
  3956. result.key = EscapeSequences_1.C0.ESC + 'OR';
  3957. }
  3958. break;
  3959. case 115:
  3960. if (modifiers) {
  3961. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'S';
  3962. }
  3963. else {
  3964. result.key = EscapeSequences_1.C0.ESC + 'OS';
  3965. }
  3966. break;
  3967. case 116:
  3968. if (modifiers) {
  3969. result.key = EscapeSequences_1.C0.ESC + '[15;' + (modifiers + 1) + '~';
  3970. }
  3971. else {
  3972. result.key = EscapeSequences_1.C0.ESC + '[15~';
  3973. }
  3974. break;
  3975. case 117:
  3976. if (modifiers) {
  3977. result.key = EscapeSequences_1.C0.ESC + '[17;' + (modifiers + 1) + '~';
  3978. }
  3979. else {
  3980. result.key = EscapeSequences_1.C0.ESC + '[17~';
  3981. }
  3982. break;
  3983. case 118:
  3984. if (modifiers) {
  3985. result.key = EscapeSequences_1.C0.ESC + '[18;' + (modifiers + 1) + '~';
  3986. }
  3987. else {
  3988. result.key = EscapeSequences_1.C0.ESC + '[18~';
  3989. }
  3990. break;
  3991. case 119:
  3992. if (modifiers) {
  3993. result.key = EscapeSequences_1.C0.ESC + '[19;' + (modifiers + 1) + '~';
  3994. }
  3995. else {
  3996. result.key = EscapeSequences_1.C0.ESC + '[19~';
  3997. }
  3998. break;
  3999. case 120:
  4000. if (modifiers) {
  4001. result.key = EscapeSequences_1.C0.ESC + '[20;' + (modifiers + 1) + '~';
  4002. }
  4003. else {
  4004. result.key = EscapeSequences_1.C0.ESC + '[20~';
  4005. }
  4006. break;
  4007. case 121:
  4008. if (modifiers) {
  4009. result.key = EscapeSequences_1.C0.ESC + '[21;' + (modifiers + 1) + '~';
  4010. }
  4011. else {
  4012. result.key = EscapeSequences_1.C0.ESC + '[21~';
  4013. }
  4014. break;
  4015. case 122:
  4016. if (modifiers) {
  4017. result.key = EscapeSequences_1.C0.ESC + '[23;' + (modifiers + 1) + '~';
  4018. }
  4019. else {
  4020. result.key = EscapeSequences_1.C0.ESC + '[23~';
  4021. }
  4022. break;
  4023. case 123:
  4024. if (modifiers) {
  4025. result.key = EscapeSequences_1.C0.ESC + '[24;' + (modifiers + 1) + '~';
  4026. }
  4027. else {
  4028. result.key = EscapeSequences_1.C0.ESC + '[24~';
  4029. }
  4030. break;
  4031. default:
  4032. if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
  4033. if (ev.keyCode >= 65 && ev.keyCode <= 90) {
  4034. result.key = String.fromCharCode(ev.keyCode - 64);
  4035. }
  4036. else if (ev.keyCode === 32) {
  4037. result.key = String.fromCharCode(0);
  4038. }
  4039. else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
  4040. result.key = String.fromCharCode(ev.keyCode - 51 + 27);
  4041. }
  4042. else if (ev.keyCode === 56) {
  4043. result.key = String.fromCharCode(127);
  4044. }
  4045. else if (ev.keyCode === 219) {
  4046. result.key = String.fromCharCode(27);
  4047. }
  4048. else if (ev.keyCode === 220) {
  4049. result.key = String.fromCharCode(28);
  4050. }
  4051. else if (ev.keyCode === 221) {
  4052. result.key = String.fromCharCode(29);
  4053. }
  4054. }
  4055. else if ((!this.browser.isMac || this.options.macOptionIsMeta) && ev.altKey && !ev.ctrlKey && !ev.metaKey) {
  4056. if (ev.keyCode >= 65 && ev.keyCode <= 90) {
  4057. result.key = EscapeSequences_1.C0.ESC + String.fromCharCode(ev.keyCode + 32);
  4058. }
  4059. else if (ev.keyCode === 192) {
  4060. result.key = EscapeSequences_1.C0.ESC + '`';
  4061. }
  4062. else if (ev.keyCode >= 48 && ev.keyCode <= 57) {
  4063. result.key = EscapeSequences_1.C0.ESC + (ev.keyCode - 48);
  4064. }
  4065. }
  4066. else if (this.browser.isMac && !ev.altKey && !ev.ctrlKey && ev.metaKey) {
  4067. if (ev.keyCode === 65) {
  4068. this.selectAll();
  4069. }
  4070. }
  4071. break;
  4072. }
  4073. return result;
  4074. };
  4075. Terminal.prototype.setgLevel = function (g) {
  4076. this.glevel = g;
  4077. this.charset = this.charsets[g];
  4078. };
  4079. Terminal.prototype.setgCharset = function (g, charset) {
  4080. this.charsets[g] = charset;
  4081. if (this.glevel === g) {
  4082. this.charset = charset;
  4083. }
  4084. };
  4085. Terminal.prototype._keyPress = function (ev) {
  4086. var key;
  4087. if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
  4088. return false;
  4089. }
  4090. this.cancel(ev);
  4091. if (ev.charCode) {
  4092. key = ev.charCode;
  4093. }
  4094. else if (ev.which == null) {
  4095. key = ev.keyCode;
  4096. }
  4097. else if (ev.which !== 0 && ev.charCode !== 0) {
  4098. key = ev.which;
  4099. }
  4100. else {
  4101. return false;
  4102. }
  4103. if (!key || ((ev.altKey || ev.ctrlKey || ev.metaKey) && !this._isThirdLevelShift(this.browser, ev))) {
  4104. return false;
  4105. }
  4106. key = String.fromCharCode(key);
  4107. this.emit('keypress', key, ev);
  4108. this.emit('key', key, ev);
  4109. this.showCursor();
  4110. this.handler(key);
  4111. return true;
  4112. };
  4113. Terminal.prototype.send = function (data) {
  4114. var _this = this;
  4115. if (!this.sendDataQueue) {
  4116. setTimeout(function () {
  4117. _this.handler(_this.sendDataQueue);
  4118. _this.sendDataQueue = '';
  4119. }, 1);
  4120. }
  4121. this.sendDataQueue += data;
  4122. };
  4123. Terminal.prototype.bell = function () {
  4124. var _this = this;
  4125. this.emit('bell');
  4126. if (this.soundBell())
  4127. this.bellAudioElement.play();
  4128. if (this.visualBell()) {
  4129. this.element.classList.add('visual-bell-active');
  4130. clearTimeout(this.visualBellTimer);
  4131. this.visualBellTimer = window.setTimeout(function () {
  4132. _this.element.classList.remove('visual-bell-active');
  4133. }, 200);
  4134. }
  4135. };
  4136. Terminal.prototype.log = function (text, data) {
  4137. if (!this.options.debug)
  4138. return;
  4139. if (!this.context.console || !this.context.console.log)
  4140. return;
  4141. this.context.console.log(text, data);
  4142. };
  4143. Terminal.prototype.error = function (text, data) {
  4144. if (!this.options.debug)
  4145. return;
  4146. if (!this.context.console || !this.context.console.error)
  4147. return;
  4148. this.context.console.error(text, data);
  4149. };
  4150. Terminal.prototype.resize = function (x, y) {
  4151. if (isNaN(x) || isNaN(y)) {
  4152. return;
  4153. }
  4154. if (x === this.cols && y === this.rows) {
  4155. if (!this.charMeasure.width || !this.charMeasure.height) {
  4156. this.charMeasure.measure(this.options);
  4157. }
  4158. return;
  4159. }
  4160. if (x < 1)
  4161. x = 1;
  4162. if (y < 1)
  4163. y = 1;
  4164. this.buffers.resize(x, y);
  4165. this.cols = x;
  4166. this.rows = y;
  4167. this.buffers.setupTabStops(this.cols);
  4168. this.charMeasure.measure(this.options);
  4169. this.refresh(0, this.rows - 1);
  4170. this.emit('resize', { cols: x, rows: y });
  4171. };
  4172. Terminal.prototype.updateRange = function (y) {
  4173. if (y < this.refreshStart)
  4174. this.refreshStart = y;
  4175. if (y > this.refreshEnd)
  4176. this.refreshEnd = y;
  4177. };
  4178. Terminal.prototype.maxRange = function () {
  4179. this.refreshStart = 0;
  4180. this.refreshEnd = this.rows - 1;
  4181. };
  4182. Terminal.prototype.eraseRight = function (x, y) {
  4183. var line = this.buffer.lines.get(this.buffer.ybase + y);
  4184. if (!line) {
  4185. return;
  4186. }
  4187. var ch = [this.eraseAttr(), ' ', 1, 32];
  4188. for (; x < this.cols; x++) {
  4189. line[x] = ch;
  4190. }
  4191. this.updateRange(y);
  4192. };
  4193. Terminal.prototype.eraseLeft = function (x, y) {
  4194. var line = this.buffer.lines.get(this.buffer.ybase + y);
  4195. if (!line) {
  4196. return;
  4197. }
  4198. var ch = [this.eraseAttr(), ' ', 1, 32];
  4199. x++;
  4200. while (x--) {
  4201. line[x] = ch;
  4202. }
  4203. this.updateRange(y);
  4204. };
  4205. Terminal.prototype.clear = function () {
  4206. if (this.buffer.ybase === 0 && this.buffer.y === 0) {
  4207. return;
  4208. }
  4209. this.buffer.lines.set(0, this.buffer.lines.get(this.buffer.ybase + this.buffer.y));
  4210. this.buffer.lines.length = 1;
  4211. this.buffer.ydisp = 0;
  4212. this.buffer.ybase = 0;
  4213. this.buffer.y = 0;
  4214. for (var i = 1; i < this.rows; i++) {
  4215. this.buffer.lines.push(this.blankLine());
  4216. }
  4217. this.refresh(0, this.rows - 1);
  4218. this.emit('scroll', this.buffer.ydisp);
  4219. };
  4220. Terminal.prototype.eraseLine = function (y) {
  4221. this.eraseRight(0, y);
  4222. };
  4223. Terminal.prototype.blankLine = function (cur, isWrapped, cols) {
  4224. var attr = cur ? this.eraseAttr() : this.defAttr;
  4225. var ch = [attr, ' ', 1, 32];
  4226. var line = [];
  4227. if (isWrapped) {
  4228. line.isWrapped = isWrapped;
  4229. }
  4230. cols = cols || this.cols;
  4231. for (var i = 0; i < cols; i++) {
  4232. line[i] = ch;
  4233. }
  4234. return line;
  4235. };
  4236. Terminal.prototype.ch = function (cur) {
  4237. if (cur) {
  4238. return [this.eraseAttr(), ' ', 1, 32];
  4239. }
  4240. return [this.defAttr, ' ', 1, 32];
  4241. };
  4242. Terminal.prototype.is = function (term) {
  4243. return (this.options.termName + '').indexOf(term) === 0;
  4244. };
  4245. Terminal.prototype.handler = function (data) {
  4246. if (this.options.disableStdin) {
  4247. return;
  4248. }
  4249. if (this.selectionManager && this.selectionManager.hasSelection) {
  4250. this.selectionManager.clearSelection();
  4251. }
  4252. if (this.buffer.ybase !== this.buffer.ydisp) {
  4253. this.scrollToBottom();
  4254. }
  4255. this.emit('data', data);
  4256. };
  4257. Terminal.prototype.handleTitle = function (title) {
  4258. this.emit('title', title);
  4259. };
  4260. Terminal.prototype.index = function () {
  4261. this.buffer.y++;
  4262. if (this.buffer.y > this.buffer.scrollBottom) {
  4263. this.buffer.y--;
  4264. this.scroll();
  4265. }
  4266. if (this.buffer.x >= this.cols) {
  4267. this.buffer.x--;
  4268. }
  4269. };
  4270. Terminal.prototype.reverseIndex = function () {
  4271. if (this.buffer.y === this.buffer.scrollTop) {
  4272. var scrollRegionHeight = this.buffer.scrollBottom - this.buffer.scrollTop;
  4273. this.buffer.lines.shiftElements(this.buffer.y + this.buffer.ybase, scrollRegionHeight, 1);
  4274. this.buffer.lines.set(this.buffer.y + this.buffer.ybase, this.blankLine(true));
  4275. this.updateRange(this.buffer.scrollTop);
  4276. this.updateRange(this.buffer.scrollBottom);
  4277. }
  4278. else {
  4279. this.buffer.y--;
  4280. }
  4281. };
  4282. Terminal.prototype.reset = function () {
  4283. this.options.rows = this.rows;
  4284. this.options.cols = this.cols;
  4285. var customKeyEventHandler = this.customKeyEventHandler;
  4286. var inputHandler = this.inputHandler;
  4287. this.setup();
  4288. this.customKeyEventHandler = customKeyEventHandler;
  4289. this.inputHandler = inputHandler;
  4290. this.refresh(0, this.rows - 1);
  4291. this.viewport.syncScrollArea();
  4292. };
  4293. Terminal.prototype.tabSet = function () {
  4294. this.buffer.tabs[this.buffer.x] = true;
  4295. };
  4296. Terminal.prototype.cancel = function (ev, force) {
  4297. if (!this.options.cancelEvents && !force) {
  4298. return;
  4299. }
  4300. ev.preventDefault();
  4301. ev.stopPropagation();
  4302. return false;
  4303. };
  4304. Terminal.prototype.matchColor = function (r1, g1, b1) {
  4305. return matchColor_(r1, g1, b1);
  4306. };
  4307. Terminal.prototype.visualBell = function () {
  4308. return false;
  4309. };
  4310. Terminal.prototype.soundBell = function () {
  4311. return this.options.bellStyle === 'sound';
  4312. };
  4313. Terminal.prototype.syncBellSound = function () {
  4314. if (!this.element) {
  4315. return;
  4316. }
  4317. if (this.soundBell() && this.bellAudioElement) {
  4318. this.bellAudioElement.setAttribute('src', this.options.bellSound);
  4319. }
  4320. else if (this.soundBell()) {
  4321. this.bellAudioElement = document.createElement('audio');
  4322. this.bellAudioElement.setAttribute('preload', 'auto');
  4323. this.bellAudioElement.setAttribute('src', this.options.bellSound);
  4324. this.helperContainer.appendChild(this.bellAudioElement);
  4325. }
  4326. else if (this.bellAudioElement) {
  4327. this.helperContainer.removeChild(this.bellAudioElement);
  4328. }
  4329. };
  4330. return Terminal;
  4331. }(EventEmitter_1.EventEmitter));
  4332. exports.Terminal = Terminal;
  4333. function globalOn(el, type, handler, capture) {
  4334. if (!Array.isArray(el)) {
  4335. el = [el];
  4336. }
  4337. el.forEach(function (element) {
  4338. element.addEventListener(type, handler, capture || false);
  4339. });
  4340. }
  4341. var on = globalOn;
  4342. function off(el, type, handler, capture) {
  4343. if (capture === void 0) { capture = false; }
  4344. el.removeEventListener(type, handler, capture);
  4345. }
  4346. function wasMondifierKeyOnlyEvent(ev) {
  4347. return ev.keyCode === 16 ||
  4348. ev.keyCode === 17 ||
  4349. ev.keyCode === 18;
  4350. }
  4351. var vcolors = (function () {
  4352. var result = ColorManager_1.DEFAULT_ANSI_COLORS.map(function (c) {
  4353. c = c.substring(1);
  4354. return [
  4355. parseInt(c.substring(0, 2), 16),
  4356. parseInt(c.substring(2, 4), 16),
  4357. parseInt(c.substring(4, 6), 16)
  4358. ];
  4359. });
  4360. var r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff];
  4361. for (var i = 0; i < 216; i++) {
  4362. result.push([
  4363. r[(i / 36) % 6 | 0],
  4364. r[(i / 6) % 6 | 0],
  4365. r[i % 6]
  4366. ]);
  4367. }
  4368. var c;
  4369. for (var i = 0; i < 24; i++) {
  4370. c = 8 + i * 10;
  4371. result.push([c, c, c]);
  4372. }
  4373. return result;
  4374. })();
  4375. var matchColorCache = {};
  4376. function matchColorDistance(r1, g1, b1, r2, g2, b2) {
  4377. return Math.pow(30 * (r1 - r2), 2)
  4378. + Math.pow(59 * (g1 - g2), 2)
  4379. + Math.pow(11 * (b1 - b2), 2);
  4380. }
  4381. function matchColor_(r1, g1, b1) {
  4382. var hash = (r1 << 16) | (g1 << 8) | b1;
  4383. if (matchColorCache[hash] != null) {
  4384. return matchColorCache[hash];
  4385. }
  4386. var ldiff = Infinity;
  4387. var li = -1;
  4388. var i = 0;
  4389. var c;
  4390. var r2;
  4391. var g2;
  4392. var b2;
  4393. var diff;
  4394. for (; i < vcolors.length; i++) {
  4395. c = vcolors[i];
  4396. r2 = c[0];
  4397. g2 = c[1];
  4398. b2 = c[2];
  4399. diff = matchColorDistance(r1, g1, b1, r2, g2, b2);
  4400. if (diff === 0) {
  4401. li = i;
  4402. break;
  4403. }
  4404. if (diff < ldiff) {
  4405. ldiff = diff;
  4406. li = i;
  4407. }
  4408. }
  4409. return matchColorCache[hash] = li;
  4410. }
  4411. },{"./Buffer":1,"./BufferSet":2,"./CompositionHelper":5,"./EscapeSequences":6,"./EventEmitter":7,"./InputHandler":8,"./Linkifier":9,"./Parser":10,"./SelectionManager":11,"./Viewport":15,"./handlers/Clipboard":17,"./input/MouseZoneManager":18,"./renderer/ColorManager":21,"./renderer/Renderer":25,"./shared/utils/Browser":30,"./utils/CharMeasure":31,"./utils/MouseHelper":33,"./utils/Sounds":35}],14:[function(require,module,exports){
  4412. "use strict";
  4413. Object.defineProperty(exports, "__esModule", { value: true });
  4414. var LinkHoverEventTypes;
  4415. (function (LinkHoverEventTypes) {
  4416. LinkHoverEventTypes["HOVER"] = "linkhover";
  4417. LinkHoverEventTypes["TOOLTIP"] = "linktooltip";
  4418. LinkHoverEventTypes["LEAVE"] = "linkleave";
  4419. })(LinkHoverEventTypes = exports.LinkHoverEventTypes || (exports.LinkHoverEventTypes = {}));
  4420. },{}],15:[function(require,module,exports){
  4421. "use strict";
  4422. Object.defineProperty(exports, "__esModule", { value: true });
  4423. var FALLBACK_SCROLL_BAR_WIDTH = 15;
  4424. var Viewport = (function () {
  4425. function Viewport(terminal, viewportElement, scrollArea, charMeasure) {
  4426. var _this = this;
  4427. this.terminal = terminal;
  4428. this.viewportElement = viewportElement;
  4429. this.scrollArea = scrollArea;
  4430. this.charMeasure = charMeasure;
  4431. this.scrollBarWidth = 0;
  4432. this.currentRowHeight = 0;
  4433. this.lastRecordedBufferLength = 0;
  4434. this.lastRecordedViewportHeight = 0;
  4435. this.lastRecordedBufferHeight = 0;
  4436. this.scrollBarWidth = (this.viewportElement.offsetWidth - this.scrollArea.offsetWidth) || FALLBACK_SCROLL_BAR_WIDTH;
  4437. this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
  4438. setTimeout(function () { return _this.syncScrollArea(); }, 0);
  4439. }
  4440. Viewport.prototype.onThemeChanged = function (colors) {
  4441. this.viewportElement.style.backgroundColor = colors.background;
  4442. };
  4443. Viewport.prototype.refresh = function () {
  4444. if (this.charMeasure.height > 0) {
  4445. this.currentRowHeight = this.terminal.renderer.dimensions.scaledCellHeight / window.devicePixelRatio;
  4446. this.lastRecordedViewportHeight = this.viewportElement.offsetHeight;
  4447. var newBufferHeight = Math.round(this.currentRowHeight * this.lastRecordedBufferLength) + (this.lastRecordedViewportHeight - this.terminal.renderer.dimensions.canvasHeight);
  4448. if (this.lastRecordedBufferHeight !== newBufferHeight) {
  4449. this.lastRecordedBufferHeight = newBufferHeight;
  4450. this.scrollArea.style.height = this.lastRecordedBufferHeight + 'px';
  4451. }
  4452. }
  4453. };
  4454. Viewport.prototype.syncScrollArea = function () {
  4455. if (this.lastRecordedBufferLength !== this.terminal.buffer.lines.length) {
  4456. this.lastRecordedBufferLength = this.terminal.buffer.lines.length;
  4457. this.refresh();
  4458. }
  4459. else if (this.lastRecordedViewportHeight !== this.terminal.renderer.dimensions.canvasHeight) {
  4460. this.refresh();
  4461. }
  4462. else {
  4463. if (this.terminal.renderer.dimensions.scaledCellHeight / window.devicePixelRatio !== this.currentRowHeight) {
  4464. this.refresh();
  4465. }
  4466. }
  4467. var scrollTop = this.terminal.buffer.ydisp * this.currentRowHeight;
  4468. if (this.viewportElement.scrollTop !== scrollTop) {
  4469. this.viewportElement.scrollTop = scrollTop;
  4470. }
  4471. };
  4472. Viewport.prototype.onScroll = function (ev) {
  4473. if (!this.viewportElement.offsetParent) {
  4474. return;
  4475. }
  4476. var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
  4477. var diff = newRow - this.terminal.buffer.ydisp;
  4478. this.terminal.scrollLines(diff, true);
  4479. };
  4480. Viewport.prototype.onWheel = function (ev) {
  4481. if (ev.deltaY === 0) {
  4482. return;
  4483. }
  4484. var multiplier = 1;
  4485. if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
  4486. multiplier = this.currentRowHeight;
  4487. }
  4488. else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  4489. multiplier = this.currentRowHeight * this.terminal.rows;
  4490. }
  4491. this.viewportElement.scrollTop += ev.deltaY * multiplier;
  4492. ev.preventDefault();
  4493. };
  4494. Viewport.prototype.onTouchStart = function (ev) {
  4495. this.lastTouchY = ev.touches[0].pageY;
  4496. };
  4497. Viewport.prototype.onTouchMove = function (ev) {
  4498. var deltaY = this.lastTouchY - ev.touches[0].pageY;
  4499. this.lastTouchY = ev.touches[0].pageY;
  4500. if (deltaY === 0) {
  4501. return;
  4502. }
  4503. this.viewportElement.scrollTop += deltaY;
  4504. ev.preventDefault();
  4505. };
  4506. return Viewport;
  4507. }());
  4508. exports.Viewport = Viewport;
  4509. },{}],16:[function(require,module,exports){
  4510. "use strict";
  4511. Object.defineProperty(exports, "__esModule", { value: true });
  4512. var EscapeSequences_1 = require("../EscapeSequences");
  4513. var Direction;
  4514. (function (Direction) {
  4515. Direction["Up"] = "A";
  4516. Direction["Down"] = "B";
  4517. Direction["Right"] = "C";
  4518. Direction["Left"] = "D";
  4519. })(Direction || (Direction = {}));
  4520. var AltClickHandler = (function () {
  4521. function AltClickHandler(_mouseEvent, _terminal) {
  4522. this._mouseEvent = _mouseEvent;
  4523. this._terminal = _terminal;
  4524. this._lines = this._terminal.buffer.lines;
  4525. this._startCol = this._terminal.buffer.x;
  4526. this._startRow = this._terminal.buffer.y;
  4527. _a = this._terminal.mouseHelper.getCoords(this._mouseEvent, this._terminal.element, this._terminal.charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows, false).map(function (coordinate) {
  4528. return coordinate - 1;
  4529. }), this._endCol = _a[0], this._endRow = _a[1];
  4530. var _a;
  4531. }
  4532. AltClickHandler.prototype.move = function () {
  4533. if (this._mouseEvent.altKey) {
  4534. this._terminal.send(this._arrowSequences());
  4535. }
  4536. };
  4537. AltClickHandler.prototype._arrowSequences = function () {
  4538. return this._resetStartingRow() +
  4539. this._moveToRequestedRow() +
  4540. this._moveToRequestedCol();
  4541. };
  4542. AltClickHandler.prototype._resetStartingRow = function () {
  4543. var startRow = this._endRow - this._wrappedRowsForRow(this._endRow);
  4544. var endRow = this._endRow;
  4545. if (this._moveToRequestedRow().length === 0) {
  4546. return '';
  4547. }
  4548. else {
  4549. return repeat(this._bufferLine(this._startCol, this._startRow, this._startCol, this._startRow - this._wrappedRowsForRow(this._startRow), false).length, this._sequence(Direction.Left));
  4550. }
  4551. };
  4552. AltClickHandler.prototype._moveToRequestedRow = function () {
  4553. var startRow = this._startRow - this._wrappedRowsForRow(this._startRow);
  4554. var endRow = this._endRow - this._wrappedRowsForRow(this._endRow);
  4555. var rowsToMove = Math.abs(startRow - endRow) - this._wrappedRowsCount();
  4556. return repeat(rowsToMove, this._sequence(this._verticalDirection()));
  4557. };
  4558. AltClickHandler.prototype._moveToRequestedCol = function () {
  4559. var startRow;
  4560. if (this._moveToRequestedRow().length > 0) {
  4561. startRow = this._endRow - this._wrappedRowsForRow(this._endRow);
  4562. }
  4563. else {
  4564. startRow = this._startRow;
  4565. }
  4566. var endRow = this._endRow;
  4567. var direction = this._horizontalDirection();
  4568. return repeat(this._bufferLine(this._startCol, startRow, this._endCol, endRow, direction === Direction.Right).length, this._sequence(direction));
  4569. };
  4570. AltClickHandler.prototype._wrappedRowsCount = function () {
  4571. var wrappedRows = 0;
  4572. var startRow = this._startRow - this._wrappedRowsForRow(this._startRow);
  4573. var endRow = this._endRow - this._wrappedRowsForRow(this._endRow);
  4574. for (var i = 0; i < Math.abs(startRow - endRow); i++) {
  4575. var direction = this._verticalDirection() === Direction.Up ? -1 : 1;
  4576. if (this._lines.get(startRow + (direction * i)).isWrapped) {
  4577. wrappedRows++;
  4578. }
  4579. }
  4580. return wrappedRows;
  4581. };
  4582. AltClickHandler.prototype._wrappedRowsForRow = function (currentRow) {
  4583. var rowCount = 0;
  4584. var lineWraps = this._lines.get(currentRow).isWrapped;
  4585. while (lineWraps && currentRow >= 0 && currentRow < this._terminal.rows) {
  4586. rowCount++;
  4587. currentRow--;
  4588. lineWraps = this._lines.get(currentRow).isWrapped;
  4589. }
  4590. return rowCount;
  4591. };
  4592. AltClickHandler.prototype._horizontalDirection = function () {
  4593. var startRow;
  4594. if (this._moveToRequestedRow().length > 0) {
  4595. startRow = this._endRow - this._wrappedRowsForRow(this._endRow);
  4596. }
  4597. else {
  4598. startRow = this._startRow;
  4599. }
  4600. if ((this._startCol < this._endCol &&
  4601. startRow <= this._endRow) ||
  4602. (this._startCol >= this._endCol &&
  4603. startRow < this._endRow)) {
  4604. return Direction.Right;
  4605. }
  4606. else {
  4607. return Direction.Left;
  4608. }
  4609. };
  4610. AltClickHandler.prototype._verticalDirection = function () {
  4611. if (this._startRow > this._endRow) {
  4612. return Direction.Up;
  4613. }
  4614. else {
  4615. return Direction.Down;
  4616. }
  4617. };
  4618. AltClickHandler.prototype._bufferLine = function (startCol, startRow, endCol, endRow, forward) {
  4619. var currentCol = startCol;
  4620. var currentRow = startRow;
  4621. var bufferStr = '';
  4622. while (currentCol !== endCol || currentRow !== endRow) {
  4623. currentCol += forward ? 1 : -1;
  4624. if (forward && currentCol > this._terminal.cols - 1) {
  4625. bufferStr += this._terminal.buffer.translateBufferLineToString(currentRow, false, startCol, currentCol);
  4626. currentCol = 0;
  4627. startCol = 0;
  4628. currentRow++;
  4629. }
  4630. else if (!forward && currentCol < 0) {
  4631. bufferStr += this._terminal.buffer.translateBufferLineToString(currentRow, false, 0, startCol + 1);
  4632. currentCol = this._terminal.cols - 1;
  4633. startCol = currentCol;
  4634. currentRow--;
  4635. }
  4636. }
  4637. return bufferStr + this._terminal.buffer.translateBufferLineToString(currentRow, false, startCol, currentCol);
  4638. };
  4639. AltClickHandler.prototype._sequence = function (direction) {
  4640. var mod = this._terminal.applicationCursor ? 'O' : '[';
  4641. return EscapeSequences_1.C0.ESC + mod + direction;
  4642. };
  4643. return AltClickHandler;
  4644. }());
  4645. exports.AltClickHandler = AltClickHandler;
  4646. function repeat(count, str) {
  4647. count = Math.floor(count);
  4648. var rpt = '';
  4649. for (var i = 0; i < count; i++) {
  4650. rpt += str;
  4651. }
  4652. return rpt;
  4653. }
  4654. },{"../EscapeSequences":6}],17:[function(require,module,exports){
  4655. "use strict";
  4656. Object.defineProperty(exports, "__esModule", { value: true });
  4657. function prepareTextForTerminal(text, isMSWindows) {
  4658. if (isMSWindows) {
  4659. return text.replace(/\r?\n/g, '\r');
  4660. }
  4661. return text;
  4662. }
  4663. exports.prepareTextForTerminal = prepareTextForTerminal;
  4664. function bracketTextForPaste(text, bracketedPasteMode) {
  4665. if (bracketedPasteMode) {
  4666. return '\x1b[200~' + text + '\x1b[201~';
  4667. }
  4668. return text;
  4669. }
  4670. exports.bracketTextForPaste = bracketTextForPaste;
  4671. function copyHandler(ev, term, selectionManager) {
  4672. if (term.browser.isMSIE) {
  4673. window.clipboardData.setData('Text', selectionManager.selectionText);
  4674. }
  4675. else {
  4676. ev.clipboardData.setData('text/plain', selectionManager.selectionText);
  4677. }
  4678. ev.preventDefault();
  4679. }
  4680. exports.copyHandler = copyHandler;
  4681. function pasteHandler(ev, term) {
  4682. ev.stopPropagation();
  4683. var text;
  4684. var dispatchPaste = function (text) {
  4685. text = prepareTextForTerminal(text, term.browser.isMSWindows);
  4686. text = bracketTextForPaste(text, term.bracketedPasteMode);
  4687. term.handler(text);
  4688. term.textarea.value = '';
  4689. term.emit('paste', text);
  4690. term.cancel(ev);
  4691. };
  4692. if (term.browser.isMSIE) {
  4693. if (window.clipboardData) {
  4694. text = window.clipboardData.getData('Text');
  4695. dispatchPaste(text);
  4696. }
  4697. }
  4698. else {
  4699. if (ev.clipboardData) {
  4700. text = ev.clipboardData.getData('text/plain');
  4701. dispatchPaste(text);
  4702. }
  4703. }
  4704. }
  4705. exports.pasteHandler = pasteHandler;
  4706. function moveTextAreaUnderMouseCursor(ev, textarea) {
  4707. textarea.style.position = 'fixed';
  4708. textarea.style.width = '20px';
  4709. textarea.style.height = '20px';
  4710. textarea.style.left = (ev.clientX - 10) + 'px';
  4711. textarea.style.top = (ev.clientY - 10) + 'px';
  4712. textarea.style.zIndex = '1000';
  4713. textarea.focus();
  4714. setTimeout(function () {
  4715. textarea.style.position = null;
  4716. textarea.style.width = null;
  4717. textarea.style.height = null;
  4718. textarea.style.left = null;
  4719. textarea.style.top = null;
  4720. textarea.style.zIndex = null;
  4721. }, 200);
  4722. }
  4723. exports.moveTextAreaUnderMouseCursor = moveTextAreaUnderMouseCursor;
  4724. function rightClickHandler(ev, textarea, selectionManager, shouldSelectWord) {
  4725. moveTextAreaUnderMouseCursor(ev, textarea);
  4726. if (shouldSelectWord && !selectionManager.isClickInSelection(ev)) {
  4727. selectionManager.selectWordAtCursor(ev);
  4728. }
  4729. textarea.value = selectionManager.selectionText;
  4730. textarea.select();
  4731. }
  4732. exports.rightClickHandler = rightClickHandler;
  4733. },{}],18:[function(require,module,exports){
  4734. "use strict";
  4735. Object.defineProperty(exports, "__esModule", { value: true });
  4736. var HOVER_DURATION = 500;
  4737. var MouseZoneManager = (function () {
  4738. function MouseZoneManager(_terminal) {
  4739. var _this = this;
  4740. this._terminal = _terminal;
  4741. this._zones = [];
  4742. this._areZonesActive = false;
  4743. this._tooltipTimeout = null;
  4744. this._currentZone = null;
  4745. this._lastHoverCoords = [null, null];
  4746. this._terminal.element.addEventListener('mousedown', function (e) { return _this._onMouseDown(e); });
  4747. this._mouseMoveListener = function (e) { return _this._onMouseMove(e); };
  4748. this._clickListener = function (e) { return _this._onClick(e); };
  4749. }
  4750. MouseZoneManager.prototype.add = function (zone) {
  4751. this._zones.push(zone);
  4752. if (this._zones.length === 1) {
  4753. this._activate();
  4754. }
  4755. };
  4756. MouseZoneManager.prototype.clearAll = function (start, end) {
  4757. if (this._zones.length === 0) {
  4758. return;
  4759. }
  4760. if (!end) {
  4761. start = 0;
  4762. end = this._terminal.rows - 1;
  4763. }
  4764. for (var i = 0; i < this._zones.length; i++) {
  4765. var zone = this._zones[i];
  4766. if (zone.y > start && zone.y <= end + 1) {
  4767. if (this._currentZone && this._currentZone === zone) {
  4768. this._currentZone.leaveCallback();
  4769. this._currentZone = null;
  4770. }
  4771. this._zones.splice(i--, 1);
  4772. }
  4773. }
  4774. if (this._zones.length === 0) {
  4775. this._deactivate();
  4776. }
  4777. };
  4778. MouseZoneManager.prototype._activate = function () {
  4779. if (!this._areZonesActive) {
  4780. this._areZonesActive = true;
  4781. this._terminal.element.addEventListener('mousemove', this._mouseMoveListener);
  4782. this._terminal.element.addEventListener('click', this._clickListener);
  4783. }
  4784. };
  4785. MouseZoneManager.prototype._deactivate = function () {
  4786. if (this._areZonesActive) {
  4787. this._areZonesActive = false;
  4788. this._terminal.element.removeEventListener('mousemove', this._mouseMoveListener);
  4789. this._terminal.element.removeEventListener('click', this._clickListener);
  4790. }
  4791. };
  4792. MouseZoneManager.prototype._onMouseMove = function (e) {
  4793. if (this._lastHoverCoords[0] !== e.pageX || this._lastHoverCoords[1] !== e.pageY) {
  4794. this._onHover(e);
  4795. this._lastHoverCoords = [e.pageX, e.pageY];
  4796. }
  4797. };
  4798. MouseZoneManager.prototype._onHover = function (e) {
  4799. var _this = this;
  4800. var zone = this._findZoneEventAt(e);
  4801. if (zone === this._currentZone) {
  4802. return;
  4803. }
  4804. if (this._currentZone) {
  4805. this._currentZone.leaveCallback();
  4806. this._currentZone = null;
  4807. if (this._tooltipTimeout) {
  4808. clearTimeout(this._tooltipTimeout);
  4809. }
  4810. }
  4811. if (!zone) {
  4812. return;
  4813. }
  4814. this._currentZone = zone;
  4815. if (zone.hoverCallback) {
  4816. zone.hoverCallback(e);
  4817. }
  4818. this._tooltipTimeout = setTimeout(function () { return _this._onTooltip(e); }, HOVER_DURATION);
  4819. };
  4820. MouseZoneManager.prototype._onTooltip = function (e) {
  4821. this._tooltipTimeout = null;
  4822. var zone = this._findZoneEventAt(e);
  4823. if (zone && zone.tooltipCallback) {
  4824. zone.tooltipCallback(e);
  4825. }
  4826. };
  4827. MouseZoneManager.prototype._onMouseDown = function (e) {
  4828. if (!this._areZonesActive) {
  4829. return;
  4830. }
  4831. var zone = this._findZoneEventAt(e);
  4832. if (zone) {
  4833. if (zone.willLinkActivate(e)) {
  4834. e.preventDefault();
  4835. e.stopImmediatePropagation();
  4836. }
  4837. }
  4838. };
  4839. MouseZoneManager.prototype._onClick = function (e) {
  4840. var zone = this._findZoneEventAt(e);
  4841. if (zone) {
  4842. zone.clickCallback(e);
  4843. e.preventDefault();
  4844. e.stopImmediatePropagation();
  4845. }
  4846. };
  4847. MouseZoneManager.prototype._findZoneEventAt = function (e) {
  4848. var coords = this._terminal.mouseHelper.getCoords(e, this._terminal.screenElement, this._terminal.charMeasure, this._terminal.options.lineHeight, this._terminal.cols, this._terminal.rows);
  4849. if (!coords) {
  4850. return null;
  4851. }
  4852. for (var i = 0; i < this._zones.length; i++) {
  4853. var zone = this._zones[i];
  4854. if (zone.y === coords[1] && zone.x1 <= coords[0] && zone.x2 > coords[0]) {
  4855. return zone;
  4856. }
  4857. }
  4858. return null;
  4859. };
  4860. return MouseZoneManager;
  4861. }());
  4862. exports.MouseZoneManager = MouseZoneManager;
  4863. var MouseZone = (function () {
  4864. function MouseZone(x1, x2, y, clickCallback, hoverCallback, tooltipCallback, leaveCallback, willLinkActivate) {
  4865. this.x1 = x1;
  4866. this.x2 = x2;
  4867. this.y = y;
  4868. this.clickCallback = clickCallback;
  4869. this.hoverCallback = hoverCallback;
  4870. this.tooltipCallback = tooltipCallback;
  4871. this.leaveCallback = leaveCallback;
  4872. this.willLinkActivate = willLinkActivate;
  4873. }
  4874. return MouseZone;
  4875. }());
  4876. exports.MouseZone = MouseZone;
  4877. },{}],19:[function(require,module,exports){
  4878. "use strict";
  4879. Object.defineProperty(exports, "__esModule", { value: true });
  4880. var CharAtlas_1 = require("./CharAtlas");
  4881. var Buffer_1 = require("../Buffer");
  4882. exports.INVERTED_DEFAULT_COLOR = -1;
  4883. var DIM_OPACITY = 0.5;
  4884. var BaseRenderLayer = (function () {
  4885. function BaseRenderLayer(_container, id, zIndex, _alpha, _colors) {
  4886. this._container = _container;
  4887. this._alpha = _alpha;
  4888. this._colors = _colors;
  4889. this._scaledCharWidth = 0;
  4890. this._scaledCharHeight = 0;
  4891. this._scaledCellWidth = 0;
  4892. this._scaledCellHeight = 0;
  4893. this._scaledCharLeft = 0;
  4894. this._scaledCharTop = 0;
  4895. this._canvas = document.createElement('canvas');
  4896. this._canvas.classList.add("xterm-" + id + "-layer");
  4897. this._canvas.style.zIndex = zIndex.toString();
  4898. this._initCanvas();
  4899. this._container.appendChild(this._canvas);
  4900. }
  4901. BaseRenderLayer.prototype._initCanvas = function () {
  4902. this._ctx = this._canvas.getContext('2d', { alpha: this._alpha });
  4903. if (!this._alpha) {
  4904. this.clearAll();
  4905. }
  4906. };
  4907. BaseRenderLayer.prototype.onOptionsChanged = function (terminal) { };
  4908. BaseRenderLayer.prototype.onBlur = function (terminal) { };
  4909. BaseRenderLayer.prototype.onFocus = function (terminal) { };
  4910. BaseRenderLayer.prototype.onCursorMove = function (terminal) { };
  4911. BaseRenderLayer.prototype.onGridChanged = function (terminal, startRow, endRow) { };
  4912. BaseRenderLayer.prototype.onSelectionChanged = function (terminal, start, end) { };
  4913. BaseRenderLayer.prototype.onThemeChanged = function (terminal, colorSet) {
  4914. this._refreshCharAtlas(terminal, colorSet);
  4915. };
  4916. BaseRenderLayer.prototype.setTransparency = function (terminal, alpha) {
  4917. if (alpha === this._alpha) {
  4918. return;
  4919. }
  4920. var oldCanvas = this._canvas;
  4921. this._alpha = alpha;
  4922. this._canvas = this._canvas.cloneNode();
  4923. this._initCanvas();
  4924. this._container.replaceChild(this._canvas, oldCanvas);
  4925. this._refreshCharAtlas(terminal, this._colors);
  4926. this.onGridChanged(terminal, 0, terminal.rows - 1);
  4927. };
  4928. BaseRenderLayer.prototype._refreshCharAtlas = function (terminal, colorSet) {
  4929. var _this = this;
  4930. if (this._scaledCharWidth <= 0 && this._scaledCharHeight <= 0) {
  4931. return;
  4932. }
  4933. this._charAtlas = null;
  4934. var result = CharAtlas_1.acquireCharAtlas(terminal, colorSet, this._scaledCharWidth, this._scaledCharHeight);
  4935. if (result instanceof HTMLCanvasElement) {
  4936. this._charAtlas = result;
  4937. }
  4938. else {
  4939. result.then(function (bitmap) { return _this._charAtlas = bitmap; });
  4940. }
  4941. };
  4942. BaseRenderLayer.prototype.resize = function (terminal, dim, charSizeChanged) {
  4943. this._scaledCellWidth = dim.scaledCellWidth;
  4944. this._scaledCellHeight = dim.scaledCellHeight;
  4945. this._scaledCharWidth = dim.scaledCharWidth;
  4946. this._scaledCharHeight = dim.scaledCharHeight;
  4947. this._scaledCharLeft = dim.scaledCharLeft;
  4948. this._scaledCharTop = dim.scaledCharTop;
  4949. this._canvas.width = dim.scaledCanvasWidth;
  4950. this._canvas.height = dim.scaledCanvasHeight;
  4951. this._canvas.style.width = dim.canvasWidth + "px";
  4952. this._canvas.style.height = dim.canvasHeight + "px";
  4953. if (!this._alpha) {
  4954. this.clearAll();
  4955. }
  4956. if (charSizeChanged) {
  4957. this._refreshCharAtlas(terminal, this._colors);
  4958. }
  4959. };
  4960. BaseRenderLayer.prototype.fillCells = function (x, y, width, height) {
  4961. this._ctx.fillRect(x * this._scaledCellWidth, y * this._scaledCellHeight, width * this._scaledCellWidth, height * this._scaledCellHeight);
  4962. };
  4963. BaseRenderLayer.prototype.fillBottomLineAtCells = function (x, y, width) {
  4964. if (width === void 0) { width = 1; }
  4965. this._ctx.fillRect(x * this._scaledCellWidth, (y + 1) * this._scaledCellHeight - window.devicePixelRatio - 1, width * this._scaledCellWidth, window.devicePixelRatio);
  4966. };
  4967. BaseRenderLayer.prototype.fillLeftLineAtCell = function (x, y) {
  4968. this._ctx.fillRect(x * this._scaledCellWidth, y * this._scaledCellHeight, window.devicePixelRatio, this._scaledCellHeight);
  4969. };
  4970. BaseRenderLayer.prototype.strokeRectAtCell = function (x, y, width, height) {
  4971. this._ctx.lineWidth = window.devicePixelRatio;
  4972. this._ctx.strokeRect(x * this._scaledCellWidth + window.devicePixelRatio / 2, y * this._scaledCellHeight + (window.devicePixelRatio / 2), width * this._scaledCellWidth - window.devicePixelRatio, (height * this._scaledCellHeight) - window.devicePixelRatio);
  4973. };
  4974. BaseRenderLayer.prototype.clearAll = function () {
  4975. if (this._alpha) {
  4976. this._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
  4977. }
  4978. else {
  4979. this._ctx.fillStyle = this._colors.background;
  4980. this._ctx.fillRect(0, 0, this._canvas.width, this._canvas.height);
  4981. }
  4982. };
  4983. BaseRenderLayer.prototype.clearCells = function (x, y, width, height) {
  4984. if (this._alpha) {
  4985. this._ctx.clearRect(x * this._scaledCellWidth, y * this._scaledCellHeight, width * this._scaledCellWidth, height * this._scaledCellHeight);
  4986. }
  4987. else {
  4988. this._ctx.fillStyle = this._colors.background;
  4989. this._ctx.fillRect(x * this._scaledCellWidth, y * this._scaledCellHeight, width * this._scaledCellWidth, height * this._scaledCellHeight);
  4990. }
  4991. };
  4992. BaseRenderLayer.prototype.fillCharTrueColor = function (terminal, charData, x, y) {
  4993. this._ctx.font = this._getFont(terminal, false);
  4994. this._ctx.textBaseline = 'top';
  4995. this._clipRow(terminal, y);
  4996. this._ctx.fillText(charData[Buffer_1.CHAR_DATA_CHAR_INDEX], x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop);
  4997. };
  4998. BaseRenderLayer.prototype.drawChar = function (terminal, char, code, width, x, y, fg, bg, bold, dim) {
  4999. var colorIndex = 0;
  5000. if (fg < 256) {
  5001. colorIndex = fg + 2;
  5002. }
  5003. else {
  5004. if (bold && terminal.options.enableBold) {
  5005. colorIndex = 1;
  5006. }
  5007. }
  5008. var isAscii = code < 256;
  5009. var isBasicColor = (colorIndex > 1 && fg < 16) && (fg < 8 || bold);
  5010. var isDefaultColor = fg >= 256;
  5011. var isDefaultBackground = bg >= 256;
  5012. if (this._charAtlas && isAscii && (isBasicColor || isDefaultColor) && isDefaultBackground) {
  5013. var charAtlasCellWidth = this._scaledCharWidth + CharAtlas_1.CHAR_ATLAS_CELL_SPACING;
  5014. var charAtlasCellHeight = this._scaledCharHeight + CharAtlas_1.CHAR_ATLAS_CELL_SPACING;
  5015. if (dim) {
  5016. this._ctx.globalAlpha = DIM_OPACITY;
  5017. }
  5018. if (bold && !terminal.options.enableBold) {
  5019. if (colorIndex > 1) {
  5020. colorIndex -= 8;
  5021. }
  5022. }
  5023. this._ctx.drawImage(this._charAtlas, code * charAtlasCellWidth, colorIndex * charAtlasCellHeight, charAtlasCellWidth, this._scaledCharHeight, x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop, charAtlasCellWidth, this._scaledCharHeight);
  5024. }
  5025. else {
  5026. this._drawUncachedChar(terminal, char, width, fg, x, y, bold && terminal.options.enableBold, dim);
  5027. }
  5028. };
  5029. BaseRenderLayer.prototype._drawUncachedChar = function (terminal, char, width, fg, x, y, bold, dim) {
  5030. this._ctx.save();
  5031. this._ctx.font = this._getFont(terminal, bold);
  5032. this._ctx.textBaseline = 'top';
  5033. if (fg === exports.INVERTED_DEFAULT_COLOR) {
  5034. this._ctx.fillStyle = this._colors.background;
  5035. }
  5036. else if (fg < 256) {
  5037. this._ctx.fillStyle = this._colors.ansi[fg];
  5038. }
  5039. else {
  5040. this._ctx.fillStyle = this._colors.foreground;
  5041. }
  5042. this._clipRow(terminal, y);
  5043. if (dim) {
  5044. this._ctx.globalAlpha = DIM_OPACITY;
  5045. }
  5046. this._ctx.fillText(char, x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop);
  5047. this._ctx.restore();
  5048. };
  5049. BaseRenderLayer.prototype._clipRow = function (terminal, y) {
  5050. this._ctx.beginPath();
  5051. this._ctx.rect(0, y * this._scaledCellHeight, terminal.cols * this._scaledCellWidth, this._scaledCellHeight);
  5052. this._ctx.clip();
  5053. };
  5054. BaseRenderLayer.prototype._getFont = function (terminal, isBold) {
  5055. var fontWeight = isBold ? terminal.options.fontWeightBold : terminal.options.fontWeight;
  5056. return fontWeight + " " + terminal.options.fontSize * window.devicePixelRatio + "px " + terminal.options.fontFamily;
  5057. };
  5058. return BaseRenderLayer;
  5059. }());
  5060. exports.BaseRenderLayer = BaseRenderLayer;
  5061. },{"../Buffer":1,"./CharAtlas":20}],20:[function(require,module,exports){
  5062. "use strict";
  5063. Object.defineProperty(exports, "__esModule", { value: true });
  5064. var CharAtlasGenerator_1 = require("../shared/CharAtlasGenerator");
  5065. exports.CHAR_ATLAS_CELL_SPACING = 1;
  5066. var charAtlasCache = [];
  5067. function acquireCharAtlas(terminal, colors, scaledCharWidth, scaledCharHeight) {
  5068. var newConfig = generateConfig(scaledCharWidth, scaledCharHeight, terminal, colors);
  5069. for (var i = 0; i < charAtlasCache.length; i++) {
  5070. var entry = charAtlasCache[i];
  5071. var ownedByIndex = entry.ownedBy.indexOf(terminal);
  5072. if (ownedByIndex >= 0) {
  5073. if (configEquals(entry.config, newConfig)) {
  5074. return entry.bitmap;
  5075. }
  5076. else {
  5077. if (entry.ownedBy.length === 1) {
  5078. charAtlasCache.splice(i, 1);
  5079. }
  5080. else {
  5081. entry.ownedBy.splice(ownedByIndex, 1);
  5082. }
  5083. break;
  5084. }
  5085. }
  5086. }
  5087. for (var i = 0; i < charAtlasCache.length; i++) {
  5088. var entry = charAtlasCache[i];
  5089. if (configEquals(entry.config, newConfig)) {
  5090. entry.ownedBy.push(terminal);
  5091. return entry.bitmap;
  5092. }
  5093. }
  5094. var canvasFactory = function (width, height) {
  5095. var canvas = document.createElement('canvas');
  5096. canvas.width = width;
  5097. canvas.height = height;
  5098. return canvas;
  5099. };
  5100. var charAtlasConfig = {
  5101. scaledCharWidth: scaledCharWidth,
  5102. scaledCharHeight: scaledCharHeight,
  5103. fontSize: terminal.options.fontSize,
  5104. fontFamily: terminal.options.fontFamily,
  5105. fontWeight: terminal.options.fontWeight,
  5106. fontWeightBold: terminal.options.fontWeightBold,
  5107. background: colors.background,
  5108. foreground: colors.foreground,
  5109. ansiColors: colors.ansi,
  5110. devicePixelRatio: window.devicePixelRatio,
  5111. allowTransparency: terminal.options.allowTransparency
  5112. };
  5113. var newEntry = {
  5114. bitmap: CharAtlasGenerator_1.generateCharAtlas(window, canvasFactory, charAtlasConfig),
  5115. config: newConfig,
  5116. ownedBy: [terminal]
  5117. };
  5118. charAtlasCache.push(newEntry);
  5119. return newEntry.bitmap;
  5120. }
  5121. exports.acquireCharAtlas = acquireCharAtlas;
  5122. function generateConfig(scaledCharWidth, scaledCharHeight, terminal, colors) {
  5123. var clonedColors = {
  5124. foreground: colors.foreground,
  5125. background: colors.background,
  5126. cursor: null,
  5127. cursorAccent: null,
  5128. selection: null,
  5129. ansi: colors.ansi.slice(0, 16)
  5130. };
  5131. return {
  5132. scaledCharWidth: scaledCharWidth,
  5133. scaledCharHeight: scaledCharHeight,
  5134. fontFamily: terminal.options.fontFamily,
  5135. fontSize: terminal.options.fontSize,
  5136. fontWeight: terminal.options.fontWeight,
  5137. fontWeightBold: terminal.options.fontWeightBold,
  5138. allowTransparency: terminal.options.allowTransparency,
  5139. colors: clonedColors
  5140. };
  5141. }
  5142. function configEquals(a, b) {
  5143. for (var i = 0; i < a.colors.ansi.length; i++) {
  5144. if (a.colors.ansi[i] !== b.colors.ansi[i]) {
  5145. return false;
  5146. }
  5147. }
  5148. return a.fontFamily === b.fontFamily &&
  5149. a.fontSize === b.fontSize &&
  5150. a.fontWeight === b.fontWeight &&
  5151. a.fontWeightBold === b.fontWeightBold &&
  5152. a.allowTransparency === b.allowTransparency &&
  5153. a.scaledCharWidth === b.scaledCharWidth &&
  5154. a.scaledCharHeight === b.scaledCharHeight &&
  5155. a.colors.foreground === b.colors.foreground &&
  5156. a.colors.background === b.colors.background;
  5157. }
  5158. },{"../shared/CharAtlasGenerator":29}],21:[function(require,module,exports){
  5159. "use strict";
  5160. Object.defineProperty(exports, "__esModule", { value: true });
  5161. var DEFAULT_FOREGROUND = '#ffffff';
  5162. var DEFAULT_BACKGROUND = '#000000';
  5163. var DEFAULT_CURSOR = '#ffffff';
  5164. var DEFAULT_CURSOR_ACCENT = '#000000';
  5165. var DEFAULT_SELECTION = 'rgba(255, 255, 255, 0.3)';
  5166. exports.DEFAULT_ANSI_COLORS = [
  5167. '#2e3436',
  5168. '#cc0000',
  5169. '#4e9a06',
  5170. '#c4a000',
  5171. '#3465a4',
  5172. '#75507b',
  5173. '#06989a',
  5174. '#d3d7cf',
  5175. '#555753',
  5176. '#ef2929',
  5177. '#8ae234',
  5178. '#fce94f',
  5179. '#729fcf',
  5180. '#ad7fa8',
  5181. '#34e2e2',
  5182. '#eeeeec'
  5183. ];
  5184. function generate256Colors(first16Colors) {
  5185. var colors = first16Colors.slice();
  5186. var v = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff];
  5187. for (var i = 0; i < 216; i++) {
  5188. var r = toPaddedHex(v[(i / 36) % 6 | 0]);
  5189. var g = toPaddedHex(v[(i / 6) % 6 | 0]);
  5190. var b = toPaddedHex(v[i % 6]);
  5191. colors.push("#" + r + g + b);
  5192. }
  5193. for (var i = 0; i < 24; i++) {
  5194. var c = toPaddedHex(8 + i * 10);
  5195. colors.push("#" + c + c + c);
  5196. }
  5197. return colors;
  5198. }
  5199. function toPaddedHex(c) {
  5200. var s = c.toString(16);
  5201. return s.length < 2 ? '0' + s : s;
  5202. }
  5203. var ColorManager = (function () {
  5204. function ColorManager() {
  5205. this.colors = {
  5206. foreground: DEFAULT_FOREGROUND,
  5207. background: DEFAULT_BACKGROUND,
  5208. cursor: DEFAULT_CURSOR,
  5209. cursorAccent: DEFAULT_CURSOR_ACCENT,
  5210. selection: DEFAULT_SELECTION,
  5211. ansi: generate256Colors(exports.DEFAULT_ANSI_COLORS)
  5212. };
  5213. }
  5214. ColorManager.prototype.setTheme = function (theme) {
  5215. this.colors.foreground = theme.foreground || DEFAULT_FOREGROUND;
  5216. this.colors.background = theme.background || DEFAULT_BACKGROUND;
  5217. this.colors.cursor = theme.cursor || DEFAULT_CURSOR;
  5218. this.colors.cursorAccent = theme.cursorAccent || DEFAULT_CURSOR_ACCENT;
  5219. this.colors.selection = theme.selection || DEFAULT_SELECTION;
  5220. this.colors.ansi[0] = theme.black || exports.DEFAULT_ANSI_COLORS[0];
  5221. this.colors.ansi[1] = theme.red || exports.DEFAULT_ANSI_COLORS[1];
  5222. this.colors.ansi[2] = theme.green || exports.DEFAULT_ANSI_COLORS[2];
  5223. this.colors.ansi[3] = theme.yellow || exports.DEFAULT_ANSI_COLORS[3];
  5224. this.colors.ansi[4] = theme.blue || exports.DEFAULT_ANSI_COLORS[4];
  5225. this.colors.ansi[5] = theme.magenta || exports.DEFAULT_ANSI_COLORS[5];
  5226. this.colors.ansi[6] = theme.cyan || exports.DEFAULT_ANSI_COLORS[6];
  5227. this.colors.ansi[7] = theme.white || exports.DEFAULT_ANSI_COLORS[7];
  5228. this.colors.ansi[8] = theme.brightBlack || exports.DEFAULT_ANSI_COLORS[8];
  5229. this.colors.ansi[9] = theme.brightRed || exports.DEFAULT_ANSI_COLORS[9];
  5230. this.colors.ansi[10] = theme.brightGreen || exports.DEFAULT_ANSI_COLORS[10];
  5231. this.colors.ansi[11] = theme.brightYellow || exports.DEFAULT_ANSI_COLORS[11];
  5232. this.colors.ansi[12] = theme.brightBlue || exports.DEFAULT_ANSI_COLORS[12];
  5233. this.colors.ansi[13] = theme.brightMagenta || exports.DEFAULT_ANSI_COLORS[13];
  5234. this.colors.ansi[14] = theme.brightCyan || exports.DEFAULT_ANSI_COLORS[14];
  5235. this.colors.ansi[15] = theme.brightWhite || exports.DEFAULT_ANSI_COLORS[15];
  5236. };
  5237. return ColorManager;
  5238. }());
  5239. exports.ColorManager = ColorManager;
  5240. },{}],22:[function(require,module,exports){
  5241. "use strict";
  5242. var __extends = (this && this.__extends) || (function () {
  5243. var extendStatics = Object.setPrototypeOf ||
  5244. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5245. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5246. return function (d, b) {
  5247. extendStatics(d, b);
  5248. function __() { this.constructor = d; }
  5249. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5250. };
  5251. })();
  5252. Object.defineProperty(exports, "__esModule", { value: true });
  5253. var Buffer_1 = require("../Buffer");
  5254. var BaseRenderLayer_1 = require("./BaseRenderLayer");
  5255. var BLINK_INTERVAL = 600;
  5256. var CursorRenderLayer = (function (_super) {
  5257. __extends(CursorRenderLayer, _super);
  5258. function CursorRenderLayer(container, zIndex, colors) {
  5259. var _this = _super.call(this, container, 'cursor', zIndex, true, colors) || this;
  5260. _this._state = {
  5261. x: null,
  5262. y: null,
  5263. isFocused: null,
  5264. style: null,
  5265. width: null,
  5266. };
  5267. _this._cursorRenderers = {
  5268. 'bar': _this._renderBarCursor.bind(_this),
  5269. 'block': _this._renderBlockCursor.bind(_this),
  5270. 'underline': _this._renderUnderlineCursor.bind(_this)
  5271. };
  5272. return _this;
  5273. }
  5274. CursorRenderLayer.prototype.resize = function (terminal, dim, charSizeChanged) {
  5275. _super.prototype.resize.call(this, terminal, dim, charSizeChanged);
  5276. this._state = {
  5277. x: null,
  5278. y: null,
  5279. isFocused: null,
  5280. style: null,
  5281. width: null,
  5282. };
  5283. };
  5284. CursorRenderLayer.prototype.reset = function (terminal) {
  5285. this._clearCursor();
  5286. if (this._cursorBlinkStateManager) {
  5287. this._cursorBlinkStateManager.dispose();
  5288. this._cursorBlinkStateManager = null;
  5289. this.onOptionsChanged(terminal);
  5290. }
  5291. };
  5292. CursorRenderLayer.prototype.onBlur = function (terminal) {
  5293. if (this._cursorBlinkStateManager) {
  5294. this._cursorBlinkStateManager.pause();
  5295. }
  5296. terminal.refresh(terminal.buffer.y, terminal.buffer.y);
  5297. };
  5298. CursorRenderLayer.prototype.onFocus = function (terminal) {
  5299. if (this._cursorBlinkStateManager) {
  5300. this._cursorBlinkStateManager.resume(terminal);
  5301. }
  5302. else {
  5303. terminal.refresh(terminal.buffer.y, terminal.buffer.y);
  5304. }
  5305. };
  5306. CursorRenderLayer.prototype.onOptionsChanged = function (terminal) {
  5307. var _this = this;
  5308. if (terminal.options.cursorBlink) {
  5309. if (!this._cursorBlinkStateManager) {
  5310. this._cursorBlinkStateManager = new CursorBlinkStateManager(terminal, function () {
  5311. _this._render(terminal, true);
  5312. });
  5313. }
  5314. }
  5315. else {
  5316. if (this._cursorBlinkStateManager) {
  5317. this._cursorBlinkStateManager.dispose();
  5318. this._cursorBlinkStateManager = null;
  5319. }
  5320. terminal.refresh(terminal.buffer.y, terminal.buffer.y);
  5321. }
  5322. };
  5323. CursorRenderLayer.prototype.onCursorMove = function (terminal) {
  5324. if (this._cursorBlinkStateManager) {
  5325. this._cursorBlinkStateManager.restartBlinkAnimation(terminal);
  5326. }
  5327. };
  5328. CursorRenderLayer.prototype.onGridChanged = function (terminal, startRow, endRow) {
  5329. if (!this._cursorBlinkStateManager || this._cursorBlinkStateManager.isPaused) {
  5330. this._render(terminal, false);
  5331. }
  5332. else {
  5333. this._cursorBlinkStateManager.restartBlinkAnimation(terminal);
  5334. }
  5335. };
  5336. CursorRenderLayer.prototype._render = function (terminal, triggeredByAnimationFrame) {
  5337. if (!terminal.cursorState || terminal.cursorHidden) {
  5338. this._clearCursor();
  5339. return;
  5340. }
  5341. var cursorY = terminal.buffer.ybase + terminal.buffer.y;
  5342. var viewportRelativeCursorY = cursorY - terminal.buffer.ydisp;
  5343. if (viewportRelativeCursorY < 0 || viewportRelativeCursorY >= terminal.rows) {
  5344. this._clearCursor();
  5345. return;
  5346. }
  5347. var charData = terminal.buffer.lines.get(cursorY)[terminal.buffer.x];
  5348. if (!charData) {
  5349. return;
  5350. }
  5351. if (!terminal.isFocused) {
  5352. this._clearCursor();
  5353. this._ctx.save();
  5354. this._ctx.fillStyle = this._colors.cursor;
  5355. this._renderBlurCursor(terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
  5356. this._ctx.restore();
  5357. this._state.x = terminal.buffer.x;
  5358. this._state.y = viewportRelativeCursorY;
  5359. this._state.isFocused = false;
  5360. this._state.style = terminal.options.cursorStyle;
  5361. this._state.width = charData[Buffer_1.CHAR_DATA_WIDTH_INDEX];
  5362. return;
  5363. }
  5364. if (this._cursorBlinkStateManager && !this._cursorBlinkStateManager.isCursorVisible) {
  5365. this._clearCursor();
  5366. return;
  5367. }
  5368. if (this._state) {
  5369. if (this._state.x === terminal.buffer.x &&
  5370. this._state.y === viewportRelativeCursorY &&
  5371. this._state.isFocused === terminal.isFocused &&
  5372. this._state.style === terminal.options.cursorStyle &&
  5373. this._state.width === charData[Buffer_1.CHAR_DATA_WIDTH_INDEX]) {
  5374. return;
  5375. }
  5376. this._clearCursor();
  5377. }
  5378. this._ctx.save();
  5379. this._cursorRenderers[terminal.options.cursorStyle || 'block'](terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
  5380. this._ctx.restore();
  5381. this._state.x = terminal.buffer.x;
  5382. this._state.y = viewportRelativeCursorY;
  5383. this._state.isFocused = false;
  5384. this._state.style = terminal.options.cursorStyle;
  5385. this._state.width = charData[Buffer_1.CHAR_DATA_WIDTH_INDEX];
  5386. };
  5387. CursorRenderLayer.prototype._clearCursor = function () {
  5388. if (this._state) {
  5389. this.clearCells(this._state.x, this._state.y, this._state.width, 1);
  5390. this._state = {
  5391. x: null,
  5392. y: null,
  5393. isFocused: null,
  5394. style: null,
  5395. width: null,
  5396. };
  5397. }
  5398. };
  5399. CursorRenderLayer.prototype._renderBarCursor = function (terminal, x, y, charData) {
  5400. this._ctx.save();
  5401. this._ctx.fillStyle = this._colors.cursor;
  5402. this.fillLeftLineAtCell(x, y);
  5403. this._ctx.restore();
  5404. };
  5405. CursorRenderLayer.prototype._renderBlockCursor = function (terminal, x, y, charData) {
  5406. this._ctx.save();
  5407. this._ctx.fillStyle = this._colors.cursor;
  5408. this.fillCells(x, y, charData[Buffer_1.CHAR_DATA_WIDTH_INDEX], 1);
  5409. this._ctx.fillStyle = this._colors.cursorAccent;
  5410. this.fillCharTrueColor(terminal, charData, x, y);
  5411. this._ctx.restore();
  5412. };
  5413. CursorRenderLayer.prototype._renderUnderlineCursor = function (terminal, x, y, charData) {
  5414. this._ctx.save();
  5415. this._ctx.fillStyle = this._colors.cursor;
  5416. this.fillBottomLineAtCells(x, y);
  5417. this._ctx.restore();
  5418. };
  5419. CursorRenderLayer.prototype._renderBlurCursor = function (terminal, x, y, charData) {
  5420. this._ctx.save();
  5421. this._ctx.strokeStyle = this._colors.cursor;
  5422. this.strokeRectAtCell(x, y, charData[Buffer_1.CHAR_DATA_WIDTH_INDEX], 1);
  5423. this._ctx.restore();
  5424. };
  5425. return CursorRenderLayer;
  5426. }(BaseRenderLayer_1.BaseRenderLayer));
  5427. exports.CursorRenderLayer = CursorRenderLayer;
  5428. var CursorBlinkStateManager = (function () {
  5429. function CursorBlinkStateManager(terminal, renderCallback) {
  5430. this.renderCallback = renderCallback;
  5431. this.isCursorVisible = true;
  5432. if (terminal.isFocused) {
  5433. this._restartInterval();
  5434. }
  5435. }
  5436. Object.defineProperty(CursorBlinkStateManager.prototype, "isPaused", {
  5437. get: function () { return !(this._blinkStartTimeout || this._blinkInterval); },
  5438. enumerable: true,
  5439. configurable: true
  5440. });
  5441. CursorBlinkStateManager.prototype.dispose = function () {
  5442. if (this._blinkInterval) {
  5443. window.clearInterval(this._blinkInterval);
  5444. this._blinkInterval = null;
  5445. }
  5446. if (this._blinkStartTimeout) {
  5447. window.clearTimeout(this._blinkStartTimeout);
  5448. this._blinkStartTimeout = null;
  5449. }
  5450. if (this._animationFrame) {
  5451. window.cancelAnimationFrame(this._animationFrame);
  5452. this._animationFrame = null;
  5453. }
  5454. };
  5455. CursorBlinkStateManager.prototype.restartBlinkAnimation = function (terminal) {
  5456. var _this = this;
  5457. if (this.isPaused) {
  5458. return;
  5459. }
  5460. this._animationTimeRestarted = Date.now();
  5461. this.isCursorVisible = true;
  5462. if (!this._animationFrame) {
  5463. this._animationFrame = window.requestAnimationFrame(function () {
  5464. _this.renderCallback();
  5465. _this._animationFrame = null;
  5466. });
  5467. }
  5468. };
  5469. CursorBlinkStateManager.prototype._restartInterval = function (timeToStart) {
  5470. var _this = this;
  5471. if (timeToStart === void 0) { timeToStart = BLINK_INTERVAL; }
  5472. if (this._blinkInterval) {
  5473. window.clearInterval(this._blinkInterval);
  5474. }
  5475. this._blinkStartTimeout = setTimeout(function () {
  5476. if (_this._animationTimeRestarted) {
  5477. var time = BLINK_INTERVAL - (Date.now() - _this._animationTimeRestarted);
  5478. _this._animationTimeRestarted = null;
  5479. if (time > 0) {
  5480. _this._restartInterval(time);
  5481. return;
  5482. }
  5483. }
  5484. _this.isCursorVisible = false;
  5485. _this._animationFrame = window.requestAnimationFrame(function () {
  5486. _this.renderCallback();
  5487. _this._animationFrame = null;
  5488. });
  5489. _this._blinkInterval = setInterval(function () {
  5490. if (_this._animationTimeRestarted) {
  5491. var time = BLINK_INTERVAL - (Date.now() - _this._animationTimeRestarted);
  5492. _this._animationTimeRestarted = null;
  5493. _this._restartInterval(time);
  5494. return;
  5495. }
  5496. _this.isCursorVisible = !_this.isCursorVisible;
  5497. _this._animationFrame = window.requestAnimationFrame(function () {
  5498. _this.renderCallback();
  5499. _this._animationFrame = null;
  5500. });
  5501. }, BLINK_INTERVAL);
  5502. }, timeToStart);
  5503. };
  5504. CursorBlinkStateManager.prototype.pause = function () {
  5505. this.isCursorVisible = true;
  5506. if (this._blinkInterval) {
  5507. window.clearInterval(this._blinkInterval);
  5508. this._blinkInterval = null;
  5509. }
  5510. if (this._blinkStartTimeout) {
  5511. window.clearTimeout(this._blinkStartTimeout);
  5512. this._blinkStartTimeout = null;
  5513. }
  5514. if (this._animationFrame) {
  5515. window.cancelAnimationFrame(this._animationFrame);
  5516. this._animationFrame = null;
  5517. }
  5518. };
  5519. CursorBlinkStateManager.prototype.resume = function (terminal) {
  5520. this._animationTimeRestarted = null;
  5521. this._restartInterval();
  5522. this.restartBlinkAnimation(terminal);
  5523. };
  5524. return CursorBlinkStateManager;
  5525. }());
  5526. },{"../Buffer":1,"./BaseRenderLayer":19}],23:[function(require,module,exports){
  5527. "use strict";
  5528. Object.defineProperty(exports, "__esModule", { value: true });
  5529. var GridCache = (function () {
  5530. function GridCache() {
  5531. this.cache = [];
  5532. }
  5533. GridCache.prototype.resize = function (width, height) {
  5534. for (var x = 0; x < width; x++) {
  5535. if (this.cache.length <= x) {
  5536. this.cache.push([]);
  5537. }
  5538. for (var y = this.cache[x].length; y < height; y++) {
  5539. this.cache[x].push(null);
  5540. }
  5541. this.cache[x].length = height;
  5542. }
  5543. this.cache.length = width;
  5544. };
  5545. GridCache.prototype.clear = function () {
  5546. for (var x = 0; x < this.cache.length; x++) {
  5547. for (var y = 0; y < this.cache[x].length; y++) {
  5548. this.cache[x][y] = null;
  5549. }
  5550. }
  5551. };
  5552. return GridCache;
  5553. }());
  5554. exports.GridCache = GridCache;
  5555. },{}],24:[function(require,module,exports){
  5556. "use strict";
  5557. var __extends = (this && this.__extends) || (function () {
  5558. var extendStatics = Object.setPrototypeOf ||
  5559. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5560. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5561. return function (d, b) {
  5562. extendStatics(d, b);
  5563. function __() { this.constructor = d; }
  5564. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5565. };
  5566. })();
  5567. Object.defineProperty(exports, "__esModule", { value: true });
  5568. var Types_1 = require("../Types");
  5569. var BaseRenderLayer_1 = require("./BaseRenderLayer");
  5570. var LinkRenderLayer = (function (_super) {
  5571. __extends(LinkRenderLayer, _super);
  5572. function LinkRenderLayer(container, zIndex, colors, terminal) {
  5573. var _this = _super.call(this, container, 'link', zIndex, true, colors) || this;
  5574. _this._state = null;
  5575. terminal.linkifier.on(Types_1.LinkHoverEventTypes.HOVER, function (e) { return _this._onLinkHover(e); });
  5576. terminal.linkifier.on(Types_1.LinkHoverEventTypes.LEAVE, function (e) { return _this._onLinkLeave(e); });
  5577. return _this;
  5578. }
  5579. LinkRenderLayer.prototype.resize = function (terminal, dim, charSizeChanged) {
  5580. _super.prototype.resize.call(this, terminal, dim, charSizeChanged);
  5581. this._state = null;
  5582. };
  5583. LinkRenderLayer.prototype.reset = function (terminal) {
  5584. this._clearCurrentLink();
  5585. };
  5586. LinkRenderLayer.prototype._clearCurrentLink = function () {
  5587. if (this._state) {
  5588. this.clearCells(this._state.x, this._state.y, this._state.length, 1);
  5589. this._state = null;
  5590. }
  5591. };
  5592. LinkRenderLayer.prototype._onLinkHover = function (e) {
  5593. this._ctx.fillStyle = this._colors.foreground;
  5594. this.fillBottomLineAtCells(e.x, e.y, e.length);
  5595. this._state = e;
  5596. };
  5597. LinkRenderLayer.prototype._onLinkLeave = function (e) {
  5598. this._clearCurrentLink();
  5599. };
  5600. return LinkRenderLayer;
  5601. }(BaseRenderLayer_1.BaseRenderLayer));
  5602. exports.LinkRenderLayer = LinkRenderLayer;
  5603. },{"../Types":14,"./BaseRenderLayer":19}],25:[function(require,module,exports){
  5604. "use strict";
  5605. var __extends = (this && this.__extends) || (function () {
  5606. var extendStatics = Object.setPrototypeOf ||
  5607. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5608. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5609. return function (d, b) {
  5610. extendStatics(d, b);
  5611. function __() { this.constructor = d; }
  5612. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5613. };
  5614. })();
  5615. Object.defineProperty(exports, "__esModule", { value: true });
  5616. var TextRenderLayer_1 = require("./TextRenderLayer");
  5617. var SelectionRenderLayer_1 = require("./SelectionRenderLayer");
  5618. var CursorRenderLayer_1 = require("./CursorRenderLayer");
  5619. var ColorManager_1 = require("./ColorManager");
  5620. var LinkRenderLayer_1 = require("./LinkRenderLayer");
  5621. var EventEmitter_1 = require("../EventEmitter");
  5622. var ScreenDprMonitor_1 = require("../utils/ScreenDprMonitor");
  5623. var Renderer = (function (_super) {
  5624. __extends(Renderer, _super);
  5625. function Renderer(_terminal, theme) {
  5626. var _this = _super.call(this) || this;
  5627. _this._terminal = _terminal;
  5628. _this._refreshRowsQueue = [];
  5629. _this._refreshAnimationFrame = null;
  5630. _this._isPaused = false;
  5631. _this._needsFullRefresh = false;
  5632. _this.colorManager = new ColorManager_1.ColorManager();
  5633. if (theme) {
  5634. _this.colorManager.setTheme(theme);
  5635. }
  5636. _this._renderLayers = [
  5637. new TextRenderLayer_1.TextRenderLayer(_this._terminal.screenElement, 0, _this.colorManager.colors, _this._terminal.options.allowTransparency),
  5638. new SelectionRenderLayer_1.SelectionRenderLayer(_this._terminal.screenElement, 1, _this.colorManager.colors),
  5639. new LinkRenderLayer_1.LinkRenderLayer(_this._terminal.screenElement, 2, _this.colorManager.colors, _this._terminal),
  5640. new CursorRenderLayer_1.CursorRenderLayer(_this._terminal.screenElement, 3, _this.colorManager.colors)
  5641. ];
  5642. _this.dimensions = {
  5643. scaledCharWidth: null,
  5644. scaledCharHeight: null,
  5645. scaledCellWidth: null,
  5646. scaledCellHeight: null,
  5647. scaledCharLeft: null,
  5648. scaledCharTop: null,
  5649. scaledCanvasWidth: null,
  5650. scaledCanvasHeight: null,
  5651. canvasWidth: null,
  5652. canvasHeight: null,
  5653. actualCellWidth: null,
  5654. actualCellHeight: null
  5655. };
  5656. _this._devicePixelRatio = window.devicePixelRatio;
  5657. _this._updateDimensions();
  5658. _this.onOptionsChanged();
  5659. _this._screenDprMonitor = new ScreenDprMonitor_1.ScreenDprMonitor();
  5660. _this._screenDprMonitor.setListener(function () { return _this.onWindowResize(window.devicePixelRatio); });
  5661. if ('IntersectionObserver' in window) {
  5662. var observer = new IntersectionObserver(function (e) { return _this.onIntersectionChange(e[0]); }, { threshold: 0 });
  5663. observer.observe(_this._terminal.element);
  5664. }
  5665. return _this;
  5666. }
  5667. Renderer.prototype.onIntersectionChange = function (entry) {
  5668. this._isPaused = entry.intersectionRatio === 0;
  5669. if (!this._isPaused && this._needsFullRefresh) {
  5670. this._terminal.refresh(0, this._terminal.rows - 1);
  5671. }
  5672. };
  5673. Renderer.prototype.onWindowResize = function (devicePixelRatio) {
  5674. if (this._devicePixelRatio !== devicePixelRatio) {
  5675. this._devicePixelRatio = devicePixelRatio;
  5676. this.onResize(this._terminal.cols, this._terminal.rows, true);
  5677. }
  5678. };
  5679. Renderer.prototype.setTheme = function (theme) {
  5680. var _this = this;
  5681. this.colorManager.setTheme(theme);
  5682. this._renderLayers.forEach(function (l) {
  5683. l.onThemeChanged(_this._terminal, _this.colorManager.colors);
  5684. l.reset(_this._terminal);
  5685. });
  5686. if (this._isPaused) {
  5687. this._needsFullRefresh = true;
  5688. }
  5689. else {
  5690. this._terminal.refresh(0, this._terminal.rows - 1);
  5691. }
  5692. return this.colorManager.colors;
  5693. };
  5694. Renderer.prototype.onResize = function (cols, rows, didCharSizeChange) {
  5695. var _this = this;
  5696. this._updateDimensions();
  5697. this._renderLayers.forEach(function (l) { return l.resize(_this._terminal, _this.dimensions, didCharSizeChange); });
  5698. if (this._isPaused) {
  5699. this._needsFullRefresh = true;
  5700. }
  5701. else {
  5702. this._terminal.refresh(0, this._terminal.rows - 1);
  5703. }
  5704. this._terminal.screenElement.style.width = this.dimensions.canvasWidth + this._terminal.viewport.scrollBarWidth + "px";
  5705. this._terminal.screenElement.style.height = this.dimensions.canvasHeight + "px";
  5706. this.emit('resize', {
  5707. width: this.dimensions.canvasWidth,
  5708. height: this.dimensions.canvasHeight
  5709. });
  5710. };
  5711. Renderer.prototype.onCharSizeChanged = function () {
  5712. this.onResize(this._terminal.cols, this._terminal.rows, true);
  5713. };
  5714. Renderer.prototype.onBlur = function () {
  5715. var _this = this;
  5716. this._runOperation(function (l) { return l.onBlur(_this._terminal); });
  5717. };
  5718. Renderer.prototype.onFocus = function () {
  5719. var _this = this;
  5720. this._runOperation(function (l) { return l.onFocus(_this._terminal); });
  5721. };
  5722. Renderer.prototype.onSelectionChanged = function (start, end) {
  5723. var _this = this;
  5724. this._runOperation(function (l) { return l.onSelectionChanged(_this._terminal, start, end); });
  5725. };
  5726. Renderer.prototype.onCursorMove = function () {
  5727. var _this = this;
  5728. this._runOperation(function (l) { return l.onCursorMove(_this._terminal); });
  5729. };
  5730. Renderer.prototype.onOptionsChanged = function () {
  5731. var _this = this;
  5732. this._runOperation(function (l) { return l.onOptionsChanged(_this._terminal); });
  5733. };
  5734. Renderer.prototype.clear = function () {
  5735. var _this = this;
  5736. this._runOperation(function (l) { return l.reset(_this._terminal); });
  5737. };
  5738. Renderer.prototype._runOperation = function (operation) {
  5739. if (this._isPaused) {
  5740. this._needsFullRefresh = true;
  5741. }
  5742. else {
  5743. this._renderLayers.forEach(function (l) { return operation(l); });
  5744. }
  5745. };
  5746. Renderer.prototype.queueRefresh = function (start, end) {
  5747. if (this._isPaused) {
  5748. this._needsFullRefresh = true;
  5749. return;
  5750. }
  5751. this._refreshRowsQueue.push({ start: start, end: end });
  5752. if (!this._refreshAnimationFrame) {
  5753. this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
  5754. }
  5755. };
  5756. Renderer.prototype._refreshLoop = function () {
  5757. var _this = this;
  5758. var start;
  5759. var end;
  5760. if (this._refreshRowsQueue.length > 4) {
  5761. start = 0;
  5762. end = this._terminal.rows - 1;
  5763. }
  5764. else {
  5765. start = this._refreshRowsQueue[0].start;
  5766. end = this._refreshRowsQueue[0].end;
  5767. for (var i = 1; i < this._refreshRowsQueue.length; i++) {
  5768. if (this._refreshRowsQueue[i].start < start) {
  5769. start = this._refreshRowsQueue[i].start;
  5770. }
  5771. if (this._refreshRowsQueue[i].end > end) {
  5772. end = this._refreshRowsQueue[i].end;
  5773. }
  5774. }
  5775. }
  5776. this._refreshRowsQueue = [];
  5777. this._refreshAnimationFrame = null;
  5778. start = Math.max(start, 0);
  5779. end = Math.min(end, this._terminal.rows - 1);
  5780. this._renderLayers.forEach(function (l) { return l.onGridChanged(_this._terminal, start, end); });
  5781. this._terminal.emit('refresh', { start: start, end: end });
  5782. };
  5783. Renderer.prototype._updateDimensions = function () {
  5784. if (!this._terminal.charMeasure.width || !this._terminal.charMeasure.height) {
  5785. return;
  5786. }
  5787. this.dimensions.scaledCharWidth = Math.floor(this._terminal.charMeasure.width * window.devicePixelRatio);
  5788. this.dimensions.scaledCharHeight = Math.ceil(this._terminal.charMeasure.height * window.devicePixelRatio);
  5789. this.dimensions.scaledCellHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.options.lineHeight);
  5790. this.dimensions.scaledCharTop = this._terminal.options.lineHeight === 1 ? 0 : Math.round((this.dimensions.scaledCellHeight - this.dimensions.scaledCharHeight) / 2);
  5791. this.dimensions.scaledCellWidth = this.dimensions.scaledCharWidth + Math.round(this._terminal.options.letterSpacing);
  5792. this.dimensions.scaledCharLeft = Math.floor(this._terminal.options.letterSpacing / 2);
  5793. this.dimensions.scaledCanvasHeight = this._terminal.rows * this.dimensions.scaledCellHeight;
  5794. this.dimensions.scaledCanvasWidth = this._terminal.cols * this.dimensions.scaledCellWidth;
  5795. this.dimensions.canvasHeight = Math.round(this.dimensions.scaledCanvasHeight / window.devicePixelRatio);
  5796. this.dimensions.canvasWidth = Math.round(this.dimensions.scaledCanvasWidth / window.devicePixelRatio);
  5797. this.dimensions.actualCellHeight = this.dimensions.canvasHeight / this._terminal.rows;
  5798. this.dimensions.actualCellWidth = this.dimensions.canvasWidth / this._terminal.cols;
  5799. };
  5800. return Renderer;
  5801. }(EventEmitter_1.EventEmitter));
  5802. exports.Renderer = Renderer;
  5803. },{"../EventEmitter":7,"../utils/ScreenDprMonitor":34,"./ColorManager":21,"./CursorRenderLayer":22,"./LinkRenderLayer":24,"./SelectionRenderLayer":26,"./TextRenderLayer":27}],26:[function(require,module,exports){
  5804. "use strict";
  5805. var __extends = (this && this.__extends) || (function () {
  5806. var extendStatics = Object.setPrototypeOf ||
  5807. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5808. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5809. return function (d, b) {
  5810. extendStatics(d, b);
  5811. function __() { this.constructor = d; }
  5812. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5813. };
  5814. })();
  5815. Object.defineProperty(exports, "__esModule", { value: true });
  5816. var BaseRenderLayer_1 = require("./BaseRenderLayer");
  5817. var SelectionRenderLayer = (function (_super) {
  5818. __extends(SelectionRenderLayer, _super);
  5819. function SelectionRenderLayer(container, zIndex, colors) {
  5820. var _this = _super.call(this, container, 'selection', zIndex, true, colors) || this;
  5821. _this._state = {
  5822. start: null,
  5823. end: null
  5824. };
  5825. return _this;
  5826. }
  5827. SelectionRenderLayer.prototype.resize = function (terminal, dim, charSizeChanged) {
  5828. _super.prototype.resize.call(this, terminal, dim, charSizeChanged);
  5829. this._state = {
  5830. start: null,
  5831. end: null
  5832. };
  5833. };
  5834. SelectionRenderLayer.prototype.reset = function (terminal) {
  5835. if (this._state.start && this._state.end) {
  5836. this._state = {
  5837. start: null,
  5838. end: null
  5839. };
  5840. this.clearAll();
  5841. }
  5842. };
  5843. SelectionRenderLayer.prototype.onSelectionChanged = function (terminal, start, end) {
  5844. if (this._state.start === start || this._state.end === end) {
  5845. return;
  5846. }
  5847. this.clearAll();
  5848. if (!start || !end) {
  5849. return;
  5850. }
  5851. var viewportStartRow = start[1] - terminal.buffer.ydisp;
  5852. var viewportEndRow = end[1] - terminal.buffer.ydisp;
  5853. var viewportCappedStartRow = Math.max(viewportStartRow, 0);
  5854. var viewportCappedEndRow = Math.min(viewportEndRow, terminal.rows - 1);
  5855. if (viewportCappedStartRow >= terminal.rows || viewportCappedEndRow < 0) {
  5856. return;
  5857. }
  5858. var startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
  5859. var startRowEndCol = viewportCappedStartRow === viewportCappedEndRow ? end[0] : terminal.cols;
  5860. this._ctx.fillStyle = this._colors.selection;
  5861. this.fillCells(startCol, viewportCappedStartRow, startRowEndCol - startCol, 1);
  5862. var middleRowsCount = Math.max(viewportCappedEndRow - viewportCappedStartRow - 1, 0);
  5863. this.fillCells(0, viewportCappedStartRow + 1, terminal.cols, middleRowsCount);
  5864. if (viewportCappedStartRow !== viewportCappedEndRow) {
  5865. var endCol = viewportEndRow === viewportCappedEndRow ? end[0] : terminal.cols;
  5866. this.fillCells(0, viewportCappedEndRow, endCol, 1);
  5867. }
  5868. this._state.start = [start[0], start[1]];
  5869. this._state.end = [end[0], end[1]];
  5870. };
  5871. return SelectionRenderLayer;
  5872. }(BaseRenderLayer_1.BaseRenderLayer));
  5873. exports.SelectionRenderLayer = SelectionRenderLayer;
  5874. },{"./BaseRenderLayer":19}],27:[function(require,module,exports){
  5875. "use strict";
  5876. var __extends = (this && this.__extends) || (function () {
  5877. var extendStatics = Object.setPrototypeOf ||
  5878. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5879. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5880. return function (d, b) {
  5881. extendStatics(d, b);
  5882. function __() { this.constructor = d; }
  5883. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5884. };
  5885. })();
  5886. Object.defineProperty(exports, "__esModule", { value: true });
  5887. var Buffer_1 = require("../Buffer");
  5888. var Types_1 = require("./Types");
  5889. var GridCache_1 = require("./GridCache");
  5890. var BaseRenderLayer_1 = require("./BaseRenderLayer");
  5891. var OVERLAP_OWNED_CHAR_DATA = [null, '', 0, -1];
  5892. var TextRenderLayer = (function (_super) {
  5893. __extends(TextRenderLayer, _super);
  5894. function TextRenderLayer(container, zIndex, colors, alpha) {
  5895. var _this = _super.call(this, container, 'text', zIndex, alpha, colors) || this;
  5896. _this._characterOverlapCache = {};
  5897. _this._state = new GridCache_1.GridCache();
  5898. return _this;
  5899. }
  5900. TextRenderLayer.prototype.resize = function (terminal, dim, charSizeChanged) {
  5901. _super.prototype.resize.call(this, terminal, dim, charSizeChanged);
  5902. var terminalFont = this._getFont(terminal, false);
  5903. if (this._characterWidth !== dim.scaledCharWidth || this._characterFont !== terminalFont) {
  5904. this._characterWidth = dim.scaledCharWidth;
  5905. this._characterFont = terminalFont;
  5906. this._characterOverlapCache = {};
  5907. }
  5908. this._state.clear();
  5909. this._state.resize(terminal.cols, terminal.rows);
  5910. };
  5911. TextRenderLayer.prototype.reset = function (terminal) {
  5912. this._state.clear();
  5913. this.clearAll();
  5914. };
  5915. TextRenderLayer.prototype.onGridChanged = function (terminal, startRow, endRow) {
  5916. if (this._state.cache.length === 0) {
  5917. return;
  5918. }
  5919. for (var y = startRow; y <= endRow; y++) {
  5920. var row = y + terminal.buffer.ydisp;
  5921. var line = terminal.buffer.lines.get(row);
  5922. this.clearCells(0, y, terminal.cols, 1);
  5923. for (var x = 0; x < terminal.cols; x++) {
  5924. var charData = line[x];
  5925. var code = charData[Buffer_1.CHAR_DATA_CODE_INDEX];
  5926. var char = charData[Buffer_1.CHAR_DATA_CHAR_INDEX];
  5927. var attr = charData[Buffer_1.CHAR_DATA_ATTR_INDEX];
  5928. var width = charData[Buffer_1.CHAR_DATA_WIDTH_INDEX];
  5929. if (width === 0) {
  5930. continue;
  5931. }
  5932. if (code === 32) {
  5933. if (x > 0) {
  5934. var previousChar = line[x - 1];
  5935. if (this._isOverlapping(previousChar)) {
  5936. continue;
  5937. }
  5938. }
  5939. }
  5940. var flags = attr >> 18;
  5941. var bg = attr & 0x1ff;
  5942. var isDefaultBackground = bg >= 256;
  5943. var isInvisible = flags & Types_1.FLAGS.INVISIBLE;
  5944. var isInverted = flags & Types_1.FLAGS.INVERSE;
  5945. if (!code || (code === 32 && isDefaultBackground && !isInverted) || isInvisible) {
  5946. continue;
  5947. }
  5948. if (width !== 0 && this._isOverlapping(charData)) {
  5949. if (x < line.length - 1 && line[x + 1][Buffer_1.CHAR_DATA_CODE_INDEX] === 32) {
  5950. width = 2;
  5951. }
  5952. }
  5953. var fg = (attr >> 9) & 0x1ff;
  5954. if (isInverted) {
  5955. var temp = bg;
  5956. bg = fg;
  5957. fg = temp;
  5958. if (fg === 256) {
  5959. fg = BaseRenderLayer_1.INVERTED_DEFAULT_COLOR;
  5960. }
  5961. if (bg === 257) {
  5962. bg = BaseRenderLayer_1.INVERTED_DEFAULT_COLOR;
  5963. }
  5964. }
  5965. if (width === 2) {
  5966. }
  5967. if (bg < 256) {
  5968. this._ctx.save();
  5969. this._ctx.fillStyle = (bg === BaseRenderLayer_1.INVERTED_DEFAULT_COLOR ? this._colors.foreground : this._colors.ansi[bg]);
  5970. this.fillCells(x, y, width, 1);
  5971. this._ctx.restore();
  5972. }
  5973. this._ctx.save();
  5974. if (flags & Types_1.FLAGS.BOLD) {
  5975. this._ctx.font = this._getFont(terminal, true);
  5976. if (fg < 8) {
  5977. fg += 8;
  5978. }
  5979. }
  5980. if (flags & Types_1.FLAGS.UNDERLINE) {
  5981. if (fg === BaseRenderLayer_1.INVERTED_DEFAULT_COLOR) {
  5982. this._ctx.fillStyle = this._colors.background;
  5983. }
  5984. else if (fg < 256) {
  5985. this._ctx.fillStyle = this._colors.ansi[fg];
  5986. }
  5987. else {
  5988. this._ctx.fillStyle = this._colors.foreground;
  5989. }
  5990. this.fillBottomLineAtCells(x, y);
  5991. }
  5992. this.drawChar(terminal, char, code, width, x, y, fg, bg, !!(flags & Types_1.FLAGS.BOLD), !!(flags & Types_1.FLAGS.DIM));
  5993. this._ctx.restore();
  5994. }
  5995. }
  5996. };
  5997. TextRenderLayer.prototype.onOptionsChanged = function (terminal) {
  5998. this.setTransparency(terminal, terminal.options.allowTransparency);
  5999. };
  6000. TextRenderLayer.prototype._isOverlapping = function (charData) {
  6001. if (charData[Buffer_1.CHAR_DATA_WIDTH_INDEX] !== 1) {
  6002. return false;
  6003. }
  6004. var code = charData[Buffer_1.CHAR_DATA_CODE_INDEX];
  6005. if (code < 256) {
  6006. return false;
  6007. }
  6008. var char = charData[Buffer_1.CHAR_DATA_CHAR_INDEX];
  6009. if (this._characterOverlapCache.hasOwnProperty(char)) {
  6010. return this._characterOverlapCache[char];
  6011. }
  6012. this._ctx.save();
  6013. this._ctx.font = this._characterFont;
  6014. var overlaps = Math.floor(this._ctx.measureText(char).width) > this._characterWidth;
  6015. this._ctx.restore();
  6016. this._characterOverlapCache[char] = overlaps;
  6017. return overlaps;
  6018. };
  6019. TextRenderLayer.prototype._clearChar = function (x, y) {
  6020. var colsToClear = 1;
  6021. var state = this._state.cache[x][y];
  6022. if (state && state[Buffer_1.CHAR_DATA_WIDTH_INDEX] === 2) {
  6023. colsToClear = 2;
  6024. }
  6025. this.clearCells(x, y, colsToClear, 1);
  6026. };
  6027. return TextRenderLayer;
  6028. }(BaseRenderLayer_1.BaseRenderLayer));
  6029. exports.TextRenderLayer = TextRenderLayer;
  6030. },{"../Buffer":1,"./BaseRenderLayer":19,"./GridCache":23,"./Types":28}],28:[function(require,module,exports){
  6031. "use strict";
  6032. Object.defineProperty(exports, "__esModule", { value: true });
  6033. var FLAGS;
  6034. (function (FLAGS) {
  6035. FLAGS[FLAGS["BOLD"] = 1] = "BOLD";
  6036. FLAGS[FLAGS["UNDERLINE"] = 2] = "UNDERLINE";
  6037. FLAGS[FLAGS["BLINK"] = 4] = "BLINK";
  6038. FLAGS[FLAGS["INVERSE"] = 8] = "INVERSE";
  6039. FLAGS[FLAGS["INVISIBLE"] = 16] = "INVISIBLE";
  6040. FLAGS[FLAGS["DIM"] = 32] = "DIM";
  6041. })(FLAGS = exports.FLAGS || (exports.FLAGS = {}));
  6042. },{}],29:[function(require,module,exports){
  6043. "use strict";
  6044. Object.defineProperty(exports, "__esModule", { value: true });
  6045. var Browser_1 = require("./utils/Browser");
  6046. exports.CHAR_ATLAS_CELL_SPACING = 1;
  6047. function generateCharAtlas(context, canvasFactory, request) {
  6048. var cellWidth = request.scaledCharWidth + exports.CHAR_ATLAS_CELL_SPACING;
  6049. var cellHeight = request.scaledCharHeight + exports.CHAR_ATLAS_CELL_SPACING;
  6050. var canvas = canvasFactory(255 * cellWidth, (2 + 16) * cellHeight);
  6051. var ctx = canvas.getContext('2d', { alpha: request.allowTransparency });
  6052. ctx.fillStyle = request.background;
  6053. ctx.fillRect(0, 0, canvas.width, canvas.height);
  6054. ctx.save();
  6055. ctx.fillStyle = request.foreground;
  6056. ctx.font = getFont(request.fontWeight, request);
  6057. ctx.textBaseline = 'top';
  6058. for (var i = 0; i < 256; i++) {
  6059. ctx.save();
  6060. ctx.beginPath();
  6061. ctx.rect(i * cellWidth, 0, cellWidth, cellHeight);
  6062. ctx.clip();
  6063. ctx.fillText(String.fromCharCode(i), i * cellWidth, 0);
  6064. ctx.restore();
  6065. }
  6066. ctx.save();
  6067. ctx.font = getFont(request.fontWeightBold, request);
  6068. for (var i = 0; i < 256; i++) {
  6069. ctx.save();
  6070. ctx.beginPath();
  6071. ctx.rect(i * cellWidth, cellHeight, cellWidth, cellHeight);
  6072. ctx.clip();
  6073. ctx.fillText(String.fromCharCode(i), i * cellWidth, cellHeight);
  6074. ctx.restore();
  6075. }
  6076. ctx.restore();
  6077. ctx.font = getFont(request.fontWeight, request);
  6078. for (var colorIndex = 0; colorIndex < 16; colorIndex++) {
  6079. if (colorIndex === 8) {
  6080. ctx.font = getFont(request.fontWeightBold, request);
  6081. }
  6082. var y = (colorIndex + 2) * cellHeight;
  6083. for (var i = 0; i < 256; i++) {
  6084. ctx.save();
  6085. ctx.beginPath();
  6086. ctx.rect(i * cellWidth, y, cellWidth, cellHeight);
  6087. ctx.clip();
  6088. ctx.fillStyle = request.ansiColors[colorIndex];
  6089. ctx.fillText(String.fromCharCode(i), i * cellWidth, y);
  6090. ctx.restore();
  6091. }
  6092. }
  6093. ctx.restore();
  6094. if (!('createImageBitmap' in context) || Browser_1.isFirefox) {
  6095. if (canvas instanceof HTMLCanvasElement) {
  6096. return canvas;
  6097. }
  6098. else {
  6099. return new Promise(function (r) { return r(canvas.transferToImageBitmap()); });
  6100. }
  6101. }
  6102. var charAtlasImageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  6103. var r = parseInt(request.background.substr(1, 2), 16);
  6104. var g = parseInt(request.background.substr(3, 2), 16);
  6105. var b = parseInt(request.background.substr(5, 2), 16);
  6106. clearColor(charAtlasImageData, r, g, b);
  6107. return context.createImageBitmap(charAtlasImageData);
  6108. }
  6109. exports.generateCharAtlas = generateCharAtlas;
  6110. function clearColor(imageData, r, g, b) {
  6111. for (var offset = 0; offset < imageData.data.length; offset += 4) {
  6112. if (imageData.data[offset] === r &&
  6113. imageData.data[offset + 1] === g &&
  6114. imageData.data[offset + 2] === b) {
  6115. imageData.data[offset + 3] = 0;
  6116. }
  6117. }
  6118. }
  6119. function getFont(fontWeight, request) {
  6120. return fontWeight + " " + request.fontSize * request.devicePixelRatio + "px " + request.fontFamily;
  6121. }
  6122. },{"./utils/Browser":30}],30:[function(require,module,exports){
  6123. "use strict";
  6124. Object.defineProperty(exports, "__esModule", { value: true });
  6125. var isNode = (typeof navigator === 'undefined') ? true : false;
  6126. var userAgent = (isNode) ? 'node' : navigator.userAgent;
  6127. var platform = (isNode) ? 'node' : navigator.platform;
  6128. exports.isFirefox = !!~userAgent.indexOf('Firefox');
  6129. exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');
  6130. exports.isMac = contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform);
  6131. exports.isIpad = platform === 'iPad';
  6132. exports.isIphone = platform === 'iPhone';
  6133. exports.isMSWindows = contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
  6134. exports.isLinux = platform.indexOf('Linux') >= 0;
  6135. function contains(arr, el) {
  6136. return arr.indexOf(el) >= 0;
  6137. }
  6138. },{}],31:[function(require,module,exports){
  6139. "use strict";
  6140. var __extends = (this && this.__extends) || (function () {
  6141. var extendStatics = Object.setPrototypeOf ||
  6142. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6143. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6144. return function (d, b) {
  6145. extendStatics(d, b);
  6146. function __() { this.constructor = d; }
  6147. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6148. };
  6149. })();
  6150. Object.defineProperty(exports, "__esModule", { value: true });
  6151. var EventEmitter_1 = require("../EventEmitter");
  6152. var CharMeasure = (function (_super) {
  6153. __extends(CharMeasure, _super);
  6154. function CharMeasure(document, parentElement) {
  6155. var _this = _super.call(this) || this;
  6156. _this._document = document;
  6157. _this._parentElement = parentElement;
  6158. _this._measureElement = _this._document.createElement('span');
  6159. _this._measureElement.style.position = 'absolute';
  6160. _this._measureElement.style.top = '0';
  6161. _this._measureElement.style.left = '-9999em';
  6162. _this._measureElement.style.lineHeight = 'normal';
  6163. _this._measureElement.textContent = 'W';
  6164. _this._measureElement.setAttribute('aria-hidden', 'true');
  6165. _this._parentElement.appendChild(_this._measureElement);
  6166. return _this;
  6167. }
  6168. Object.defineProperty(CharMeasure.prototype, "width", {
  6169. get: function () {
  6170. return this._width;
  6171. },
  6172. enumerable: true,
  6173. configurable: true
  6174. });
  6175. Object.defineProperty(CharMeasure.prototype, "height", {
  6176. get: function () {
  6177. return this._height;
  6178. },
  6179. enumerable: true,
  6180. configurable: true
  6181. });
  6182. CharMeasure.prototype.measure = function (options) {
  6183. this._measureElement.style.fontFamily = options.fontFamily;
  6184. this._measureElement.style.fontSize = options.fontSize + "px";
  6185. var geometry = this._measureElement.getBoundingClientRect();
  6186. if (geometry.width === 0 || geometry.height === 0) {
  6187. return;
  6188. }
  6189. if (this._width !== geometry.width || this._height !== geometry.height) {
  6190. this._width = geometry.width;
  6191. this._height = Math.ceil(geometry.height);
  6192. this.emit('charsizechanged');
  6193. }
  6194. };
  6195. return CharMeasure;
  6196. }(EventEmitter_1.EventEmitter));
  6197. exports.CharMeasure = CharMeasure;
  6198. },{"../EventEmitter":7}],32:[function(require,module,exports){
  6199. "use strict";
  6200. var __extends = (this && this.__extends) || (function () {
  6201. var extendStatics = Object.setPrototypeOf ||
  6202. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6203. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6204. return function (d, b) {
  6205. extendStatics(d, b);
  6206. function __() { this.constructor = d; }
  6207. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6208. };
  6209. })();
  6210. Object.defineProperty(exports, "__esModule", { value: true });
  6211. var EventEmitter_1 = require("../EventEmitter");
  6212. var CircularList = (function (_super) {
  6213. __extends(CircularList, _super);
  6214. function CircularList(_maxLength) {
  6215. var _this = _super.call(this) || this;
  6216. _this._maxLength = _maxLength;
  6217. _this._array = new Array(_this._maxLength);
  6218. _this._startIndex = 0;
  6219. _this._length = 0;
  6220. return _this;
  6221. }
  6222. Object.defineProperty(CircularList.prototype, "maxLength", {
  6223. get: function () {
  6224. return this._maxLength;
  6225. },
  6226. set: function (newMaxLength) {
  6227. if (this._maxLength === newMaxLength) {
  6228. return;
  6229. }
  6230. var newArray = new Array(newMaxLength);
  6231. for (var i = 0; i < Math.min(newMaxLength, this.length); i++) {
  6232. newArray[i] = this._array[this._getCyclicIndex(i)];
  6233. }
  6234. this._array = newArray;
  6235. this._maxLength = newMaxLength;
  6236. this._startIndex = 0;
  6237. },
  6238. enumerable: true,
  6239. configurable: true
  6240. });
  6241. Object.defineProperty(CircularList.prototype, "length", {
  6242. get: function () {
  6243. return this._length;
  6244. },
  6245. set: function (newLength) {
  6246. if (newLength > this._length) {
  6247. for (var i = this._length; i < newLength; i++) {
  6248. this._array[i] = undefined;
  6249. }
  6250. }
  6251. this._length = newLength;
  6252. },
  6253. enumerable: true,
  6254. configurable: true
  6255. });
  6256. Object.defineProperty(CircularList.prototype, "forEach", {
  6257. get: function () {
  6258. var _this = this;
  6259. return function (callbackfn) {
  6260. var i = 0;
  6261. var length = _this.length;
  6262. for (var i_1 = 0; i_1 < length; i_1++) {
  6263. callbackfn(_this.get(i_1), i_1);
  6264. }
  6265. };
  6266. },
  6267. enumerable: true,
  6268. configurable: true
  6269. });
  6270. CircularList.prototype.get = function (index) {
  6271. return this._array[this._getCyclicIndex(index)];
  6272. };
  6273. CircularList.prototype.set = function (index, value) {
  6274. this._array[this._getCyclicIndex(index)] = value;
  6275. };
  6276. CircularList.prototype.push = function (value) {
  6277. this._array[this._getCyclicIndex(this._length)] = value;
  6278. if (this._length === this._maxLength) {
  6279. this._startIndex++;
  6280. if (this._startIndex === this._maxLength) {
  6281. this._startIndex = 0;
  6282. }
  6283. this.emit('trim', 1);
  6284. }
  6285. else {
  6286. this._length++;
  6287. }
  6288. };
  6289. CircularList.prototype.pop = function () {
  6290. return this._array[this._getCyclicIndex(this._length-- - 1)];
  6291. };
  6292. CircularList.prototype.splice = function (start, deleteCount) {
  6293. var items = [];
  6294. for (var _i = 2; _i < arguments.length; _i++) {
  6295. items[_i - 2] = arguments[_i];
  6296. }
  6297. if (deleteCount) {
  6298. for (var i = start; i < this._length - deleteCount; i++) {
  6299. this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
  6300. }
  6301. this._length -= deleteCount;
  6302. }
  6303. if (items && items.length) {
  6304. for (var i = this._length - 1; i >= start; i--) {
  6305. this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
  6306. }
  6307. for (var i = 0; i < items.length; i++) {
  6308. this._array[this._getCyclicIndex(start + i)] = items[i];
  6309. }
  6310. if (this._length + items.length > this.maxLength) {
  6311. var countToTrim = (this._length + items.length) - this.maxLength;
  6312. this._startIndex += countToTrim;
  6313. this._length = this.maxLength;
  6314. this.emit('trim', countToTrim);
  6315. }
  6316. else {
  6317. this._length += items.length;
  6318. }
  6319. }
  6320. };
  6321. CircularList.prototype.trimStart = function (count) {
  6322. if (count > this._length) {
  6323. count = this._length;
  6324. }
  6325. this._startIndex += count;
  6326. this._length -= count;
  6327. this.emit('trim', count);
  6328. };
  6329. CircularList.prototype.shiftElements = function (start, count, offset) {
  6330. if (count <= 0) {
  6331. return;
  6332. }
  6333. if (start < 0 || start >= this._length) {
  6334. throw new Error('start argument out of range');
  6335. }
  6336. if (start + offset < 0) {
  6337. throw new Error('Cannot shift elements in list beyond index 0');
  6338. }
  6339. if (offset > 0) {
  6340. for (var i = count - 1; i >= 0; i--) {
  6341. this.set(start + i + offset, this.get(start + i));
  6342. }
  6343. var expandListBy = (start + count + offset) - this._length;
  6344. if (expandListBy > 0) {
  6345. this._length += expandListBy;
  6346. while (this._length > this.maxLength) {
  6347. this._length--;
  6348. this._startIndex++;
  6349. this.emit('trim', 1);
  6350. }
  6351. }
  6352. }
  6353. else {
  6354. for (var i = 0; i < count; i++) {
  6355. this.set(start + i + offset, this.get(start + i));
  6356. }
  6357. }
  6358. };
  6359. CircularList.prototype._getCyclicIndex = function (index) {
  6360. return (this._startIndex + index) % this.maxLength;
  6361. };
  6362. return CircularList;
  6363. }(EventEmitter_1.EventEmitter));
  6364. exports.CircularList = CircularList;
  6365. },{"../EventEmitter":7}],33:[function(require,module,exports){
  6366. "use strict";
  6367. Object.defineProperty(exports, "__esModule", { value: true });
  6368. var MouseHelper = (function () {
  6369. function MouseHelper(_renderer) {
  6370. this._renderer = _renderer;
  6371. }
  6372. MouseHelper.getCoordsRelativeToElement = function (event, element) {
  6373. if (event.pageX == null) {
  6374. return null;
  6375. }
  6376. var originalElement = element;
  6377. var x = event.pageX;
  6378. var y = event.pageY;
  6379. while (element) {
  6380. x -= element.offsetLeft;
  6381. y -= element.offsetTop;
  6382. element = element.offsetParent;
  6383. }
  6384. element = originalElement;
  6385. while (element && element !== element.ownerDocument.body) {
  6386. x += element.scrollLeft;
  6387. y += element.scrollTop;
  6388. element = element.parentElement;
  6389. }
  6390. return [x, y];
  6391. };
  6392. MouseHelper.prototype.getCoords = function (event, element, charMeasure, lineHeight, colCount, rowCount, isSelection) {
  6393. if (!charMeasure.width || !charMeasure.height) {
  6394. return null;
  6395. }
  6396. var coords = MouseHelper.getCoordsRelativeToElement(event, element);
  6397. if (!coords) {
  6398. return null;
  6399. }
  6400. coords[0] = Math.ceil((coords[0] + (isSelection ? this._renderer.dimensions.actualCellWidth / 2 : 0)) / this._renderer.dimensions.actualCellWidth);
  6401. coords[1] = Math.ceil(coords[1] / this._renderer.dimensions.actualCellHeight);
  6402. coords[0] = Math.min(Math.max(coords[0], 1), colCount + (isSelection ? 1 : 0));
  6403. coords[1] = Math.min(Math.max(coords[1], 1), rowCount);
  6404. return coords;
  6405. };
  6406. MouseHelper.prototype.getRawByteCoords = function (event, element, charMeasure, lineHeight, colCount, rowCount) {
  6407. var coords = this.getCoords(event, element, charMeasure, lineHeight, colCount, rowCount);
  6408. var x = coords[0];
  6409. var y = coords[1];
  6410. x += 32;
  6411. y += 32;
  6412. return { x: x, y: y };
  6413. };
  6414. return MouseHelper;
  6415. }());
  6416. exports.MouseHelper = MouseHelper;
  6417. },{}],34:[function(require,module,exports){
  6418. "use strict";
  6419. Object.defineProperty(exports, "__esModule", { value: true });
  6420. var ScreenDprMonitor = (function () {
  6421. function ScreenDprMonitor() {
  6422. }
  6423. ScreenDprMonitor.prototype.setListener = function (listener) {
  6424. var _this = this;
  6425. if (this._listener) {
  6426. this.clearListener();
  6427. }
  6428. this._listener = listener;
  6429. this._outerListener = function () {
  6430. _this._listener(window.devicePixelRatio, _this._currentDevicePixelRatio);
  6431. _this._updateDpr();
  6432. };
  6433. this._updateDpr();
  6434. };
  6435. ScreenDprMonitor.prototype._updateDpr = function () {
  6436. if (this._resolutionMediaMatchList) {
  6437. this._resolutionMediaMatchList.removeListener(this._outerListener);
  6438. }
  6439. this._currentDevicePixelRatio = window.devicePixelRatio;
  6440. this._resolutionMediaMatchList = window.matchMedia("screen and (resolution: " + window.devicePixelRatio + "dppx)");
  6441. this._resolutionMediaMatchList.addListener(this._outerListener);
  6442. };
  6443. ScreenDprMonitor.prototype.clearListener = function () {
  6444. if (!this._listener) {
  6445. return;
  6446. }
  6447. this._resolutionMediaMatchList.removeListener(this._outerListener);
  6448. this._listener = null;
  6449. this._outerListener = null;
  6450. };
  6451. return ScreenDprMonitor;
  6452. }());
  6453. exports.ScreenDprMonitor = ScreenDprMonitor;
  6454. },{}],35:[function(require,module,exports){
  6455. "use strict";
  6456. Object.defineProperty(exports, "__esModule", { value: true });
  6457. exports.BELL_SOUND = 'data:audio/wav;base64,UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg==';
  6458. },{}],36:[function(require,module,exports){
  6459. "use strict";
  6460. Object.defineProperty(exports, "__esModule", { value: true });
  6461. var Terminal_1 = require("./Terminal");
  6462. module.exports = Terminal_1.Terminal;
  6463. },{"./Terminal":13}]},{},[36])(36)
  6464. });
  6465. //# sourceMappingURL=xterm.js.map