You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

xterm.js 186 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959
  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. exports.CHARSETS = {};
  5. exports.DEFAULT_CHARSET = exports.CHARSETS['B'];
  6. exports.CHARSETS['0'] = {
  7. '`': '\u25c6',
  8. 'a': '\u2592',
  9. 'b': '\u0009',
  10. 'c': '\u000c',
  11. 'd': '\u000d',
  12. 'e': '\u000a',
  13. 'f': '\u00b0',
  14. 'g': '\u00b1',
  15. 'h': '\u2424',
  16. 'i': '\u000b',
  17. 'j': '\u2518',
  18. 'k': '\u2510',
  19. 'l': '\u250c',
  20. 'm': '\u2514',
  21. 'n': '\u253c',
  22. 'o': '\u23ba',
  23. 'p': '\u23bb',
  24. 'q': '\u2500',
  25. 'r': '\u23bc',
  26. 's': '\u23bd',
  27. 't': '\u251c',
  28. 'u': '\u2524',
  29. 'v': '\u2534',
  30. 'w': '\u252c',
  31. 'x': '\u2502',
  32. 'y': '\u2264',
  33. 'z': '\u2265',
  34. '{': '\u03c0',
  35. '|': '\u2260',
  36. '}': '\u00a3',
  37. '~': '\u00b7'
  38. };
  39. exports.CHARSETS['A'] = {
  40. '#': '£'
  41. };
  42. exports.CHARSETS['B'] = null;
  43. exports.CHARSETS['4'] = {
  44. '#': '£',
  45. '@': '¾',
  46. '[': 'ij',
  47. '\\': '½',
  48. ']': '|',
  49. '{': '¨',
  50. '|': 'f',
  51. '}': '¼',
  52. '~': '´'
  53. };
  54. exports.CHARSETS['C'] =
  55. exports.CHARSETS['5'] = {
  56. '[': 'Ä',
  57. '\\': 'Ö',
  58. ']': 'Å',
  59. '^': 'Ü',
  60. '`': 'é',
  61. '{': 'ä',
  62. '|': 'ö',
  63. '}': 'å',
  64. '~': 'ü'
  65. };
  66. exports.CHARSETS['R'] = {
  67. '#': '£',
  68. '@': 'à',
  69. '[': '°',
  70. '\\': 'ç',
  71. ']': '§',
  72. '{': 'é',
  73. '|': 'ù',
  74. '}': 'è',
  75. '~': '¨'
  76. };
  77. exports.CHARSETS['Q'] = {
  78. '@': 'à',
  79. '[': 'â',
  80. '\\': 'ç',
  81. ']': 'ê',
  82. '^': 'î',
  83. '`': 'ô',
  84. '{': 'é',
  85. '|': 'ù',
  86. '}': 'è',
  87. '~': 'û'
  88. };
  89. exports.CHARSETS['K'] = {
  90. '@': '§',
  91. '[': 'Ä',
  92. '\\': 'Ö',
  93. ']': 'Ü',
  94. '{': 'ä',
  95. '|': 'ö',
  96. '}': 'ü',
  97. '~': 'ß'
  98. };
  99. exports.CHARSETS['Y'] = {
  100. '#': '£',
  101. '@': '§',
  102. '[': '°',
  103. '\\': 'ç',
  104. ']': 'é',
  105. '`': 'ù',
  106. '{': 'à',
  107. '|': 'ò',
  108. '}': 'è',
  109. '~': 'ì'
  110. };
  111. exports.CHARSETS['E'] =
  112. exports.CHARSETS['6'] = {
  113. '@': 'Ä',
  114. '[': 'Æ',
  115. '\\': 'Ø',
  116. ']': 'Å',
  117. '^': 'Ü',
  118. '`': 'ä',
  119. '{': 'æ',
  120. '|': 'ø',
  121. '}': 'å',
  122. '~': 'ü'
  123. };
  124. exports.CHARSETS['Z'] = {
  125. '#': '£',
  126. '@': '§',
  127. '[': '¡',
  128. '\\': 'Ñ',
  129. ']': '¿',
  130. '{': '°',
  131. '|': 'ñ',
  132. '}': 'ç'
  133. };
  134. exports.CHARSETS['H'] =
  135. exports.CHARSETS['7'] = {
  136. '@': 'É',
  137. '[': 'Ä',
  138. '\\': 'Ö',
  139. ']': 'Å',
  140. '^': 'Ü',
  141. '`': 'é',
  142. '{': 'ä',
  143. '|': 'ö',
  144. '}': 'å',
  145. '~': 'ü'
  146. };
  147. exports.CHARSETS['='] = {
  148. '#': 'ù',
  149. '@': 'à',
  150. '[': 'é',
  151. '\\': 'ç',
  152. ']': 'ê',
  153. '^': 'î',
  154. '_': 'è',
  155. '`': 'ô',
  156. '{': 'ä',
  157. '|': 'ö',
  158. '}': 'ü',
  159. '~': 'û'
  160. };
  161. },{}],2:[function(require,module,exports){
  162. "use strict";
  163. Object.defineProperty(exports, "__esModule", { value: true });
  164. var CompositionHelper = (function () {
  165. function CompositionHelper(textarea, compositionView, terminal) {
  166. this.textarea = textarea;
  167. this.compositionView = compositionView;
  168. this.terminal = terminal;
  169. this.isComposing = false;
  170. this.isSendingComposition = false;
  171. this.compositionPosition = { start: null, end: null };
  172. }
  173. CompositionHelper.prototype.compositionstart = function () {
  174. this.isComposing = true;
  175. this.compositionPosition.start = this.textarea.value.length;
  176. this.compositionView.textContent = '';
  177. this.compositionView.classList.add('active');
  178. };
  179. CompositionHelper.prototype.compositionupdate = function (ev) {
  180. var _this = this;
  181. this.compositionView.textContent = ev.data;
  182. this.updateCompositionElements();
  183. setTimeout(function () {
  184. _this.compositionPosition.end = _this.textarea.value.length;
  185. }, 0);
  186. };
  187. CompositionHelper.prototype.compositionend = function () {
  188. this.finalizeComposition(true);
  189. };
  190. CompositionHelper.prototype.keydown = function (ev) {
  191. if (this.isComposing || this.isSendingComposition) {
  192. if (ev.keyCode === 229) {
  193. return false;
  194. }
  195. else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
  196. return false;
  197. }
  198. else {
  199. this.finalizeComposition(false);
  200. }
  201. }
  202. if (ev.keyCode === 229) {
  203. this.handleAnyTextareaChanges();
  204. return false;
  205. }
  206. return true;
  207. };
  208. CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) {
  209. var _this = this;
  210. this.compositionView.classList.remove('active');
  211. this.isComposing = false;
  212. this.clearTextareaPosition();
  213. if (!waitForPropogation) {
  214. this.isSendingComposition = false;
  215. var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end);
  216. this.terminal.handler(input);
  217. }
  218. else {
  219. var currentCompositionPosition_1 = {
  220. start: this.compositionPosition.start,
  221. end: this.compositionPosition.end,
  222. };
  223. this.isSendingComposition = true;
  224. setTimeout(function () {
  225. if (_this.isSendingComposition) {
  226. _this.isSendingComposition = false;
  227. var input = void 0;
  228. if (_this.isComposing) {
  229. input = _this.textarea.value.substring(currentCompositionPosition_1.start, currentCompositionPosition_1.end);
  230. }
  231. else {
  232. input = _this.textarea.value.substring(currentCompositionPosition_1.start);
  233. }
  234. _this.terminal.handler(input);
  235. }
  236. }, 0);
  237. }
  238. };
  239. CompositionHelper.prototype.handleAnyTextareaChanges = function () {
  240. var _this = this;
  241. var oldValue = this.textarea.value;
  242. setTimeout(function () {
  243. if (!_this.isComposing) {
  244. var newValue = _this.textarea.value;
  245. var diff = newValue.replace(oldValue, '');
  246. if (diff.length > 0) {
  247. _this.terminal.handler(diff);
  248. }
  249. }
  250. }, 0);
  251. };
  252. CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) {
  253. var _this = this;
  254. if (!this.isComposing) {
  255. return;
  256. }
  257. var cursor = this.terminal.element.querySelector('.terminal-cursor');
  258. if (cursor) {
  259. var xtermRows = this.terminal.element.querySelector('.xterm-rows');
  260. var cursorTop = xtermRows.offsetTop + cursor.offsetTop;
  261. this.compositionView.style.left = cursor.offsetLeft + 'px';
  262. this.compositionView.style.top = cursorTop + 'px';
  263. this.compositionView.style.height = cursor.offsetHeight + 'px';
  264. this.compositionView.style.lineHeight = cursor.offsetHeight + 'px';
  265. var compositionViewBounds = this.compositionView.getBoundingClientRect();
  266. this.textarea.style.left = cursor.offsetLeft + 'px';
  267. this.textarea.style.top = cursorTop + 'px';
  268. this.textarea.style.width = compositionViewBounds.width + 'px';
  269. this.textarea.style.height = compositionViewBounds.height + 'px';
  270. this.textarea.style.lineHeight = compositionViewBounds.height + 'px';
  271. }
  272. if (!dontRecurse) {
  273. setTimeout(function () { return _this.updateCompositionElements(true); }, 0);
  274. }
  275. };
  276. ;
  277. CompositionHelper.prototype.clearTextareaPosition = function () {
  278. this.textarea.style.left = '';
  279. this.textarea.style.top = '';
  280. };
  281. ;
  282. return CompositionHelper;
  283. }());
  284. exports.CompositionHelper = CompositionHelper;
  285. },{}],3:[function(require,module,exports){
  286. "use strict";
  287. Object.defineProperty(exports, "__esModule", { value: true });
  288. var C0;
  289. (function (C0) {
  290. C0.NUL = '\x00';
  291. C0.SOH = '\x01';
  292. C0.STX = '\x02';
  293. C0.ETX = '\x03';
  294. C0.EOT = '\x04';
  295. C0.ENQ = '\x05';
  296. C0.ACK = '\x06';
  297. C0.BEL = '\x07';
  298. C0.BS = '\x08';
  299. C0.HT = '\x09';
  300. C0.LF = '\x0a';
  301. C0.VT = '\x0b';
  302. C0.FF = '\x0c';
  303. C0.CR = '\x0d';
  304. C0.SO = '\x0e';
  305. C0.SI = '\x0f';
  306. C0.DLE = '\x10';
  307. C0.DC1 = '\x11';
  308. C0.DC2 = '\x12';
  309. C0.DC3 = '\x13';
  310. C0.DC4 = '\x14';
  311. C0.NAK = '\x15';
  312. C0.SYN = '\x16';
  313. C0.ETB = '\x17';
  314. C0.CAN = '\x18';
  315. C0.EM = '\x19';
  316. C0.SUB = '\x1a';
  317. C0.ESC = '\x1b';
  318. C0.FS = '\x1c';
  319. C0.GS = '\x1d';
  320. C0.RS = '\x1e';
  321. C0.US = '\x1f';
  322. C0.SP = '\x20';
  323. C0.DEL = '\x7f';
  324. })(C0 = exports.C0 || (exports.C0 = {}));
  325. ;
  326. },{}],4:[function(require,module,exports){
  327. "use strict";
  328. Object.defineProperty(exports, "__esModule", { value: true });
  329. ;
  330. var EventEmitter = (function () {
  331. function EventEmitter() {
  332. this._events = this._events || {};
  333. }
  334. EventEmitter.prototype.on = function (type, listener) {
  335. this._events[type] = this._events[type] || [];
  336. this._events[type].push(listener);
  337. };
  338. EventEmitter.prototype.off = function (type, listener) {
  339. if (!this._events[type]) {
  340. return;
  341. }
  342. var obj = this._events[type];
  343. var i = obj.length;
  344. while (i--) {
  345. if (obj[i] === listener || obj[i].listener === listener) {
  346. obj.splice(i, 1);
  347. return;
  348. }
  349. }
  350. };
  351. EventEmitter.prototype.removeAllListeners = function (type) {
  352. if (this._events[type]) {
  353. delete this._events[type];
  354. }
  355. };
  356. EventEmitter.prototype.once = function (type, listener) {
  357. function on() {
  358. var args = Array.prototype.slice.call(arguments);
  359. this.off(type, on);
  360. return listener.apply(this, args);
  361. }
  362. on.listener = listener;
  363. return this.on(type, on);
  364. };
  365. EventEmitter.prototype.emit = function (type) {
  366. var args = [];
  367. for (var _i = 1; _i < arguments.length; _i++) {
  368. args[_i - 1] = arguments[_i];
  369. }
  370. if (!this._events[type]) {
  371. return;
  372. }
  373. var obj = this._events[type];
  374. for (var i = 0; i < obj.length; i++) {
  375. obj[i].apply(this, args);
  376. }
  377. };
  378. EventEmitter.prototype.listeners = function (type) {
  379. return this._events[type] || [];
  380. };
  381. return EventEmitter;
  382. }());
  383. exports.EventEmitter = EventEmitter;
  384. },{}],5:[function(require,module,exports){
  385. "use strict";
  386. Object.defineProperty(exports, "__esModule", { value: true });
  387. var EscapeSequences_1 = require("./EscapeSequences");
  388. var Charsets_1 = require("./Charsets");
  389. var InputHandler = (function () {
  390. function InputHandler(_terminal) {
  391. this._terminal = _terminal;
  392. }
  393. InputHandler.prototype.addChar = function (char, code) {
  394. if (char >= ' ') {
  395. var ch_width = wcwidth(code);
  396. if (this._terminal.charset && this._terminal.charset[char]) {
  397. char = this._terminal.charset[char];
  398. }
  399. var row = this._terminal.y + this._terminal.ybase;
  400. if (!ch_width && this._terminal.x) {
  401. if (this._terminal.lines.get(row)[this._terminal.x - 1]) {
  402. if (!this._terminal.lines.get(row)[this._terminal.x - 1][2]) {
  403. if (this._terminal.lines.get(row)[this._terminal.x - 2])
  404. this._terminal.lines.get(row)[this._terminal.x - 2][1] += char;
  405. }
  406. else {
  407. this._terminal.lines.get(row)[this._terminal.x - 1][1] += char;
  408. }
  409. this._terminal.updateRange(this._terminal.y);
  410. }
  411. return;
  412. }
  413. if (this._terminal.x + ch_width - 1 >= this._terminal.cols) {
  414. if (this._terminal.wraparoundMode) {
  415. this._terminal.x = 0;
  416. this._terminal.y++;
  417. if (this._terminal.y > this._terminal.scrollBottom) {
  418. this._terminal.y--;
  419. this._terminal.scroll(true);
  420. }
  421. else {
  422. this._terminal.lines.get(this._terminal.y).isWrapped = true;
  423. }
  424. }
  425. else {
  426. if (ch_width === 2)
  427. return;
  428. }
  429. }
  430. row = this._terminal.y + this._terminal.ybase;
  431. if (this._terminal.insertMode) {
  432. for (var moves = 0; moves < ch_width; ++moves) {
  433. var removed = this._terminal.lines.get(this._terminal.y + this._terminal.ybase).pop();
  434. if (removed[2] === 0
  435. && this._terminal.lines.get(row)[this._terminal.cols - 2]
  436. && this._terminal.lines.get(row)[this._terminal.cols - 2][2] === 2) {
  437. this._terminal.lines.get(row)[this._terminal.cols - 2] = [this._terminal.curAttr, ' ', 1];
  438. }
  439. this._terminal.lines.get(row).splice(this._terminal.x, 0, [this._terminal.curAttr, ' ', 1]);
  440. }
  441. }
  442. this._terminal.lines.get(row)[this._terminal.x] = [this._terminal.curAttr, char, ch_width];
  443. this._terminal.x++;
  444. this._terminal.updateRange(this._terminal.y);
  445. if (ch_width === 2) {
  446. this._terminal.lines.get(row)[this._terminal.x] = [this._terminal.curAttr, '', 0];
  447. this._terminal.x++;
  448. }
  449. }
  450. };
  451. InputHandler.prototype.bell = function () {
  452. var _this = this;
  453. if (!this._terminal.visualBell) {
  454. return;
  455. }
  456. this._terminal.element.style.borderColor = 'white';
  457. setTimeout(function () { return _this._terminal.element.style.borderColor = ''; }, 10);
  458. if (this._terminal.popOnBell) {
  459. this._terminal.focus();
  460. }
  461. };
  462. InputHandler.prototype.lineFeed = function () {
  463. if (this._terminal.convertEol) {
  464. this._terminal.x = 0;
  465. }
  466. this._terminal.y++;
  467. if (this._terminal.y > this._terminal.scrollBottom) {
  468. this._terminal.y--;
  469. this._terminal.scroll();
  470. }
  471. if (this._terminal.x >= this._terminal.cols) {
  472. this._terminal.x--;
  473. }
  474. };
  475. InputHandler.prototype.carriageReturn = function () {
  476. this._terminal.x = 0;
  477. };
  478. InputHandler.prototype.backspace = function () {
  479. if (this._terminal.x > 0) {
  480. this._terminal.x--;
  481. }
  482. };
  483. InputHandler.prototype.tab = function () {
  484. this._terminal.x = this._terminal.nextStop();
  485. };
  486. InputHandler.prototype.shiftOut = function () {
  487. this._terminal.setgLevel(1);
  488. };
  489. InputHandler.prototype.shiftIn = function () {
  490. this._terminal.setgLevel(0);
  491. };
  492. InputHandler.prototype.insertChars = function (params) {
  493. var param, row, j, ch;
  494. param = params[0];
  495. if (param < 1)
  496. param = 1;
  497. row = this._terminal.y + this._terminal.ybase;
  498. j = this._terminal.x;
  499. ch = [this._terminal.eraseAttr(), ' ', 1];
  500. while (param-- && j < this._terminal.cols) {
  501. this._terminal.lines.get(row).splice(j++, 0, ch);
  502. this._terminal.lines.get(row).pop();
  503. }
  504. };
  505. InputHandler.prototype.cursorUp = function (params) {
  506. var param = params[0];
  507. if (param < 1) {
  508. param = 1;
  509. }
  510. this._terminal.y -= param;
  511. if (this._terminal.y < 0) {
  512. this._terminal.y = 0;
  513. }
  514. };
  515. InputHandler.prototype.cursorDown = function (params) {
  516. var param = params[0];
  517. if (param < 1) {
  518. param = 1;
  519. }
  520. this._terminal.y += param;
  521. if (this._terminal.y >= this._terminal.rows) {
  522. this._terminal.y = this._terminal.rows - 1;
  523. }
  524. if (this._terminal.x >= this._terminal.cols) {
  525. this._terminal.x--;
  526. }
  527. };
  528. InputHandler.prototype.cursorForward = function (params) {
  529. var param = params[0];
  530. if (param < 1) {
  531. param = 1;
  532. }
  533. this._terminal.x += param;
  534. if (this._terminal.x >= this._terminal.cols) {
  535. this._terminal.x = this._terminal.cols - 1;
  536. }
  537. };
  538. InputHandler.prototype.cursorBackward = function (params) {
  539. var param = params[0];
  540. if (param < 1) {
  541. param = 1;
  542. }
  543. if (this._terminal.x >= this._terminal.cols) {
  544. this._terminal.x--;
  545. }
  546. this._terminal.x -= param;
  547. if (this._terminal.x < 0) {
  548. this._terminal.x = 0;
  549. }
  550. };
  551. InputHandler.prototype.cursorNextLine = function (params) {
  552. var param = params[0];
  553. if (param < 1) {
  554. param = 1;
  555. }
  556. this._terminal.y += param;
  557. if (this._terminal.y >= this._terminal.rows) {
  558. this._terminal.y = this._terminal.rows - 1;
  559. }
  560. this._terminal.x = 0;
  561. };
  562. ;
  563. InputHandler.prototype.cursorPrecedingLine = function (params) {
  564. var param = params[0];
  565. if (param < 1) {
  566. param = 1;
  567. }
  568. this._terminal.y -= param;
  569. if (this._terminal.y < 0) {
  570. this._terminal.y = 0;
  571. }
  572. this._terminal.x = 0;
  573. };
  574. ;
  575. InputHandler.prototype.cursorCharAbsolute = function (params) {
  576. var param = params[0];
  577. if (param < 1) {
  578. param = 1;
  579. }
  580. this._terminal.x = param - 1;
  581. };
  582. InputHandler.prototype.cursorPosition = function (params) {
  583. var row, col;
  584. row = params[0] - 1;
  585. if (params.length >= 2) {
  586. col = params[1] - 1;
  587. }
  588. else {
  589. col = 0;
  590. }
  591. if (row < 0) {
  592. row = 0;
  593. }
  594. else if (row >= this._terminal.rows) {
  595. row = this._terminal.rows - 1;
  596. }
  597. if (col < 0) {
  598. col = 0;
  599. }
  600. else if (col >= this._terminal.cols) {
  601. col = this._terminal.cols - 1;
  602. }
  603. this._terminal.x = col;
  604. this._terminal.y = row;
  605. };
  606. InputHandler.prototype.cursorForwardTab = function (params) {
  607. var param = params[0] || 1;
  608. while (param--) {
  609. this._terminal.x = this._terminal.nextStop();
  610. }
  611. };
  612. InputHandler.prototype.eraseInDisplay = function (params) {
  613. var j;
  614. switch (params[0]) {
  615. case 0:
  616. this._terminal.eraseRight(this._terminal.x, this._terminal.y);
  617. j = this._terminal.y + 1;
  618. for (; j < this._terminal.rows; j++) {
  619. this._terminal.eraseLine(j);
  620. }
  621. break;
  622. case 1:
  623. this._terminal.eraseLeft(this._terminal.x, this._terminal.y);
  624. j = this._terminal.y;
  625. while (j--) {
  626. this._terminal.eraseLine(j);
  627. }
  628. break;
  629. case 2:
  630. j = this._terminal.rows;
  631. while (j--)
  632. this._terminal.eraseLine(j);
  633. break;
  634. case 3:
  635. var scrollBackSize = this._terminal.lines.length - this._terminal.rows;
  636. if (scrollBackSize > 0) {
  637. this._terminal.lines.trimStart(scrollBackSize);
  638. this._terminal.ybase = Math.max(this._terminal.ybase - scrollBackSize, 0);
  639. this._terminal.ydisp = Math.max(this._terminal.ydisp - scrollBackSize, 0);
  640. }
  641. break;
  642. }
  643. };
  644. InputHandler.prototype.eraseInLine = function (params) {
  645. switch (params[0]) {
  646. case 0:
  647. this._terminal.eraseRight(this._terminal.x, this._terminal.y);
  648. break;
  649. case 1:
  650. this._terminal.eraseLeft(this._terminal.x, this._terminal.y);
  651. break;
  652. case 2:
  653. this._terminal.eraseLine(this._terminal.y);
  654. break;
  655. }
  656. };
  657. InputHandler.prototype.insertLines = function (params) {
  658. var param, row, j;
  659. param = params[0];
  660. if (param < 1) {
  661. param = 1;
  662. }
  663. row = this._terminal.y + this._terminal.ybase;
  664. j = this._terminal.rows - 1 - this._terminal.scrollBottom;
  665. j = this._terminal.rows - 1 + this._terminal.ybase - j + 1;
  666. while (param--) {
  667. if (this._terminal.lines.length === this._terminal.lines.maxLength) {
  668. this._terminal.lines.trimStart(1);
  669. this._terminal.ybase--;
  670. this._terminal.ydisp--;
  671. row--;
  672. j--;
  673. }
  674. this._terminal.lines.splice(row, 0, this._terminal.blankLine(true));
  675. this._terminal.lines.splice(j, 1);
  676. }
  677. this._terminal.updateRange(this._terminal.y);
  678. this._terminal.updateRange(this._terminal.scrollBottom);
  679. };
  680. InputHandler.prototype.deleteLines = function (params) {
  681. var param, row, j;
  682. param = params[0];
  683. if (param < 1) {
  684. param = 1;
  685. }
  686. row = this._terminal.y + this._terminal.ybase;
  687. j = this._terminal.rows - 1 - this._terminal.scrollBottom;
  688. j = this._terminal.rows - 1 + this._terminal.ybase - j;
  689. while (param--) {
  690. if (this._terminal.lines.length === this._terminal.lines.maxLength) {
  691. this._terminal.lines.trimStart(1);
  692. this._terminal.ybase -= 1;
  693. this._terminal.ydisp -= 1;
  694. }
  695. this._terminal.lines.splice(j + 1, 0, this._terminal.blankLine(true));
  696. this._terminal.lines.splice(row, 1);
  697. }
  698. this._terminal.updateRange(this._terminal.y);
  699. this._terminal.updateRange(this._terminal.scrollBottom);
  700. };
  701. InputHandler.prototype.deleteChars = function (params) {
  702. var param, row, ch;
  703. param = params[0];
  704. if (param < 1) {
  705. param = 1;
  706. }
  707. row = this._terminal.y + this._terminal.ybase;
  708. ch = [this._terminal.eraseAttr(), ' ', 1];
  709. while (param--) {
  710. this._terminal.lines.get(row).splice(this._terminal.x, 1);
  711. this._terminal.lines.get(row).push(ch);
  712. }
  713. };
  714. InputHandler.prototype.scrollUp = function (params) {
  715. var param = params[0] || 1;
  716. while (param--) {
  717. this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollTop, 1);
  718. this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollBottom, 0, this._terminal.blankLine());
  719. }
  720. this._terminal.updateRange(this._terminal.scrollTop);
  721. this._terminal.updateRange(this._terminal.scrollBottom);
  722. };
  723. InputHandler.prototype.scrollDown = function (params) {
  724. var param = params[0] || 1;
  725. while (param--) {
  726. this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollBottom, 1);
  727. this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollTop, 0, this._terminal.blankLine());
  728. }
  729. this._terminal.updateRange(this._terminal.scrollTop);
  730. this._terminal.updateRange(this._terminal.scrollBottom);
  731. };
  732. InputHandler.prototype.eraseChars = function (params) {
  733. var param, row, j, ch;
  734. param = params[0];
  735. if (param < 1) {
  736. param = 1;
  737. }
  738. row = this._terminal.y + this._terminal.ybase;
  739. j = this._terminal.x;
  740. ch = [this._terminal.eraseAttr(), ' ', 1];
  741. while (param-- && j < this._terminal.cols) {
  742. this._terminal.lines.get(row)[j++] = ch;
  743. }
  744. };
  745. InputHandler.prototype.cursorBackwardTab = function (params) {
  746. var param = params[0] || 1;
  747. while (param--) {
  748. this._terminal.x = this._terminal.prevStop();
  749. }
  750. };
  751. InputHandler.prototype.charPosAbsolute = function (params) {
  752. var param = params[0];
  753. if (param < 1) {
  754. param = 1;
  755. }
  756. this._terminal.x = param - 1;
  757. if (this._terminal.x >= this._terminal.cols) {
  758. this._terminal.x = this._terminal.cols - 1;
  759. }
  760. };
  761. InputHandler.prototype.HPositionRelative = function (params) {
  762. var param = params[0];
  763. if (param < 1) {
  764. param = 1;
  765. }
  766. this._terminal.x += param;
  767. if (this._terminal.x >= this._terminal.cols) {
  768. this._terminal.x = this._terminal.cols - 1;
  769. }
  770. };
  771. InputHandler.prototype.repeatPrecedingCharacter = function (params) {
  772. var param = params[0] || 1, line = this._terminal.lines.get(this._terminal.ybase + this._terminal.y), ch = line[this._terminal.x - 1] || [this._terminal.defAttr, ' ', 1];
  773. while (param--) {
  774. line[this._terminal.x++] = ch;
  775. }
  776. };
  777. InputHandler.prototype.sendDeviceAttributes = function (params) {
  778. if (params[0] > 0) {
  779. return;
  780. }
  781. if (!this._terminal.prefix) {
  782. if (this._terminal.is('xterm') || this._terminal.is('rxvt-unicode') || this._terminal.is('screen')) {
  783. this._terminal.send(EscapeSequences_1.C0.ESC + '[?1;2c');
  784. }
  785. else if (this._terminal.is('linux')) {
  786. this._terminal.send(EscapeSequences_1.C0.ESC + '[?6c');
  787. }
  788. }
  789. else if (this._terminal.prefix === '>') {
  790. if (this._terminal.is('xterm')) {
  791. this._terminal.send(EscapeSequences_1.C0.ESC + '[>0;276;0c');
  792. }
  793. else if (this._terminal.is('rxvt-unicode')) {
  794. this._terminal.send(EscapeSequences_1.C0.ESC + '[>85;95;0c');
  795. }
  796. else if (this._terminal.is('linux')) {
  797. this._terminal.send(params[0] + 'c');
  798. }
  799. else if (this._terminal.is('screen')) {
  800. this._terminal.send(EscapeSequences_1.C0.ESC + '[>83;40003;0c');
  801. }
  802. }
  803. };
  804. InputHandler.prototype.linePosAbsolute = function (params) {
  805. var param = params[0];
  806. if (param < 1) {
  807. param = 1;
  808. }
  809. this._terminal.y = param - 1;
  810. if (this._terminal.y >= this._terminal.rows) {
  811. this._terminal.y = this._terminal.rows - 1;
  812. }
  813. };
  814. InputHandler.prototype.VPositionRelative = function (params) {
  815. var param = params[0];
  816. if (param < 1) {
  817. param = 1;
  818. }
  819. this._terminal.y += param;
  820. if (this._terminal.y >= this._terminal.rows) {
  821. this._terminal.y = this._terminal.rows - 1;
  822. }
  823. if (this._terminal.x >= this._terminal.cols) {
  824. this._terminal.x--;
  825. }
  826. };
  827. InputHandler.prototype.HVPosition = function (params) {
  828. if (params[0] < 1)
  829. params[0] = 1;
  830. if (params[1] < 1)
  831. params[1] = 1;
  832. this._terminal.y = params[0] - 1;
  833. if (this._terminal.y >= this._terminal.rows) {
  834. this._terminal.y = this._terminal.rows - 1;
  835. }
  836. this._terminal.x = params[1] - 1;
  837. if (this._terminal.x >= this._terminal.cols) {
  838. this._terminal.x = this._terminal.cols - 1;
  839. }
  840. };
  841. InputHandler.prototype.tabClear = function (params) {
  842. var param = params[0];
  843. if (param <= 0) {
  844. delete this._terminal.tabs[this._terminal.x];
  845. }
  846. else if (param === 3) {
  847. this._terminal.tabs = {};
  848. }
  849. };
  850. InputHandler.prototype.setMode = function (params) {
  851. if (params.length > 1) {
  852. for (var i = 0; i < params.length; i++) {
  853. this.setMode([params[i]]);
  854. }
  855. return;
  856. }
  857. if (!this._terminal.prefix) {
  858. switch (params[0]) {
  859. case 4:
  860. this._terminal.insertMode = true;
  861. break;
  862. case 20:
  863. break;
  864. }
  865. }
  866. else if (this._terminal.prefix === '?') {
  867. switch (params[0]) {
  868. case 1:
  869. this._terminal.applicationCursor = true;
  870. break;
  871. case 2:
  872. this._terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
  873. this._terminal.setgCharset(1, Charsets_1.DEFAULT_CHARSET);
  874. this._terminal.setgCharset(2, Charsets_1.DEFAULT_CHARSET);
  875. this._terminal.setgCharset(3, Charsets_1.DEFAULT_CHARSET);
  876. break;
  877. case 3:
  878. this._terminal.savedCols = this._terminal.cols;
  879. this._terminal.resize(132, this._terminal.rows);
  880. break;
  881. case 6:
  882. this._terminal.originMode = true;
  883. break;
  884. case 7:
  885. this._terminal.wraparoundMode = true;
  886. break;
  887. case 12:
  888. break;
  889. case 66:
  890. this._terminal.log('Serial port requested application keypad.');
  891. this._terminal.applicationKeypad = true;
  892. this._terminal.viewport.syncScrollArea();
  893. break;
  894. case 9:
  895. case 1000:
  896. case 1002:
  897. case 1003:
  898. this._terminal.x10Mouse = params[0] === 9;
  899. this._terminal.vt200Mouse = params[0] === 1000;
  900. this._terminal.normalMouse = params[0] > 1000;
  901. this._terminal.mouseEvents = true;
  902. this._terminal.element.classList.add('enable-mouse-events');
  903. this._terminal.selectionManager.disable();
  904. this._terminal.log('Binding to mouse events.');
  905. break;
  906. case 1004:
  907. this._terminal.sendFocus = true;
  908. break;
  909. case 1005:
  910. this._terminal.utfMouse = true;
  911. break;
  912. case 1006:
  913. this._terminal.sgrMouse = true;
  914. break;
  915. case 1015:
  916. this._terminal.urxvtMouse = true;
  917. break;
  918. case 25:
  919. this._terminal.cursorHidden = false;
  920. break;
  921. case 1049:
  922. ;
  923. case 47:
  924. case 1047:
  925. if (!this._terminal.normal) {
  926. var normal = {
  927. lines: this._terminal.lines,
  928. ybase: this._terminal.ybase,
  929. ydisp: this._terminal.ydisp,
  930. x: this._terminal.x,
  931. y: this._terminal.y,
  932. scrollTop: this._terminal.scrollTop,
  933. scrollBottom: this._terminal.scrollBottom,
  934. tabs: this._terminal.tabs
  935. };
  936. this._terminal.reset();
  937. this._terminal.viewport.syncScrollArea();
  938. this._terminal.normal = normal;
  939. this._terminal.showCursor();
  940. }
  941. break;
  942. }
  943. }
  944. };
  945. InputHandler.prototype.resetMode = function (params) {
  946. if (params.length > 1) {
  947. for (var i = 0; i < params.length; i++) {
  948. this.resetMode([params[i]]);
  949. }
  950. return;
  951. }
  952. if (!this._terminal.prefix) {
  953. switch (params[0]) {
  954. case 4:
  955. this._terminal.insertMode = false;
  956. break;
  957. case 20:
  958. break;
  959. }
  960. }
  961. else if (this._terminal.prefix === '?') {
  962. switch (params[0]) {
  963. case 1:
  964. this._terminal.applicationCursor = false;
  965. break;
  966. case 3:
  967. if (this._terminal.cols === 132 && this._terminal.savedCols) {
  968. this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
  969. }
  970. delete this._terminal.savedCols;
  971. break;
  972. case 6:
  973. this._terminal.originMode = false;
  974. break;
  975. case 7:
  976. this._terminal.wraparoundMode = false;
  977. break;
  978. case 12:
  979. break;
  980. case 66:
  981. this._terminal.log('Switching back to normal keypad.');
  982. this._terminal.applicationKeypad = false;
  983. this._terminal.viewport.syncScrollArea();
  984. break;
  985. case 9:
  986. case 1000:
  987. case 1002:
  988. case 1003:
  989. this._terminal.x10Mouse = false;
  990. this._terminal.vt200Mouse = false;
  991. this._terminal.normalMouse = false;
  992. this._terminal.mouseEvents = false;
  993. this._terminal.element.classList.remove('enable-mouse-events');
  994. this._terminal.selectionManager.enable();
  995. break;
  996. case 1004:
  997. this._terminal.sendFocus = false;
  998. break;
  999. case 1005:
  1000. this._terminal.utfMouse = false;
  1001. break;
  1002. case 1006:
  1003. this._terminal.sgrMouse = false;
  1004. break;
  1005. case 1015:
  1006. this._terminal.urxvtMouse = false;
  1007. break;
  1008. case 25:
  1009. this._terminal.cursorHidden = true;
  1010. break;
  1011. case 1049:
  1012. ;
  1013. case 47:
  1014. case 1047:
  1015. if (this._terminal.normal) {
  1016. this._terminal.lines = this._terminal.normal.lines;
  1017. this._terminal.ybase = this._terminal.normal.ybase;
  1018. this._terminal.ydisp = this._terminal.normal.ydisp;
  1019. this._terminal.x = this._terminal.normal.x;
  1020. this._terminal.y = this._terminal.normal.y;
  1021. this._terminal.scrollTop = this._terminal.normal.scrollTop;
  1022. this._terminal.scrollBottom = this._terminal.normal.scrollBottom;
  1023. this._terminal.tabs = this._terminal.normal.tabs;
  1024. this._terminal.normal = null;
  1025. this._terminal.selectionManager.setBuffer(this._terminal.lines);
  1026. this._terminal.refresh(0, this._terminal.rows - 1);
  1027. this._terminal.viewport.syncScrollArea();
  1028. this._terminal.showCursor();
  1029. }
  1030. break;
  1031. }
  1032. }
  1033. };
  1034. InputHandler.prototype.charAttributes = function (params) {
  1035. if (params.length === 1 && params[0] === 0) {
  1036. this._terminal.curAttr = this._terminal.defAttr;
  1037. return;
  1038. }
  1039. var l = params.length, i = 0, flags = this._terminal.curAttr >> 18, fg = (this._terminal.curAttr >> 9) & 0x1ff, bg = this._terminal.curAttr & 0x1ff, p;
  1040. for (; i < l; i++) {
  1041. p = params[i];
  1042. if (p >= 30 && p <= 37) {
  1043. fg = p - 30;
  1044. }
  1045. else if (p >= 40 && p <= 47) {
  1046. bg = p - 40;
  1047. }
  1048. else if (p >= 90 && p <= 97) {
  1049. p += 8;
  1050. fg = p - 90;
  1051. }
  1052. else if (p >= 100 && p <= 107) {
  1053. p += 8;
  1054. bg = p - 100;
  1055. }
  1056. else if (p === 0) {
  1057. flags = this._terminal.defAttr >> 18;
  1058. fg = (this._terminal.defAttr >> 9) & 0x1ff;
  1059. bg = this._terminal.defAttr & 0x1ff;
  1060. }
  1061. else if (p === 1) {
  1062. flags |= 1;
  1063. }
  1064. else if (p === 4) {
  1065. flags |= 2;
  1066. }
  1067. else if (p === 5) {
  1068. flags |= 4;
  1069. }
  1070. else if (p === 7) {
  1071. flags |= 8;
  1072. }
  1073. else if (p === 8) {
  1074. flags |= 16;
  1075. }
  1076. else if (p === 22) {
  1077. flags &= ~1;
  1078. }
  1079. else if (p === 24) {
  1080. flags &= ~2;
  1081. }
  1082. else if (p === 25) {
  1083. flags &= ~4;
  1084. }
  1085. else if (p === 27) {
  1086. flags &= ~8;
  1087. }
  1088. else if (p === 28) {
  1089. flags &= ~16;
  1090. }
  1091. else if (p === 39) {
  1092. fg = (this._terminal.defAttr >> 9) & 0x1ff;
  1093. }
  1094. else if (p === 49) {
  1095. bg = this._terminal.defAttr & 0x1ff;
  1096. }
  1097. else if (p === 38) {
  1098. if (params[i + 1] === 2) {
  1099. i += 2;
  1100. fg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
  1101. if (fg === -1)
  1102. fg = 0x1ff;
  1103. i += 2;
  1104. }
  1105. else if (params[i + 1] === 5) {
  1106. i += 2;
  1107. p = params[i] & 0xff;
  1108. fg = p;
  1109. }
  1110. }
  1111. else if (p === 48) {
  1112. if (params[i + 1] === 2) {
  1113. i += 2;
  1114. bg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
  1115. if (bg === -1)
  1116. bg = 0x1ff;
  1117. i += 2;
  1118. }
  1119. else if (params[i + 1] === 5) {
  1120. i += 2;
  1121. p = params[i] & 0xff;
  1122. bg = p;
  1123. }
  1124. }
  1125. else if (p === 100) {
  1126. fg = (this._terminal.defAttr >> 9) & 0x1ff;
  1127. bg = this._terminal.defAttr & 0x1ff;
  1128. }
  1129. else {
  1130. this._terminal.error('Unknown SGR attribute: %d.', p);
  1131. }
  1132. }
  1133. this._terminal.curAttr = (flags << 18) | (fg << 9) | bg;
  1134. };
  1135. InputHandler.prototype.deviceStatus = function (params) {
  1136. if (!this._terminal.prefix) {
  1137. switch (params[0]) {
  1138. case 5:
  1139. this._terminal.send(EscapeSequences_1.C0.ESC + '[0n');
  1140. break;
  1141. case 6:
  1142. this._terminal.send(EscapeSequences_1.C0.ESC + '['
  1143. + (this._terminal.y + 1)
  1144. + ';'
  1145. + (this._terminal.x + 1)
  1146. + 'R');
  1147. break;
  1148. }
  1149. }
  1150. else if (this._terminal.prefix === '?') {
  1151. switch (params[0]) {
  1152. case 6:
  1153. this._terminal.send(EscapeSequences_1.C0.ESC + '[?'
  1154. + (this._terminal.y + 1)
  1155. + ';'
  1156. + (this._terminal.x + 1)
  1157. + 'R');
  1158. break;
  1159. case 15:
  1160. break;
  1161. case 25:
  1162. break;
  1163. case 26:
  1164. break;
  1165. case 53:
  1166. break;
  1167. }
  1168. }
  1169. };
  1170. InputHandler.prototype.softReset = function (params) {
  1171. this._terminal.cursorHidden = false;
  1172. this._terminal.insertMode = false;
  1173. this._terminal.originMode = false;
  1174. this._terminal.wraparoundMode = true;
  1175. this._terminal.applicationKeypad = false;
  1176. this._terminal.viewport.syncScrollArea();
  1177. this._terminal.applicationCursor = false;
  1178. this._terminal.scrollTop = 0;
  1179. this._terminal.scrollBottom = this._terminal.rows - 1;
  1180. this._terminal.curAttr = this._terminal.defAttr;
  1181. this._terminal.x = this._terminal.y = 0;
  1182. this._terminal.charset = null;
  1183. this._terminal.glevel = 0;
  1184. this._terminal.charsets = [null];
  1185. };
  1186. InputHandler.prototype.setCursorStyle = function (params) {
  1187. var param = params[0] < 1 ? 1 : params[0];
  1188. switch (param) {
  1189. case 1:
  1190. case 2:
  1191. this._terminal.setOption('cursorStyle', 'block');
  1192. break;
  1193. case 3:
  1194. case 4:
  1195. this._terminal.setOption('cursorStyle', 'underline');
  1196. break;
  1197. case 5:
  1198. case 6:
  1199. this._terminal.setOption('cursorStyle', 'bar');
  1200. break;
  1201. }
  1202. var isBlinking = param % 2 === 1;
  1203. this._terminal.setOption('cursorBlink', isBlinking);
  1204. };
  1205. InputHandler.prototype.setScrollRegion = function (params) {
  1206. if (this._terminal.prefix)
  1207. return;
  1208. this._terminal.scrollTop = (params[0] || 1) - 1;
  1209. this._terminal.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
  1210. this._terminal.x = 0;
  1211. this._terminal.y = 0;
  1212. };
  1213. InputHandler.prototype.saveCursor = function (params) {
  1214. this._terminal.savedX = this._terminal.x;
  1215. this._terminal.savedY = this._terminal.y;
  1216. };
  1217. InputHandler.prototype.restoreCursor = function (params) {
  1218. this._terminal.x = this._terminal.savedX || 0;
  1219. this._terminal.y = this._terminal.savedY || 0;
  1220. };
  1221. return InputHandler;
  1222. }());
  1223. exports.InputHandler = InputHandler;
  1224. var wcwidth = (function (opts) {
  1225. var COMBINING = [
  1226. [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
  1227. [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
  1228. [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
  1229. [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
  1230. [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
  1231. [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
  1232. [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
  1233. [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
  1234. [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
  1235. [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
  1236. [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
  1237. [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
  1238. [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
  1239. [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
  1240. [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
  1241. [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
  1242. [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
  1243. [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
  1244. [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
  1245. [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
  1246. [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
  1247. [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
  1248. [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
  1249. [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
  1250. [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
  1251. [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
  1252. [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
  1253. [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
  1254. [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
  1255. [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
  1256. [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
  1257. [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
  1258. [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
  1259. [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
  1260. [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
  1261. [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
  1262. [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
  1263. [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
  1264. [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
  1265. [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
  1266. [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
  1267. [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
  1268. [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
  1269. [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
  1270. [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
  1271. [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
  1272. [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
  1273. [0xE0100, 0xE01EF]
  1274. ];
  1275. function bisearch(ucs) {
  1276. var min = 0;
  1277. var max = COMBINING.length - 1;
  1278. var mid;
  1279. if (ucs < COMBINING[0][0] || ucs > COMBINING[max][1])
  1280. return false;
  1281. while (max >= min) {
  1282. mid = Math.floor((min + max) / 2);
  1283. if (ucs > COMBINING[mid][1])
  1284. min = mid + 1;
  1285. else if (ucs < COMBINING[mid][0])
  1286. max = mid - 1;
  1287. else
  1288. return true;
  1289. }
  1290. return false;
  1291. }
  1292. function wcwidth(ucs) {
  1293. if (ucs === 0)
  1294. return opts.nul;
  1295. if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
  1296. return opts.control;
  1297. if (bisearch(ucs))
  1298. return 0;
  1299. if (isWide(ucs)) {
  1300. return 2;
  1301. }
  1302. return 1;
  1303. }
  1304. function isWide(ucs) {
  1305. return (ucs >= 0x1100 && (ucs <= 0x115f ||
  1306. ucs === 0x2329 ||
  1307. ucs === 0x232a ||
  1308. (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs !== 0x303f) ||
  1309. (ucs >= 0xac00 && ucs <= 0xd7a3) ||
  1310. (ucs >= 0xf900 && ucs <= 0xfaff) ||
  1311. (ucs >= 0xfe10 && ucs <= 0xfe19) ||
  1312. (ucs >= 0xfe30 && ucs <= 0xfe6f) ||
  1313. (ucs >= 0xff00 && ucs <= 0xff60) ||
  1314. (ucs >= 0xffe0 && ucs <= 0xffe6) ||
  1315. (ucs >= 0x20000 && ucs <= 0x2fffd) ||
  1316. (ucs >= 0x30000 && ucs <= 0x3fffd)));
  1317. }
  1318. return wcwidth;
  1319. })({ nul: 0, control: 0 });
  1320. },{"./Charsets":1,"./EscapeSequences":3}],6:[function(require,module,exports){
  1321. "use strict";
  1322. Object.defineProperty(exports, "__esModule", { value: true });
  1323. var INVALID_LINK_CLASS = 'xterm-invalid-link';
  1324. var protocolClause = '(https?:\\/\\/)';
  1325. var domainCharacterSet = '[\\da-z\\.-]+';
  1326. var negatedDomainCharacterSet = '[^\\da-z\\.-]+';
  1327. var domainBodyClause = '(' + domainCharacterSet + ')';
  1328. var tldClause = '([a-z\\.]{2,6})';
  1329. var ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
  1330. var localHostClause = '(localhost)';
  1331. var portClause = '(:\\d{1,5})';
  1332. var hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
  1333. var pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
  1334. var queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
  1335. var queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
  1336. var hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';
  1337. var negatedPathCharacterSet = '[^\\/\\w\\.\\-%]+';
  1338. var bodyClause = hostClause + pathClause + queryStringClause + hashFragmentClause;
  1339. var start = '(?:^|' + negatedDomainCharacterSet + ')(';
  1340. var end = ')($|' + negatedPathCharacterSet + ')';
  1341. var strictUrlRegex = new RegExp(start + protocolClause + bodyClause + end);
  1342. var HYPERTEXT_LINK_MATCHER_ID = 0;
  1343. var Linkifier = (function () {
  1344. function Linkifier() {
  1345. this._nextLinkMatcherId = HYPERTEXT_LINK_MATCHER_ID;
  1346. this._rowTimeoutIds = [];
  1347. this._linkMatchers = [];
  1348. this.registerLinkMatcher(strictUrlRegex, null, { matchIndex: 1 });
  1349. }
  1350. Linkifier.prototype.attachToDom = function (document, rows) {
  1351. this._document = document;
  1352. this._rows = rows;
  1353. };
  1354. Linkifier.prototype.linkifyRow = function (rowIndex) {
  1355. if (!this._document) {
  1356. return;
  1357. }
  1358. var timeoutId = this._rowTimeoutIds[rowIndex];
  1359. if (timeoutId) {
  1360. clearTimeout(timeoutId);
  1361. }
  1362. this._rowTimeoutIds[rowIndex] = setTimeout(this._linkifyRow.bind(this, rowIndex), Linkifier.TIME_BEFORE_LINKIFY);
  1363. };
  1364. Linkifier.prototype.setHypertextLinkHandler = function (handler) {
  1365. this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].handler = handler;
  1366. };
  1367. Linkifier.prototype.setHypertextValidationCallback = function (callback) {
  1368. this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].validationCallback = callback;
  1369. };
  1370. Linkifier.prototype.registerLinkMatcher = function (regex, handler, options) {
  1371. if (options === void 0) { options = {}; }
  1372. if (this._nextLinkMatcherId !== HYPERTEXT_LINK_MATCHER_ID && !handler) {
  1373. throw new Error('handler must be defined');
  1374. }
  1375. var matcher = {
  1376. id: this._nextLinkMatcherId++,
  1377. regex: regex,
  1378. handler: handler,
  1379. matchIndex: options.matchIndex,
  1380. validationCallback: options.validationCallback,
  1381. priority: options.priority || 0
  1382. };
  1383. this._addLinkMatcherToList(matcher);
  1384. return matcher.id;
  1385. };
  1386. Linkifier.prototype._addLinkMatcherToList = function (matcher) {
  1387. if (this._linkMatchers.length === 0) {
  1388. this._linkMatchers.push(matcher);
  1389. return;
  1390. }
  1391. for (var i = this._linkMatchers.length - 1; i >= 0; i--) {
  1392. if (matcher.priority <= this._linkMatchers[i].priority) {
  1393. this._linkMatchers.splice(i + 1, 0, matcher);
  1394. return;
  1395. }
  1396. }
  1397. this._linkMatchers.splice(0, 0, matcher);
  1398. };
  1399. Linkifier.prototype.deregisterLinkMatcher = function (matcherId) {
  1400. for (var i = 1; i < this._linkMatchers.length; i++) {
  1401. if (this._linkMatchers[i].id === matcherId) {
  1402. this._linkMatchers.splice(i, 1);
  1403. return true;
  1404. }
  1405. }
  1406. return false;
  1407. };
  1408. Linkifier.prototype._linkifyRow = function (rowIndex) {
  1409. var row = this._rows[rowIndex];
  1410. if (!row) {
  1411. return;
  1412. }
  1413. var text = row.textContent;
  1414. for (var i = 0; i < this._linkMatchers.length; i++) {
  1415. var matcher = this._linkMatchers[i];
  1416. var linkElements = this._doLinkifyRow(row, matcher);
  1417. if (linkElements.length > 0) {
  1418. if (matcher.validationCallback) {
  1419. var _loop_1 = function (j) {
  1420. var element = linkElements[j];
  1421. matcher.validationCallback(element.textContent, element, function (isValid) {
  1422. if (!isValid) {
  1423. element.classList.add(INVALID_LINK_CLASS);
  1424. }
  1425. });
  1426. };
  1427. for (var j = 0; j < linkElements.length; j++) {
  1428. _loop_1(j);
  1429. }
  1430. }
  1431. return;
  1432. }
  1433. }
  1434. };
  1435. Linkifier.prototype._doLinkifyRow = function (row, matcher) {
  1436. var result = [];
  1437. var isHttpLinkMatcher = matcher.id === HYPERTEXT_LINK_MATCHER_ID;
  1438. var nodes = row.childNodes;
  1439. var match = row.textContent.match(matcher.regex);
  1440. if (!match || match.length === 0) {
  1441. return result;
  1442. }
  1443. var uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
  1444. var rowStartIndex = match.index + uri.length;
  1445. for (var i = 0; i < nodes.length; i++) {
  1446. var node = nodes[i];
  1447. var searchIndex = node.textContent.indexOf(uri);
  1448. if (searchIndex >= 0) {
  1449. var linkElement = this._createAnchorElement(uri, matcher.handler, isHttpLinkMatcher);
  1450. if (node.textContent.length === uri.length) {
  1451. if (node.nodeType === 3) {
  1452. this._replaceNode(node, linkElement);
  1453. }
  1454. else {
  1455. var element = node;
  1456. if (element.nodeName === 'A') {
  1457. return result;
  1458. }
  1459. element.innerHTML = '';
  1460. element.appendChild(linkElement);
  1461. }
  1462. }
  1463. else if (node.childNodes.length > 1) {
  1464. for (var j = 0; j < node.childNodes.length; j++) {
  1465. var childNode = node.childNodes[j];
  1466. var childSearchIndex = childNode.textContent.indexOf(uri);
  1467. if (childSearchIndex !== -1) {
  1468. this._replaceNodeSubstringWithNode(childNode, linkElement, uri, childSearchIndex);
  1469. break;
  1470. }
  1471. }
  1472. }
  1473. else {
  1474. var nodesAdded = this._replaceNodeSubstringWithNode(node, linkElement, uri, searchIndex);
  1475. i += nodesAdded;
  1476. }
  1477. result.push(linkElement);
  1478. match = row.textContent.substring(rowStartIndex).match(matcher.regex);
  1479. if (!match || match.length === 0) {
  1480. return result;
  1481. }
  1482. uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
  1483. rowStartIndex += match.index + uri.length;
  1484. }
  1485. }
  1486. return result;
  1487. };
  1488. Linkifier.prototype._createAnchorElement = function (uri, handler, isHypertextLinkHandler) {
  1489. var element = this._document.createElement('a');
  1490. element.textContent = uri;
  1491. element.draggable = false;
  1492. if (isHypertextLinkHandler) {
  1493. element.href = uri;
  1494. element.target = '_blank';
  1495. element.addEventListener('click', function (event) {
  1496. if (handler) {
  1497. return handler(event, uri);
  1498. }
  1499. });
  1500. }
  1501. else {
  1502. element.addEventListener('click', function (event) {
  1503. if (element.classList.contains(INVALID_LINK_CLASS)) {
  1504. return;
  1505. }
  1506. return handler(event, uri);
  1507. });
  1508. }
  1509. return element;
  1510. };
  1511. Linkifier.prototype._replaceNode = function (oldNode) {
  1512. var newNodes = [];
  1513. for (var _i = 1; _i < arguments.length; _i++) {
  1514. newNodes[_i - 1] = arguments[_i];
  1515. }
  1516. var parent = oldNode.parentNode;
  1517. for (var i = 0; i < newNodes.length; i++) {
  1518. parent.insertBefore(newNodes[i], oldNode);
  1519. }
  1520. parent.removeChild(oldNode);
  1521. };
  1522. Linkifier.prototype._replaceNodeSubstringWithNode = function (targetNode, newNode, substring, substringIndex) {
  1523. if (targetNode.childNodes.length === 1) {
  1524. targetNode = targetNode.childNodes[0];
  1525. }
  1526. if (targetNode.nodeType !== 3) {
  1527. throw new Error('targetNode must be a text node or only contain a single text node');
  1528. }
  1529. var fullText = targetNode.textContent;
  1530. if (substringIndex === 0) {
  1531. var rightText_1 = fullText.substring(substring.length);
  1532. var rightTextNode_1 = this._document.createTextNode(rightText_1);
  1533. this._replaceNode(targetNode, newNode, rightTextNode_1);
  1534. return 0;
  1535. }
  1536. if (substringIndex === targetNode.textContent.length - substring.length) {
  1537. var leftText_1 = fullText.substring(0, substringIndex);
  1538. var leftTextNode_1 = this._document.createTextNode(leftText_1);
  1539. this._replaceNode(targetNode, leftTextNode_1, newNode);
  1540. return 0;
  1541. }
  1542. var leftText = fullText.substring(0, substringIndex);
  1543. var leftTextNode = this._document.createTextNode(leftText);
  1544. var rightText = fullText.substring(substringIndex + substring.length);
  1545. var rightTextNode = this._document.createTextNode(rightText);
  1546. this._replaceNode(targetNode, leftTextNode, newNode, rightTextNode);
  1547. return 1;
  1548. };
  1549. return Linkifier;
  1550. }());
  1551. Linkifier.TIME_BEFORE_LINKIFY = 200;
  1552. exports.Linkifier = Linkifier;
  1553. },{}],7:[function(require,module,exports){
  1554. "use strict";
  1555. Object.defineProperty(exports, "__esModule", { value: true });
  1556. var EscapeSequences_1 = require("./EscapeSequences");
  1557. var Charsets_1 = require("./Charsets");
  1558. var normalStateHandler = {};
  1559. normalStateHandler[EscapeSequences_1.C0.BEL] = function (parser, handler) { return handler.bell(); };
  1560. normalStateHandler[EscapeSequences_1.C0.LF] = function (parser, handler) { return handler.lineFeed(); };
  1561. normalStateHandler[EscapeSequences_1.C0.VT] = normalStateHandler[EscapeSequences_1.C0.LF];
  1562. normalStateHandler[EscapeSequences_1.C0.FF] = normalStateHandler[EscapeSequences_1.C0.LF];
  1563. normalStateHandler[EscapeSequences_1.C0.CR] = function (parser, handler) { return handler.carriageReturn(); };
  1564. normalStateHandler[EscapeSequences_1.C0.BS] = function (parser, handler) { return handler.backspace(); };
  1565. normalStateHandler[EscapeSequences_1.C0.HT] = function (parser, handler) { return handler.tab(); };
  1566. normalStateHandler[EscapeSequences_1.C0.SO] = function (parser, handler) { return handler.shiftOut(); };
  1567. normalStateHandler[EscapeSequences_1.C0.SI] = function (parser, handler) { return handler.shiftIn(); };
  1568. normalStateHandler[EscapeSequences_1.C0.ESC] = function (parser, handler) { return parser.setState(ParserState.ESCAPED); };
  1569. var escapedStateHandler = {};
  1570. escapedStateHandler['['] = function (parser, terminal) {
  1571. terminal.params = [];
  1572. terminal.currentParam = 0;
  1573. parser.setState(ParserState.CSI_PARAM);
  1574. };
  1575. escapedStateHandler[']'] = function (parser, terminal) {
  1576. terminal.params = [];
  1577. terminal.currentParam = 0;
  1578. parser.setState(ParserState.OSC);
  1579. };
  1580. escapedStateHandler['P'] = function (parser, terminal) {
  1581. terminal.params = [];
  1582. terminal.currentParam = 0;
  1583. parser.setState(ParserState.DCS);
  1584. };
  1585. escapedStateHandler['_'] = function (parser, terminal) {
  1586. parser.setState(ParserState.IGNORE);
  1587. };
  1588. escapedStateHandler['^'] = function (parser, terminal) {
  1589. parser.setState(ParserState.IGNORE);
  1590. };
  1591. escapedStateHandler['c'] = function (parser, terminal) {
  1592. terminal.reset();
  1593. };
  1594. escapedStateHandler['E'] = function (parser, terminal) {
  1595. terminal.x = 0;
  1596. terminal.index();
  1597. parser.setState(ParserState.NORMAL);
  1598. };
  1599. escapedStateHandler['D'] = function (parser, terminal) {
  1600. terminal.index();
  1601. parser.setState(ParserState.NORMAL);
  1602. };
  1603. escapedStateHandler['M'] = function (parser, terminal) {
  1604. terminal.reverseIndex();
  1605. parser.setState(ParserState.NORMAL);
  1606. };
  1607. escapedStateHandler['%'] = function (parser, terminal) {
  1608. terminal.setgLevel(0);
  1609. terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
  1610. parser.setState(ParserState.NORMAL);
  1611. parser.skipNextChar();
  1612. };
  1613. escapedStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
  1614. var csiParamStateHandler = {};
  1615. csiParamStateHandler['?'] = function (parser) { return parser.setPrefix('?'); };
  1616. csiParamStateHandler['>'] = function (parser) { return parser.setPrefix('>'); };
  1617. csiParamStateHandler['!'] = function (parser) { return parser.setPrefix('!'); };
  1618. csiParamStateHandler['0'] = function (parser) { return parser.setParam(parser.getParam() * 10); };
  1619. csiParamStateHandler['1'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 1); };
  1620. csiParamStateHandler['2'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 2); };
  1621. csiParamStateHandler['3'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 3); };
  1622. csiParamStateHandler['4'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 4); };
  1623. csiParamStateHandler['5'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 5); };
  1624. csiParamStateHandler['6'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 6); };
  1625. csiParamStateHandler['7'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 7); };
  1626. csiParamStateHandler['8'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 8); };
  1627. csiParamStateHandler['9'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 9); };
  1628. csiParamStateHandler['$'] = function (parser) { return parser.setPostfix('$'); };
  1629. csiParamStateHandler['"'] = function (parser) { return parser.setPostfix('"'); };
  1630. csiParamStateHandler[' '] = function (parser) { return parser.setPostfix(' '); };
  1631. csiParamStateHandler['\''] = function (parser) { return parser.setPostfix('\''); };
  1632. csiParamStateHandler[';'] = function (parser) { return parser.finalizeParam(); };
  1633. csiParamStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
  1634. var csiStateHandler = {};
  1635. csiStateHandler['@'] = function (handler, params, prefix) { return handler.insertChars(params); };
  1636. csiStateHandler['A'] = function (handler, params, prefix) { return handler.cursorUp(params); };
  1637. csiStateHandler['B'] = function (handler, params, prefix) { return handler.cursorDown(params); };
  1638. csiStateHandler['C'] = function (handler, params, prefix) { return handler.cursorForward(params); };
  1639. csiStateHandler['D'] = function (handler, params, prefix) { return handler.cursorBackward(params); };
  1640. csiStateHandler['E'] = function (handler, params, prefix) { return handler.cursorNextLine(params); };
  1641. csiStateHandler['F'] = function (handler, params, prefix) { return handler.cursorPrecedingLine(params); };
  1642. csiStateHandler['G'] = function (handler, params, prefix) { return handler.cursorCharAbsolute(params); };
  1643. csiStateHandler['H'] = function (handler, params, prefix) { return handler.cursorPosition(params); };
  1644. csiStateHandler['I'] = function (handler, params, prefix) { return handler.cursorForwardTab(params); };
  1645. csiStateHandler['J'] = function (handler, params, prefix) { return handler.eraseInDisplay(params); };
  1646. csiStateHandler['K'] = function (handler, params, prefix) { return handler.eraseInLine(params); };
  1647. csiStateHandler['L'] = function (handler, params, prefix) { return handler.insertLines(params); };
  1648. csiStateHandler['M'] = function (handler, params, prefix) { return handler.deleteLines(params); };
  1649. csiStateHandler['P'] = function (handler, params, prefix) { return handler.deleteChars(params); };
  1650. csiStateHandler['S'] = function (handler, params, prefix) { return handler.scrollUp(params); };
  1651. csiStateHandler['T'] = function (handler, params, prefix) {
  1652. if (params.length < 2 && !prefix) {
  1653. handler.scrollDown(params);
  1654. }
  1655. };
  1656. csiStateHandler['X'] = function (handler, params, prefix) { return handler.eraseChars(params); };
  1657. csiStateHandler['Z'] = function (handler, params, prefix) { return handler.cursorBackwardTab(params); };
  1658. csiStateHandler['`'] = function (handler, params, prefix) { return handler.charPosAbsolute(params); };
  1659. csiStateHandler['a'] = function (handler, params, prefix) { return handler.HPositionRelative(params); };
  1660. csiStateHandler['b'] = function (handler, params, prefix) { return handler.repeatPrecedingCharacter(params); };
  1661. csiStateHandler['c'] = function (handler, params, prefix) { return handler.sendDeviceAttributes(params); };
  1662. csiStateHandler['d'] = function (handler, params, prefix) { return handler.linePosAbsolute(params); };
  1663. csiStateHandler['e'] = function (handler, params, prefix) { return handler.VPositionRelative(params); };
  1664. csiStateHandler['f'] = function (handler, params, prefix) { return handler.HVPosition(params); };
  1665. csiStateHandler['g'] = function (handler, params, prefix) { return handler.tabClear(params); };
  1666. csiStateHandler['h'] = function (handler, params, prefix) { return handler.setMode(params); };
  1667. csiStateHandler['l'] = function (handler, params, prefix) { return handler.resetMode(params); };
  1668. csiStateHandler['m'] = function (handler, params, prefix) { return handler.charAttributes(params); };
  1669. csiStateHandler['n'] = function (handler, params, prefix) { return handler.deviceStatus(params); };
  1670. csiStateHandler['p'] = function (handler, params, prefix) {
  1671. switch (prefix) {
  1672. case '!':
  1673. handler.softReset(params);
  1674. break;
  1675. }
  1676. };
  1677. csiStateHandler['q'] = function (handler, params, prefix, postfix) {
  1678. if (postfix === ' ') {
  1679. handler.setCursorStyle(params);
  1680. }
  1681. };
  1682. csiStateHandler['r'] = function (handler, params) { return handler.setScrollRegion(params); };
  1683. csiStateHandler['s'] = function (handler, params) { return handler.saveCursor(params); };
  1684. csiStateHandler['u'] = function (handler, params) { return handler.restoreCursor(params); };
  1685. csiStateHandler[EscapeSequences_1.C0.CAN] = function (handler, params, prefix, postfix, parser) { return parser.setState(ParserState.NORMAL); };
  1686. var ParserState;
  1687. (function (ParserState) {
  1688. ParserState[ParserState["NORMAL"] = 0] = "NORMAL";
  1689. ParserState[ParserState["ESCAPED"] = 1] = "ESCAPED";
  1690. ParserState[ParserState["CSI_PARAM"] = 2] = "CSI_PARAM";
  1691. ParserState[ParserState["CSI"] = 3] = "CSI";
  1692. ParserState[ParserState["OSC"] = 4] = "OSC";
  1693. ParserState[ParserState["CHARSET"] = 5] = "CHARSET";
  1694. ParserState[ParserState["DCS"] = 6] = "DCS";
  1695. ParserState[ParserState["IGNORE"] = 7] = "IGNORE";
  1696. })(ParserState || (ParserState = {}));
  1697. var Parser = (function () {
  1698. function Parser(_inputHandler, _terminal) {
  1699. this._inputHandler = _inputHandler;
  1700. this._terminal = _terminal;
  1701. this._state = ParserState.NORMAL;
  1702. }
  1703. Parser.prototype.parse = function (data) {
  1704. var l = data.length, j, cs, ch, code, low;
  1705. this._position = 0;
  1706. if (this._terminal.surrogate_high) {
  1707. data = this._terminal.surrogate_high + data;
  1708. this._terminal.surrogate_high = '';
  1709. }
  1710. for (; this._position < l; this._position++) {
  1711. ch = data[this._position];
  1712. code = data.charCodeAt(this._position);
  1713. if (0xD800 <= code && code <= 0xDBFF) {
  1714. low = data.charCodeAt(this._position + 1);
  1715. if (isNaN(low)) {
  1716. this._terminal.surrogate_high = ch;
  1717. continue;
  1718. }
  1719. code = ((code - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
  1720. ch += data.charAt(this._position + 1);
  1721. }
  1722. if (0xDC00 <= code && code <= 0xDFFF)
  1723. continue;
  1724. switch (this._state) {
  1725. case ParserState.NORMAL:
  1726. if (ch in normalStateHandler) {
  1727. normalStateHandler[ch](this, this._inputHandler);
  1728. }
  1729. else {
  1730. this._inputHandler.addChar(ch, code);
  1731. }
  1732. break;
  1733. case ParserState.ESCAPED:
  1734. if (ch in escapedStateHandler) {
  1735. escapedStateHandler[ch](this, this._terminal);
  1736. break;
  1737. }
  1738. switch (ch) {
  1739. case '(':
  1740. case ')':
  1741. case '*':
  1742. case '+':
  1743. case '-':
  1744. case '.':
  1745. switch (ch) {
  1746. case '(':
  1747. this._terminal.gcharset = 0;
  1748. break;
  1749. case ')':
  1750. this._terminal.gcharset = 1;
  1751. break;
  1752. case '*':
  1753. this._terminal.gcharset = 2;
  1754. break;
  1755. case '+':
  1756. this._terminal.gcharset = 3;
  1757. break;
  1758. case '-':
  1759. this._terminal.gcharset = 1;
  1760. break;
  1761. case '.':
  1762. this._terminal.gcharset = 2;
  1763. break;
  1764. }
  1765. this._state = ParserState.CHARSET;
  1766. break;
  1767. case '/':
  1768. this._terminal.gcharset = 3;
  1769. this._state = ParserState.CHARSET;
  1770. this._position--;
  1771. break;
  1772. case 'N':
  1773. break;
  1774. case 'O':
  1775. break;
  1776. case 'n':
  1777. this._terminal.setgLevel(2);
  1778. break;
  1779. case 'o':
  1780. this._terminal.setgLevel(3);
  1781. break;
  1782. case '|':
  1783. this._terminal.setgLevel(3);
  1784. break;
  1785. case '}':
  1786. this._terminal.setgLevel(2);
  1787. break;
  1788. case '~':
  1789. this._terminal.setgLevel(1);
  1790. break;
  1791. case '7':
  1792. this._inputHandler.saveCursor();
  1793. this._state = ParserState.NORMAL;
  1794. break;
  1795. case '8':
  1796. this._inputHandler.restoreCursor();
  1797. this._state = ParserState.NORMAL;
  1798. break;
  1799. case '#':
  1800. this._state = ParserState.NORMAL;
  1801. this._position++;
  1802. break;
  1803. case 'H':
  1804. this._terminal.tabSet();
  1805. this._state = ParserState.NORMAL;
  1806. break;
  1807. case '=':
  1808. this._terminal.log('Serial port requested application keypad.');
  1809. this._terminal.applicationKeypad = true;
  1810. this._terminal.viewport.syncScrollArea();
  1811. this._state = ParserState.NORMAL;
  1812. break;
  1813. case '>':
  1814. this._terminal.log('Switching back to normal keypad.');
  1815. this._terminal.applicationKeypad = false;
  1816. this._terminal.viewport.syncScrollArea();
  1817. this._state = ParserState.NORMAL;
  1818. break;
  1819. default:
  1820. this._state = ParserState.NORMAL;
  1821. this._terminal.error('Unknown ESC control: %s.', ch);
  1822. break;
  1823. }
  1824. break;
  1825. case ParserState.CHARSET:
  1826. if (ch in Charsets_1.CHARSETS) {
  1827. cs = Charsets_1.CHARSETS[ch];
  1828. if (ch === '/') {
  1829. this.skipNextChar();
  1830. }
  1831. }
  1832. else {
  1833. cs = Charsets_1.DEFAULT_CHARSET;
  1834. }
  1835. this._terminal.setgCharset(this._terminal.gcharset, cs);
  1836. this._terminal.gcharset = null;
  1837. this._state = ParserState.NORMAL;
  1838. break;
  1839. case ParserState.OSC:
  1840. if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
  1841. if (ch === EscapeSequences_1.C0.ESC)
  1842. this._position++;
  1843. this._terminal.params.push(this._terminal.currentParam);
  1844. switch (this._terminal.params[0]) {
  1845. case 0:
  1846. case 1:
  1847. case 2:
  1848. if (this._terminal.params[1]) {
  1849. this._terminal.title = this._terminal.params[1];
  1850. this._terminal.handleTitle(this._terminal.title);
  1851. }
  1852. break;
  1853. case 3:
  1854. break;
  1855. case 4:
  1856. case 5:
  1857. break;
  1858. case 10:
  1859. case 11:
  1860. case 12:
  1861. case 13:
  1862. case 14:
  1863. case 15:
  1864. case 16:
  1865. case 17:
  1866. case 18:
  1867. case 19:
  1868. break;
  1869. case 46:
  1870. break;
  1871. case 50:
  1872. break;
  1873. case 51:
  1874. break;
  1875. case 52:
  1876. break;
  1877. case 104:
  1878. case 105:
  1879. case 110:
  1880. case 111:
  1881. case 112:
  1882. case 113:
  1883. case 114:
  1884. case 115:
  1885. case 116:
  1886. case 117:
  1887. case 118:
  1888. break;
  1889. }
  1890. this._terminal.params = [];
  1891. this._terminal.currentParam = 0;
  1892. this._state = ParserState.NORMAL;
  1893. }
  1894. else {
  1895. if (!this._terminal.params.length) {
  1896. if (ch >= '0' && ch <= '9') {
  1897. this._terminal.currentParam =
  1898. this._terminal.currentParam * 10 + ch.charCodeAt(0) - 48;
  1899. }
  1900. else if (ch === ';') {
  1901. this._terminal.params.push(this._terminal.currentParam);
  1902. this._terminal.currentParam = '';
  1903. }
  1904. }
  1905. else {
  1906. this._terminal.currentParam += ch;
  1907. }
  1908. }
  1909. break;
  1910. case ParserState.CSI_PARAM:
  1911. if (ch in csiParamStateHandler) {
  1912. csiParamStateHandler[ch](this);
  1913. break;
  1914. }
  1915. this.finalizeParam();
  1916. this._state = ParserState.CSI;
  1917. case ParserState.CSI:
  1918. if (ch in csiStateHandler) {
  1919. csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
  1920. }
  1921. else {
  1922. this._terminal.error('Unknown CSI code: %s.', ch);
  1923. }
  1924. this._state = ParserState.NORMAL;
  1925. this._terminal.prefix = '';
  1926. this._terminal.postfix = '';
  1927. break;
  1928. case ParserState.DCS:
  1929. if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
  1930. if (ch === EscapeSequences_1.C0.ESC)
  1931. this._position++;
  1932. var pt = void 0;
  1933. var valid = void 0;
  1934. switch (this._terminal.prefix) {
  1935. case '':
  1936. break;
  1937. case '$q':
  1938. pt = this._terminal.currentParam;
  1939. valid = false;
  1940. switch (pt) {
  1941. case '"q':
  1942. pt = '0"q';
  1943. break;
  1944. case '"p':
  1945. pt = '61"p';
  1946. break;
  1947. case 'r':
  1948. pt = ''
  1949. + (this._terminal.scrollTop + 1)
  1950. + ';'
  1951. + (this._terminal.scrollBottom + 1)
  1952. + 'r';
  1953. break;
  1954. case 'm':
  1955. pt = '0m';
  1956. break;
  1957. default:
  1958. this._terminal.error('Unknown DCS Pt: %s.', pt);
  1959. pt = '';
  1960. break;
  1961. }
  1962. this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '$r' + pt + EscapeSequences_1.C0.ESC + '\\');
  1963. break;
  1964. case '+p':
  1965. break;
  1966. case '+q':
  1967. pt = this._terminal.currentParam;
  1968. valid = false;
  1969. this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '+r' + pt + EscapeSequences_1.C0.ESC + '\\');
  1970. break;
  1971. default:
  1972. this._terminal.error('Unknown DCS prefix: %s.', this._terminal.prefix);
  1973. break;
  1974. }
  1975. this._terminal.currentParam = 0;
  1976. this._terminal.prefix = '';
  1977. this._state = ParserState.NORMAL;
  1978. }
  1979. else if (!this._terminal.currentParam) {
  1980. if (!this._terminal.prefix && ch !== '$' && ch !== '+') {
  1981. this._terminal.currentParam = ch;
  1982. }
  1983. else if (this._terminal.prefix.length === 2) {
  1984. this._terminal.currentParam = ch;
  1985. }
  1986. else {
  1987. this._terminal.prefix += ch;
  1988. }
  1989. }
  1990. else {
  1991. this._terminal.currentParam += ch;
  1992. }
  1993. break;
  1994. case ParserState.IGNORE:
  1995. if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
  1996. if (ch === EscapeSequences_1.C0.ESC)
  1997. this._position++;
  1998. this._state = ParserState.NORMAL;
  1999. }
  2000. break;
  2001. }
  2002. }
  2003. return this._state;
  2004. };
  2005. Parser.prototype.setState = function (state) {
  2006. this._state = state;
  2007. };
  2008. Parser.prototype.setPrefix = function (prefix) {
  2009. this._terminal.prefix = prefix;
  2010. };
  2011. Parser.prototype.setPostfix = function (postfix) {
  2012. this._terminal.postfix = postfix;
  2013. };
  2014. Parser.prototype.setParam = function (param) {
  2015. this._terminal.currentParam = param;
  2016. };
  2017. Parser.prototype.getParam = function () {
  2018. return this._terminal.currentParam;
  2019. };
  2020. Parser.prototype.finalizeParam = function () {
  2021. this._terminal.params.push(this._terminal.currentParam);
  2022. this._terminal.currentParam = 0;
  2023. };
  2024. Parser.prototype.skipNextChar = function () {
  2025. this._position++;
  2026. };
  2027. return Parser;
  2028. }());
  2029. exports.Parser = Parser;
  2030. },{"./Charsets":1,"./EscapeSequences":3}],8:[function(require,module,exports){
  2031. "use strict";
  2032. Object.defineProperty(exports, "__esModule", { value: true });
  2033. var DomElementObjectPool_1 = require("./utils/DomElementObjectPool");
  2034. var MAX_REFRESH_FRAME_SKIP = 5;
  2035. var FLAGS;
  2036. (function (FLAGS) {
  2037. FLAGS[FLAGS["BOLD"] = 1] = "BOLD";
  2038. FLAGS[FLAGS["UNDERLINE"] = 2] = "UNDERLINE";
  2039. FLAGS[FLAGS["BLINK"] = 4] = "BLINK";
  2040. FLAGS[FLAGS["INVERSE"] = 8] = "INVERSE";
  2041. FLAGS[FLAGS["INVISIBLE"] = 16] = "INVISIBLE";
  2042. })(FLAGS || (FLAGS = {}));
  2043. ;
  2044. var brokenBold = null;
  2045. var Renderer = (function () {
  2046. function Renderer(_terminal) {
  2047. this._terminal = _terminal;
  2048. this._refreshRowsQueue = [];
  2049. this._refreshFramesSkipped = 0;
  2050. this._refreshAnimationFrame = null;
  2051. this._spanElementObjectPool = new DomElementObjectPool_1.DomElementObjectPool('span');
  2052. if (brokenBold === null) {
  2053. brokenBold = checkBoldBroken(this._terminal.element);
  2054. }
  2055. this._spanElementObjectPool = new DomElementObjectPool_1.DomElementObjectPool('span');
  2056. }
  2057. Renderer.prototype.queueRefresh = function (start, end) {
  2058. this._refreshRowsQueue.push({ start: start, end: end });
  2059. if (!this._refreshAnimationFrame) {
  2060. this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
  2061. }
  2062. };
  2063. Renderer.prototype._refreshLoop = function () {
  2064. var skipFrame = this._terminal.writeBuffer.length > 0 && this._refreshFramesSkipped++ <= MAX_REFRESH_FRAME_SKIP;
  2065. if (skipFrame) {
  2066. this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
  2067. return;
  2068. }
  2069. this._refreshFramesSkipped = 0;
  2070. var start;
  2071. var end;
  2072. if (this._refreshRowsQueue.length > 4) {
  2073. start = 0;
  2074. end = this._terminal.rows - 1;
  2075. }
  2076. else {
  2077. start = this._refreshRowsQueue[0].start;
  2078. end = this._refreshRowsQueue[0].end;
  2079. for (var i = 1; i < this._refreshRowsQueue.length; i++) {
  2080. if (this._refreshRowsQueue[i].start < start) {
  2081. start = this._refreshRowsQueue[i].start;
  2082. }
  2083. if (this._refreshRowsQueue[i].end > end) {
  2084. end = this._refreshRowsQueue[i].end;
  2085. }
  2086. }
  2087. }
  2088. this._refreshRowsQueue = [];
  2089. this._refreshAnimationFrame = null;
  2090. this._refresh(start, end);
  2091. };
  2092. Renderer.prototype._refresh = function (start, end) {
  2093. var parent;
  2094. if (end - start >= this._terminal.rows / 2) {
  2095. parent = this._terminal.element.parentNode;
  2096. if (parent) {
  2097. this._terminal.element.removeChild(this._terminal.rowContainer);
  2098. }
  2099. }
  2100. var width = this._terminal.cols;
  2101. var y = start;
  2102. if (end >= this._terminal.rows) {
  2103. this._terminal.log('`end` is too large. Most likely a bad CSR.');
  2104. end = this._terminal.rows - 1;
  2105. }
  2106. for (; y <= end; y++) {
  2107. var row = y + this._terminal.ydisp;
  2108. var line = this._terminal.lines.get(row);
  2109. var x = void 0;
  2110. if (this._terminal.y === y - (this._terminal.ybase - this._terminal.ydisp) &&
  2111. this._terminal.cursorState &&
  2112. !this._terminal.cursorHidden) {
  2113. x = this._terminal.x;
  2114. }
  2115. else {
  2116. x = -1;
  2117. }
  2118. var attr = this._terminal.defAttr;
  2119. var documentFragment = document.createDocumentFragment();
  2120. var innerHTML = '';
  2121. var currentElement = void 0;
  2122. while (this._terminal.children[y].children.length) {
  2123. var child = this._terminal.children[y].children[0];
  2124. this._terminal.children[y].removeChild(child);
  2125. this._spanElementObjectPool.release(child);
  2126. }
  2127. for (var i = 0; i < width; i++) {
  2128. var data = line[i][0];
  2129. var ch = line[i][1];
  2130. var ch_width = line[i][2];
  2131. if (!ch_width) {
  2132. continue;
  2133. }
  2134. if (i === x) {
  2135. data = -1;
  2136. }
  2137. if (data !== attr) {
  2138. if (attr !== this._terminal.defAttr) {
  2139. if (innerHTML) {
  2140. currentElement.innerHTML = innerHTML;
  2141. innerHTML = '';
  2142. }
  2143. documentFragment.appendChild(currentElement);
  2144. currentElement = null;
  2145. }
  2146. if (data !== this._terminal.defAttr) {
  2147. if (innerHTML && !currentElement) {
  2148. currentElement = this._spanElementObjectPool.acquire();
  2149. }
  2150. if (currentElement) {
  2151. if (innerHTML) {
  2152. currentElement.innerHTML = innerHTML;
  2153. innerHTML = '';
  2154. }
  2155. documentFragment.appendChild(currentElement);
  2156. }
  2157. currentElement = this._spanElementObjectPool.acquire();
  2158. if (data === -1) {
  2159. currentElement.classList.add('reverse-video');
  2160. currentElement.classList.add('terminal-cursor');
  2161. }
  2162. else {
  2163. var bg = data & 0x1ff;
  2164. var fg = (data >> 9) & 0x1ff;
  2165. var flags = data >> 18;
  2166. if (flags & FLAGS.BOLD) {
  2167. if (!brokenBold) {
  2168. currentElement.classList.add('xterm-bold');
  2169. }
  2170. if (fg < 8) {
  2171. fg += 8;
  2172. }
  2173. }
  2174. if (flags & FLAGS.UNDERLINE) {
  2175. currentElement.classList.add('xterm-underline');
  2176. }
  2177. if (flags & FLAGS.BLINK) {
  2178. currentElement.classList.add('xterm-blink');
  2179. }
  2180. if (flags & FLAGS.INVERSE) {
  2181. var temp = bg;
  2182. bg = fg;
  2183. fg = temp;
  2184. if ((flags & 1) && fg < 8) {
  2185. fg += 8;
  2186. }
  2187. }
  2188. if (flags & FLAGS.INVISIBLE) {
  2189. currentElement.classList.add('xterm-hidden');
  2190. }
  2191. if (flags & FLAGS.INVERSE) {
  2192. if (bg === 257) {
  2193. bg = 15;
  2194. }
  2195. if (fg === 256) {
  2196. fg = 0;
  2197. }
  2198. }
  2199. if (bg < 256) {
  2200. currentElement.classList.add("xterm-bg-color-" + bg);
  2201. }
  2202. if (fg < 256) {
  2203. currentElement.classList.add("xterm-color-" + fg);
  2204. }
  2205. }
  2206. }
  2207. }
  2208. if (ch_width === 2) {
  2209. innerHTML += "<span class=\"xterm-wide-char\">" + ch + "</span>";
  2210. }
  2211. else if (ch.charCodeAt(0) > 255) {
  2212. innerHTML += "<span class=\"xterm-normal-char\">" + ch + "</span>";
  2213. }
  2214. else {
  2215. switch (ch) {
  2216. case '&':
  2217. innerHTML += '&amp;';
  2218. break;
  2219. case '<':
  2220. innerHTML += '&lt;';
  2221. break;
  2222. case '>':
  2223. innerHTML += '&gt;';
  2224. break;
  2225. default:
  2226. if (ch <= ' ') {
  2227. innerHTML += '&nbsp;';
  2228. }
  2229. else {
  2230. innerHTML += ch;
  2231. }
  2232. break;
  2233. }
  2234. }
  2235. attr = data;
  2236. }
  2237. if (innerHTML && !currentElement) {
  2238. currentElement = this._spanElementObjectPool.acquire();
  2239. }
  2240. if (currentElement) {
  2241. if (innerHTML) {
  2242. currentElement.innerHTML = innerHTML;
  2243. innerHTML = '';
  2244. }
  2245. documentFragment.appendChild(currentElement);
  2246. currentElement = null;
  2247. }
  2248. this._terminal.children[y].appendChild(documentFragment);
  2249. }
  2250. if (parent) {
  2251. this._terminal.element.appendChild(this._terminal.rowContainer);
  2252. }
  2253. this._terminal.emit('refresh', { element: this._terminal.element, start: start, end: end });
  2254. };
  2255. ;
  2256. Renderer.prototype.refreshSelection = function (start, end) {
  2257. while (this._terminal.selectionContainer.children.length) {
  2258. this._terminal.selectionContainer.removeChild(this._terminal.selectionContainer.children[0]);
  2259. }
  2260. if (!start || !end) {
  2261. return;
  2262. }
  2263. var viewportStartRow = start[1] - this._terminal.ydisp;
  2264. var viewportEndRow = end[1] - this._terminal.ydisp;
  2265. var viewportCappedStartRow = Math.max(viewportStartRow, 0);
  2266. var viewportCappedEndRow = Math.min(viewportEndRow, this._terminal.rows - 1);
  2267. if (viewportCappedStartRow >= this._terminal.rows || viewportCappedEndRow < 0) {
  2268. return;
  2269. }
  2270. var documentFragment = document.createDocumentFragment();
  2271. var startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
  2272. var endCol = viewportCappedStartRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
  2273. documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow, startCol, endCol));
  2274. var middleRowsCount = viewportCappedEndRow - viewportCappedStartRow - 1;
  2275. documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow + 1, 0, this._terminal.cols, middleRowsCount));
  2276. if (viewportCappedStartRow !== viewportCappedEndRow) {
  2277. var endCol_1 = viewportEndRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
  2278. documentFragment.appendChild(this._createSelectionElement(viewportCappedEndRow, 0, endCol_1));
  2279. }
  2280. this._terminal.selectionContainer.appendChild(documentFragment);
  2281. };
  2282. Renderer.prototype._createSelectionElement = function (row, colStart, colEnd, rowCount) {
  2283. if (rowCount === void 0) { rowCount = 1; }
  2284. var element = document.createElement('div');
  2285. element.style.height = rowCount * this._terminal.charMeasure.height + "px";
  2286. element.style.top = row * this._terminal.charMeasure.height + "px";
  2287. element.style.left = colStart * this._terminal.charMeasure.width + "px";
  2288. element.style.width = this._terminal.charMeasure.width * (colEnd - colStart) + "px";
  2289. return element;
  2290. };
  2291. return Renderer;
  2292. }());
  2293. exports.Renderer = Renderer;
  2294. function checkBoldBroken(terminal) {
  2295. var document = terminal.ownerDocument;
  2296. var el = document.createElement('span');
  2297. el.innerHTML = 'hello world';
  2298. terminal.appendChild(el);
  2299. var w1 = el.offsetWidth;
  2300. var h1 = el.offsetHeight;
  2301. el.style.fontWeight = 'bold';
  2302. var w2 = el.offsetWidth;
  2303. var h2 = el.offsetHeight;
  2304. terminal.removeChild(el);
  2305. return w1 !== w2 || h1 !== h2;
  2306. }
  2307. },{"./utils/DomElementObjectPool":16}],9:[function(require,module,exports){
  2308. "use strict";
  2309. var __extends = (this && this.__extends) || (function () {
  2310. var extendStatics = Object.setPrototypeOf ||
  2311. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2312. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2313. return function (d, b) {
  2314. extendStatics(d, b);
  2315. function __() { this.constructor = d; }
  2316. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2317. };
  2318. })();
  2319. Object.defineProperty(exports, "__esModule", { value: true });
  2320. var Mouse = require("./utils/Mouse");
  2321. var Browser = require("./utils/Browser");
  2322. var EventEmitter_1 = require("./EventEmitter");
  2323. var SelectionModel_1 = require("./SelectionModel");
  2324. var DRAG_SCROLL_MAX_THRESHOLD = 50;
  2325. var DRAG_SCROLL_MAX_SPEED = 15;
  2326. var DRAG_SCROLL_INTERVAL = 50;
  2327. var CLEAR_MOUSE_DOWN_TIME = 400;
  2328. var CLEAR_MOUSE_DISTANCE = 10;
  2329. var WORD_SEPARATORS = ' ()[]{}\'"';
  2330. var LINE_DATA_CHAR_INDEX = 1;
  2331. var LINE_DATA_WIDTH_INDEX = 2;
  2332. var NON_BREAKING_SPACE_CHAR = String.fromCharCode(160);
  2333. var ALL_NON_BREAKING_SPACE_REGEX = new RegExp(NON_BREAKING_SPACE_CHAR, 'g');
  2334. var SelectionMode;
  2335. (function (SelectionMode) {
  2336. SelectionMode[SelectionMode["NORMAL"] = 0] = "NORMAL";
  2337. SelectionMode[SelectionMode["WORD"] = 1] = "WORD";
  2338. SelectionMode[SelectionMode["LINE"] = 2] = "LINE";
  2339. })(SelectionMode || (SelectionMode = {}));
  2340. var SelectionManager = (function (_super) {
  2341. __extends(SelectionManager, _super);
  2342. function SelectionManager(_terminal, _buffer, _rowContainer, _charMeasure) {
  2343. var _this = _super.call(this) || this;
  2344. _this._terminal = _terminal;
  2345. _this._buffer = _buffer;
  2346. _this._rowContainer = _rowContainer;
  2347. _this._charMeasure = _charMeasure;
  2348. _this._initListeners();
  2349. _this.enable();
  2350. _this._model = new SelectionModel_1.SelectionModel(_terminal);
  2351. _this._lastMouseDownTime = 0;
  2352. _this._activeSelectionMode = SelectionMode.NORMAL;
  2353. return _this;
  2354. }
  2355. SelectionManager.prototype._initListeners = function () {
  2356. var _this = this;
  2357. this._bufferTrimListener = function (amount) { return _this._onTrim(amount); };
  2358. this._mouseMoveListener = function (event) { return _this._onMouseMove(event); };
  2359. this._mouseDownListener = function (event) { return _this._onMouseDown(event); };
  2360. this._mouseUpListener = function (event) { return _this._onMouseUp(event); };
  2361. };
  2362. SelectionManager.prototype.disable = function () {
  2363. this.clearSelection();
  2364. this._buffer.off('trim', this._bufferTrimListener);
  2365. this._rowContainer.removeEventListener('mousedown', this._mouseDownListener);
  2366. };
  2367. SelectionManager.prototype.enable = function () {
  2368. this._buffer.on('trim', this._bufferTrimListener);
  2369. this._rowContainer.addEventListener('mousedown', this._mouseDownListener);
  2370. };
  2371. SelectionManager.prototype.setBuffer = function (buffer) {
  2372. this._buffer = buffer;
  2373. this.clearSelection();
  2374. };
  2375. Object.defineProperty(SelectionManager.prototype, "hasSelection", {
  2376. get: function () {
  2377. var start = this._model.finalSelectionStart;
  2378. var end = this._model.finalSelectionEnd;
  2379. if (!start || !end) {
  2380. return false;
  2381. }
  2382. return start[0] !== end[0] || start[1] !== end[1];
  2383. },
  2384. enumerable: true,
  2385. configurable: true
  2386. });
  2387. Object.defineProperty(SelectionManager.prototype, "selectionText", {
  2388. get: function () {
  2389. var start = this._model.finalSelectionStart;
  2390. var end = this._model.finalSelectionEnd;
  2391. if (!start || !end) {
  2392. return '';
  2393. }
  2394. var startRowEndCol = start[1] === end[1] ? end[0] : null;
  2395. var result = [];
  2396. result.push(this._translateBufferLineToString(this._buffer.get(start[1]), true, start[0], startRowEndCol));
  2397. for (var i = start[1] + 1; i <= end[1] - 1; i++) {
  2398. var bufferLine = this._buffer.get(i);
  2399. var lineText = this._translateBufferLineToString(bufferLine, true);
  2400. if (bufferLine.isWrapped) {
  2401. result[result.length - 1] += lineText;
  2402. }
  2403. else {
  2404. result.push(lineText);
  2405. }
  2406. }
  2407. if (start[1] !== end[1]) {
  2408. var bufferLine = this._buffer.get(end[1]);
  2409. var lineText = this._translateBufferLineToString(bufferLine, true, 0, end[0]);
  2410. if (bufferLine.isWrapped) {
  2411. result[result.length - 1] += lineText;
  2412. }
  2413. else {
  2414. result.push(lineText);
  2415. }
  2416. }
  2417. var formattedResult = result.map(function (line) {
  2418. return line.replace(ALL_NON_BREAKING_SPACE_REGEX, ' ');
  2419. }).join(Browser.isMSWindows ? '\r\n' : '\n');
  2420. return formattedResult;
  2421. },
  2422. enumerable: true,
  2423. configurable: true
  2424. });
  2425. SelectionManager.prototype.clearSelection = function () {
  2426. this._model.clearSelection();
  2427. this._removeMouseDownListeners();
  2428. this.refresh();
  2429. };
  2430. SelectionManager.prototype._translateBufferLineToString = function (line, trimRight, startCol, endCol) {
  2431. if (startCol === void 0) { startCol = 0; }
  2432. if (endCol === void 0) { endCol = null; }
  2433. var lineString = '';
  2434. var widthAdjustedStartCol = startCol;
  2435. var widthAdjustedEndCol = endCol;
  2436. for (var i = 0; i < line.length; i++) {
  2437. var char = line[i];
  2438. lineString += char[LINE_DATA_CHAR_INDEX];
  2439. if (char[LINE_DATA_WIDTH_INDEX] === 0) {
  2440. if (startCol >= i) {
  2441. widthAdjustedStartCol--;
  2442. }
  2443. if (endCol >= i) {
  2444. widthAdjustedEndCol--;
  2445. }
  2446. }
  2447. }
  2448. var finalEndCol = widthAdjustedEndCol || line.length;
  2449. if (trimRight) {
  2450. var rightWhitespaceIndex = lineString.search(/\s+$/);
  2451. if (rightWhitespaceIndex !== -1) {
  2452. finalEndCol = Math.min(finalEndCol, rightWhitespaceIndex);
  2453. }
  2454. if (finalEndCol <= widthAdjustedStartCol) {
  2455. return '';
  2456. }
  2457. }
  2458. return lineString.substring(widthAdjustedStartCol, finalEndCol);
  2459. };
  2460. SelectionManager.prototype.refresh = function (isNewSelection) {
  2461. var _this = this;
  2462. if (!this._refreshAnimationFrame) {
  2463. this._refreshAnimationFrame = window.requestAnimationFrame(function () { return _this._refresh(); });
  2464. }
  2465. if (Browser.isLinux && isNewSelection) {
  2466. var selectionText = this.selectionText;
  2467. if (selectionText.length) {
  2468. this.emit('newselection', this.selectionText);
  2469. }
  2470. }
  2471. };
  2472. SelectionManager.prototype._refresh = function () {
  2473. this._refreshAnimationFrame = null;
  2474. this.emit('refresh', { start: this._model.finalSelectionStart, end: this._model.finalSelectionEnd });
  2475. };
  2476. SelectionManager.prototype.selectAll = function () {
  2477. this._model.isSelectAllActive = true;
  2478. this.refresh();
  2479. };
  2480. SelectionManager.prototype._onTrim = function (amount) {
  2481. var needsRefresh = this._model.onTrim(amount);
  2482. if (needsRefresh) {
  2483. this.refresh();
  2484. }
  2485. };
  2486. SelectionManager.prototype._getMouseBufferCoords = function (event) {
  2487. var coords = Mouse.getCoords(event, this._rowContainer, this._charMeasure, this._terminal.cols, this._terminal.rows, true);
  2488. coords[0]--;
  2489. coords[1]--;
  2490. coords[1] += this._terminal.ydisp;
  2491. return coords;
  2492. };
  2493. SelectionManager.prototype._getMouseEventScrollAmount = function (event) {
  2494. var offset = Mouse.getCoordsRelativeToElement(event, this._rowContainer)[1];
  2495. var terminalHeight = this._terminal.rows * this._charMeasure.height;
  2496. if (offset >= 0 && offset <= terminalHeight) {
  2497. return 0;
  2498. }
  2499. if (offset > terminalHeight) {
  2500. offset -= terminalHeight;
  2501. }
  2502. offset = Math.min(Math.max(offset, -DRAG_SCROLL_MAX_THRESHOLD), DRAG_SCROLL_MAX_THRESHOLD);
  2503. offset /= DRAG_SCROLL_MAX_THRESHOLD;
  2504. return (offset / Math.abs(offset)) + Math.round(offset * (DRAG_SCROLL_MAX_SPEED - 1));
  2505. };
  2506. SelectionManager.prototype._onMouseDown = function (event) {
  2507. if (event.button !== 0) {
  2508. return;
  2509. }
  2510. event.preventDefault();
  2511. this._dragScrollAmount = 0;
  2512. this._setMouseClickCount(event);
  2513. if (event.shiftKey) {
  2514. this._onShiftClick(event);
  2515. }
  2516. else {
  2517. if (this._clickCount === 1) {
  2518. this._onSingleClick(event);
  2519. }
  2520. else if (this._clickCount === 2) {
  2521. this._onDoubleClick(event);
  2522. }
  2523. else if (this._clickCount === 3) {
  2524. this._onTripleClick(event);
  2525. }
  2526. }
  2527. this._addMouseDownListeners();
  2528. this.refresh(true);
  2529. };
  2530. SelectionManager.prototype._addMouseDownListeners = function () {
  2531. var _this = this;
  2532. this._rowContainer.ownerDocument.addEventListener('mousemove', this._mouseMoveListener);
  2533. this._rowContainer.ownerDocument.addEventListener('mouseup', this._mouseUpListener);
  2534. this._dragScrollIntervalTimer = setInterval(function () { return _this._dragScroll(); }, DRAG_SCROLL_INTERVAL);
  2535. };
  2536. SelectionManager.prototype._removeMouseDownListeners = function () {
  2537. this._rowContainer.ownerDocument.removeEventListener('mousemove', this._mouseMoveListener);
  2538. this._rowContainer.ownerDocument.removeEventListener('mouseup', this._mouseUpListener);
  2539. clearInterval(this._dragScrollIntervalTimer);
  2540. this._dragScrollIntervalTimer = null;
  2541. };
  2542. SelectionManager.prototype._onShiftClick = function (event) {
  2543. if (this._model.selectionStart) {
  2544. this._model.selectionEnd = this._getMouseBufferCoords(event);
  2545. }
  2546. };
  2547. SelectionManager.prototype._onSingleClick = function (event) {
  2548. this._model.selectionStartLength = 0;
  2549. this._model.isSelectAllActive = false;
  2550. this._activeSelectionMode = SelectionMode.NORMAL;
  2551. this._model.selectionStart = this._getMouseBufferCoords(event);
  2552. if (this._model.selectionStart) {
  2553. this._model.selectionEnd = null;
  2554. var char = this._buffer.get(this._model.selectionStart[1])[this._model.selectionStart[0]];
  2555. if (char[LINE_DATA_WIDTH_INDEX] === 0) {
  2556. this._model.selectionStart[0]++;
  2557. }
  2558. }
  2559. };
  2560. SelectionManager.prototype._onDoubleClick = function (event) {
  2561. var coords = this._getMouseBufferCoords(event);
  2562. if (coords) {
  2563. this._activeSelectionMode = SelectionMode.WORD;
  2564. this._selectWordAt(coords);
  2565. }
  2566. };
  2567. SelectionManager.prototype._onTripleClick = function (event) {
  2568. var coords = this._getMouseBufferCoords(event);
  2569. if (coords) {
  2570. this._activeSelectionMode = SelectionMode.LINE;
  2571. this._selectLineAt(coords[1]);
  2572. }
  2573. };
  2574. SelectionManager.prototype._setMouseClickCount = function (event) {
  2575. var currentTime = (new Date()).getTime();
  2576. if (currentTime - this._lastMouseDownTime > CLEAR_MOUSE_DOWN_TIME || this._distanceFromLastMousePosition(event) > CLEAR_MOUSE_DISTANCE) {
  2577. this._clickCount = 0;
  2578. }
  2579. this._lastMouseDownTime = currentTime;
  2580. this._lastMousePosition = [event.pageX, event.pageY];
  2581. this._clickCount++;
  2582. };
  2583. SelectionManager.prototype._distanceFromLastMousePosition = function (event) {
  2584. var result = Math.max(Math.abs(this._lastMousePosition[0] - event.pageX), Math.abs(this._lastMousePosition[1] - event.pageY));
  2585. return result;
  2586. };
  2587. SelectionManager.prototype._onMouseMove = function (event) {
  2588. var previousSelectionEnd = this._model.selectionEnd ? [this._model.selectionEnd[0], this._model.selectionEnd[1]] : null;
  2589. this._model.selectionEnd = this._getMouseBufferCoords(event);
  2590. if (this._activeSelectionMode === SelectionMode.LINE) {
  2591. if (this._model.selectionEnd[1] < this._model.selectionStart[1]) {
  2592. this._model.selectionEnd[0] = 0;
  2593. }
  2594. else {
  2595. this._model.selectionEnd[0] = this._terminal.cols;
  2596. }
  2597. }
  2598. else if (this._activeSelectionMode === SelectionMode.WORD) {
  2599. this._selectToWordAt(this._model.selectionEnd);
  2600. }
  2601. this._dragScrollAmount = this._getMouseEventScrollAmount(event);
  2602. if (this._dragScrollAmount > 0) {
  2603. this._model.selectionEnd[0] = this._terminal.cols - 1;
  2604. }
  2605. else if (this._dragScrollAmount < 0) {
  2606. this._model.selectionEnd[0] = 0;
  2607. }
  2608. if (this._model.selectionEnd[1] < this._buffer.length) {
  2609. var char = this._buffer.get(this._model.selectionEnd[1])[this._model.selectionEnd[0]];
  2610. if (char && char[2] === 0) {
  2611. this._model.selectionEnd[0]++;
  2612. }
  2613. }
  2614. if (!previousSelectionEnd ||
  2615. previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
  2616. previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
  2617. this.refresh(true);
  2618. }
  2619. };
  2620. SelectionManager.prototype._dragScroll = function () {
  2621. if (this._dragScrollAmount) {
  2622. this._terminal.scrollDisp(this._dragScrollAmount, false);
  2623. if (this._dragScrollAmount > 0) {
  2624. this._model.selectionEnd = [this._terminal.cols - 1, this._terminal.ydisp + this._terminal.rows];
  2625. }
  2626. else {
  2627. this._model.selectionEnd = [0, this._terminal.ydisp];
  2628. }
  2629. this.refresh();
  2630. }
  2631. };
  2632. SelectionManager.prototype._onMouseUp = function (event) {
  2633. this._removeMouseDownListeners();
  2634. };
  2635. SelectionManager.prototype._convertViewportColToCharacterIndex = function (bufferLine, coords) {
  2636. var charIndex = coords[0];
  2637. for (var i = 0; coords[0] >= i; i++) {
  2638. var char = bufferLine[i];
  2639. if (char[LINE_DATA_WIDTH_INDEX] === 0) {
  2640. charIndex--;
  2641. }
  2642. }
  2643. return charIndex;
  2644. };
  2645. SelectionManager.prototype._getWordAt = function (coords) {
  2646. var bufferLine = this._buffer.get(coords[1]);
  2647. var line = this._translateBufferLineToString(bufferLine, false);
  2648. var endIndex = this._convertViewportColToCharacterIndex(bufferLine, coords);
  2649. var startIndex = endIndex;
  2650. var charOffset = coords[0] - startIndex;
  2651. var leftWideCharCount = 0;
  2652. var rightWideCharCount = 0;
  2653. if (line.charAt(startIndex) === ' ') {
  2654. while (startIndex > 0 && line.charAt(startIndex - 1) === ' ') {
  2655. startIndex--;
  2656. }
  2657. while (endIndex < line.length && line.charAt(endIndex + 1) === ' ') {
  2658. endIndex++;
  2659. }
  2660. }
  2661. else {
  2662. var startCol = coords[0];
  2663. var endCol = coords[0];
  2664. if (bufferLine[startCol][LINE_DATA_WIDTH_INDEX] === 0) {
  2665. leftWideCharCount++;
  2666. startCol--;
  2667. }
  2668. if (bufferLine[endCol][LINE_DATA_WIDTH_INDEX] === 2) {
  2669. rightWideCharCount++;
  2670. endCol++;
  2671. }
  2672. while (startIndex > 0 && !this._isCharWordSeparator(line.charAt(startIndex - 1))) {
  2673. if (bufferLine[startCol - 1][LINE_DATA_WIDTH_INDEX] === 0) {
  2674. leftWideCharCount++;
  2675. startCol--;
  2676. }
  2677. startIndex--;
  2678. startCol--;
  2679. }
  2680. while (endIndex + 1 < line.length && !this._isCharWordSeparator(line.charAt(endIndex + 1))) {
  2681. if (bufferLine[endCol + 1][LINE_DATA_WIDTH_INDEX] === 2) {
  2682. rightWideCharCount++;
  2683. endCol++;
  2684. }
  2685. endIndex++;
  2686. endCol++;
  2687. }
  2688. }
  2689. var start = startIndex + charOffset - leftWideCharCount;
  2690. var length = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1, this._terminal.cols);
  2691. return { start: start, length: length };
  2692. };
  2693. SelectionManager.prototype._selectWordAt = function (coords) {
  2694. var wordPosition = this._getWordAt(coords);
  2695. this._model.selectionStart = [wordPosition.start, coords[1]];
  2696. this._model.selectionStartLength = wordPosition.length;
  2697. };
  2698. SelectionManager.prototype._selectToWordAt = function (coords) {
  2699. var wordPosition = this._getWordAt(coords);
  2700. this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : (wordPosition.start + wordPosition.length), coords[1]];
  2701. };
  2702. SelectionManager.prototype._isCharWordSeparator = function (char) {
  2703. return WORD_SEPARATORS.indexOf(char) >= 0;
  2704. };
  2705. SelectionManager.prototype._selectLineAt = function (line) {
  2706. this._model.selectionStart = [0, line];
  2707. this._model.selectionStartLength = this._terminal.cols;
  2708. };
  2709. return SelectionManager;
  2710. }(EventEmitter_1.EventEmitter));
  2711. exports.SelectionManager = SelectionManager;
  2712. },{"./EventEmitter":4,"./SelectionModel":10,"./utils/Browser":13,"./utils/Mouse":18}],10:[function(require,module,exports){
  2713. "use strict";
  2714. Object.defineProperty(exports, "__esModule", { value: true });
  2715. var SelectionModel = (function () {
  2716. function SelectionModel(_terminal) {
  2717. this._terminal = _terminal;
  2718. this.clearSelection();
  2719. }
  2720. SelectionModel.prototype.clearSelection = function () {
  2721. this.selectionStart = null;
  2722. this.selectionEnd = null;
  2723. this.isSelectAllActive = false;
  2724. this.selectionStartLength = 0;
  2725. };
  2726. Object.defineProperty(SelectionModel.prototype, "finalSelectionStart", {
  2727. get: function () {
  2728. if (this.isSelectAllActive) {
  2729. return [0, 0];
  2730. }
  2731. if (!this.selectionEnd || !this.selectionStart) {
  2732. return this.selectionStart;
  2733. }
  2734. return this.areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
  2735. },
  2736. enumerable: true,
  2737. configurable: true
  2738. });
  2739. Object.defineProperty(SelectionModel.prototype, "finalSelectionEnd", {
  2740. get: function () {
  2741. if (this.isSelectAllActive) {
  2742. return [this._terminal.cols, this._terminal.ybase + this._terminal.rows - 1];
  2743. }
  2744. if (!this.selectionStart) {
  2745. return null;
  2746. }
  2747. if (!this.selectionEnd || this.areSelectionValuesReversed()) {
  2748. return [this.selectionStart[0] + this.selectionStartLength, this.selectionStart[1]];
  2749. }
  2750. if (this.selectionStartLength) {
  2751. if (this.selectionEnd[1] === this.selectionStart[1]) {
  2752. return [Math.max(this.selectionStart[0] + this.selectionStartLength, this.selectionEnd[0]), this.selectionEnd[1]];
  2753. }
  2754. }
  2755. return this.selectionEnd;
  2756. },
  2757. enumerable: true,
  2758. configurable: true
  2759. });
  2760. SelectionModel.prototype.areSelectionValuesReversed = function () {
  2761. var start = this.selectionStart;
  2762. var end = this.selectionEnd;
  2763. return start[1] > end[1] || (start[1] === end[1] && start[0] > end[0]);
  2764. };
  2765. SelectionModel.prototype.onTrim = function (amount) {
  2766. if (this.selectionStart) {
  2767. this.selectionStart[1] -= amount;
  2768. }
  2769. if (this.selectionEnd) {
  2770. this.selectionEnd[1] -= amount;
  2771. }
  2772. if (this.selectionEnd && this.selectionEnd[1] < 0) {
  2773. this.clearSelection();
  2774. return true;
  2775. }
  2776. if (this.selectionStart && this.selectionStart[1] < 0) {
  2777. this.selectionStart[1] = 0;
  2778. }
  2779. return false;
  2780. };
  2781. return SelectionModel;
  2782. }());
  2783. exports.SelectionModel = SelectionModel;
  2784. },{}],11:[function(require,module,exports){
  2785. "use strict";
  2786. Object.defineProperty(exports, "__esModule", { value: true });
  2787. var Viewport = (function () {
  2788. function Viewport(terminal, viewportElement, scrollArea, charMeasure) {
  2789. var _this = this;
  2790. this.terminal = terminal;
  2791. this.viewportElement = viewportElement;
  2792. this.scrollArea = scrollArea;
  2793. this.charMeasure = charMeasure;
  2794. this.currentRowHeight = 0;
  2795. this.lastRecordedBufferLength = 0;
  2796. this.lastRecordedViewportHeight = 0;
  2797. this.terminal.on('scroll', this.syncScrollArea.bind(this));
  2798. this.terminal.on('resize', this.syncScrollArea.bind(this));
  2799. this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
  2800. setTimeout(function () { return _this.syncScrollArea(); }, 0);
  2801. }
  2802. Viewport.prototype.refresh = function () {
  2803. if (this.charMeasure.height > 0) {
  2804. var rowHeightChanged = this.charMeasure.height !== this.currentRowHeight;
  2805. if (rowHeightChanged) {
  2806. this.currentRowHeight = this.charMeasure.height;
  2807. this.viewportElement.style.lineHeight = this.charMeasure.height + 'px';
  2808. this.terminal.rowContainer.style.lineHeight = this.charMeasure.height + 'px';
  2809. }
  2810. var viewportHeightChanged = this.lastRecordedViewportHeight !== this.terminal.rows;
  2811. if (rowHeightChanged || viewportHeightChanged) {
  2812. this.lastRecordedViewportHeight = this.terminal.rows;
  2813. this.viewportElement.style.height = this.charMeasure.height * this.terminal.rows + 'px';
  2814. this.terminal.selectionContainer.style.height = this.viewportElement.style.height;
  2815. }
  2816. this.scrollArea.style.height = (this.charMeasure.height * this.lastRecordedBufferLength) + 'px';
  2817. }
  2818. };
  2819. Viewport.prototype.syncScrollArea = function () {
  2820. if (this.lastRecordedBufferLength !== this.terminal.lines.length) {
  2821. this.lastRecordedBufferLength = this.terminal.lines.length;
  2822. this.refresh();
  2823. }
  2824. else if (this.lastRecordedViewportHeight !== this.terminal.rows) {
  2825. this.refresh();
  2826. }
  2827. else {
  2828. if (this.charMeasure.height !== this.currentRowHeight) {
  2829. this.refresh();
  2830. }
  2831. }
  2832. var scrollTop = this.terminal.ydisp * this.currentRowHeight;
  2833. if (this.viewportElement.scrollTop !== scrollTop) {
  2834. this.viewportElement.scrollTop = scrollTop;
  2835. }
  2836. };
  2837. Viewport.prototype.onScroll = function (ev) {
  2838. var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
  2839. var diff = newRow - this.terminal.ydisp;
  2840. this.terminal.scrollDisp(diff, true);
  2841. };
  2842. Viewport.prototype.onWheel = function (ev) {
  2843. if (ev.deltaY === 0) {
  2844. return;
  2845. }
  2846. var multiplier = 1;
  2847. if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
  2848. multiplier = this.currentRowHeight;
  2849. }
  2850. else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2851. multiplier = this.currentRowHeight * this.terminal.rows;
  2852. }
  2853. this.viewportElement.scrollTop += ev.deltaY * multiplier;
  2854. ev.preventDefault();
  2855. };
  2856. ;
  2857. Viewport.prototype.onTouchStart = function (ev) {
  2858. this.lastTouchY = ev.touches[0].pageY;
  2859. };
  2860. ;
  2861. Viewport.prototype.onTouchMove = function (ev) {
  2862. var deltaY = this.lastTouchY - ev.touches[0].pageY;
  2863. this.lastTouchY = ev.touches[0].pageY;
  2864. if (deltaY === 0) {
  2865. return;
  2866. }
  2867. this.viewportElement.scrollTop += deltaY;
  2868. ev.preventDefault();
  2869. };
  2870. ;
  2871. return Viewport;
  2872. }());
  2873. exports.Viewport = Viewport;
  2874. },{}],12:[function(require,module,exports){
  2875. "use strict";
  2876. Object.defineProperty(exports, "__esModule", { value: true });
  2877. function prepareTextForTerminal(text, isMSWindows) {
  2878. if (isMSWindows) {
  2879. return text.replace(/\r?\n/g, '\r');
  2880. }
  2881. return text;
  2882. }
  2883. exports.prepareTextForTerminal = prepareTextForTerminal;
  2884. function copyHandler(ev, term, selectionManager) {
  2885. if (term.browser.isMSIE) {
  2886. window.clipboardData.setData('Text', selectionManager.selectionText);
  2887. }
  2888. else {
  2889. ev.clipboardData.setData('text/plain', selectionManager.selectionText);
  2890. }
  2891. ev.preventDefault();
  2892. }
  2893. exports.copyHandler = copyHandler;
  2894. function pasteHandler(ev, term) {
  2895. ev.stopPropagation();
  2896. var text;
  2897. var dispatchPaste = function (text) {
  2898. text = prepareTextForTerminal(text, term.browser.isMSWindows);
  2899. term.handler(text);
  2900. term.textarea.value = '';
  2901. term.emit('paste', text);
  2902. return term.cancel(ev);
  2903. };
  2904. if (term.browser.isMSIE) {
  2905. if (window.clipboardData) {
  2906. text = window.clipboardData.getData('Text');
  2907. dispatchPaste(text);
  2908. }
  2909. }
  2910. else {
  2911. if (ev.clipboardData) {
  2912. text = ev.clipboardData.getData('text/plain');
  2913. dispatchPaste(text);
  2914. }
  2915. }
  2916. }
  2917. exports.pasteHandler = pasteHandler;
  2918. function moveTextAreaUnderMouseCursor(ev, textarea) {
  2919. textarea.style.position = 'fixed';
  2920. textarea.style.width = '20px';
  2921. textarea.style.height = '20px';
  2922. textarea.style.left = (ev.clientX - 10) + 'px';
  2923. textarea.style.top = (ev.clientY - 10) + 'px';
  2924. textarea.style.zIndex = '1000';
  2925. textarea.focus();
  2926. setTimeout(function () {
  2927. textarea.style.position = null;
  2928. textarea.style.width = null;
  2929. textarea.style.height = null;
  2930. textarea.style.left = null;
  2931. textarea.style.top = null;
  2932. textarea.style.zIndex = null;
  2933. }, 4);
  2934. }
  2935. exports.moveTextAreaUnderMouseCursor = moveTextAreaUnderMouseCursor;
  2936. function rightClickHandler(ev, textarea, selectionManager) {
  2937. moveTextAreaUnderMouseCursor(ev, textarea);
  2938. textarea.value = selectionManager.selectionText;
  2939. textarea.select();
  2940. }
  2941. exports.rightClickHandler = rightClickHandler;
  2942. },{}],13:[function(require,module,exports){
  2943. "use strict";
  2944. Object.defineProperty(exports, "__esModule", { value: true });
  2945. var Generic_1 = require("./Generic");
  2946. var isNode = (typeof navigator === 'undefined') ? true : false;
  2947. var userAgent = (isNode) ? 'node' : navigator.userAgent;
  2948. var platform = (isNode) ? 'node' : navigator.platform;
  2949. exports.isFirefox = !!~userAgent.indexOf('Firefox');
  2950. exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');
  2951. exports.isMac = Generic_1.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform);
  2952. exports.isIpad = platform === 'iPad';
  2953. exports.isIphone = platform === 'iPhone';
  2954. exports.isMSWindows = Generic_1.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
  2955. exports.isLinux = platform.indexOf('Linux') >= 0;
  2956. },{"./Generic":17}],14:[function(require,module,exports){
  2957. "use strict";
  2958. var __extends = (this && this.__extends) || (function () {
  2959. var extendStatics = Object.setPrototypeOf ||
  2960. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  2961. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  2962. return function (d, b) {
  2963. extendStatics(d, b);
  2964. function __() { this.constructor = d; }
  2965. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2966. };
  2967. })();
  2968. Object.defineProperty(exports, "__esModule", { value: true });
  2969. var EventEmitter_js_1 = require("../EventEmitter.js");
  2970. var CharMeasure = (function (_super) {
  2971. __extends(CharMeasure, _super);
  2972. function CharMeasure(document, parentElement) {
  2973. var _this = _super.call(this) || this;
  2974. _this._document = document;
  2975. _this._parentElement = parentElement;
  2976. return _this;
  2977. }
  2978. Object.defineProperty(CharMeasure.prototype, "width", {
  2979. get: function () {
  2980. return this._width;
  2981. },
  2982. enumerable: true,
  2983. configurable: true
  2984. });
  2985. Object.defineProperty(CharMeasure.prototype, "height", {
  2986. get: function () {
  2987. return this._height;
  2988. },
  2989. enumerable: true,
  2990. configurable: true
  2991. });
  2992. CharMeasure.prototype.measure = function () {
  2993. var _this = this;
  2994. if (!this._measureElement) {
  2995. this._measureElement = this._document.createElement('span');
  2996. this._measureElement.style.position = 'absolute';
  2997. this._measureElement.style.top = '0';
  2998. this._measureElement.style.left = '-9999em';
  2999. this._measureElement.textContent = 'W';
  3000. this._measureElement.setAttribute('aria-hidden', 'true');
  3001. this._parentElement.appendChild(this._measureElement);
  3002. setTimeout(function () { return _this._doMeasure(); }, 0);
  3003. }
  3004. else {
  3005. this._doMeasure();
  3006. }
  3007. };
  3008. CharMeasure.prototype._doMeasure = function () {
  3009. var geometry = this._measureElement.getBoundingClientRect();
  3010. if (geometry.width === 0 || geometry.height === 0) {
  3011. return;
  3012. }
  3013. if (this._width !== geometry.width || this._height !== geometry.height) {
  3014. this._width = geometry.width;
  3015. this._height = geometry.height;
  3016. this.emit('charsizechanged');
  3017. }
  3018. };
  3019. return CharMeasure;
  3020. }(EventEmitter_js_1.EventEmitter));
  3021. exports.CharMeasure = CharMeasure;
  3022. },{"../EventEmitter.js":4}],15:[function(require,module,exports){
  3023. "use strict";
  3024. var __extends = (this && this.__extends) || (function () {
  3025. var extendStatics = Object.setPrototypeOf ||
  3026. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  3027. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  3028. return function (d, b) {
  3029. extendStatics(d, b);
  3030. function __() { this.constructor = d; }
  3031. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3032. };
  3033. })();
  3034. Object.defineProperty(exports, "__esModule", { value: true });
  3035. var EventEmitter_1 = require("../EventEmitter");
  3036. var CircularList = (function (_super) {
  3037. __extends(CircularList, _super);
  3038. function CircularList(maxLength) {
  3039. var _this = _super.call(this) || this;
  3040. _this._array = new Array(maxLength);
  3041. _this._startIndex = 0;
  3042. _this._length = 0;
  3043. return _this;
  3044. }
  3045. Object.defineProperty(CircularList.prototype, "maxLength", {
  3046. get: function () {
  3047. return this._array.length;
  3048. },
  3049. set: function (newMaxLength) {
  3050. var newArray = new Array(newMaxLength);
  3051. for (var i = 0; i < Math.min(newMaxLength, this.length); i++) {
  3052. newArray[i] = this._array[this._getCyclicIndex(i)];
  3053. }
  3054. this._array = newArray;
  3055. this._startIndex = 0;
  3056. },
  3057. enumerable: true,
  3058. configurable: true
  3059. });
  3060. Object.defineProperty(CircularList.prototype, "length", {
  3061. get: function () {
  3062. return this._length;
  3063. },
  3064. set: function (newLength) {
  3065. if (newLength > this._length) {
  3066. for (var i = this._length; i < newLength; i++) {
  3067. this._array[i] = undefined;
  3068. }
  3069. }
  3070. this._length = newLength;
  3071. },
  3072. enumerable: true,
  3073. configurable: true
  3074. });
  3075. Object.defineProperty(CircularList.prototype, "forEach", {
  3076. get: function () {
  3077. var _this = this;
  3078. return function (callbackfn) {
  3079. var i = 0;
  3080. var length = _this.length;
  3081. for (var i_1 = 0; i_1 < length; i_1++) {
  3082. callbackfn(_this.get(i_1), i_1);
  3083. }
  3084. };
  3085. },
  3086. enumerable: true,
  3087. configurable: true
  3088. });
  3089. CircularList.prototype.get = function (index) {
  3090. return this._array[this._getCyclicIndex(index)];
  3091. };
  3092. CircularList.prototype.set = function (index, value) {
  3093. this._array[this._getCyclicIndex(index)] = value;
  3094. };
  3095. CircularList.prototype.push = function (value) {
  3096. this._array[this._getCyclicIndex(this._length)] = value;
  3097. if (this._length === this.maxLength) {
  3098. this._startIndex++;
  3099. if (this._startIndex === this.maxLength) {
  3100. this._startIndex = 0;
  3101. }
  3102. this.emit('trim', 1);
  3103. }
  3104. else {
  3105. this._length++;
  3106. }
  3107. };
  3108. CircularList.prototype.pop = function () {
  3109. return this._array[this._getCyclicIndex(this._length-- - 1)];
  3110. };
  3111. CircularList.prototype.splice = function (start, deleteCount) {
  3112. var items = [];
  3113. for (var _i = 2; _i < arguments.length; _i++) {
  3114. items[_i - 2] = arguments[_i];
  3115. }
  3116. if (deleteCount) {
  3117. for (var i = start; i < this._length - deleteCount; i++) {
  3118. this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
  3119. }
  3120. this._length -= deleteCount;
  3121. }
  3122. if (items && items.length) {
  3123. for (var i = this._length - 1; i >= start; i--) {
  3124. this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
  3125. }
  3126. for (var i = 0; i < items.length; i++) {
  3127. this._array[this._getCyclicIndex(start + i)] = items[i];
  3128. }
  3129. if (this._length + items.length > this.maxLength) {
  3130. var countToTrim = (this._length + items.length) - this.maxLength;
  3131. this._startIndex += countToTrim;
  3132. this._length = this.maxLength;
  3133. this.emit('trim', countToTrim);
  3134. }
  3135. else {
  3136. this._length += items.length;
  3137. }
  3138. }
  3139. };
  3140. CircularList.prototype.trimStart = function (count) {
  3141. if (count > this._length) {
  3142. count = this._length;
  3143. }
  3144. this._startIndex += count;
  3145. this._length -= count;
  3146. this.emit('trim', count);
  3147. };
  3148. CircularList.prototype.shiftElements = function (start, count, offset) {
  3149. if (count <= 0) {
  3150. return;
  3151. }
  3152. if (start < 0 || start >= this._length) {
  3153. throw new Error('start argument out of range');
  3154. }
  3155. if (start + offset < 0) {
  3156. throw new Error('Cannot shift elements in list beyond index 0');
  3157. }
  3158. if (offset > 0) {
  3159. for (var i = count - 1; i >= 0; i--) {
  3160. this.set(start + i + offset, this.get(start + i));
  3161. }
  3162. var expandListBy = (start + count + offset) - this._length;
  3163. if (expandListBy > 0) {
  3164. this._length += expandListBy;
  3165. while (this._length > this.maxLength) {
  3166. this._length--;
  3167. this._startIndex++;
  3168. this.emit('trim', 1);
  3169. }
  3170. }
  3171. }
  3172. else {
  3173. for (var i = 0; i < count; i++) {
  3174. this.set(start + i + offset, this.get(start + i));
  3175. }
  3176. }
  3177. };
  3178. CircularList.prototype._getCyclicIndex = function (index) {
  3179. return (this._startIndex + index) % this.maxLength;
  3180. };
  3181. return CircularList;
  3182. }(EventEmitter_1.EventEmitter));
  3183. exports.CircularList = CircularList;
  3184. },{"../EventEmitter":4}],16:[function(require,module,exports){
  3185. "use strict";
  3186. Object.defineProperty(exports, "__esModule", { value: true });
  3187. var DomElementObjectPool = (function () {
  3188. function DomElementObjectPool(type) {
  3189. this.type = type;
  3190. this._type = type;
  3191. this._pool = [];
  3192. this._inUse = {};
  3193. }
  3194. DomElementObjectPool.prototype.acquire = function () {
  3195. var element;
  3196. if (this._pool.length === 0) {
  3197. element = this._createNew();
  3198. }
  3199. else {
  3200. element = this._pool.pop();
  3201. }
  3202. this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)] = element;
  3203. return element;
  3204. };
  3205. DomElementObjectPool.prototype.release = function (element) {
  3206. if (!this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)]) {
  3207. throw new Error('Could not release an element not yet acquired');
  3208. }
  3209. delete this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)];
  3210. this._cleanElement(element);
  3211. this._pool.push(element);
  3212. };
  3213. DomElementObjectPool.prototype._createNew = function () {
  3214. var element = document.createElement(this._type);
  3215. var id = DomElementObjectPool._objectCount++;
  3216. element.setAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE, id.toString(10));
  3217. return element;
  3218. };
  3219. DomElementObjectPool.prototype._cleanElement = function (element) {
  3220. element.className = '';
  3221. element.innerHTML = '';
  3222. };
  3223. return DomElementObjectPool;
  3224. }());
  3225. DomElementObjectPool.OBJECT_ID_ATTRIBUTE = 'data-obj-id';
  3226. DomElementObjectPool._objectCount = 0;
  3227. exports.DomElementObjectPool = DomElementObjectPool;
  3228. },{}],17:[function(require,module,exports){
  3229. "use strict";
  3230. Object.defineProperty(exports, "__esModule", { value: true });
  3231. function contains(arr, el) {
  3232. return arr.indexOf(el) >= 0;
  3233. }
  3234. exports.contains = contains;
  3235. ;
  3236. },{}],18:[function(require,module,exports){
  3237. "use strict";
  3238. Object.defineProperty(exports, "__esModule", { value: true });
  3239. function getCoordsRelativeToElement(event, element) {
  3240. if (event.pageX == null) {
  3241. return null;
  3242. }
  3243. var x = event.pageX;
  3244. var y = event.pageY;
  3245. while (element && element !== self.document.documentElement) {
  3246. x -= element.offsetLeft;
  3247. y -= element.offsetTop;
  3248. element = 'offsetParent' in element ? element.offsetParent : element.parentElement;
  3249. }
  3250. return [x, y];
  3251. }
  3252. exports.getCoordsRelativeToElement = getCoordsRelativeToElement;
  3253. function getCoords(event, rowContainer, charMeasure, colCount, rowCount, isSelection) {
  3254. var coords = getCoordsRelativeToElement(event, rowContainer);
  3255. coords[0] = Math.ceil((coords[0] + (isSelection ? charMeasure.width / 2 : 0)) / charMeasure.width);
  3256. coords[1] = Math.ceil(coords[1] / charMeasure.height);
  3257. coords[0] = Math.min(Math.max(coords[0], 1), colCount + 1);
  3258. coords[1] = Math.min(Math.max(coords[1], 1), rowCount + 1);
  3259. return coords;
  3260. }
  3261. exports.getCoords = getCoords;
  3262. function getRawByteCoords(event, rowContainer, charMeasure, colCount, rowCount) {
  3263. var coords = getCoords(event, rowContainer, charMeasure, colCount, rowCount);
  3264. var x = coords[0];
  3265. var y = coords[1];
  3266. x += 32;
  3267. y += 32;
  3268. return { x: x, y: y };
  3269. }
  3270. exports.getRawByteCoords = getRawByteCoords;
  3271. },{}],19:[function(require,module,exports){
  3272. "use strict";
  3273. Object.defineProperty(exports, "__esModule", { value: true });
  3274. var CompositionHelper_1 = require("./CompositionHelper");
  3275. var EventEmitter_1 = require("./EventEmitter");
  3276. var Viewport_1 = require("./Viewport");
  3277. var Clipboard_1 = require("./handlers/Clipboard");
  3278. var CircularList_1 = require("./utils/CircularList");
  3279. var EscapeSequences_1 = require("./EscapeSequences");
  3280. var InputHandler_1 = require("./InputHandler");
  3281. var Parser_1 = require("./Parser");
  3282. var Renderer_1 = require("./Renderer");
  3283. var Linkifier_1 = require("./Linkifier");
  3284. var SelectionManager_1 = require("./SelectionManager");
  3285. var CharMeasure_1 = require("./utils/CharMeasure");
  3286. var Browser = require("./utils/Browser");
  3287. var Mouse_1 = require("./utils/Mouse");
  3288. var document = (typeof window != 'undefined') ? window.document : null;
  3289. var WRITE_BUFFER_PAUSE_THRESHOLD = 5;
  3290. var WRITE_BATCH_SIZE = 300;
  3291. var CURSOR_BLINK_INTERVAL = 600;
  3292. function Terminal(options) {
  3293. var self = this;
  3294. if (!(this instanceof Terminal)) {
  3295. return new Terminal(arguments[0], arguments[1], arguments[2]);
  3296. }
  3297. self.browser = Browser;
  3298. self.cancel = Terminal.cancel;
  3299. EventEmitter_1.EventEmitter.call(this);
  3300. if (typeof options === 'number') {
  3301. options = {
  3302. cols: arguments[0],
  3303. rows: arguments[1],
  3304. handler: arguments[2]
  3305. };
  3306. }
  3307. options = options || {};
  3308. Object.keys(Terminal.defaults).forEach(function (key) {
  3309. if (options[key] == null) {
  3310. options[key] = Terminal.options[key];
  3311. if (Terminal[key] !== Terminal.defaults[key]) {
  3312. options[key] = Terminal[key];
  3313. }
  3314. }
  3315. self[key] = options[key];
  3316. });
  3317. if (options.colors.length === 8) {
  3318. options.colors = options.colors.concat(Terminal._colors.slice(8));
  3319. }
  3320. else if (options.colors.length === 16) {
  3321. options.colors = options.colors.concat(Terminal._colors.slice(16));
  3322. }
  3323. else if (options.colors.length === 10) {
  3324. options.colors = options.colors.slice(0, -2).concat(Terminal._colors.slice(8, -2), options.colors.slice(-2));
  3325. }
  3326. else if (options.colors.length === 18) {
  3327. options.colors = options.colors.concat(Terminal._colors.slice(16, -2), options.colors.slice(-2));
  3328. }
  3329. this.colors = options.colors;
  3330. this.options = options;
  3331. this.parent = options.body || options.parent || (document ? document.getElementsByTagName('body')[0] : null);
  3332. this.cols = options.cols || options.geometry[0];
  3333. this.rows = options.rows || options.geometry[1];
  3334. this.geometry = [this.cols, this.rows];
  3335. if (options.handler) {
  3336. this.on('data', options.handler);
  3337. }
  3338. this.ybase = 0;
  3339. this.ydisp = 0;
  3340. this.x = 0;
  3341. this.y = 0;
  3342. this.cursorState = 0;
  3343. this.cursorHidden = false;
  3344. this.convertEol;
  3345. this.queue = '';
  3346. this.scrollTop = 0;
  3347. this.scrollBottom = this.rows - 1;
  3348. this.customKeyEventHandler = null;
  3349. this.cursorBlinkInterval = null;
  3350. this.applicationKeypad = false;
  3351. this.applicationCursor = false;
  3352. this.originMode = false;
  3353. this.insertMode = false;
  3354. this.wraparoundMode = true;
  3355. this.normal = null;
  3356. this.charset = null;
  3357. this.gcharset = null;
  3358. this.glevel = 0;
  3359. this.charsets = [null];
  3360. this.decLocator;
  3361. this.x10Mouse;
  3362. this.vt200Mouse;
  3363. this.vt300Mouse;
  3364. this.normalMouse;
  3365. this.mouseEvents;
  3366. this.sendFocus;
  3367. this.utfMouse;
  3368. this.sgrMouse;
  3369. this.urxvtMouse;
  3370. this.element;
  3371. this.children;
  3372. this.refreshStart;
  3373. this.refreshEnd;
  3374. this.savedX;
  3375. this.savedY;
  3376. this.savedCols;
  3377. this.readable = true;
  3378. this.writable = true;
  3379. this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
  3380. this.curAttr = this.defAttr;
  3381. this.params = [];
  3382. this.currentParam = 0;
  3383. this.prefix = '';
  3384. this.postfix = '';
  3385. this.inputHandler = new InputHandler_1.InputHandler(this);
  3386. this.parser = new Parser_1.Parser(this.inputHandler, this);
  3387. this.renderer = this.renderer || null;
  3388. this.selectionManager = this.selectionManager || null;
  3389. this.linkifier = this.linkifier || new Linkifier_1.Linkifier();
  3390. this.writeBuffer = [];
  3391. this.writeInProgress = false;
  3392. this.xoffSentToCatchUp = false;
  3393. this.writeStopped = false;
  3394. this.surrogate_high = '';
  3395. this.lines = new CircularList_1.CircularList(this.scrollback);
  3396. var i = this.rows;
  3397. while (i--) {
  3398. this.lines.push(this.blankLine());
  3399. }
  3400. if (this.selectionManager) {
  3401. this.selectionManager.setBuffer(this.lines);
  3402. }
  3403. this.tabs;
  3404. this.setupStops();
  3405. this.userScrolling = false;
  3406. }
  3407. inherits(Terminal, EventEmitter_1.EventEmitter);
  3408. Terminal.prototype.eraseAttr = function () {
  3409. return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
  3410. };
  3411. Terminal.tangoColors = [
  3412. '#2e3436',
  3413. '#cc0000',
  3414. '#4e9a06',
  3415. '#c4a000',
  3416. '#3465a4',
  3417. '#75507b',
  3418. '#06989a',
  3419. '#d3d7cf',
  3420. '#555753',
  3421. '#ef2929',
  3422. '#8ae234',
  3423. '#fce94f',
  3424. '#729fcf',
  3425. '#ad7fa8',
  3426. '#34e2e2',
  3427. '#eeeeec'
  3428. ];
  3429. Terminal.colors = (function () {
  3430. var colors = Terminal.tangoColors.slice(), r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i;
  3431. i = 0;
  3432. for (; i < 216; i++) {
  3433. out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]);
  3434. }
  3435. i = 0;
  3436. for (; i < 24; i++) {
  3437. r = 8 + i * 10;
  3438. out(r, r, r);
  3439. }
  3440. function out(r, g, b) {
  3441. colors.push('#' + hex(r) + hex(g) + hex(b));
  3442. }
  3443. function hex(c) {
  3444. c = c.toString(16);
  3445. return c.length < 2 ? '0' + c : c;
  3446. }
  3447. return colors;
  3448. })();
  3449. Terminal._colors = Terminal.colors.slice();
  3450. Terminal.vcolors = (function () {
  3451. var out = [], colors = Terminal.colors, i = 0, color;
  3452. for (; i < 256; i++) {
  3453. color = parseInt(colors[i].substring(1), 16);
  3454. out.push([
  3455. (color >> 16) & 0xff,
  3456. (color >> 8) & 0xff,
  3457. color & 0xff
  3458. ]);
  3459. }
  3460. return out;
  3461. })();
  3462. Terminal.defaults = {
  3463. colors: Terminal.colors,
  3464. theme: 'default',
  3465. convertEol: false,
  3466. termName: 'xterm',
  3467. geometry: [80, 24],
  3468. cursorBlink: false,
  3469. cursorStyle: 'block',
  3470. visualBell: false,
  3471. popOnBell: false,
  3472. scrollback: 1000,
  3473. screenKeys: false,
  3474. debug: false,
  3475. cancelEvents: false,
  3476. disableStdin: false,
  3477. useFlowControl: false,
  3478. tabStopWidth: 8
  3479. };
  3480. Terminal.options = {};
  3481. Terminal.focus = null;
  3482. each(keys(Terminal.defaults), function (key) {
  3483. Terminal[key] = Terminal.defaults[key];
  3484. Terminal.options[key] = Terminal.defaults[key];
  3485. });
  3486. Terminal.prototype.focus = function () {
  3487. return this.textarea.focus();
  3488. };
  3489. Terminal.prototype.getOption = function (key, value) {
  3490. if (!(key in Terminal.defaults)) {
  3491. throw new Error('No option with key "' + key + '"');
  3492. }
  3493. if (typeof this.options[key] !== 'undefined') {
  3494. return this.options[key];
  3495. }
  3496. return this[key];
  3497. };
  3498. Terminal.prototype.setOption = function (key, value) {
  3499. if (!(key in Terminal.defaults)) {
  3500. throw new Error('No option with key "' + key + '"');
  3501. }
  3502. switch (key) {
  3503. case 'scrollback':
  3504. if (value < this.rows) {
  3505. var msg = 'Setting the scrollback value less than the number of rows ';
  3506. msg += "(" + this.rows + ") is not allowed.";
  3507. console.warn(msg);
  3508. return false;
  3509. }
  3510. if (this.options[key] !== value) {
  3511. if (this.lines.length > value) {
  3512. var amountToTrim = this.lines.length - value;
  3513. var needsRefresh = (this.ydisp - amountToTrim < 0);
  3514. this.lines.trimStart(amountToTrim);
  3515. this.ybase = Math.max(this.ybase - amountToTrim, 0);
  3516. this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
  3517. if (needsRefresh) {
  3518. this.refresh(0, this.rows - 1);
  3519. }
  3520. }
  3521. this.lines.maxLength = value;
  3522. this.viewport.syncScrollArea();
  3523. }
  3524. break;
  3525. }
  3526. this[key] = value;
  3527. this.options[key] = value;
  3528. switch (key) {
  3529. case 'cursorBlink':
  3530. this.setCursorBlinking(value);
  3531. break;
  3532. case 'cursorStyle':
  3533. this.element.classList.toggle("xterm-cursor-style-underline", value === 'underline');
  3534. this.element.classList.toggle("xterm-cursor-style-bar", value === 'bar');
  3535. break;
  3536. case 'tabStopWidth':
  3537. this.setupStops();
  3538. break;
  3539. }
  3540. };
  3541. Terminal.prototype.restartCursorBlinking = function () {
  3542. this.setCursorBlinking(this.options.cursorBlink);
  3543. };
  3544. Terminal.prototype.setCursorBlinking = function (enabled) {
  3545. this.element.classList.toggle('xterm-cursor-blink', enabled);
  3546. this.clearCursorBlinkingInterval();
  3547. if (enabled) {
  3548. var self = this;
  3549. this.cursorBlinkInterval = setInterval(function () {
  3550. self.element.classList.toggle('xterm-cursor-blink-on');
  3551. }, CURSOR_BLINK_INTERVAL);
  3552. }
  3553. };
  3554. Terminal.prototype.clearCursorBlinkingInterval = function () {
  3555. this.element.classList.remove('xterm-cursor-blink-on');
  3556. if (this.cursorBlinkInterval) {
  3557. clearInterval(this.cursorBlinkInterval);
  3558. this.cursorBlinkInterval = null;
  3559. }
  3560. };
  3561. Terminal.bindFocus = function (term) {
  3562. on(term.textarea, 'focus', function (ev) {
  3563. if (term.sendFocus) {
  3564. term.send(EscapeSequences_1.C0.ESC + '[I');
  3565. }
  3566. term.element.classList.add('focus');
  3567. term.showCursor();
  3568. term.restartCursorBlinking.apply(term);
  3569. Terminal.focus = term;
  3570. term.emit('focus', { terminal: term });
  3571. });
  3572. };
  3573. Terminal.prototype.blur = function () {
  3574. return this.textarea.blur();
  3575. };
  3576. Terminal.bindBlur = function (term) {
  3577. on(term.textarea, 'blur', function (ev) {
  3578. term.refresh(term.y, term.y);
  3579. if (term.sendFocus) {
  3580. term.send(EscapeSequences_1.C0.ESC + '[O');
  3581. }
  3582. term.element.classList.remove('focus');
  3583. term.clearCursorBlinkingInterval.apply(term);
  3584. Terminal.focus = null;
  3585. term.emit('blur', { terminal: term });
  3586. });
  3587. };
  3588. Terminal.prototype.initGlobal = function () {
  3589. var _this = this;
  3590. var term = this;
  3591. Terminal.bindKeys(this);
  3592. Terminal.bindFocus(this);
  3593. Terminal.bindBlur(this);
  3594. on(this.element, 'copy', function (event) {
  3595. if (_this.mouseEvents) {
  3596. return;
  3597. }
  3598. Clipboard_1.copyHandler(event, term, _this.selectionManager);
  3599. });
  3600. var pasteHandlerWrapper = function (event) { return Clipboard_1.pasteHandler(event, term); };
  3601. on(this.textarea, 'paste', pasteHandlerWrapper);
  3602. on(this.element, 'paste', pasteHandlerWrapper);
  3603. if (term.browser.isFirefox) {
  3604. on(this.element, 'mousedown', function (event) {
  3605. if (event.button == 2) {
  3606. Clipboard_1.rightClickHandler(event, _this.textarea, _this.selectionManager);
  3607. }
  3608. });
  3609. }
  3610. else {
  3611. on(this.element, 'contextmenu', function (event) {
  3612. Clipboard_1.rightClickHandler(event, _this.textarea, _this.selectionManager);
  3613. });
  3614. }
  3615. if (term.browser.isLinux) {
  3616. on(this.element, 'auxclick', function (event) {
  3617. if (event.button === 1) {
  3618. Clipboard_1.moveTextAreaUnderMouseCursor(event, _this.textarea, _this.selectionManager);
  3619. }
  3620. });
  3621. }
  3622. };
  3623. Terminal.bindKeys = function (term) {
  3624. on(term.element, 'keydown', function (ev) {
  3625. if (document.activeElement != this) {
  3626. return;
  3627. }
  3628. term.keyDown(ev);
  3629. }, true);
  3630. on(term.element, 'keypress', function (ev) {
  3631. if (document.activeElement != this) {
  3632. return;
  3633. }
  3634. term.keyPress(ev);
  3635. }, true);
  3636. on(term.element, 'keyup', function (ev) {
  3637. if (!wasMondifierKeyOnlyEvent(ev)) {
  3638. term.focus(term);
  3639. }
  3640. }, true);
  3641. on(term.textarea, 'keydown', function (ev) {
  3642. term.keyDown(ev);
  3643. }, true);
  3644. on(term.textarea, 'keypress', function (ev) {
  3645. term.keyPress(ev);
  3646. this.value = '';
  3647. }, true);
  3648. on(term.textarea, 'compositionstart', term.compositionHelper.compositionstart.bind(term.compositionHelper));
  3649. on(term.textarea, 'compositionupdate', term.compositionHelper.compositionupdate.bind(term.compositionHelper));
  3650. on(term.textarea, 'compositionend', term.compositionHelper.compositionend.bind(term.compositionHelper));
  3651. term.on('refresh', term.compositionHelper.updateCompositionElements.bind(term.compositionHelper));
  3652. term.on('refresh', function (data) {
  3653. term.queueLinkification(data.start, data.end);
  3654. });
  3655. };
  3656. Terminal.prototype.insertRow = function (row) {
  3657. if (typeof row != 'object') {
  3658. row = document.createElement('div');
  3659. }
  3660. this.rowContainer.appendChild(row);
  3661. this.children.push(row);
  3662. return row;
  3663. };
  3664. Terminal.prototype.open = function (parent, focus) {
  3665. var _this = this;
  3666. var self = this, i = 0, div;
  3667. this.parent = parent || this.parent;
  3668. if (!this.parent) {
  3669. throw new Error('Terminal requires a parent element.');
  3670. }
  3671. this.context = this.parent.ownerDocument.defaultView;
  3672. this.document = this.parent.ownerDocument;
  3673. this.body = this.document.getElementsByTagName('body')[0];
  3674. this.element = this.document.createElement('div');
  3675. this.element.classList.add('terminal');
  3676. this.element.classList.add('xterm');
  3677. this.element.classList.add('xterm-theme-' + this.theme);
  3678. this.setCursorBlinking(this.options.cursorBlink);
  3679. this.element.setAttribute('tabindex', 0);
  3680. this.viewportElement = document.createElement('div');
  3681. this.viewportElement.classList.add('xterm-viewport');
  3682. this.element.appendChild(this.viewportElement);
  3683. this.viewportScrollArea = document.createElement('div');
  3684. this.viewportScrollArea.classList.add('xterm-scroll-area');
  3685. this.viewportElement.appendChild(this.viewportScrollArea);
  3686. this.selectionContainer = document.createElement('div');
  3687. this.selectionContainer.classList.add('xterm-selection');
  3688. this.element.appendChild(this.selectionContainer);
  3689. this.rowContainer = document.createElement('div');
  3690. this.rowContainer.classList.add('xterm-rows');
  3691. this.element.appendChild(this.rowContainer);
  3692. this.children = [];
  3693. this.linkifier.attachToDom(document, this.children);
  3694. this.helperContainer = document.createElement('div');
  3695. this.helperContainer.classList.add('xterm-helpers');
  3696. this.element.appendChild(this.helperContainer);
  3697. this.textarea = document.createElement('textarea');
  3698. this.textarea.classList.add('xterm-helper-textarea');
  3699. this.textarea.setAttribute('autocorrect', 'off');
  3700. this.textarea.setAttribute('autocapitalize', 'off');
  3701. this.textarea.setAttribute('spellcheck', 'false');
  3702. this.textarea.setAttribute('autofocus', 'true');
  3703. this.textarea.tabIndex = 0;
  3704. this.textarea.addEventListener('focus', function () {
  3705. self.emit('focus', { terminal: self });
  3706. });
  3707. this.textarea.addEventListener('blur', function () {
  3708. self.emit('blur', { terminal: self });
  3709. });
  3710. this.helperContainer.appendChild(this.textarea);
  3711. this.compositionView = document.createElement('div');
  3712. this.compositionView.classList.add('composition-view');
  3713. this.compositionHelper = new CompositionHelper_1.CompositionHelper(this.textarea, this.compositionView, this);
  3714. this.helperContainer.appendChild(this.compositionView);
  3715. this.charSizeStyleElement = document.createElement('style');
  3716. this.helperContainer.appendChild(this.charSizeStyleElement);
  3717. for (; i < this.rows; i++) {
  3718. this.insertRow();
  3719. }
  3720. this.parent.appendChild(this.element);
  3721. this.charMeasure = new CharMeasure_1.CharMeasure(document, this.helperContainer);
  3722. this.charMeasure.on('charsizechanged', function () {
  3723. self.updateCharSizeStyles();
  3724. });
  3725. this.charMeasure.measure();
  3726. this.viewport = new Viewport_1.Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
  3727. this.renderer = new Renderer_1.Renderer(this);
  3728. this.selectionManager = new SelectionManager_1.SelectionManager(this, this.lines, this.rowContainer, this.charMeasure);
  3729. this.selectionManager.on('refresh', function (data) {
  3730. _this.renderer.refreshSelection(data.start, data.end);
  3731. });
  3732. this.selectionManager.on('newselection', function (text) {
  3733. _this.textarea.value = text;
  3734. _this.textarea.focus();
  3735. _this.textarea.select();
  3736. });
  3737. this.on('scroll', function () { return _this.selectionManager.refresh(); });
  3738. this.viewportElement.addEventListener('scroll', function () { return _this.selectionManager.refresh(); });
  3739. this.refresh(0, this.rows - 1);
  3740. this.initGlobal();
  3741. if (typeof focus == 'undefined') {
  3742. var message = 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
  3743. message += 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
  3744. message += 'it will default to `false`.';
  3745. console.warn(message);
  3746. focus = true;
  3747. }
  3748. if (focus) {
  3749. this.focus();
  3750. }
  3751. on(this.element, 'click', function () {
  3752. var selection = document.getSelection(), collapsed = selection.isCollapsed, isRange = typeof collapsed == 'boolean' ? !collapsed : selection.type == 'Range';
  3753. if (!isRange) {
  3754. self.focus();
  3755. }
  3756. });
  3757. this.bindMouse();
  3758. this.emit('open');
  3759. };
  3760. Terminal.loadAddon = function (addon, callback) {
  3761. if (typeof exports === 'object' && typeof module === 'object') {
  3762. return require('./addons/' + addon + '/' + addon);
  3763. }
  3764. else if (typeof define == 'function') {
  3765. return require(['./addons/' + addon + '/' + addon], callback);
  3766. }
  3767. else {
  3768. console.error('Cannot load a module without a CommonJS or RequireJS environment.');
  3769. return false;
  3770. }
  3771. };
  3772. Terminal.prototype.updateCharSizeStyles = function () {
  3773. this.charSizeStyleElement.textContent =
  3774. ".xterm-wide-char{width:" + this.charMeasure.width * 2 + "px;}" +
  3775. (".xterm-normal-char{width:" + this.charMeasure.width + "px;}") +
  3776. (".xterm-rows > div{height:" + this.charMeasure.height + "px;}");
  3777. };
  3778. Terminal.prototype.bindMouse = function () {
  3779. var el = this.element, self = this, pressed = 32;
  3780. function sendButton(ev) {
  3781. var button, pos;
  3782. button = getButton(ev);
  3783. pos = Mouse_1.getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
  3784. if (!pos)
  3785. return;
  3786. sendEvent(button, pos);
  3787. switch (ev.overrideType || ev.type) {
  3788. case 'mousedown':
  3789. pressed = button;
  3790. break;
  3791. case 'mouseup':
  3792. pressed = 32;
  3793. break;
  3794. case 'wheel':
  3795. break;
  3796. }
  3797. }
  3798. function sendMove(ev) {
  3799. var button = pressed, pos;
  3800. pos = Mouse_1.getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
  3801. if (!pos)
  3802. return;
  3803. button += 32;
  3804. sendEvent(button, pos);
  3805. }
  3806. function encode(data, ch) {
  3807. if (!self.utfMouse) {
  3808. if (ch === 255)
  3809. return data.push(0);
  3810. if (ch > 127)
  3811. ch = 127;
  3812. data.push(ch);
  3813. }
  3814. else {
  3815. if (ch === 2047)
  3816. return data.push(0);
  3817. if (ch < 127) {
  3818. data.push(ch);
  3819. }
  3820. else {
  3821. if (ch > 2047)
  3822. ch = 2047;
  3823. data.push(0xC0 | (ch >> 6));
  3824. data.push(0x80 | (ch & 0x3F));
  3825. }
  3826. }
  3827. }
  3828. function sendEvent(button, pos) {
  3829. if (self.vt300Mouse) {
  3830. button &= 3;
  3831. pos.x -= 32;
  3832. pos.y -= 32;
  3833. var data = EscapeSequences_1.C0.ESC + '[24';
  3834. if (button === 0)
  3835. data += '1';
  3836. else if (button === 1)
  3837. data += '3';
  3838. else if (button === 2)
  3839. data += '5';
  3840. else if (button === 3)
  3841. return;
  3842. else
  3843. data += '0';
  3844. data += '~[' + pos.x + ',' + pos.y + ']\r';
  3845. self.send(data);
  3846. return;
  3847. }
  3848. if (self.decLocator) {
  3849. button &= 3;
  3850. pos.x -= 32;
  3851. pos.y -= 32;
  3852. if (button === 0)
  3853. button = 2;
  3854. else if (button === 1)
  3855. button = 4;
  3856. else if (button === 2)
  3857. button = 6;
  3858. else if (button === 3)
  3859. button = 3;
  3860. self.send(EscapeSequences_1.C0.ESC + '['
  3861. + button
  3862. + ';'
  3863. + (button === 3 ? 4 : 0)
  3864. + ';'
  3865. + pos.y
  3866. + ';'
  3867. + pos.x
  3868. + ';'
  3869. + (pos.page || 0)
  3870. + '&w');
  3871. return;
  3872. }
  3873. if (self.urxvtMouse) {
  3874. pos.x -= 32;
  3875. pos.y -= 32;
  3876. pos.x++;
  3877. pos.y++;
  3878. self.send(EscapeSequences_1.C0.ESC + '[' + button + ';' + pos.x + ';' + pos.y + 'M');
  3879. return;
  3880. }
  3881. if (self.sgrMouse) {
  3882. pos.x -= 32;
  3883. pos.y -= 32;
  3884. self.send(EscapeSequences_1.C0.ESC + '[<'
  3885. + (((button & 3) === 3 ? button & ~3 : button) - 32)
  3886. + ';'
  3887. + pos.x
  3888. + ';'
  3889. + pos.y
  3890. + ((button & 3) === 3 ? 'm' : 'M'));
  3891. return;
  3892. }
  3893. var data = [];
  3894. encode(data, button);
  3895. encode(data, pos.x);
  3896. encode(data, pos.y);
  3897. self.send(EscapeSequences_1.C0.ESC + '[M' + String.fromCharCode.apply(String, data));
  3898. }
  3899. function getButton(ev) {
  3900. var button, shift, meta, ctrl, mod;
  3901. switch (ev.overrideType || ev.type) {
  3902. case 'mousedown':
  3903. button = ev.button != null
  3904. ? +ev.button
  3905. : ev.which != null
  3906. ? ev.which - 1
  3907. : null;
  3908. if (self.browser.isMSIE) {
  3909. button = button === 1 ? 0 : button === 4 ? 1 : button;
  3910. }
  3911. break;
  3912. case 'mouseup':
  3913. button = 3;
  3914. break;
  3915. case 'DOMMouseScroll':
  3916. button = ev.detail < 0
  3917. ? 64
  3918. : 65;
  3919. break;
  3920. case 'wheel':
  3921. button = ev.wheelDeltaY > 0
  3922. ? 64
  3923. : 65;
  3924. break;
  3925. }
  3926. shift = ev.shiftKey ? 4 : 0;
  3927. meta = ev.metaKey ? 8 : 0;
  3928. ctrl = ev.ctrlKey ? 16 : 0;
  3929. mod = shift | meta | ctrl;
  3930. if (self.vt200Mouse) {
  3931. mod &= ctrl;
  3932. }
  3933. else if (!self.normalMouse) {
  3934. mod = 0;
  3935. }
  3936. button = (32 + (mod << 2)) + button;
  3937. return button;
  3938. }
  3939. on(el, 'mousedown', function (ev) {
  3940. if (!self.mouseEvents)
  3941. return;
  3942. sendButton(ev);
  3943. self.focus();
  3944. if (self.vt200Mouse) {
  3945. ev.overrideType = 'mouseup';
  3946. sendButton(ev);
  3947. return self.cancel(ev);
  3948. }
  3949. if (self.normalMouse)
  3950. on(self.document, 'mousemove', sendMove);
  3951. if (!self.x10Mouse) {
  3952. on(self.document, 'mouseup', function up(ev) {
  3953. sendButton(ev);
  3954. if (self.normalMouse)
  3955. off(self.document, 'mousemove', sendMove);
  3956. off(self.document, 'mouseup', up);
  3957. return self.cancel(ev);
  3958. });
  3959. }
  3960. return self.cancel(ev);
  3961. });
  3962. on(el, 'wheel', function (ev) {
  3963. if (!self.mouseEvents)
  3964. return;
  3965. if (self.x10Mouse
  3966. || self.vt300Mouse
  3967. || self.decLocator)
  3968. return;
  3969. sendButton(ev);
  3970. return self.cancel(ev);
  3971. });
  3972. on(el, 'wheel', function (ev) {
  3973. if (self.mouseEvents)
  3974. return;
  3975. self.viewport.onWheel(ev);
  3976. return self.cancel(ev);
  3977. });
  3978. on(el, 'touchstart', function (ev) {
  3979. if (self.mouseEvents)
  3980. return;
  3981. self.viewport.onTouchStart(ev);
  3982. return self.cancel(ev);
  3983. });
  3984. on(el, 'touchmove', function (ev) {
  3985. if (self.mouseEvents)
  3986. return;
  3987. self.viewport.onTouchMove(ev);
  3988. return self.cancel(ev);
  3989. });
  3990. };
  3991. Terminal.prototype.destroy = function () {
  3992. this.readable = false;
  3993. this.writable = false;
  3994. this._events = {};
  3995. this.handler = function () { };
  3996. this.write = function () { };
  3997. if (this.element && this.element.parentNode) {
  3998. this.element.parentNode.removeChild(this.element);
  3999. }
  4000. };
  4001. Terminal.prototype.refresh = function (start, end) {
  4002. if (this.renderer) {
  4003. this.renderer.queueRefresh(start, end);
  4004. }
  4005. };
  4006. Terminal.prototype.queueLinkification = function (start, end) {
  4007. if (this.linkifier) {
  4008. for (var i = start; i <= end; i++) {
  4009. this.linkifier.linkifyRow(i);
  4010. }
  4011. }
  4012. };
  4013. Terminal.prototype.showCursor = function () {
  4014. if (!this.cursorState) {
  4015. this.cursorState = 1;
  4016. this.refresh(this.y, this.y);
  4017. }
  4018. };
  4019. Terminal.prototype.scroll = function (isWrapped) {
  4020. var row;
  4021. if (this.lines.length === this.lines.maxLength) {
  4022. this.lines.trimStart(1);
  4023. this.ybase--;
  4024. if (this.ydisp !== 0) {
  4025. this.ydisp--;
  4026. }
  4027. }
  4028. this.ybase++;
  4029. if (!this.userScrolling) {
  4030. this.ydisp = this.ybase;
  4031. }
  4032. row = this.ybase + this.rows - 1;
  4033. row -= this.rows - 1 - this.scrollBottom;
  4034. if (row === this.lines.length) {
  4035. this.lines.push(this.blankLine(undefined, isWrapped));
  4036. }
  4037. else {
  4038. this.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
  4039. }
  4040. if (this.scrollTop !== 0) {
  4041. if (this.ybase !== 0) {
  4042. this.ybase--;
  4043. if (!this.userScrolling) {
  4044. this.ydisp = this.ybase;
  4045. }
  4046. }
  4047. this.lines.splice(this.ybase + this.scrollTop, 1);
  4048. }
  4049. this.updateRange(this.scrollTop);
  4050. this.updateRange(this.scrollBottom);
  4051. this.emit('scroll', this.ydisp);
  4052. };
  4053. Terminal.prototype.scrollDisp = function (disp, suppressScrollEvent) {
  4054. if (disp < 0) {
  4055. if (this.ydisp === 0) {
  4056. return;
  4057. }
  4058. this.userScrolling = true;
  4059. }
  4060. else if (disp + this.ydisp >= this.ybase) {
  4061. this.userScrolling = false;
  4062. }
  4063. this.ydisp += disp;
  4064. if (this.ydisp > this.ybase) {
  4065. this.ydisp = this.ybase;
  4066. }
  4067. else if (this.ydisp < 0) {
  4068. this.ydisp = 0;
  4069. }
  4070. if (!suppressScrollEvent) {
  4071. this.emit('scroll', this.ydisp);
  4072. }
  4073. this.refresh(0, this.rows - 1);
  4074. };
  4075. Terminal.prototype.scrollPages = function (pageCount) {
  4076. this.scrollDisp(pageCount * (this.rows - 1));
  4077. };
  4078. Terminal.prototype.scrollToTop = function () {
  4079. this.scrollDisp(-this.ydisp);
  4080. };
  4081. Terminal.prototype.scrollToBottom = function () {
  4082. this.scrollDisp(this.ybase - this.ydisp);
  4083. };
  4084. Terminal.prototype.write = function (data) {
  4085. this.writeBuffer.push(data);
  4086. if (this.options.useFlowControl && !this.xoffSentToCatchUp && this.writeBuffer.length >= WRITE_BUFFER_PAUSE_THRESHOLD) {
  4087. this.send(EscapeSequences_1.C0.DC3);
  4088. this.xoffSentToCatchUp = true;
  4089. }
  4090. if (!this.writeInProgress && this.writeBuffer.length > 0) {
  4091. this.writeInProgress = true;
  4092. var self = this;
  4093. setTimeout(function () {
  4094. self.innerWrite();
  4095. });
  4096. }
  4097. };
  4098. Terminal.prototype.innerWrite = function () {
  4099. var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
  4100. while (writeBatch.length > 0) {
  4101. var data = writeBatch.shift();
  4102. var l = data.length, i = 0, j, cs, ch, code, low, ch_width, row;
  4103. if (this.xoffSentToCatchUp && writeBatch.length === 0 && this.writeBuffer.length === 0) {
  4104. this.send(EscapeSequences_1.C0.DC1);
  4105. this.xoffSentToCatchUp = false;
  4106. }
  4107. this.refreshStart = this.y;
  4108. this.refreshEnd = this.y;
  4109. var state = this.parser.parse(data);
  4110. this.parser.setState(state);
  4111. this.updateRange(this.y);
  4112. this.refresh(this.refreshStart, this.refreshEnd);
  4113. }
  4114. if (this.writeBuffer.length > 0) {
  4115. var self = this;
  4116. setTimeout(function () {
  4117. self.innerWrite();
  4118. }, 0);
  4119. }
  4120. else {
  4121. this.writeInProgress = false;
  4122. }
  4123. };
  4124. Terminal.prototype.writeln = function (data) {
  4125. this.write(data + '\r\n');
  4126. };
  4127. Terminal.prototype.attachCustomKeydownHandler = function (customKeydownHandler) {
  4128. var message = 'attachCustomKeydownHandler() is DEPRECATED and will be removed soon. Please use attachCustomKeyEventHandler() instead.';
  4129. console.warn(message);
  4130. this.attachCustomKeyEventHandler(customKeydownHandler);
  4131. };
  4132. Terminal.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler) {
  4133. this.customKeyEventHandler = customKeyEventHandler;
  4134. };
  4135. Terminal.prototype.setHypertextLinkHandler = function (handler) {
  4136. if (!this.linkifier) {
  4137. throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
  4138. }
  4139. this.linkifier.setHypertextLinkHandler(handler);
  4140. this.refresh(0, this.rows - 1);
  4141. };
  4142. Terminal.prototype.setHypertextValidationCallback = function (callback) {
  4143. if (!this.linkifier) {
  4144. throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
  4145. }
  4146. this.linkifier.setHypertextValidationCallback(callback);
  4147. this.refresh(0, this.rows - 1);
  4148. };
  4149. Terminal.prototype.registerLinkMatcher = function (regex, handler, options) {
  4150. if (this.linkifier) {
  4151. var matcherId = this.linkifier.registerLinkMatcher(regex, handler, options);
  4152. this.refresh(0, this.rows - 1);
  4153. return matcherId;
  4154. }
  4155. };
  4156. Terminal.prototype.deregisterLinkMatcher = function (matcherId) {
  4157. if (this.linkifier) {
  4158. if (this.linkifier.deregisterLinkMatcher(matcherId)) {
  4159. this.refresh(0, this.rows - 1);
  4160. }
  4161. }
  4162. };
  4163. Terminal.prototype.hasSelection = function () {
  4164. return this.selectionManager.hasSelection;
  4165. };
  4166. Terminal.prototype.getSelection = function () {
  4167. return this.selectionManager.selectionText;
  4168. };
  4169. Terminal.prototype.clearSelection = function () {
  4170. this.selectionManager.clearSelection();
  4171. };
  4172. Terminal.prototype.selectAll = function () {
  4173. this.selectionManager.selectAll();
  4174. };
  4175. Terminal.prototype.keyDown = function (ev) {
  4176. if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
  4177. return false;
  4178. }
  4179. this.restartCursorBlinking();
  4180. if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) {
  4181. if (this.ybase !== this.ydisp) {
  4182. this.scrollToBottom();
  4183. }
  4184. return false;
  4185. }
  4186. var self = this;
  4187. var result = this.evaluateKeyEscapeSequence(ev);
  4188. if (result.key === EscapeSequences_1.C0.DC3) {
  4189. this.writeStopped = true;
  4190. }
  4191. else if (result.key === EscapeSequences_1.C0.DC1) {
  4192. this.writeStopped = false;
  4193. }
  4194. if (result.scrollDisp) {
  4195. this.scrollDisp(result.scrollDisp);
  4196. return this.cancel(ev, true);
  4197. }
  4198. if (isThirdLevelShift(this, ev)) {
  4199. return true;
  4200. }
  4201. if (result.cancel) {
  4202. this.cancel(ev, true);
  4203. }
  4204. if (!result.key) {
  4205. return true;
  4206. }
  4207. this.emit('keydown', ev);
  4208. this.emit('key', result.key, ev);
  4209. this.showCursor();
  4210. this.handler(result.key);
  4211. return this.cancel(ev, true);
  4212. };
  4213. Terminal.prototype.evaluateKeyEscapeSequence = function (ev) {
  4214. var result = {
  4215. cancel: false,
  4216. key: undefined,
  4217. scrollDisp: undefined
  4218. };
  4219. var modifiers = ev.shiftKey << 0 | ev.altKey << 1 | ev.ctrlKey << 2 | ev.metaKey << 3;
  4220. switch (ev.keyCode) {
  4221. case 8:
  4222. if (ev.shiftKey) {
  4223. result.key = EscapeSequences_1.C0.BS;
  4224. break;
  4225. }
  4226. result.key = EscapeSequences_1.C0.DEL;
  4227. break;
  4228. case 9:
  4229. if (ev.shiftKey) {
  4230. result.key = EscapeSequences_1.C0.ESC + '[Z';
  4231. break;
  4232. }
  4233. result.key = EscapeSequences_1.C0.HT;
  4234. result.cancel = true;
  4235. break;
  4236. case 13:
  4237. result.key = EscapeSequences_1.C0.CR;
  4238. result.cancel = true;
  4239. break;
  4240. case 27:
  4241. result.key = EscapeSequences_1.C0.ESC;
  4242. result.cancel = true;
  4243. break;
  4244. case 37:
  4245. if (modifiers) {
  4246. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'D';
  4247. if (result.key == EscapeSequences_1.C0.ESC + '[1;3D') {
  4248. result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'b' : EscapeSequences_1.C0.ESC + '[1;5D';
  4249. }
  4250. }
  4251. else if (this.applicationCursor) {
  4252. result.key = EscapeSequences_1.C0.ESC + 'OD';
  4253. }
  4254. else {
  4255. result.key = EscapeSequences_1.C0.ESC + '[D';
  4256. }
  4257. break;
  4258. case 39:
  4259. if (modifiers) {
  4260. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'C';
  4261. if (result.key == EscapeSequences_1.C0.ESC + '[1;3C') {
  4262. result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'f' : EscapeSequences_1.C0.ESC + '[1;5C';
  4263. }
  4264. }
  4265. else if (this.applicationCursor) {
  4266. result.key = EscapeSequences_1.C0.ESC + 'OC';
  4267. }
  4268. else {
  4269. result.key = EscapeSequences_1.C0.ESC + '[C';
  4270. }
  4271. break;
  4272. case 38:
  4273. if (modifiers) {
  4274. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'A';
  4275. if (result.key == EscapeSequences_1.C0.ESC + '[1;3A') {
  4276. result.key = EscapeSequences_1.C0.ESC + '[1;5A';
  4277. }
  4278. }
  4279. else if (this.applicationCursor) {
  4280. result.key = EscapeSequences_1.C0.ESC + 'OA';
  4281. }
  4282. else {
  4283. result.key = EscapeSequences_1.C0.ESC + '[A';
  4284. }
  4285. break;
  4286. case 40:
  4287. if (modifiers) {
  4288. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'B';
  4289. if (result.key == EscapeSequences_1.C0.ESC + '[1;3B') {
  4290. result.key = EscapeSequences_1.C0.ESC + '[1;5B';
  4291. }
  4292. }
  4293. else if (this.applicationCursor) {
  4294. result.key = EscapeSequences_1.C0.ESC + 'OB';
  4295. }
  4296. else {
  4297. result.key = EscapeSequences_1.C0.ESC + '[B';
  4298. }
  4299. break;
  4300. case 45:
  4301. if (!ev.shiftKey && !ev.ctrlKey) {
  4302. result.key = EscapeSequences_1.C0.ESC + '[2~';
  4303. }
  4304. break;
  4305. case 46:
  4306. if (modifiers) {
  4307. result.key = EscapeSequences_1.C0.ESC + '[3;' + (modifiers + 1) + '~';
  4308. }
  4309. else {
  4310. result.key = EscapeSequences_1.C0.ESC + '[3~';
  4311. }
  4312. break;
  4313. case 36:
  4314. if (modifiers)
  4315. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'H';
  4316. else if (this.applicationCursor)
  4317. result.key = EscapeSequences_1.C0.ESC + 'OH';
  4318. else
  4319. result.key = EscapeSequences_1.C0.ESC + '[H';
  4320. break;
  4321. case 35:
  4322. if (modifiers)
  4323. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'F';
  4324. else if (this.applicationCursor)
  4325. result.key = EscapeSequences_1.C0.ESC + 'OF';
  4326. else
  4327. result.key = EscapeSequences_1.C0.ESC + '[F';
  4328. break;
  4329. case 33:
  4330. if (ev.shiftKey) {
  4331. result.scrollDisp = -(this.rows - 1);
  4332. }
  4333. else {
  4334. result.key = EscapeSequences_1.C0.ESC + '[5~';
  4335. }
  4336. break;
  4337. case 34:
  4338. if (ev.shiftKey) {
  4339. result.scrollDisp = this.rows - 1;
  4340. }
  4341. else {
  4342. result.key = EscapeSequences_1.C0.ESC + '[6~';
  4343. }
  4344. break;
  4345. case 112:
  4346. if (modifiers) {
  4347. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'P';
  4348. }
  4349. else {
  4350. result.key = EscapeSequences_1.C0.ESC + 'OP';
  4351. }
  4352. break;
  4353. case 113:
  4354. if (modifiers) {
  4355. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'Q';
  4356. }
  4357. else {
  4358. result.key = EscapeSequences_1.C0.ESC + 'OQ';
  4359. }
  4360. break;
  4361. case 114:
  4362. if (modifiers) {
  4363. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'R';
  4364. }
  4365. else {
  4366. result.key = EscapeSequences_1.C0.ESC + 'OR';
  4367. }
  4368. break;
  4369. case 115:
  4370. if (modifiers) {
  4371. result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'S';
  4372. }
  4373. else {
  4374. result.key = EscapeSequences_1.C0.ESC + 'OS';
  4375. }
  4376. break;
  4377. case 116:
  4378. if (modifiers) {
  4379. result.key = EscapeSequences_1.C0.ESC + '[15;' + (modifiers + 1) + '~';
  4380. }
  4381. else {
  4382. result.key = EscapeSequences_1.C0.ESC + '[15~';
  4383. }
  4384. break;
  4385. case 117:
  4386. if (modifiers) {
  4387. result.key = EscapeSequences_1.C0.ESC + '[17;' + (modifiers + 1) + '~';
  4388. }
  4389. else {
  4390. result.key = EscapeSequences_1.C0.ESC + '[17~';
  4391. }
  4392. break;
  4393. case 118:
  4394. if (modifiers) {
  4395. result.key = EscapeSequences_1.C0.ESC + '[18;' + (modifiers + 1) + '~';
  4396. }
  4397. else {
  4398. result.key = EscapeSequences_1.C0.ESC + '[18~';
  4399. }
  4400. break;
  4401. case 119:
  4402. if (modifiers) {
  4403. result.key = EscapeSequences_1.C0.ESC + '[19;' + (modifiers + 1) + '~';
  4404. }
  4405. else {
  4406. result.key = EscapeSequences_1.C0.ESC + '[19~';
  4407. }
  4408. break;
  4409. case 120:
  4410. if (modifiers) {
  4411. result.key = EscapeSequences_1.C0.ESC + '[20;' + (modifiers + 1) + '~';
  4412. }
  4413. else {
  4414. result.key = EscapeSequences_1.C0.ESC + '[20~';
  4415. }
  4416. break;
  4417. case 121:
  4418. if (modifiers) {
  4419. result.key = EscapeSequences_1.C0.ESC + '[21;' + (modifiers + 1) + '~';
  4420. }
  4421. else {
  4422. result.key = EscapeSequences_1.C0.ESC + '[21~';
  4423. }
  4424. break;
  4425. case 122:
  4426. if (modifiers) {
  4427. result.key = EscapeSequences_1.C0.ESC + '[23;' + (modifiers + 1) + '~';
  4428. }
  4429. else {
  4430. result.key = EscapeSequences_1.C0.ESC + '[23~';
  4431. }
  4432. break;
  4433. case 123:
  4434. if (modifiers) {
  4435. result.key = EscapeSequences_1.C0.ESC + '[24;' + (modifiers + 1) + '~';
  4436. }
  4437. else {
  4438. result.key = EscapeSequences_1.C0.ESC + '[24~';
  4439. }
  4440. break;
  4441. default:
  4442. if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
  4443. if (ev.keyCode >= 65 && ev.keyCode <= 90) {
  4444. result.key = String.fromCharCode(ev.keyCode - 64);
  4445. }
  4446. else if (ev.keyCode === 32) {
  4447. result.key = String.fromCharCode(0);
  4448. }
  4449. else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
  4450. result.key = String.fromCharCode(ev.keyCode - 51 + 27);
  4451. }
  4452. else if (ev.keyCode === 56) {
  4453. result.key = String.fromCharCode(127);
  4454. }
  4455. else if (ev.keyCode === 219) {
  4456. result.key = String.fromCharCode(27);
  4457. }
  4458. else if (ev.keyCode === 220) {
  4459. result.key = String.fromCharCode(28);
  4460. }
  4461. else if (ev.keyCode === 221) {
  4462. result.key = String.fromCharCode(29);
  4463. }
  4464. }
  4465. else if (!this.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) {
  4466. if (ev.keyCode >= 65 && ev.keyCode <= 90) {
  4467. result.key = EscapeSequences_1.C0.ESC + String.fromCharCode(ev.keyCode + 32);
  4468. }
  4469. else if (ev.keyCode === 192) {
  4470. result.key = EscapeSequences_1.C0.ESC + '`';
  4471. }
  4472. else if (ev.keyCode >= 48 && ev.keyCode <= 57) {
  4473. result.key = EscapeSequences_1.C0.ESC + (ev.keyCode - 48);
  4474. }
  4475. }
  4476. else if (this.browser.isMac && !ev.altKey && !ev.ctrlKey && ev.metaKey) {
  4477. if (ev.keyCode === 65) {
  4478. this.selectAll();
  4479. }
  4480. }
  4481. break;
  4482. }
  4483. return result;
  4484. };
  4485. Terminal.prototype.setgLevel = function (g) {
  4486. this.glevel = g;
  4487. this.charset = this.charsets[g];
  4488. };
  4489. Terminal.prototype.setgCharset = function (g, charset) {
  4490. this.charsets[g] = charset;
  4491. if (this.glevel === g) {
  4492. this.charset = charset;
  4493. }
  4494. };
  4495. Terminal.prototype.keyPress = function (ev) {
  4496. var key;
  4497. if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
  4498. return false;
  4499. }
  4500. this.cancel(ev);
  4501. if (ev.charCode) {
  4502. key = ev.charCode;
  4503. }
  4504. else if (ev.which == null) {
  4505. key = ev.keyCode;
  4506. }
  4507. else if (ev.which !== 0 && ev.charCode !== 0) {
  4508. key = ev.which;
  4509. }
  4510. else {
  4511. return false;
  4512. }
  4513. if (!key || ((ev.altKey || ev.ctrlKey || ev.metaKey) && !isThirdLevelShift(this, ev))) {
  4514. return false;
  4515. }
  4516. key = String.fromCharCode(key);
  4517. this.emit('keypress', key, ev);
  4518. this.emit('key', key, ev);
  4519. this.showCursor();
  4520. this.handler(key);
  4521. return true;
  4522. };
  4523. Terminal.prototype.send = function (data) {
  4524. var self = this;
  4525. if (!this.queue) {
  4526. setTimeout(function () {
  4527. self.handler(self.queue);
  4528. self.queue = '';
  4529. }, 1);
  4530. }
  4531. this.queue += data;
  4532. };
  4533. Terminal.prototype.bell = function () {
  4534. if (!this.visualBell)
  4535. return;
  4536. var self = this;
  4537. this.element.style.borderColor = 'white';
  4538. setTimeout(function () {
  4539. self.element.style.borderColor = '';
  4540. }, 10);
  4541. if (this.popOnBell)
  4542. this.focus();
  4543. };
  4544. Terminal.prototype.log = function () {
  4545. if (!this.debug)
  4546. return;
  4547. if (!this.context.console || !this.context.console.log)
  4548. return;
  4549. var args = Array.prototype.slice.call(arguments);
  4550. this.context.console.log.apply(this.context.console, args);
  4551. };
  4552. Terminal.prototype.error = function () {
  4553. if (!this.debug)
  4554. return;
  4555. if (!this.context.console || !this.context.console.error)
  4556. return;
  4557. var args = Array.prototype.slice.call(arguments);
  4558. this.context.console.error.apply(this.context.console, args);
  4559. };
  4560. Terminal.prototype.resize = function (x, y) {
  4561. if (isNaN(x) || isNaN(y)) {
  4562. return;
  4563. }
  4564. if (y > this.getOption('scrollback')) {
  4565. this.setOption('scrollback', y);
  4566. }
  4567. var line, el, i, j, ch, addToY;
  4568. if (x === this.cols && y === this.rows) {
  4569. return;
  4570. }
  4571. if (x < 1)
  4572. x = 1;
  4573. if (y < 1)
  4574. y = 1;
  4575. j = this.cols;
  4576. if (j < x) {
  4577. ch = [this.defAttr, ' ', 1];
  4578. i = this.lines.length;
  4579. while (i--) {
  4580. while (this.lines.get(i).length < x) {
  4581. this.lines.get(i).push(ch);
  4582. }
  4583. }
  4584. }
  4585. this.cols = x;
  4586. this.setupStops(this.cols);
  4587. j = this.rows;
  4588. addToY = 0;
  4589. if (j < y) {
  4590. el = this.element;
  4591. while (j++ < y) {
  4592. if (this.lines.length < y + this.ybase) {
  4593. if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) {
  4594. this.ybase--;
  4595. addToY++;
  4596. if (this.ydisp > 0) {
  4597. this.ydisp--;
  4598. }
  4599. }
  4600. else {
  4601. this.lines.push(this.blankLine());
  4602. }
  4603. }
  4604. if (this.children.length < y) {
  4605. this.insertRow();
  4606. }
  4607. }
  4608. }
  4609. else {
  4610. while (j-- > y) {
  4611. if (this.lines.length > y + this.ybase) {
  4612. if (this.lines.length > this.ybase + this.y + 1) {
  4613. this.lines.pop();
  4614. }
  4615. else {
  4616. this.ybase++;
  4617. this.ydisp++;
  4618. }
  4619. }
  4620. if (this.children.length > y) {
  4621. el = this.children.shift();
  4622. if (!el)
  4623. continue;
  4624. el.parentNode.removeChild(el);
  4625. }
  4626. }
  4627. }
  4628. this.rows = y;
  4629. if (this.y >= y) {
  4630. this.y = y - 1;
  4631. }
  4632. if (addToY) {
  4633. this.y += addToY;
  4634. }
  4635. if (this.x >= x) {
  4636. this.x = x - 1;
  4637. }
  4638. this.scrollTop = 0;
  4639. this.scrollBottom = y - 1;
  4640. this.charMeasure.measure();
  4641. this.refresh(0, this.rows - 1);
  4642. this.normal = null;
  4643. this.geometry = [this.cols, this.rows];
  4644. this.emit('resize', { terminal: this, cols: x, rows: y });
  4645. };
  4646. Terminal.prototype.updateRange = function (y) {
  4647. if (y < this.refreshStart)
  4648. this.refreshStart = y;
  4649. if (y > this.refreshEnd)
  4650. this.refreshEnd = y;
  4651. };
  4652. Terminal.prototype.maxRange = function () {
  4653. this.refreshStart = 0;
  4654. this.refreshEnd = this.rows - 1;
  4655. };
  4656. Terminal.prototype.setupStops = function (i) {
  4657. if (i != null) {
  4658. if (!this.tabs[i]) {
  4659. i = this.prevStop(i);
  4660. }
  4661. }
  4662. else {
  4663. this.tabs = {};
  4664. i = 0;
  4665. }
  4666. for (; i < this.cols; i += this.getOption('tabStopWidth')) {
  4667. this.tabs[i] = true;
  4668. }
  4669. };
  4670. Terminal.prototype.prevStop = function (x) {
  4671. if (x == null)
  4672. x = this.x;
  4673. while (!this.tabs[--x] && x > 0)
  4674. ;
  4675. return x >= this.cols
  4676. ? this.cols - 1
  4677. : x < 0 ? 0 : x;
  4678. };
  4679. Terminal.prototype.nextStop = function (x) {
  4680. if (x == null)
  4681. x = this.x;
  4682. while (!this.tabs[++x] && x < this.cols)
  4683. ;
  4684. return x >= this.cols
  4685. ? this.cols - 1
  4686. : x < 0 ? 0 : x;
  4687. };
  4688. Terminal.prototype.eraseRight = function (x, y) {
  4689. var line = this.lines.get(this.ybase + y);
  4690. if (!line) {
  4691. return;
  4692. }
  4693. var ch = [this.eraseAttr(), ' ', 1];
  4694. for (; x < this.cols; x++) {
  4695. line[x] = ch;
  4696. }
  4697. this.updateRange(y);
  4698. };
  4699. Terminal.prototype.eraseLeft = function (x, y) {
  4700. var line = this.lines.get(this.ybase + y);
  4701. if (!line) {
  4702. return;
  4703. }
  4704. var ch = [this.eraseAttr(), ' ', 1];
  4705. x++;
  4706. while (x--) {
  4707. line[x] = ch;
  4708. }
  4709. this.updateRange(y);
  4710. };
  4711. Terminal.prototype.clear = function () {
  4712. if (this.ybase === 0 && this.y === 0) {
  4713. return;
  4714. }
  4715. this.lines.set(0, this.lines.get(this.ybase + this.y));
  4716. this.lines.length = 1;
  4717. this.ydisp = 0;
  4718. this.ybase = 0;
  4719. this.y = 0;
  4720. for (var i = 1; i < this.rows; i++) {
  4721. this.lines.push(this.blankLine());
  4722. }
  4723. this.refresh(0, this.rows - 1);
  4724. this.emit('scroll', this.ydisp);
  4725. };
  4726. Terminal.prototype.eraseLine = function (y) {
  4727. this.eraseRight(0, y);
  4728. };
  4729. Terminal.prototype.blankLine = function (cur, isWrapped) {
  4730. var attr = cur
  4731. ? this.eraseAttr()
  4732. : this.defAttr;
  4733. var ch = [attr, ' ', 1], line = [], i = 0;
  4734. if (isWrapped) {
  4735. line.isWrapped = isWrapped;
  4736. }
  4737. for (; i < this.cols; i++) {
  4738. line[i] = ch;
  4739. }
  4740. return line;
  4741. };
  4742. Terminal.prototype.ch = function (cur) {
  4743. return cur
  4744. ? [this.eraseAttr(), ' ', 1]
  4745. : [this.defAttr, ' ', 1];
  4746. };
  4747. Terminal.prototype.is = function (term) {
  4748. var name = this.termName;
  4749. return (name + '').indexOf(term) === 0;
  4750. };
  4751. Terminal.prototype.handler = function (data) {
  4752. if (this.options.disableStdin) {
  4753. return;
  4754. }
  4755. if (this.ybase !== this.ydisp) {
  4756. this.scrollToBottom();
  4757. }
  4758. this.emit('data', data);
  4759. };
  4760. Terminal.prototype.handleTitle = function (title) {
  4761. this.emit('title', title);
  4762. };
  4763. Terminal.prototype.index = function () {
  4764. this.y++;
  4765. if (this.y > this.scrollBottom) {
  4766. this.y--;
  4767. this.scroll();
  4768. }
  4769. if (this.x >= this.cols) {
  4770. this.x--;
  4771. }
  4772. };
  4773. Terminal.prototype.reverseIndex = function () {
  4774. var j;
  4775. if (this.y === this.scrollTop) {
  4776. this.lines.shiftElements(this.y + this.ybase, this.rows - 1, 1);
  4777. this.lines.set(this.y + this.ybase, this.blankLine(true));
  4778. this.updateRange(this.scrollTop);
  4779. this.updateRange(this.scrollBottom);
  4780. }
  4781. else {
  4782. this.y--;
  4783. }
  4784. };
  4785. Terminal.prototype.reset = function () {
  4786. this.options.rows = this.rows;
  4787. this.options.cols = this.cols;
  4788. var customKeyEventHandler = this.customKeyEventHandler;
  4789. var cursorBlinkInterval = this.cursorBlinkInterval;
  4790. Terminal.call(this, this.options);
  4791. this.customKeyEventHandler = customKeyEventHandler;
  4792. this.cursorBlinkInterval = cursorBlinkInterval;
  4793. this.refresh(0, this.rows - 1);
  4794. this.viewport.syncScrollArea();
  4795. };
  4796. Terminal.prototype.tabSet = function () {
  4797. this.tabs[this.x] = true;
  4798. };
  4799. function on(el, type, handler, capture) {
  4800. if (!Array.isArray(el)) {
  4801. el = [el];
  4802. }
  4803. el.forEach(function (element) {
  4804. element.addEventListener(type, handler, capture || false);
  4805. });
  4806. }
  4807. function off(el, type, handler, capture) {
  4808. el.removeEventListener(type, handler, capture || false);
  4809. }
  4810. function cancel(ev, force) {
  4811. if (!this.cancelEvents && !force) {
  4812. return;
  4813. }
  4814. ev.preventDefault();
  4815. ev.stopPropagation();
  4816. return false;
  4817. }
  4818. function inherits(child, parent) {
  4819. function f() {
  4820. this.constructor = child;
  4821. }
  4822. f.prototype = parent.prototype;
  4823. child.prototype = new f;
  4824. }
  4825. function indexOf(obj, el) {
  4826. var i = obj.length;
  4827. while (i--) {
  4828. if (obj[i] === el)
  4829. return i;
  4830. }
  4831. return -1;
  4832. }
  4833. function isThirdLevelShift(term, ev) {
  4834. var thirdLevelKey = (term.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
  4835. (term.browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
  4836. if (ev.type == 'keypress') {
  4837. return thirdLevelKey;
  4838. }
  4839. return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47);
  4840. }
  4841. Terminal.prototype.matchColor = matchColor;
  4842. function matchColor(r1, g1, b1) {
  4843. var hash = (r1 << 16) | (g1 << 8) | b1;
  4844. if (matchColor._cache[hash] != null) {
  4845. return matchColor._cache[hash];
  4846. }
  4847. var ldiff = Infinity, li = -1, i = 0, c, r2, g2, b2, diff;
  4848. for (; i < Terminal.vcolors.length; i++) {
  4849. c = Terminal.vcolors[i];
  4850. r2 = c[0];
  4851. g2 = c[1];
  4852. b2 = c[2];
  4853. diff = matchColor.distance(r1, g1, b1, r2, g2, b2);
  4854. if (diff === 0) {
  4855. li = i;
  4856. break;
  4857. }
  4858. if (diff < ldiff) {
  4859. ldiff = diff;
  4860. li = i;
  4861. }
  4862. }
  4863. return matchColor._cache[hash] = li;
  4864. }
  4865. matchColor._cache = {};
  4866. matchColor.distance = function (r1, g1, b1, r2, g2, b2) {
  4867. return Math.pow(30 * (r1 - r2), 2)
  4868. + Math.pow(59 * (g1 - g2), 2)
  4869. + Math.pow(11 * (b1 - b2), 2);
  4870. };
  4871. function each(obj, iter, con) {
  4872. if (obj.forEach)
  4873. return obj.forEach(iter, con);
  4874. for (var i = 0; i < obj.length; i++) {
  4875. iter.call(con, obj[i], i, obj);
  4876. }
  4877. }
  4878. function wasMondifierKeyOnlyEvent(ev) {
  4879. return ev.keyCode === 16 ||
  4880. ev.keyCode === 17 ||
  4881. ev.keyCode === 18;
  4882. }
  4883. function keys(obj) {
  4884. if (Object.keys)
  4885. return Object.keys(obj);
  4886. var key, keys = [];
  4887. for (key in obj) {
  4888. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  4889. keys.push(key);
  4890. }
  4891. }
  4892. return keys;
  4893. }
  4894. Terminal.EventEmitter = EventEmitter_1.EventEmitter;
  4895. Terminal.inherits = inherits;
  4896. Terminal.on = on;
  4897. Terminal.off = off;
  4898. Terminal.cancel = cancel;
  4899. module.exports = Terminal;
  4900. },{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Linkifier":6,"./Parser":7,"./Renderer":8,"./SelectionManager":9,"./Viewport":11,"./handlers/Clipboard":12,"./utils/Browser":13,"./utils/CharMeasure":14,"./utils/CircularList":15,"./utils/Mouse":18}]},{},[19])(19)
  4901. });
  4902. //# sourceMappingURL=xterm.js.map

人工智能研发终端

Contributors (1)