Compare commits

...
371 Commits
Author SHA1 Message Date
Paris Kasidiaris 479fb0e782 Bump version to 2.8.0
Signed-off-by: Paris Kasidiaris <paris@sourcelair.com>
2017-07-04 16:45:20 +00:00
Paris Kasidiaris 8ba11a2bd0 Merge pull request #752 from LucianBuzzo/751-IE11-demo
Add a Promise polyfill to the demo so that it works in IE11
2017-07-04 12:53:13 +03:00
Paris Kasidiaris abc3f3b94d Merge branch 'master' into 751-IE11-demo 2017-07-04 12:50:37 +03:00
Daniel Imms 67bc0456e0 Merge pull request #747 from anishathalye/master
Add scroll functionality for mobile
2017-07-03 21:48:00 -07:00
Daniel Imms 3e8ddd1966 Add jsdoc 2017-07-03 21:43:52 -07:00
Anish Athalye 6223342890 Add scroll functionality for mobile 2017-07-03 19:49:16 -07:00
Daniel Imms 9ddabb3fee Merge pull request #750 from irokas/Rows-fix
Set minimum scrollback value to number of rows if needed on resize
2017-07-03 18:23:48 -07:00
Daniel Imms af0030b580 Merge branch 'master' into Rows-fix 2017-07-03 18:14:31 -07:00
Paris Kasidiaris b93271d9cd Merge branch 'master' into 751-IE11-demo 2017-07-03 14:55:48 +03:00
Paris Kasidiaris 934ca6508f Merge pull request #754 from LucianBuzzo/753-ie11-terminal-cursor
Add one class at a time to element for IE11 compatibility
2017-07-03 14:55:01 +03:00
Lucian Buzzo 7e210c7e6b Add one class at a time to element for IE11 compatibility
Connects to #753

Element.classList.add() does not work with multiple arguments in IE.
2017-07-03 11:22:37 +01:00
Lucian Buzzo e4970266d8 Add a Promise polyfill to the demo so that it works in IE11
Connects to #751
2017-07-03 11:05:35 +01:00
irokas 0a5d7a7bd2 Set minimum scrollback value to number of rows if needed on resize 2017-07-02 21:10:18 +00:00
Daniel Imms 31aab8ea6f Merge pull request #746 from Tyriar/745_colon_word_sep
Remove colon from the selection word separators
2017-07-02 12:36:46 -07:00
Daniel Imms 857d9bcf2a Merge branch 'master' into 745_colon_word_sep 2017-07-02 12:30:45 -07:00
Daniel Imms 7463166aec Fix tests 2017-07-02 12:29:31 -07:00
Paris Kasidiaris f80159fedc Merge pull request #749 from irokas/fix-scrollback
Fix issue with small scrollback value
2017-07-02 14:39:07 +03:00
irokas 3180a6f6ec Add test for scrollback fix 2017-07-02 14:34:19 +03:00
irokas 35d26f1d27 Fix issue with small scrollback value.
Closes #506
2017-07-02 14:22:24 +03:00
Daniel Imms ca03f8928d Remove colon from the word separators
Fixes #745
2017-06-30 17:07:52 -07:00
Daniel Imms 0b3d1e50a8 Merge pull request #741 from AndrienkoAleksandr/codeCleanUp
Little code clean up.
2017-06-30 09:50:54 -07:00
Daniel Imms 401886c7c3 Merge branch 'master' into codeCleanUp 2017-06-30 09:46:54 -07:00
Daniel Imms 4eac7661c2 Merge pull request #733 from Tyriar/732_drop_selection_on_alt
Drop selection when the active buffer changes
2017-06-30 09:40:49 -07:00
Daniel Imms b8163cfbbf Merge branch 'master' into 732_drop_selection_on_alt 2017-06-30 09:36:26 -07:00
Paris Kasidiaris a9f82907ee Merge pull request #743 from nechitai/add-user
Add hexlet.io to the users list
2017-06-30 15:40:30 +03:00
Artem Arbatskiy 57f4ae5320 Add hexlet.io to the users list 2017-06-30 18:30:02 +07:00
Aleksandr Andriienko d1712424c8 Fix docs. 2017-06-30 09:57:24 +03:00
Oleksandr Andriienko 16f865987d Little code clean up. 2017-06-29 23:36:07 +03:00
Daniel Imms f071531494 Merge branch 'master' into 732_drop_selection_on_alt 2017-06-29 12:13:10 -07:00
Daniel Imms 618768c7ed Merge pull request #738 from Tyriar/737_crlf_windows
Use crlf when copying on Windows
2017-06-29 12:12:56 -07:00
Daniel Imms cfe22e6fd2 Use crlf when copying on Windows
Fixes #737
2017-06-29 07:38:41 -07:00
Daniel Imms 3961dd5a44 Merge branch 'master' into 732_drop_selection_on_alt 2017-06-28 15:21:27 -07:00
Daniel Imms 471e332036 Merge pull request #736 from AndrienkoAleksandr/master
Fix 'CR' issue on Linux based OS.
2017-06-28 12:45:16 -07:00
Oleksandr Andriienko 467e8c563a Fix up. 2017-06-28 00:48:13 +03:00
Oleksandr Andriienko 5971630f64 Simplify .gitattributes
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
2017-06-28 00:39:16 +03:00
Oleksandr Andriienko f7cc1058c7 Fix 'CR' issue on Linux based OS.
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
2017-06-27 23:25:01 +03:00
Daniel Imms 645a5920da Drop selection when the active buffer changes
Fixes #732
2017-06-27 10:13:16 -07:00
Paris Kasidiaris f95bc64971 Merge pull request #712 from chabou/customKeypressHandler
Add attachCustomKeyEventsHandler
2017-06-22 16:16:23 +03:00
Daniel Imms 0c7c307de3 Merge branch 'master' into customKeypressHandler 2017-06-21 08:51:15 -07:00
Daniel Imms 1c84881d00 Merge pull request #725 from Tyriar/724_fix_hasSelection
Have Terminal.hasSelection return false when no selection
2017-06-21 08:38:43 -07:00
Daniel Imms f1252abbbe Merge branch 'master' into 724_fix_hasSelection 2017-06-21 08:34:33 -07:00
Daniel Imms 11d6ca2aa1 Merge pull request #723 from Tyriar/699_linux_middle_click
Fix select and middle click to paste selection
2017-06-21 08:34:06 -07:00
Daniel Imms eb59b90790 Merge branch 'master' into 699_linux_middle_click 2017-06-21 08:29:54 -07:00
Daniel Imms 4c3aa97917 Merge pull request #719 from Tyriar/718_selection_on_top
Render selection on top of rows
2017-06-21 08:29:40 -07:00
Daniel Imms ba54f25b8c Merge branch 'master' into 718_selection_on_top 2017-06-21 08:25:05 -07:00
Daniel Imms af268f4968 Merge pull request #722 from Tyriar/721_firefox_contextmenu
Fix context menu in firefox
2017-06-21 08:24:52 -07:00
Daniel Imms 63d63c27e7 Ensure outside selection pastes are respected
We were resetting the selection on every auxclick, meaning outside
selections could not be pasted in when the terminal had a current
selection.
2017-06-20 11:17:12 -07:00
Daniel Imms ef1e2ab9e2 Use auxclick event 2017-06-20 10:49:58 -07:00
Daniel Imms 7b46940772 Have Terminal.hasSelection return false when no selection
Fixes #724
2017-06-20 10:38:33 -07:00
Daniel Imms 6f5f68df1a Add a comment 2017-06-20 10:24:16 -07:00
Daniel Imms dc165175cf Handle middle click to paste selection
This appears to work in Chrome but not Firefox
2017-06-20 10:18:29 -07:00
Daniel Imms 32f1782c84 Fix context menu in firefox
Fixes #721
2017-06-20 10:01:39 -07:00
Daniel Imms 8811d96a8b Fix selection going to clipboard
Part of #699
2017-06-19 15:45:18 -07:00
CHaBou d11d74688e Merge branch 'master' into customKeypressHandler 2017-06-19 22:10:03 +02:00
CHaBou 8e79d53d78 Add attachCustomKeyEventHandler()
Use a uniq customKeyEventHandler for keyDown and keyPress events
Mark and warn attachCustomKeydownHandler() as deprecated.
2017-06-19 22:03:19 +02:00
Daniel Imms 6dbc476cdc Allow mouse events to pass through selection 2017-06-19 11:26:52 -07:00
Daniel Imms 57921e3fe0 Render selection on top of rows
Fixes #718
2017-06-19 11:18:55 -07:00
Daniel Imms 75b74ac4ff Merge pull request #716 from Tyriar/697_select_to_word
Select to the word at the mouse after double click
2017-06-19 07:56:35 -07:00
Daniel Imms 1c659841fa Merge branch 'master' into 697_select_to_word 2017-06-19 07:47:40 -07:00
Daniel Imms 9573357778 Merge pull request #715 from Tyriar/709_improve_selection
Improve selection cell selection
2017-06-19 07:47:15 -07:00
Daniel Imms f11362a80d Merge branch 'master' into 709_improve_selection 2017-06-19 07:39:29 -07:00
Daniel Imms a01fbb636a Merge pull request #714 from Tyriar/713_dblclick_word_separators
Don't select colon, quotes or brackets when double clicking
2017-06-19 07:39:15 -07:00
Daniel Imms 320fb55ddc Use an enum for selection mode 2017-06-18 12:56:32 -07:00
Daniel Imms 4b170ca43f Select to the word at the mouse after double click
Fixes #697
2017-06-18 12:52:43 -07:00
Daniel Imms c6e7fb74ab Merge branch 'master' into 709_improve_selection 2017-06-18 12:03:30 -07:00
Daniel Imms b05814e6a5 Improve selection cell selection
Fixes #709
2017-06-18 12:02:58 -07:00
Daniel Imms 07882c42dc Also consider ' and " word separators
For example URIs in json
2017-06-18 11:51:00 -07:00
Daniel Imms a59b2f8433 Merge branch 'master' into 713_dblclick_word_separators 2017-06-18 11:08:22 -07:00
Daniel Imms 7f2e94c30c Don't select colon or brackets when double clicking
Fixes #713
2017-06-18 10:38:04 -07:00
CHaBou 95aed8fcb0 Add customKeypressHandler 2017-06-16 20:23:48 +02:00
Daniel Imms 663d3b24cd Merge pull request #711 from sourcelair/Tyriar-patch-1
Move latest addition to real world use cases to the end
2017-06-16 07:17:39 -07:00
Daniel Imms a87303f375 Move latest addition to real world use cases to the end
Seems a little unfair to not be at the end, to date it's sorted by date added.
2017-06-16 07:13:03 -07:00
Paris Kasidiaris 259858fac2 Merge pull request #710 from alex-kovoy/alex-kovoy-patch-1
Added 'Gravitational Teleport' to Real-world uses
2017-06-15 23:15:04 +01:00
Alexey Kontsevoy a4514ee98a Added 'Gravitational Teleport' to Real-world uses
We use xterm.js in Gravitational Teleport.
2017-06-15 18:05:07 -04:00
Daniel Imms d27b7bfa7a Merge pull request #707 from jdanyow/issue-683
normalize line endings to \r
2017-06-14 15:22:04 -07:00
Jeremy Danyow ce61795c38 normalize line endings to \r
fixes #683
2017-06-14 14:51:36 -07:00
Daniel Imms 9cc878cea7 Merge pull request #688 from Tyriar/642_link_wrapped_char_duplication
Fix issue with strings in wrapped spans being duplicated
2017-06-13 14:53:23 -07:00
Daniel Imms 087acf8a9a Merge branch 'master' into 642_link_wrapped_char_duplication 2017-06-13 14:45:17 -07:00
Daniel Imms 7612180276 Merge pull request #691 from Tyriar/mid_selection_single_element
Use a single element for the middle of the selection
2017-06-13 14:45:11 -07:00
Daniel Imms 201e3e4dab Merge branch 'master' into mid_selection_single_element 2017-06-13 14:40:48 -07:00
Daniel Imms 55f51ad169 Merge pull request #693 from Tyriar/443_retain_wrapped_lines_copy
Retain wrapped line state when copying
2017-06-13 14:40:41 -07:00
Daniel Imms 405d1ee52d Merge branch 'master' into 443_retain_wrapped_lines_copy 2017-06-13 14:32:01 -07:00
Daniel Imms 5f9ad5c19e Merge pull request #700 from Tyriar/698_mousedown_preventDefault
Prevent mousedown event default selection behavior
2017-06-13 14:31:50 -07:00
Daniel Imms c5cfa409b1 Merge branch 'master' into 698_mousedown_preventDefault 2017-06-12 14:53:48 -07:00
Daniel Imms 2a0f44b0fb Prevent mousedown event default selection behavior
Fixes #698
2017-06-12 14:51:58 -07:00
Daniel Imms 7d0e585c44 Merge branch 'master' into 642_link_wrapped_char_duplication 2017-06-11 11:34:22 -07:00
Daniel Imms a5ced5d909 Merge branch 'master' into mid_selection_single_element 2017-06-11 11:34:20 -07:00
Daniel Imms 0a99f65f01 Merge branch 'master' into 443_retain_wrapped_lines_copy 2017-06-11 11:34:17 -07:00
Daniel Imms c33814a7a6 Merge pull request #680 from Tyriar/set_row_height_explicitly
Set row height when char size is changed
2017-06-10 10:25:06 -07:00
Daniel Imms 0950369a5c Merge remote-tracking branch 'origin/master' into set_row_height_explicitly 2017-06-10 10:21:20 -07:00
Daniel Imms 346b5177bc Retain wrapped line state when copying
Fixes #443
2017-06-09 17:12:00 -07:00
Daniel Imms 9246d524cb Use a single element for the middle of the selection
This reduces the number of DOM nodes used for the selection dramatically.
2017-06-09 16:35:26 -07:00
Daniel Imms a889fef752 Merge pull request #670 from Tyriar/207_selection_manager
Reimplement selection in the terminal
2017-06-09 13:41:34 -07:00
Daniel Imms 6075498c24 Add class header comments 2017-06-09 12:47:16 -07:00
Daniel Imms ee1da73a69 Add regression test 2017-06-09 11:59:18 -07:00
Daniel Imms 29ac6a153e Fix issue with strings in wrapped spans being duplicated
This was happening because the linkifier assumed that top-level spans
in the terminal would only contain single text nodes

Fixes #642
2017-06-09 11:48:12 -07:00
Daniel Imms 264757e964 Use user-select supported by other browsers 2017-06-07 19:23:46 -07:00
Daniel Imms e88a9ffd89 Fix bug when selection end is less than start 2017-06-07 19:17:38 -07:00
Daniel Imms d56a611a19 Add .gitattributes file
Makes working on Windows less bothersome.
2017-06-07 19:16:59 -07:00
Daniel Imms 28ed7772c6 Select last character in bottom right in select all 2017-06-07 14:44:16 -07:00
Daniel Imms a047359f81 Add more selection manager/model tests 2017-06-07 14:37:09 -07:00
Daniel Imms b81c165bea Add SelectionModel tests 2017-06-07 14:15:18 -07:00
Daniel Imms 4405f5e163 Fix clearSelection in select all mode 2017-06-07 13:48:12 -07:00
Daniel Imms 2012c8c91d Move prepareTextForClipboard logic into SelectionManager 2017-06-07 13:42:08 -07:00
Daniel Imms f719a4e91b Fix tests 2017-06-07 13:20:44 -07:00
Daniel Imms 5d33727ae4 Add clearSelection API 2017-06-07 13:07:34 -07:00
Daniel Imms 1343b83fc3 Add hasSelection public API 2017-06-07 12:40:48 -07:00
Daniel Imms 9e47ec9af2 Add getSelectionText API
This allows consumers to implement their own copy functionality/keybindings
2017-06-07 11:59:28 -07:00
Daniel Imms 9c459aacc7 Explicitly size selectionContainer to allow for more flexible layouts 2017-06-07 11:48:31 -07:00
Daniel Imms 72724abac8 Ensure host program handles copy if mouseevents are active 2017-06-07 11:20:03 -07:00
Daniel Imms 9a86eeb333 Support copying in the alt buffer 2017-06-07 11:10:05 -07:00
Daniel Imms 46f6fd18b0 Merge remote-tracking branch 'ups/master' into set_row_height_explicitly 2017-06-06 14:34:07 -07:00
Daniel Imms 603f22a7bb Set row height when char size is changed
When zoomed in line-height and actual rendered row height differs. This
can be seen in the viewport being too large when zoomed in right now
but also has additional impacts in the new selection model #207
2017-06-06 14:31:57 -07:00
Daniel Imms 13c401cbaa Only refresh the selection on an animation frame 2017-06-06 10:52:42 -07:00
Daniel Imms b812991072 Fix multiple drag scroll intervals being registered 2017-06-06 10:40:22 -07:00
Daniel Imms 2b2431824f Fix select all with no start and include content below viewport 2017-06-06 23:13:50 -07:00
Daniel Imms 7147787441 Undo CiruclarList id changes, fix null check, lint 2017-06-06 22:59:16 -07:00
Daniel Imms ec3bf1139d Resolve TODOs 2017-06-06 22:33:32 -07:00
Daniel Imms d0b603d033 jsdoc all of SelectionManager 2017-06-06 21:55:52 -07:00
Daniel Imms 2621be819e Resolve more TODOs, add jsdoc 2017-06-06 21:43:19 -07:00
Daniel Imms f380153f42 Resolve some TODOs 2017-06-06 21:29:30 -07:00
Daniel Imms fd91c5e1a8 Add _selectLineAt test 2017-06-06 15:22:35 -07:00
Daniel Imms f61d852f3c Don't allow double click selection on empty row going out of viewport 2017-06-06 15:05:22 -07:00
Daniel Imms 5bc1112151 Select lines when dragging a triple click 2017-06-06 15:02:52 -07:00
Daniel Imms 59cc0b675e Merge remote-tracking branch 'ups/master' into 207_selection_manager 2017-06-06 14:35:06 -07:00
Daniel Imms db8ded2a02 Implement shift+click 2017-06-06 14:19:12 -07:00
Paris Kasidiaris 4b7279146a Bump version to 2.7.0
Signed-off-by: Paris Kasidiaris <paris@sourcelair.com>
2017-06-06 15:04:59 +00:00
Paris Kasidiaris c4a2f7911d Merge pull request #674 from sourcelair/issue-#671-restore-paste-event
Restore the "paste" terminal event
2017-06-06 11:23:18 +03:00
Paris Kasidiaris db9fe53af3 Merge branch 'master' into issue-#671-restore-paste-event 2017-06-06 11:16:16 +03:00
Daniel Imms d3865ad23f Add some SelectionManager selectWorkAt tests, fix lint 2017-06-01 17:36:47 -07:00
Daniel Imms 8b1067d180 Remove no longer valid clipboard test and add new one 2017-06-01 17:11:07 -07:00
Daniel Imms a53a0acd65 Fix issue with trimming whitespace 2017-06-01 17:04:59 -07:00
Daniel Imms 42724c7f42 Merge pull request #672 from Tyriar/662_parser_state_hack
Fix bug with parser state when using vtop
2017-05-27 15:07:52 -07:00
Paris Kasidiaris 616f069538 Fix #671 - Restore paste event 2017-05-27 15:30:26 +03:00
Daniel Imms 11cec31da6 Clean up wide char select word code 2017-05-25 21:12:44 -07:00
Daniel Imms d9991b25a4 Support wide char double click 2017-05-25 20:48:48 -07:00
Daniel Imms cb6533f3a6 Get double click selection for wide chars mostly working 2017-05-25 20:22:43 -07:00
Daniel Imms 54e7f65d4e Support selecting wide characters 2017-05-25 19:34:32 -07:00
Daniel Imms ec61f3acf0 Only trim the right whitespace from selection
Fixes #673
2017-05-25 18:52:06 -07:00
Daniel Imms 910aa1ad7f Properly prepare text for clipboard for context menu
This makes the context menu in macOS embed the right text
2017-05-25 18:12:03 -07:00
Daniel Imms 24bed01fa4 Support copy and paste via context menu 2017-05-25 16:17:43 -07:00
Daniel Imms f7d6ab5f2a Move the selection model to its own module 2017-05-25 13:20:57 -07:00
Daniel Imms 0716cffd7d Tidy up _areSelectionValuesReversed 2017-05-25 12:46:54 -07:00
Daniel Imms e29ab29441 Fix drag when selectioning via double/triple click 2017-05-25 12:46:08 -07:00
Daniel Imms 9f271de803 Implement triple click to select line 2017-05-25 12:27:47 -07:00
Daniel Imms 43c796a781 Support copying of select all text 2017-05-25 11:35:22 -07:00
Daniel Imms 25152e4441 Add select all API 2017-05-25 10:14:40 -07:00
Daniel Imms 3846fe0a7d Add null checks to fix trim related crash 2017-05-25 09:55:08 -07:00
Daniel Imms b3b2bd1faf Don't flag user scrolling if no scrolling happens 2017-05-25 09:51:13 -07:00
Daniel Imms 2c3d98abc8 Fix bug with parser state when using vtop
Fixes #662
2017-05-25 09:36:59 -07:00
Daniel Imms 0dc3dd0336 Initial scroll drag implementation 2017-05-23 11:20:55 -07:00
Daniel Imms c4762e7228 Merge remote-tracking branch 'ups/master' into 207_selection_manager 2017-05-22 19:51:42 -07:00
Daniel Imms 35b32b721e Merge pull request #668 from Tyriar/fix_pt_valid_var_declarations
Declare pt and valid vars in correct spot
2017-05-22 08:19:52 -07:00
Daniel Imms ccf1a047d3 Merge branch 'master' into fix_pt_valid_var_declarations 2017-05-22 08:03:53 -07:00
Daniel Imms db0338cbcf Merge pull request #669 from Tyriar/pull_getCoords_into_module
Pull get coords into module
2017-05-22 08:03:31 -07:00
Daniel Imms 06742eb507 Merge branch 'master' into pull_getCoords_into_module 2017-05-22 07:57:55 -07:00
Daniel Imms 0fab4ff5d1 Merge pull request #667 from Tyriar/add_missing_emit_arg
Add missing EventEmitter.emit args/types
2017-05-22 07:57:35 -07:00
Daniel Imms d2b0d514f8 Add missing semi-colons 2017-05-21 13:51:02 -07:00
Daniel Imms ab40908fa4 Disable selection manager in mouse mode
This allows the application to take full control of the selection
2017-05-21 12:35:07 -07:00
Daniel Imms a5c48c891e Temp fix until mouse getCoords PR merged 2017-05-21 12:16:36 -07:00
Daniel Imms 70e35de56b Polish comments and cap code 2017-05-21 12:05:30 -07:00
Daniel Imms c323e0ad4a jsdoc 2017-05-21 11:57:24 -07:00
Daniel Imms 4d32826891 Pull getCoords into a Mouse util module
This is part of the work to prepare for the upcoing selection changes

Related #207
2017-05-21 11:50:01 -07:00
Daniel Imms 13088f55a0 Declare pt and valid vars in correct spot 2017-05-21 11:27:57 -07:00
Daniel Imms ea008411e4 Add missing EventEmitter.emit args/types 2017-05-21 11:25:18 -07:00
Daniel Imms e63fdf580b Clean up 2017-05-20 15:21:12 -07:00
Daniel Imms 597c6939c8 Handle basic double click select 2017-05-20 00:17:23 -07:00
Daniel Imms 293ae18a11 Fix copy after scroll 2017-05-20 00:01:55 -07:00
Daniel Imms 32b34cbe4c Handle copy 2017-05-19 23:53:20 -07:00
Daniel Imms 2f6d05f99d Handle scrolling of selection 2017-05-19 23:32:26 -07:00
Daniel Imms ad3ae67e70 Get selection partially rendering 2017-05-19 23:29:51 -07:00
Daniel Imms b594407cd5 Tell renderer to draw selection 2017-05-19 20:06:05 -07:00
Daniel Imms 207c4cf961 More work on SelectionManager 2017-05-19 19:57:52 -07:00
Daniel Imms fe11837a61 Create new entries when shifting 2017-05-19 19:11:28 -07:00
Daniel Imms fee912023f Merge remote-tracking branch 'ups/master' into 207_selection_manager 2017-05-19 18:38:24 -07:00
Daniel Imms a95ac990ff Merge pull request #450 from Tyriar/449_keep_span_pool
Keep row spans in an object pool to reduce garbage collection by reusing DOM nodes
2017-05-16 10:12:27 -07:00
Daniel Imms aad8439542 Fix lint errors 2017-05-16 10:07:55 -07:00
Daniel Imms 1a777edffe Add missing return type 2017-05-16 10:04:12 -07:00
Daniel Imms 537018f71f DomElementObjectPool jsdoc 2017-05-16 10:03:56 -07:00
Daniel Imms 67ca3a9334 More string interpolation 2017-05-16 09:57:50 -07:00
Daniel Imms 5fb30979c1 Add jsdoc back, was lost in merge 2017-05-14 14:28:06 -07:00
Daniel Imms cf863d4849 Use string interpolation 2017-05-14 14:26:45 -07:00
Daniel Imms 47814847f9 Remove var usages 2017-05-14 12:47:17 -07:00
Daniel Imms 9ec8974545 More clean up 2017-05-14 12:40:45 -07:00
Daniel Imms c887c6e0f6 Clean up 2017-05-14 12:27:06 -07:00
Daniel Imms 6c8949bba1 Only wrap single width unicode chars 2017-05-14 12:20:01 -07:00
Daniel Imms 508d3ab68c Merge remote-tracking branch 'ups/master' into 449_keep_span_pool 2017-05-14 12:09:47 -07:00
Paris Kasidiaris 6dad013783 Merge pull request #659 from jdanyow/paste
Normalize line endings on paste
2017-05-11 12:28:38 +03:00
Jeremy Danyow 0532e5cbf0 Normalize line endings on paste 2017-05-09 15:21:56 -07:00
Daniel Imms abcdf3e252 Merge branch 'master' into 449_keep_span_pool 2017-05-08 11:35:42 -07:00
Daniel Imms 3baa6b9237 Wrap all characters temporarily in spans to force fixed with
Fixes #467
2017-05-07 16:08:01 -07:00
Daniel Imms 23e6a475ee Merge remote-tracking branch 'origin/master' into 449_keep_span_pool 2017-05-07 15:49:40 -07:00
Daniel Imms 65256c8751 Support an entry ID in CircularList
This is needed to keep track of which row is which outside of the class
2017-05-05 20:24:25 -07:00
Daniel Imms b36d8780fd Clean up 2017-05-05 17:40:23 -07:00
Daniel Imms 70fda99415 Basic fetching of coordinates 2017-05-05 17:36:15 -07:00
Paris Kasidiaris 2221f70ff0 Bump version to 2.6.0
Signed-off-by: Paris Kasidiaris <paris@sourcelair.com>
2017-05-04 15:38:52 +00:00
Daniel Imms daad8d9c04 Merge pull request #652 from Tyriar/651_fix_travis_fail
Force failing mocha tests to return a exit code of 1
2017-05-04 08:35:37 -07:00
Daniel Imms 03d26e39c7 Force failing mocha tests to return a exit code of 1
Fixes #651
2017-05-03 10:06:53 -07:00
Paris Kasidiaris 64d3c089a2 Merge pull request #647 from Martin1994/orion_use
Add "Eclipse Orion" to "Real-World Uses".
2017-05-02 00:37:38 +03:00
Martin Chloride 938c011e63 Added "Eclipse Orion" to "Real-World Uses". 2017-05-01 17:12:07 -04:00
Paris Kasidiaris 66f6b88333 Merge pull request #645 from sourcelair/issue-#640-do-not-focus-on-open
Add `focus` argument in `Terminal.prototype.open`
2017-05-01 01:07:00 +03:00
Paris Kasidiaris 35f746c925 Add focus argument in Terminal.prototype.open
Fix #640
2017-04-26 10:37:07 +00:00
Paris Kasidiaris 944da28089 Merge pull request #643 from jsmecham/patch-1
Add "Terminal for Atom" to Real-World Uses
2017-04-24 17:43:20 +03:00
Justin Mecham 8f3e2b645a Added "Terminal for Atom" to Real-World Uses. 2017-04-23 14:36:01 -04:00
Daniel Imms 82b2a5305f Merge pull request #639 from Tyriar/638_retain_cursor_blink_interface
Keep cursor blink interval after a reset
2017-04-21 17:59:51 -07:00
Daniel Imms 6a2852ee26 Merge branch 'master' into 638_retain_cursor_blink_interface 2017-04-21 17:53:49 -07:00
Daniel Imms 526d6c4da9 Merge pull request #641 from Tyriar/support_demo_cursorStyle
Support cursorStyle selection in demo
2017-04-20 10:33:30 -07:00
Daniel Imms 46d62f4972 Support cursorStyle selection in demo 2017-04-19 18:16:48 -07:00
Daniel Imms 5cafcdb695 Keep cursor blink interval after a reset
Fixes #638
2017-04-19 11:22:18 -07:00
Paris Kasidiaris 2674258ead Merge pull request #635 from rstudio/master
Update README with RStudio under real-world uses.
2017-04-15 01:15:27 +03:00
Gary Ritchie b38be3a1d0 Update README with RStudio under real-world uses. 2017-04-14 10:50:15 -07:00
Daniel Imms 18a9f05626 Merge pull request #628 from saulcosta18/patch-1
Added Codevolve.com to README
2017-04-06 13:01:16 -07:00
Saul Costa bf34980c43 Added Codevolve.com to README
We use xterm.js for our courses at Codevolve.
2017-04-06 12:50:41 -07:00
Paris Kasidiaris d2f8f9dc1a Bump version to 2.5.0
Signed-off-by: Paris Kasidiaris <paris@sourcelair.com>
2017-04-05 18:48:57 +00:00
Daniel Imms df13469b6e Merge pull request #627 from Tyriar/591_element_on_validation
Give API access to valid link elements
2017-04-05 11:34:34 -07:00
Daniel Imms 584ec681af Merge remote-tracking branch 'ups/master' into 591_element_on_validation 2017-04-04 09:50:04 -07:00
Daniel Imms 0c5b5cca4a Merge pull request #623 from Tyriar/612_multiple_links_in_row
Support multiple link matches in a single row
2017-04-04 09:41:19 -07:00
Daniel Imms 64663bf4a8 Fix tests 2017-04-04 09:35:52 -07:00
Daniel Imms fe8334a873 Merge remote-tracking branch 'ups/master' into 612_multiple_links_in_row 2017-04-04 09:33:53 -07:00
Daniel Imms c74fd40e2a Merge pull request #619 from Tyriar/618_register_link_before_dom
Allow links to be registered before terminal is attached to DOM
2017-04-04 09:13:09 -07:00
Daniel Imms 0f8ff67451 Merge branch 'master' into 618_register_link_before_dom 2017-04-04 09:02:37 -07:00
Daniel Imms 8b0032c210 Merge branch 'master' into 612_multiple_links_in_row 2017-04-04 09:02:35 -07:00
Daniel Imms d9254ef2d9 Merge pull request #626 from Tyriar/625_cursor_blink_perf
Use setInterval over animation for cursor blink
2017-04-04 09:02:27 -07:00
Daniel Imms 66be05a962 Merge branch 'master' into 612_multiple_links_in_row 2017-04-04 09:00:47 -07:00
Daniel Imms 0e85a09dd3 Merge branch 'master' into 618_register_link_before_dom 2017-04-04 08:58:43 -07:00
Daniel Imms 0c4ba9fd67 Clear cursor blink interval on blur 2017-04-03 15:09:38 -07:00
Daniel Imms aca81c764a Use setInterval over animation for cursor blink
Fixes #625
2017-04-03 14:49:21 -07:00
Daniel Imms 6b3ddb97d1 Merge pull request #624 from InDieTasten/patch-1
Fix typos in comment
2017-03-31 13:27:29 -07:00
InDieTasten 26ccf2a316 Fix typos in comment 2017-03-31 22:16:11 +02:00
Daniel Imms 361894194a Merge branch 'master' into 612_multiple_links_in_row 2017-03-31 03:06:23 -07:00
Daniel Imms 8c2db8ddb8 More tests 2017-03-31 02:10:07 -07:00
Daniel Imms 5546baa927 Fix edge case 2017-03-31 01:54:21 -07:00
Daniel Imms d814009721 Add tests 2017-03-31 01:48:51 -07:00
Daniel Imms 08fd050c3f Support multiple link matches in a single row
Fixes #612
2017-03-31 01:48:35 -07:00
Daniel Imms 0b096d7d55 Merge pull request #621 from coderaiser/patch-1
Added Cloud Commander to real world uses
2017-03-30 11:31:11 -07:00
coderaiser 44cfb2dc87 Added Cloud Commander to real world uses 2017-03-30 14:26:56 +03:00
Daniel Imms b0624cadb7 Allow links to be registered before terminal is attached to DOM
Fixes #618
2017-03-24 11:04:04 -07:00
Paris Kasidiaris 045f361b0d Merge pull request #616 from LucianBuzzo/crop-lines
Prevent line data from being discarded on resize.
2017-03-20 09:52:22 +00:00
Lucian Buzzo cb77b9dc1a Prevent line data from being discarded on resize. 2017-03-19 08:26:37 +00:00
Paris Kasidiaris 0723dac596 Merge pull request #615 from andfoy/patch-1
Added Spyder IDE Terminal as a xterm case-use application
2017-03-19 00:26:41 +00:00
Edgar Andrés Margffoy Tuay 365f9b4c1b Added Spyder IDE as a xterm case-use application 2017-03-18 18:05:05 -05:00
Daniel Imms 2cf90d90f7 Merge pull request #610 from Tyriar/non_draggable_links
Ensure terminal links are not draggable
2017-03-17 09:22:05 -07:00
Daniel Imms da14f64d1b Merge branch 'master' into non_draggable_links 2017-03-17 02:27:07 -07:00
Paris Kasidiaris ef1b1c8ffc Merge pull request #608 from sourcelair/add-logo
Add xterm.js logo
2017-03-17 08:18:08 +00:00
Daniel Imms adde8ab2c3 Ensure terminal links are not draggable 2017-03-16 12:07:25 -07:00
Paris Kasidiaris 22cc8079dc Add xterm.js logo 2017-03-16 08:54:07 +00:00
Daniel Imms 6d25706300 Merge pull request #606 from Tyriar/vscode22640_tilde_path
Allow ~ char in linkify path and query fragments
2017-03-15 18:01:47 -07:00
Paris Kasidiaris 81419c980b Merge pull request #603 from sourcelair/fix-blurred-terminal-cursor
Fix cursor style on blurred terminals
2017-03-15 22:09:18 +00:00
Paris Kasidiaris 097e21f641 Merge pull request #604 from sourcelair/rebuild-on-css
Rebuild xterm.js even when CSS changes
2017-03-15 22:09:03 +00:00
Daniel Imms b68180b97b Allow ~ char in linkify path and query fragments 2017-03-15 13:55:57 -07:00
Daniel Imms d9059d18c0 Merge pull request #600 from sourcelair/Tyriar-patch-1
Polish development and contribution section
2017-03-15 10:53:03 -07:00
Paris Kasidiaris 5225a6e27a Rebuild xterm.js even when CSS changes
Otherwise you had to run `npm build` manually every time you changed a CSS file to see the updated result in the demo.
2017-03-15 18:36:06 +02:00
Paris Kasidiaris 9055bace96 Fix cursor style on blurred terminals 2017-03-15 18:28:17 +02:00
Paris Kasidiaris eb25e88754 Merge pull request #598 from mikesir87/fix-fit-calculation
Fixed characterHeight calculation, which could cause overflowing
2017-03-15 14:34:13 +00:00
Michael Irwin 0cb8ecc6f7 Use boundingClientRect instead of style to get actual height
PR #598
2017-03-15 09:06:56 -04:00
Daniel Imms 8cf76cc6e9 Polish development and contribution section 2017-03-14 15:15:36 -07:00
Michael Irwin 3c3a646d42 Fixed characterHeight calculation, which could cause overflowing
The previous calculation was simply using the height of the letter
W, but wasn't taking into account that each row has a lineHeight,
which might be greater. If the lineHeight is .4px off, after many
rows, it will cause the proposedGeometry to have an extra row,
potentially causing hidden rows (based on layout).
2017-03-14 17:02:53 -04:00
Paris Kasidiaris ff29fd69a3 Merge pull request #572 from AndrienkoAleksandr/gulpImprove
Use tsconfig.json data in gulpfile.js instead of hardcoded values.
2017-03-11 13:21:47 +00:00
Daniel Imms 91994a399c Merge pull request #582 from tmyt/propose/row-height
Support checking height in checkBoldBroken
2017-03-10 12:53:12 -08:00
Daniel Imms bef7137c92 Fix bug 2017-03-09 10:47:09 -08:00
Daniel Imms 11f62bab34 Expose setHypertextValidationCallback 2017-03-09 10:39:08 -08:00
Daniel Imms b66776a047 Include element in validationCallback
Fixes #591
2017-03-09 10:23:59 -08:00
Daniel Imms 2c151f444c Merge pull request #589 from warpdesign/patch-1
FIXED: typo
2017-03-08 15:52:55 -08:00
Nicolas Ramz d8f8b060cb FIXED: typo
`<div id="terminal"></div>` wasn't used, instead, a new one was created and used since getElementById('#terminal') returned null.
2017-03-09 00:47:29 +01:00
Daniel Imms ea9376019c Merge pull request #586 from AndrienkoAleksandr/cleanUpTsConfig
Clean up tsconfig.json.
2017-03-08 12:02:09 -08:00
Daniel Imms 008d1df106 Merge remote-tracking branch 'up/master' into cleanUpTsConfig 2017-03-08 11:47:56 -08:00
Daniel Imms ec91a6c7f4 Merge pull request #588 from Tyriar/587_csi_3_J
Implement CSI 3 J - Erase saved lines
2017-03-08 11:08:46 -08:00
yutaka 4b2ae6a79f Use rendered height for detect broken bold font. 2017-03-08 11:30:23 +00:00
yutaka 2ec756fd6b Use offsetWidth instead of scrollWidth
scrollWidth does not work on Chrome with `display: inline` element.
2017-03-08 05:11:26 +00:00
yutaka f0d5b40121 Detect bold font was broken correctly. 2017-03-08 04:54:18 +00:00
yutaka 31a0996b2f Revert "Set charMeasure.height values to each row height"
This reverts commit 43cb4f471f.
2017-03-08 00:27:22 +00:00
Daniel Imms 0bbd8f0a16 Implement CSI 3 J - Erase saved lines
Fixes #587
2017-03-07 14:01:42 -08:00
Paris Kasidiaris b1619e42fd Bump version to 2.4.0
Signed-off-by: Paris Kasidiaris <paris@sourcelair.com>
2017-03-07 09:38:48 +00:00
Daniel Imms 4cfec2fc09 Merge pull request #579 from Tyriar/578_ctrl_click_links
Require ctrl for link clicks
2017-03-06 07:21:58 -08:00
Aleksandr Andrienko 3d721a95bb Clean up tsconfig.json.
'include' field in the tsconfig.json defines source scope (top level of this scope is "src" folder), so we do not need 'exclude' folders in the root of the project, because this folders had already excluded by 'include' scope.

Signed-off-by: Aleksandr Andrienko <aandrienko@codenvy.com>
2017-03-06 13:17:01 +02:00
Aleksandr Andrienko dc3a136704 Use tsconfig.json data in gulpfile.js instead of hardcoded values.
Use tsconfig.json data in gulpfile.js instead of hardcoded values. Little code clean up

Signed-off-by: Aleksandr Andrienko <aandrienko@codenvy.com>
2017-03-06 12:25:22 +02:00
Daniel Imms 235ae2fbb9 Fix http link handler logic 2017-03-04 15:02:08 -08:00
Daniel Imms 1f518b0b45 Allow http link handler to fallback to standard handler 2017-03-04 14:44:11 -08:00
Daniel Imms ab34d53d6b Remove unused import 2017-03-04 14:09:13 -08:00
Daniel Imms aafb5333b9 Give event to handler 2017-03-04 14:08:05 -08:00
Daniel Imms 5e2791f981 Revert "Add fail handler"
This reverts commit 1ecc5674ac.
2017-03-04 14:01:40 -08:00
Daniel Imms 1ecc5674ac Add fail handler 2017-03-04 14:01:34 -08:00
Daniel Imms c9ad3a595a Merge pull request #584 from coderaiser/patch-1
Fix demo: wrong pid on windows #567
2017-03-03 14:38:55 -08:00
coderaiser 43558fa1dc Fix demo: wrong pid on windows #567 2017-03-03 23:40:36 +02:00
Daniel Imms 15a867d2b7 Support cmd+click on mac 2017-03-03 12:37:34 -08:00
yutaka 43cb4f471f Set charMeasure.height values to each row height 2017-03-03 07:57:05 +00:00
Daniel Imms 012051c1db Fix matchIndex on http 2017-03-02 17:35:10 -08:00
Daniel Imms b5483898da Merge remote-tracking branch 'upstream/master' into 578_ctrl_click_links 2017-03-02 17:34:30 -08:00
Daniel Imms c7b4c2beaf Require ctrl for link clicks
Fixes #578
2017-03-02 17:33:58 -08:00
Daniel Imms 8693d067e3 Merge pull request #577 from Tyriar/549_link_priority
Implement link matcher priorities
2017-03-02 15:24:09 -08:00
Daniel Imms 78d5fc9506 Fix bug with priority 2017-03-02 12:05:34 -08:00
Daniel Imms 7ac4f1a9be Implement link matcher priorities
Fixes #549
2017-03-02 11:25:27 -08:00
Daniel Imms 670fb01fbf Merge pull request #566 from Tyriar/linkify_issues
Linkify issues
2017-03-02 09:02:24 -08:00
Daniel Imms ec9608d54b Merge pull request #574 from Tyriar/link_validation_fixes
Link validation fixes
2017-03-02 00:42:01 -08:00
Daniel Imms dcffaf1c8c Ensure linkElement exists before firing validation callback 2017-03-01 09:38:59 -08:00
Daniel Imms efac5293c0 Use text cursor for invalid links
Part of #570
2017-03-01 09:37:30 -08:00
Daniel Imms c7563346a2 Merge pull request #571 from Tyriar/570_link_validation
Implement link validation
2017-03-01 09:12:53 -08:00
Daniel Imms 69906532b1 Remove test harness 2017-02-27 15:44:10 -08:00
Daniel Imms 9404fae725 Merge remote-tracking branch 'upstream/master' into linkify_issues 2017-02-27 12:59:59 -08:00
Daniel Imms 3542f15575 Don't expose CharMeasure/Linkifier for tests 2017-02-27 12:57:18 -08:00
Daniel Imms 15d79143e2 Get rid of exposed test method (phantom is gone) 2017-02-27 12:56:54 -08:00
Daniel Imms f6dafee748 Remove dead code 2017-02-27 12:52:54 -08:00
Daniel Imms 356d86ae74 Merge remote-tracking branch 'upstream/master' into 570_link_validation 2017-02-27 12:47:53 -08:00
Daniel Imms e673c6ec97 Upgrade to TypeScript 2.2 2017-02-27 11:54:55 -08:00
Daniel Imms 3e5fcf7004 Merge pull request #569 from wavebeem/issue/562
Fixes #562 adds Windows demo setup help
2017-02-27 11:52:47 -08:00
Daniel Imms 96d2a2bc68 Pin TypeScript at v2.1 to fix PhantomJS error 2017-02-27 11:47:57 -08:00
Daniel Imms b401992178 Add jsdom types 2017-02-27 11:22:59 -08:00
Daniel Imms 4c34351383 Remove PhantomJS completely 2017-02-27 11:22:50 -08:00
Daniel Imms 202b54afbb Convert CharMeasure phantom test to jsdom 2017-02-27 11:18:00 -08:00
Daniel Imms 26ebc3d944 Use jsdom instead of phantomjs for linkifier test 2017-02-27 11:00:12 -08:00
Daniel Imms d0f36e9939 Pin typescript 2.1 to prevent exports error 2017-02-27 10:02:12 -08:00
Daniel Imms 4c99c032ca Add tests 2017-02-27 09:47:36 -08:00
Daniel Imms 6198556e50 Implement link validation
Fixes #570
2017-02-27 08:35:59 -08:00
Brian Mock 514eba0e4e Fixes #562 adds Windows demo setup help 2017-02-25 12:16:18 -08:00
Daniel Imms 7279ee0f5f Support % in URLs 2017-02-24 08:56:42 -08:00
Daniel Imms ccadf3fcca Support percent and numbers in query/hash fragments 2017-02-23 10:02:18 -08:00
Daniel Imms cb80ce0d2c Link . and - in hash fragments and query strings 2017-02-23 09:55:05 -08:00
Daniel Imms 9aae43961f Support linking hash fragments 2017-02-23 09:53:20 -08:00
Daniel Imms b810687163 Support linking = in query strings 2017-02-23 09:42:59 -08:00
Daniel Imms 28d4ec779d Fix localhost links 2017-02-23 09:37:35 -08:00
Paris Kasidiaris cf4da6c748 Merge pull request #565 from sourcelair/issue-#531-coveralls
Fix #531: Submit code coverage to coveralls.io
2017-02-22 19:15:04 +02:00
Paris Kasidiaris e569b5669a Add coveralls badge 2017-02-22 16:22:50 +02:00
Paris Kasidiaris 695a9523fe Fix #531: Submit code coverage to coveralls.io 2017-02-22 16:17:22 +02:00
Daniel Imms 01b8e28a7d Merge pull request #556 from Tyriar/555_fix_mouse_coords
Use CharMeasure to determine mouse coordinates
2017-02-20 03:17:50 -08:00
Daniel Imms e221030a2b Merge pull request #559 from Tyriar/558_linkify_bad_trim
Remove bad trim optimization from Linkifier
2017-02-20 03:17:42 -08:00
Daniel Imms 88dc697392 Merge pull request #557 from Tyriar/CharMeasure_aria_hidden
Hide CharMeasure element from assistive technologies
2017-02-20 03:17:34 -08:00
Daniel Imms 99a270216c Remove bad trim optimization from Linkifier
This prevents whitespace from going missing after links are applied.

Fixes #558
2017-02-19 15:17:03 -08:00
Daniel Imms d06c920a2d Hide CharMeasure element from assistive technologies 2017-02-19 13:20:36 -08:00
Daniel Imms 5452986ce3 Use CharMeasure to determine mouse coordinates
Fixes #555
2017-02-19 12:34:36 -08:00
Daniel Imms ae69841174 Merge pull request #538 from Tyriar/455_linkify
Implement web links and custom link matcher registration
2017-02-17 11:40:59 -08:00
Daniel Imms e6fc80c13b Fix link matcher iteration direction 2017-02-17 10:22:55 -08:00
Daniel Imms a10ee8f58c Revert priority change, http handler needs to be top 2017-02-17 10:18:46 -08:00
Daniel Imms 3f69da2455 Support query string in linkifier 2017-02-17 10:06:35 -08:00
Daniel Imms a14a0834e9 Merge remote-tracking branch 'upstream/master' into 455_linkify 2017-02-17 10:05:22 -08:00
Daniel Imms c4f431849b Add a null check on linkifyRow 2017-02-16 22:41:08 -08:00
Daniel Imms ade3389cea Merge pull request #535 from Tyriar/534_phantomjs
Add PhantomJS test support and CharMeasure tests
2017-02-15 13:29:50 -08:00
Paris Kasidiaris 6873ba0909 Merge pull request #541 from AndrienkoAleksandr/FixSoftReset
Fix 'Autowrap Mode' after 'Soft Terminal reset' command.
2017-02-15 11:24:42 +02:00
Daniel Imms c3f31b5f65 Apply link matchers in reverse
This enables consumers to have full control.
2017-02-14 20:06:15 -08:00
Daniel Imms 3b62aa444b Improve jsdoc 2017-02-14 19:45:22 -08:00
Daniel Imms fb2b10b565 Merge pull request #545 from Martin1994/blink_cursor_color
Let blink animation support style inheritance
2017-02-14 19:23:22 -08:00
Martin Wang 345553012f Let blink animation support style inheritance
With this change, blinking cursor will use the same font and background
color that set before.
2017-02-14 12:35:39 -05:00
Daniel Imms fddc13d98e Merge pull request #544 from LucianBuzzo/master
Make fit plugin guard against non-existent parent element.
2017-02-13 13:26:14 -08:00
Lucian Buzzo aeb9f798c9 Make fit plugin guard against non-existent parent element. 2017-02-13 21:01:28 +00:00
Paris Kasidiaris 8fd44266a2 Bump version to 2.3.2
Signed-off-by: Paris Kasidiaris <paris@sourcelair.com>
2017-02-13 18:05:47 +00:00
Paris Kasidiaris ef4155fbf6 Merge pull request #542 from Tyriar/539_fix_initial_viewport_sync
Perform initial viewport sync after CharMeasure is ready
2017-02-13 20:05:03 +02:00
Daniel Imms 92f27d3144 Fix tests 2017-02-13 09:48:22 -08:00
Daniel Imms 5183332f6e Next link matcher ID must be non-static 2017-02-10 12:29:36 -08:00
Daniel Imms ee1de0980f Perform initial viewport sync after CharMeasure is ready
Fixes #539
2017-02-10 09:55:35 -08:00
Aleksandr Andrienko c53183d94b Fix default 'wraparoundMode' value for 'Soft reset'() XTERM terminal. 2017-02-10 16:52:19 +02:00
Daniel Imms 1ee774d01d Remove linkify test 2017-02-09 22:03:31 -08:00
Daniel Imms 1c030f57ef Force a refresh after register/deregister link matcher 2017-02-09 21:12:28 -08:00
Daniel Imms c8bb321654 Get custom link matcher working 2017-02-09 21:08:50 -08:00
Daniel Imms a1d71c9198 Properly queue linkify after refresh 2017-02-09 20:35:06 -08:00
Daniel Imms 55cb43d70b Add license 2017-02-09 20:12:35 -08:00
Daniel Imms 551159e0c3 Remove linkify addon 2017-02-09 20:10:01 -08:00
Daniel Imms 3bf31aa478 Polish 2017-02-09 20:09:47 -08:00
Daniel Imms 1316682343 Merge pull request #532 from AndrienkoAleksandr/cleanUpDependency
Remove excess library.
2017-02-09 20:01:46 -08:00
Daniel Imms 7167b06bf8 Add custom link handlers, use generic way for http handler 2017-02-08 20:44:22 -08:00
Daniel Imms 34582f9f65 Remove logs 2017-02-08 20:21:18 -08:00
Daniel Imms 8dc9ec5733 Only show underline on hover 2017-02-08 20:20:18 -08:00
Daniel Imms e8adf8ad2b Use gulp-mocha and attach run both test type in npm test 2017-02-08 20:06:14 -08:00
Daniel Imms 1306431e7c Add PhantomJS test support and CharMeasure tests
Fixes #534
2017-02-08 19:53:32 -08:00
Daniel Imms f7bc0fba4d Remove unnecessary variables 2017-02-08 18:57:45 -08:00
Daniel Imms 0f3ee21d9d Enable custom http link handlers 2017-02-08 14:13:30 -08:00
Daniel Imms a489037ec4 Improve node insertion, support custom link handlers 2017-02-08 13:50:36 -08:00
Aleksandr Andrienko c48388af14 Remove excess library.
Tsify lib used for browserify typescript sources. But folder /lib consist of js files has already compiled from TypeScript sources (by gulp task tsc). So Tsify library does nothing in this case.

Signed-off-by: Aleksandr Andrienko <aandrienko@codenvy.com>
2017-02-08 23:15:54 +02:00
Daniel Imms 2207d356f2 Initial linkify implementation
Part of 455
2017-02-08 11:11:52 -08:00
Daniel Imms 6b5ced0078 Merge remote-tracking branch 'upstream/master' into 449_keep_span_pool 2017-01-08 17:09:23 -08:00
Daniel Imms c7e8498166 Clear row and return spans before generating row 2017-01-04 09:44:58 -08:00
Daniel Imms 2b4c019f13 Use object pool in refresh 2017-01-04 09:32:23 -08:00
Daniel Imms 335850380e Implement DomElementObjectPool with tests 2017-01-04 08:50:19 -08:00
49 changed files with 4343 additions and 979 deletions
+1
View File
@@ -0,0 +1 @@
* text=auto
+3
View File
@@ -13,3 +13,6 @@ npm-debug.log
.env
build/
.vscode/
# Directories needed for code coverage
/coverage/
+1
View File
@@ -16,3 +16,4 @@ addons:
notifications:
email: false
script: npm run $NPM_COMMAND
after_success: npm run coveralls
+21
View File
@@ -1,10 +1,15 @@
List of xterm.js contributors. Updated before every release.
Aleksandr Andrienko <aandrienko@codenvy.com>
Aleksandr Andriienko <oandriie@redhat.com>
Alessandro Nadalin <alessandro.nadalin@gmail.com>
Alexander Olsson <noseglid@gmail.com>
Alexey Kontsevoy <alexey@gravitational.com>
Anish Athalye <me@anishathalye.com>
Antonis Kalipetis <akalipetis@sourcelair.com>
Anton Skshidlevsky <meefik@gmail.com>
Anton Yurovskykh <anton.yurovskykh@gmail.com>
Artem Arbatskiy <artyom.arbatskiy@gmail.com>
Austin Robertson <austinrobertson@gmail.com>
ayapi <colors.aya@gmail.com>
Ben Hall <ben@benhall.me.uk>
@@ -12,30 +17,46 @@ Benjamin Fischer <benjamin.fischer@rwth-aachen.de>
Bill Church <billchurch@users.noreply.github.com>
Bob Reid <bobreid@Bobs-MacBook-Pro.local>
bottleofwater <nison.mael+bottleofwater@gmail.com>
Brian Mock <brian@mockbrian.com>
Carson Anderson <carson@betterservers.com>
CHaBou <chabup@delean.fr>
Christian Budde Christensen <budde377@gmail.com>
Christopher Jeffrey <chjjeffrey@gmail.com>
coderaiser <mnemonic.enemy@gmail.com>
Daniel Imms <daimms@microsoft.com>
Daniel Risacher <drisacher@gmail.com>
Dan Kaplun <dbkaplun@twitch.tv>
Darin Morrison <freebroccolo@users.noreply.github.com>
Edgar Andrés Margffoy Tuay <andfoy@gmail.com>
Elliot Saba <staticfloat@gmail.com>
Gary Ritchie <gary@rstudio.com>
hiro-su <h.sugipon@gmail.com>
Ian Lewis <ianlewis@google.com>
imoses <ido@twiggle.com>
InDieTasten <indietasten@gmail.com>
irokas <akasidiari@inf.uth.gr>
Jean Bruenn <himself@jeanbruenn.info>
Jeremy Danyow <jedanyow@microsoft.com>
Jörg Breitbart <jerch@rockborn.de>
Justin Mecham <justin@mecham.me>
Lucian Buzzo <lucian.buzzo@gmail.com>
Maël Nison <nison.mael@gmail.com>
Martin Chloride <i@martincl2.me>
Martin Wang <jiahaow@ca.ibm.com>
Michael Irwin <mikesir87@gmail.com>
Mikko Karvonen <mikko.karvonen@arm.com>
Nicolas Ramz <nicolas.ramz@gmail.com>
Oleksandr Andriienko <oandriie@redhat.com>
Paris Kasidiaris <pariskasidiaris@gmail.com>
Paris Kasidiaris <paris@sourcelair.com>
runarberg <runar@greenqloud.com>
Saswat Das <saswatds@users.noreply.github.com>
Saul Costa <saul@codevolve.com>
Shuanglei Tao <tsl0922@gmail.com>
Steven Silvester <steven.silvester@ieee.org>
Thanasis Daglis <thanasis@sourcelair.com>
Tine Jozelj <tine.jozelj@outlook.com>
Tyler Jewell <tjewell@codenvy.com>
Vincent Woo <me@vincentwoo.com>
yutaka <shigure@refy.net>
YuviPanda <yuvipanda@gmail.com>
+32 -29
View File
@@ -1,6 +1,6 @@
# xterm.js
# [![xterm.js logo](logo.png)](https://xtermjs.org)
[![xterm.js build status](https://api.travis-ci.org/sourcelair/xterm.js.svg)](https://travis-ci.org/sourcelair/xterm.js) [![Gitter](https://badges.gitter.im/sourcelair/xterm.js.svg)](https://gitter.im/sourcelair/xterm.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![xterm.js build status](https://api.travis-ci.org/sourcelair/xterm.js.svg)](https://travis-ci.org/sourcelair/xterm.js) [![Coverage Status](https://coveralls.io/repos/github/sourcelair/xterm.js/badge.svg)](https://coveralls.io/github/sourcelair/xterm.js) [![Gitter](https://badges.gitter.im/sourcelair/xterm.js.svg)](https://gitter.im/sourcelair/xterm.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Xterm.js is a terminal front-end component written in JavaScript that works in the browser.
@@ -30,6 +30,14 @@ Xterm.js is used in several world-class applications to provide great terminal e
- [**Codenvy**](http://www.codenvy.com): Cloud workspaces for development teams.
- [**CoderPad**](https://coderpad.io): Online interviewing platform for programmers. Run code in many programming languages, with results displayed by `xterm.js`.
- [**WebSSH2**](https://github.com/billchurch/WebSSH2): A web based SSH2 client using `xterm.js`, socket.io, and ssh2.
- [**Spyder Terminal**](https://github.com/spyder-ide/spyder-terminal): A full fledged system terminal embedded on Spyder IDE.
- [**Cloud Commander**](https://cloudcmd.io "Cloud Commander"): Orthodox web file manager with console and editor.
- [**Codevolve**](https://www.codevolve.com "Codevolve"): Online platform for interactive coding and web development courses. Live container-backed terminal uses `xterm.js`.
- [**RStudio**](https://www.rstudio.com/products/RStudio "RStudio"): RStudio is an integrated development environment (IDE) for R.
- [**Terminal for Atom**](https://github.com/jsmecham/atom-terminal-tab): A simple terminal for the Atom text editor.
- [**Eclipse Orion**](https://orionhub.org): A modern, open source software development environment that runs in the cloud. Code, deploy and run in the cloud.
- [**Gravitational Teleport**](https://github.com/gravitational/teleport): Gravitational Teleport is a modern SSH server for remotely accessing clusters of Linux servers via SSH or HTTPS.
- [**Hexlet**](https://en.hexlet.io): Practical programming courses (JavaScript, PHP, Unix, databases, functional programming). A steady path from the first line of code to the first job.
Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it in our list.
@@ -48,14 +56,29 @@ Xterm.js works seamlessly in Electron apps and may even work on earlier versions
## Demo
To launch the demo simply run:
### Linux or macOS
Run the following commands:
```
npm install
npm start
$ npm install
$ npm start
```
Then open http://0.0.0.0:3000 in a web browser (use http://127.0.0.1:3000 if running under Windows).
Then open http://0.0.0.0:3000 in a web browser.
### Windows
First, ensure [node-gyp](https://github.com/nodejs/node-gyp) is installed and configured correctly, then run these commands.
Note: Do not use ConEmu, as it seems to break the demo for some reason.
```
> npm install
> npm start
```
Then open http://127.0.0.1:3000 in a web browser.
## Getting Started
@@ -71,13 +94,13 @@ To start using xterm.js on your browser, add the `xterm.js` and `xterm.css` to t
<div id="terminal"></div>
<script>
var term = new Terminal();
term.open(document.getElementById('#terminal'));
term.open(document.getElementById('terminal'));
term.write('Hello from \033[1;3;31mxterm.js\033[0m $ ')
</script>
</body>
</html>
```
Finally instantiate the `Terminal` object and then call the `open` function with the DOM object of the `div`.
Finally instantiate the `Terminal` object and then call the `open` function with the DOM object of the `div`.
## Addons
@@ -106,27 +129,7 @@ The existing releases are available at this GitHub repo's [Releases](https://git
Xterm.js is maintained by [SourceLair](https://www.sourcelair.com/) and a few external contributors, but we would love to receive contributions from everyone!
To contribute either code, documentation or issues to xterm.js please read the [Contributing document](CONTRIBUTING.md) before.
The development of xterm.js does not require any special tool. All you need is an editor that supports JavaScript and a browser (if you would like to run the demo you will need Node.js to get all features).
It is recommended though to use a development tool that uses xterm.js internally, to develop for xterm.js. [Eating our own dogfood](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) has been proved extremely beneficial for this project. Known tools that use xterm.js internally are:
#### [SourceLair](https://www.sourcelair.com)
Visit https://lair.io/sourcelair/xterm and follow the instructions. All development will happen in your browser.
#### [Visual Studio Code](http://code.visualstudio.com/)
[Download Visual Studio Code](http://code.visualstudio.com/Download), clone xterm.js and you are all set.
#### [Eclipse Che](http://www.eclipse.org/che)
You can start Eclipse Che with `docker run eclipse/che start`.
#### [Codenvy](http://www.codenvy.io)
You can create a trial account or install an enterprise version with `docker run codenvy/cli start`.
To contribute either code, documentation or issues to xterm.js please read the [Contributing document](CONTRIBUTING.md) beforehand. The development of xterm.js does not require any special tool. All you need is an editor that supports JavaScript/TypeScript and a browser. You will need Node.js installed locally to get all the features working in the demo.
## License Agreement
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xterm.js",
"version": "2.3.1",
"version": "2.8.0",
"ignore": ["demo", "test", ".gitignore"],
"main": [
"dist/xterm.js",
+1 -1
View File
@@ -69,7 +69,7 @@ app.ws('/terminals/:pid', function (ws, req) {
term.write(msg);
});
ws.on('close', function () {
process.kill(term.pid);
term.kill();
console.log('Closed terminal ' + term.pid);
// Clean things up
delete terminals[term.pid];
+11
View File
@@ -5,6 +5,7 @@
<link rel="stylesheet" href="/build/xterm.css" />
<link rel="stylesheet" href="/build/addons/fullscreen/fullscreen.css" />
<link rel="stylesheet" href="style.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
<script src="/build/xterm.js" ></script>
<script src="/build/addons/attach/attach.js" ></script>
@@ -19,6 +20,16 @@
<p>
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
</p>
<p>
<label>
cursorStyle
<select id="option-cursor-style">
<option value="block">block</option>
<option value="underline">underline</option>
<option value="bar">bar</option>
</select>
</label>
</p>
<p>
<label>scrollback <input type="number" id="option-scrollback" value="1000" /></label>
</p>
+4
View File
@@ -9,6 +9,7 @@ var term,
var terminalContainer = document.getElementById('terminal-container'),
optionElements = {
cursorBlink: document.querySelector('#option-cursor-blink'),
cursorStyle: document.querySelector('#option-cursor-style'),
scrollback: document.querySelector('#option-scrollback'),
tabstopwidth: document.querySelector('#option-tabstopwidth')
},
@@ -32,6 +33,9 @@ rowsElement.addEventListener('change', setTerminalSize);
optionElements.cursorBlink.addEventListener('change', function () {
term.setOption('cursorBlink', optionElements.cursorBlink.checked);
});
optionElements.cursorStyle.addEventListener('change', function () {
term.setOption('cursorStyle', optionElements.cursorStyle.value);
});
optionElements.scrollback.addEventListener('change', function () {
term.setOption('scrollback', parseInt(optionElements.scrollback.value, 10));
});
+7 -2
View File
@@ -32,6 +32,9 @@
var exports = {};
exports.proposeGeometry = function (term) {
if (!term.element.parentElement) {
return null;
}
var parentElementStyle = window.getComputedStyle(term.element.parentElement),
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17),
@@ -53,7 +56,7 @@
subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
characterWidth = subjectRow.getBoundingClientRect().width;
subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
characterHeight = parseInt(subjectRow.offsetHeight);
characterHeight = subjectRow.getBoundingClientRect().height;
subjectRow.innerHTML = contentBuffer;
rows = parseInt(availableHeight / characterHeight);
@@ -66,7 +69,9 @@
exports.fit = function (term) {
var geometry = exports.proposeGeometry(term);
term.resize(geometry.cols, geometry.rows);
if (geometry) {
term.resize(geometry.cols, geometry.rows);
}
};
Xterm.prototype.proposeGeometry = function () {
+48 -20
View File
@@ -41,6 +41,9 @@
font-family: courier-new, courier, monospace;
font-feature-settings: "liga" 0;
position: relative;
user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
}
.terminal.focus,
@@ -71,7 +74,22 @@
resize: none;
}
.terminal:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar) .terminal-cursor {
.terminal a {
color: inherit;
text-decoration: none;
}
.terminal a:hover {
cursor: pointer;
text-decoration: underline;
}
.terminal a.xterm-invalid-link:hover {
cursor: text;
text-decoration: none;
}
.terminal.focus:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar) .terminal-cursor {
background-color: #fff;
color: #000;
}
@@ -82,19 +100,9 @@
background-color: transparent;
}
.terminal:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar).focus.xterm-cursor-blink .terminal-cursor {
animation: xterm-cursor-blink 1.2s infinite step-end;
}
@keyframes xterm-cursor-blink {
0% {
background-color: #fff;
color: #000;
}
50% {
background-color: transparent;
color: #FFF;
}
.terminal:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar).focus.xterm-cursor-blink-on .terminal-cursor {
background-color: transparent;
color: inherit;
}
.terminal.xterm-cursor-style-bar .terminal-cursor,
@@ -120,13 +128,13 @@
right: 0;
height: 1px;
}
.terminal.xterm-cursor-style-bar.focus.xterm-cursor-blink.xterm-cursor-blink-on .terminal-cursor::before,
.terminal.xterm-cursor-style-underline.focus.xterm-cursor-blink.xterm-cursor-blink-on .terminal-cursor::before {
background-color: transparent;
}
.terminal.xterm-cursor-style-bar.focus.xterm-cursor-blink .terminal-cursor::before,
.terminal.xterm-cursor-style-underline.focus.xterm-cursor-blink .terminal-cursor::before {
animation: xterm-cursor-non-bar-blink 1.2s infinite step-end;
}
@keyframes xterm-cursor-non-bar-blink {
0% { background-color: #fff; }
50% { background-color: transparent; }
background-color: #fff;
}
.terminal .composition-view {
@@ -148,7 +156,8 @@
overflow-y: scroll;
}
.terminal .xterm-wide-char {
.terminal .xterm-wide-char,
.terminal .xterm-normal-char {
display: inline-block;
}
@@ -174,6 +183,25 @@
left: -9999em;
}
.terminal.enable-mouse-events {
/* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
cursor: default;
}
.terminal .xterm-selection {
position: absolute;
top: 0;
left: 0;
z-index: 1;
opacity: 0.3;
pointer-events: none;
}
.terminal .xterm-selection div {
position: absolute;
background-color: #fff;
}
/*
* Determine default colors for xterm.js
*/
+1318 -233
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
File diff suppressed because one or more lines are too long
+44 -20
View File
@@ -1,37 +1,40 @@
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const coveralls = require('gulp-coveralls');
const fs = require('fs-extra');
const gulp = require('gulp');
const istanbul = require('gulp-istanbul');
const merge = require('merge-stream');
const mocha = require('gulp-mocha');
const sorcery = require('sorcery');
const source = require('vinyl-source-stream');
const sourcemaps = require('gulp-sourcemaps');
const ts = require('gulp-typescript');
const tsify = require('tsify');
let buildDir = process.env.BUILD_DIR || 'build';
let tsProject = ts.createProject('tsconfig.json');
let srcDir = tsProject.config.compilerOptions.rootDir;
let outDir = tsProject.config.compilerOptions.outDir;
/**
* Compile TypeScript sources to JavaScript files and create a source map file for each TypeScript
* file compiled.
*/
gulp.task('tsc', function () {
// Remove the lib/ directory to prevent confusion if files were deleted in src/
fs.emptyDirSync('lib');
// Remove the ${outDir}/ directory to prevent confusion if files were deleted in ${srcDir}/
fs.emptyDirSync(`${outDir}`);
// Build all TypeScript files (including tests) to lib/, based on the configuration defined in
// Build all TypeScript files (including tests) to ${outDir}/, based on the configuration defined in
// `tsconfig.json`.
let tsProject = ts.createProject('tsconfig.json');
let tsResult = tsProject.src().pipe(sourcemaps.init()).pipe(tsProject());
let tsc = tsResult.js.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: ''})).pipe(gulp.dest('lib'));
let tsc = tsResult.js.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: ''})).pipe(gulp.dest(outDir));
// Copy all addons from src/ to lib/
let copyAddons = gulp.src('src/addons/**/*').pipe(gulp.dest('lib/addons'));
// Copy all addons from ${srcDir}/ to ${outDir}/
let copyAddons = gulp.src(`${srcDir}/addons/**/*`).pipe(gulp.dest(`${outDir}/addons`));
// Copy stylesheets from src/ to lib/
let copyStylesheets = gulp.src('src/**/*.css').pipe(gulp.dest('lib'));
// Copy stylesheets from ${srcDir}/ to ${outDir}/
let copyStylesheets = gulp.src(`${srcDir}/**/*.css`).pipe(gulp.dest(outDir));
return merge(tsc, copyAddons, copyStylesheets);
});
@@ -47,13 +50,12 @@ gulp.task('browserify', ['tsc'], function() {
let browserifyOptions = {
basedir: buildDir,
debug: true,
entries: ['../lib/xterm.js'],
entries: [`../${outDir}/xterm.js`],
standalone: 'Terminal',
cache: {},
packageCache: {}
};
let bundleStream = browserify(browserifyOptions)
.plugin(tsify)
.bundle()
.pipe(source('xterm.js'))
.pipe(buffer())
@@ -61,27 +63,49 @@ gulp.task('browserify', ['tsc'], function() {
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(buildDir));
// Copy all add-ons from lib/ to buildDir
let copyAddons = gulp.src('lib/addons/**/*').pipe(gulp.dest(`${buildDir}/addons`));
// Copy all add-ons from ${outDir}/ to buildDir
let copyAddons = gulp.src(`${outDir}/addons/**/*`).pipe(gulp.dest(`${buildDir}/addons`));
// Copy stylesheets from src/ to lib/
let copyStylesheets = gulp.src('lib/**/*.css').pipe(gulp.dest(buildDir));
// Copy stylesheets from ${outDir}/ to ${buildDir}/
let copyStylesheets = gulp.src(`${outDir}/**/*.css`).pipe(gulp.dest(buildDir));
return merge(bundleStream, copyAddons, copyStylesheets);
});
gulp.task('instrument-test', function () {
return gulp.src([`${outDir}/**/*.js`])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('mocha', ['instrument-test'], function () {
return gulp.src([`${outDir}/*test.js`, `${outDir}/**/*test.js`], {read: false})
.pipe(mocha())
.once('error', () => process.exit(1))
.pipe(istanbul.writeReports());
});
/**
* Use `sorcery` to resolve the source map chain and point back to the TypeScript files.
* (Without this task the source maps produced for the JavaScript bundle points into the
* compiled JavaScript files in lib/).
* compiled JavaScript files in ${outDir}/).
*/
gulp.task('sorcery', ['browserify'], function () {
var chain = sorcery.loadSync(`${buildDir}/xterm.js`);
var map = chain.apply();
chain.apply();
chain.writeSync();
});
gulp.task('build', ['sorcery']);
/**
* Submit coverage results to coveralls.io
*/
gulp.task('coveralls', function () {
gulp.src('coverage/**/lcov.info')
.pipe(coveralls());
});
gulp.task('build', ['sorcery']);
gulp.task('test', ['mocha']);
gulp.task('default', ['build']);
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

+11 -7
View File
@@ -1,7 +1,7 @@
{
"name": "xterm",
"description": "Full xterm terminal, in your browser",
"version": "2.3.1",
"version": "2.8.0",
"ignore": [
"demo",
"test",
@@ -36,6 +36,7 @@
],
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/jsdom": "^2.0.30",
"@types/mocha": "^2.2.33",
"@types/node": "^6.0.41",
"browserify": "^13.1.0",
@@ -47,29 +48,32 @@
"glob": "^7.0.5",
"gulp": "^3.9.1",
"gulp-cli": "^1.2.2",
"gulp-coveralls": "^0.1.4",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
"gulp-sourcemaps": "1.9.1",
"gulp-typescript": "^3.1.3",
"jsdoc": "3.4.3",
"jsdom": "^9.11.0",
"merge-stream": "^1.0.1",
"mocha": "2.5.3",
"node-pty": "^0.4.1",
"nodemon": "1.10.2",
"sleep": "^3.0.1",
"sorcery": "^0.10.0",
"tsify": "^3.0.0",
"tslint": "^4.0.2",
"typescript": "^2.0.3",
"typescript": "~2.2.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
"prestart": "npm run build",
"start": "node demo/app",
"dev": "nodemon -e js,ts --watch src --watch demo --exec npm start",
"dev": "nodemon -e js,ts,css --watch src --watch demo --exec npm start",
"lint": "tslint src/*.ts src/**/*.ts",
"test": "mocha --recursive ./lib",
"test": "gulp test",
"build:docs": "jsdoc -c jsdoc.json",
"build": "gulp build",
"prepublish": "npm run build"
"prepublish": "npm run build",
"coveralls": "gulp coveralls"
}
}
+4
View File
@@ -1,3 +1,7 @@
/**
* @license MIT
*/
/**
* C0 control codes
* See = https://en.wikipedia.org/wiki/C0_and_C1_control_codes
+1 -4
View File
@@ -53,14 +53,11 @@ export class EventEmitter {
return this.on(type, on);
}
public emit(type): void {
public emit(type: string, ...args: any[]): void {
if (!this._events[type]) {
return;
}
let args = Array.prototype.slice.call(arguments, 1);
let obj = this._events[type];
for (let i = 0; i < obj.length; i++) {
obj[i].apply(this, args);
}
+17 -6
View File
@@ -57,7 +57,7 @@ export class InputHandler implements IInputHandler {
this._terminal.y++;
if (this._terminal.y > this._terminal.scrollBottom) {
this._terminal.y--;
this._terminal.scroll();
this._terminal.scroll(true);
}
} else {
if (ch_width === 2) // FIXME: check for xterm behavior
@@ -75,8 +75,9 @@ export class InputHandler implements IInputHandler {
const removed = this._terminal.lines.get(this._terminal.y + this._terminal.ybase).pop();
if (removed[2] === 0
&& this._terminal.lines.get(row)[this._terminal.cols - 2]
&& this._terminal.lines.get(row)[this._terminal.cols - 2][2] === 2)
&& this._terminal.lines.get(row)[this._terminal.cols - 2][2] === 2) {
this._terminal.lines.get(row)[this._terminal.cols - 2] = [this._terminal.curAttr, ' ', 1];
}
// insert empty cell at cursor
this._terminal.lines.get(row).splice(this._terminal.x, 0, [this._terminal.curAttr, ' ', 1]);
@@ -385,7 +386,13 @@ export class InputHandler implements IInputHandler {
while (j--) this._terminal.eraseLine(j);
break;
case 3:
; // no saved lines
// Clear scrollback (everything not in viewport)
const scrollBackSize = this._terminal.lines.length - this._terminal.rows;
if (scrollBackSize > 0) {
this._terminal.lines.trimStart(scrollBackSize);
this._terminal.ybase = Math.max(this._terminal.ybase - scrollBackSize, 0);
this._terminal.ydisp = Math.max(this._terminal.ydisp - scrollBackSize, 0);
}
break;
}
}
@@ -897,7 +904,8 @@ export class InputHandler implements IInputHandler {
this._terminal.vt200Mouse = params[0] === 1000;
this._terminal.normalMouse = params[0] > 1000;
this._terminal.mouseEvents = true;
this._terminal.element.style.cursor = 'default';
this._terminal.element.classList.add('enable-mouse-events');
this._terminal.selectionManager.disable();
this._terminal.log('Binding to mouse events.');
break;
case 1004: // send focusin/focusout events
@@ -1090,7 +1098,8 @@ export class InputHandler implements IInputHandler {
this._terminal.vt200Mouse = false;
this._terminal.normalMouse = false;
this._terminal.mouseEvents = false;
this._terminal.element.style.cursor = '';
this._terminal.element.classList.remove('enable-mouse-events');
this._terminal.selectionManager.enable();
break;
case 1004: // send focusin/focusout events
this._terminal.sendFocus = false;
@@ -1121,6 +1130,8 @@ export class InputHandler implements IInputHandler {
this._terminal.scrollBottom = this._terminal.normal.scrollBottom;
this._terminal.tabs = this._terminal.normal.tabs;
this._terminal.normal = null;
// Ensure the selection manager has the correct buffer
this._terminal.selectionManager.setBuffer(this._terminal.lines);
// if (params === 1049) {
// this.x = this.savedX;
// this.y = this.savedY;
@@ -1394,7 +1405,7 @@ export class InputHandler implements IInputHandler {
this._terminal.cursorHidden = false;
this._terminal.insertMode = false;
this._terminal.originMode = false;
this._terminal.wraparoundMode = false; // autowrap
this._terminal.wraparoundMode = true; // defaults: xterm - true, vt100 - false
this._terminal.applicationKeypad = false; // ?
this._terminal.viewport.syncScrollArea();
this._terminal.applicationCursor = false;
+41
View File
@@ -2,6 +2,9 @@
* @license MIT
*/
import { LinkMatcherOptions } from './Interfaces';
import { LinkMatcherHandler, LinkMatcherValidationCallback } from './Types';
export interface IBrowser {
isNode: boolean;
userAgent: string;
@@ -17,6 +20,8 @@ export interface IBrowser {
export interface ITerminal {
element: HTMLElement;
rowContainer: HTMLElement;
selectionContainer: HTMLElement;
charMeasure: ICharMeasure;
textarea: HTMLTextAreaElement;
ybase: number;
ydisp: number;
@@ -44,6 +49,23 @@ export interface ITerminal {
emit(event: string, data: any);
}
export interface ISelectionManager {
selectionText: string;
}
export interface ICharMeasure {
width: number;
height: number;
measure(): void;
}
export interface ILinkifier {
linkifyRow(rowIndex: number): void;
attachHypertextLinkHandler(handler: LinkMatcherHandler): void;
registerLinkMatcher(regex: RegExp, handler: LinkMatcherHandler, options?: LinkMatcherOptions): number;
deregisterLinkMatcher(matcherId: number): boolean;
}
interface ICircularList<T> {
length: number;
maxLength: number;
@@ -58,6 +80,25 @@ interface ICircularList<T> {
shiftElements(start: number, count: number, offset: number): void;
}
export interface LinkMatcherOptions {
/**
* The index of the link from the regex.match(text) call. This defaults to 0
* (for regular expressions without capture groups).
*/
matchIndex?: number;
/**
* A callback that validates an individual link, returning true if valid and
* false if invalid.
*/
validationCallback?: LinkMatcherValidationCallback;
/**
* The priority of the link matcher, this defines the order in which the link
* matcher is evaluated relative to others, from highest to lowest. The
* default value is 0.
*/
priority?: number;
}
/**
* Handles actions generated by the parser.
*/
+193
View File
@@ -0,0 +1,193 @@
/**
* @license MIT
*/
import jsdom = require('jsdom');
import { assert } from 'chai';
import { ITerminal, ILinkifier } from './Interfaces';
import { Linkifier } from './Linkifier';
import { LinkMatcher } from './Types';
class TestLinkifier extends Linkifier {
constructor() {
Linkifier.TIME_BEFORE_LINKIFY = 0;
super();
}
public get linkMatchers(): LinkMatcher[] { return this._linkMatchers; }
}
describe('Linkifier', () => {
let window: Window;
let document: Document;
let container: HTMLElement;
let rows: HTMLElement[];
let linkifier: TestLinkifier;
beforeEach(done => {
jsdom.env('', (err, w) => {
window = w;
document = window.document;
linkifier = new TestLinkifier();
done();
});
});
function addRow(html: string) {
const element = document.createElement('div');
element.innerHTML = html;
container.appendChild(element);
rows.push(element);
}
describe('before attachToDom', () => {
it('should allow link matcher registration', done => {
assert.doesNotThrow(() => {
const linkMatcherId = linkifier.registerLinkMatcher(/foo/, () => {});
assert.isTrue(linkifier.deregisterLinkMatcher(linkMatcherId));
done();
});
});
});
describe('after attachToDom', () => {
beforeEach(() => {
rows = [];
linkifier.attachToDom(document, rows);
container = document.createElement('div');
document.body.appendChild(container);
});
function clickElement(element: Node) {
const event = document.createEvent('MouseEvent');
event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
element.dispatchEvent(event);
}
function assertLinkifiesEntireRow(uri: string, done: MochaDone) {
addRow(uri);
linkifier.linkifyRow(0);
setTimeout(() => {
assert.equal((<HTMLElement>rows[0].firstChild).tagName, 'A');
assert.equal((<HTMLElement>rows[0].firstChild).textContent, uri);
done();
}, 0);
}
describe('http links', () => {
function assertLinkifiesEntireRow(uri: string, done: MochaDone) {
addRow(uri);
linkifier.linkifyRow(0);
setTimeout(() => {
assert.equal((<HTMLElement>rows[0].firstChild).tagName, 'A');
assert.equal((<HTMLElement>rows[0].firstChild).textContent, uri);
done();
}, 0);
}
it('should allow ~ character in URI path', done => assertLinkifiesEntireRow('http://foo.com/a~b#c~d?e~f', done));
});
describe('link matcher', () => {
function assertLinkifiesRow(rowText: string, linkMatcherRegex: RegExp, expectedHtml: string, done: MochaDone) {
addRow(rowText);
linkifier.registerLinkMatcher(linkMatcherRegex, () => {});
linkifier.linkifyRow(0);
// Allow linkify to happen
setTimeout(() => {
assert.equal(rows[0].innerHTML, expectedHtml);
done();
}, 0);
}
it('should match a single link', done => {
assertLinkifiesRow('foo', /foo/, '<a>foo</a>', done);
});
it('should match a single link at the start of a text node', done => {
assertLinkifiesRow('foo bar', /foo/, '<a>foo</a> bar', done);
});
it('should match a single link in the middle of a text node', done => {
assertLinkifiesRow('foo bar baz', /bar/, 'foo <a>bar</a> baz', done);
});
it('should match a single link at the end of a text node', done => {
assertLinkifiesRow('foo bar', /bar/, 'foo <a>bar</a>', done);
});
it('should match a link after a link at the start of a text node', done => {
assertLinkifiesRow('foo bar', /foo|bar/, '<a>foo</a> <a>bar</a>', done);
});
it('should match a link after a link in the middle of a text node', done => {
assertLinkifiesRow('foo bar baz', /bar|baz/, 'foo <a>bar</a> <a>baz</a>', done);
});
it('should match a link immediately after a link at the end of a text node', done => {
assertLinkifiesRow('<span>foo bar</span>baz', /bar|baz/, '<span>foo <a>bar</a></span><a>baz</a>', done);
});
it('should not duplicate text after a unicode character (wrapped in a span)', done => {
// This is a regression test for an issue that came about when using
// an oh-my-zsh theme that added the large blue diamond unicode
// character (U+1F537) which caused the path to be duplicated. See #642.
assertLinkifiesRow('echo \'<span class="xterm-normal-char">🔷</span>foo\'', /foo/, 'echo \'<span class="xterm-normal-char">🔷</span><a>foo</a>\'', done);
});
});
describe('validationCallback', () => {
it('should enable link if true', done => {
addRow('test');
linkifier.registerLinkMatcher(/test/, () => done(), {
validationCallback: (url, element, cb) => {
cb(true);
assert.equal((<HTMLElement>rows[0].firstChild).tagName, 'A');
setTimeout(() => clickElement(rows[0].firstChild), 0);
}
});
linkifier.linkifyRow(0);
});
it('should disable link if false', done => {
addRow('test');
linkifier.registerLinkMatcher(/test/, () => assert.fail(), {
validationCallback: (url, element, cb) => {
cb(false);
assert.equal((<HTMLElement>rows[0].firstChild).tagName, 'A');
setTimeout(() => clickElement(rows[0].firstChild), 0);
}
});
linkifier.linkifyRow(0);
// Allow time for the click to be performed
setTimeout(() => done(), 10);
});
it('should trigger for multiple link matches on one row', done => {
addRow('test test');
let count = 0;
linkifier.registerLinkMatcher(/test/, () => assert.fail(), {
validationCallback: (url, element, cb) => {
count += 1;
if (count === 2) {
done();
}
cb(false);
}
});
linkifier.linkifyRow(0);
});
});
describe('priority', () => {
it('should order the list from highest priority to lowest #1', () => {
const aId = linkifier.registerLinkMatcher(/a/, () => {}, { priority: 1 });
const bId = linkifier.registerLinkMatcher(/b/, () => {}, { priority: -1 });
assert.deepEqual(linkifier.linkMatchers.map(lm => lm.id), [aId, 0, bId]);
});
it('should order the list from highest priority to lowest #2', () => {
const aId = linkifier.registerLinkMatcher(/a/, () => {}, { priority: -1 });
const bId = linkifier.registerLinkMatcher(/b/, () => {}, { priority: 1 });
assert.deepEqual(linkifier.linkMatchers.map(lm => lm.id), [bId, 0, aId]);
});
it('should order items of equal priority in the order they are added', () => {
const aId = linkifier.registerLinkMatcher(/a/, () => {}, { priority: 0 });
const bId = linkifier.registerLinkMatcher(/b/, () => {}, { priority: 0 });
assert.deepEqual(linkifier.linkMatchers.map(lm => lm.id), [0, aId, bId]);
});
});
});
});
+363
View File
@@ -0,0 +1,363 @@
/**
* @license MIT
*/
import { LinkMatcherOptions } from './Interfaces';
import { LinkMatcher, LinkMatcherHandler, LinkMatcherValidationCallback } from './Types';
const INVALID_LINK_CLASS = 'xterm-invalid-link';
const protocolClause = '(https?:\\/\\/)';
const domainCharacterSet = '[\\da-z\\.-]+';
const negatedDomainCharacterSet = '[^\\da-z\\.-]+';
const domainBodyClause = '(' + domainCharacterSet + ')';
const tldClause = '([a-z\\.]{2,6})';
const ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
const localHostClause = '(localhost)';
const portClause = '(:\\d{1,5})';
const hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
const pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
const queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
const queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
const hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';
const negatedPathCharacterSet = '[^\\/\\w\\.\\-%]+';
const bodyClause = hostClause + pathClause + queryStringClause + hashFragmentClause;
const start = '(?:^|' + negatedDomainCharacterSet + ')(';
const end = ')($|' + negatedPathCharacterSet + ')';
const strictUrlRegex = new RegExp(start + protocolClause + bodyClause + end);
/**
* The ID of the built in http(s) link matcher.
*/
const HYPERTEXT_LINK_MATCHER_ID = 0;
/**
* The Linkifier applies links to rows shortly after they have been refreshed.
*/
export class Linkifier {
/**
* The time to wait after a row is changed before it is linkified. This prevents
* the costly operation of searching every row multiple times, potentially a
* huge amount of times.
*/
protected static TIME_BEFORE_LINKIFY = 200;
protected _linkMatchers: LinkMatcher[];
private _document: Document;
private _rows: HTMLElement[];
private _rowTimeoutIds: number[];
private _nextLinkMatcherId = HYPERTEXT_LINK_MATCHER_ID;
constructor() {
this._rowTimeoutIds = [];
this._linkMatchers = [];
this.registerLinkMatcher(strictUrlRegex, null, { matchIndex: 1 });
}
/**
* Attaches the linkifier to the DOM, enabling linkification.
* @param document The document object.
* @param rows The array of rows to apply links to.
*/
public attachToDom(document: Document, rows: HTMLElement[]) {
this._document = document;
this._rows = rows;
}
/**
* Queues a row for linkification.
* @param {number} rowIndex The index of the row to linkify.
*/
public linkifyRow(rowIndex: number): void {
// Don't attempt linkify if not yet attached to DOM
if (!this._document) {
return;
}
const timeoutId = this._rowTimeoutIds[rowIndex];
if (timeoutId) {
clearTimeout(timeoutId);
}
this._rowTimeoutIds[rowIndex] = setTimeout(this._linkifyRow.bind(this, rowIndex), Linkifier.TIME_BEFORE_LINKIFY);
}
/**
* Attaches a handler for hypertext links, overriding default <a> behavior
* for standard http(s) links.
* @param {LinkHandler} handler The handler to use, this can be cleared with
* null.
*/
public setHypertextLinkHandler(handler: LinkMatcherHandler): void {
this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].handler = handler;
}
/**
* Attaches a validation callback for hypertext links.
* @param {LinkMatcherValidationCallback} callback The callback to use, this
* can be cleared with null.
*/
public setHypertextValidationCallback(callback: LinkMatcherValidationCallback): void {
this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].validationCallback = callback;
}
/**
* Registers a link matcher, allowing custom link patterns to be matched and
* handled.
* @param {RegExp} regex The regular expression to search for, specifically
* this searches the textContent of the rows. You will want to use \s to match
* a space ' ' character for example.
* @param {LinkHandler} handler The callback when the link is called.
* @param {LinkMatcherOptions} [options] Options for the link matcher.
* @return {number} The ID of the new matcher, this can be used to deregister.
*/
public registerLinkMatcher(regex: RegExp, handler: LinkMatcherHandler, options: LinkMatcherOptions = {}): number {
if (this._nextLinkMatcherId !== HYPERTEXT_LINK_MATCHER_ID && !handler) {
throw new Error('handler must be defined');
}
const matcher: LinkMatcher = {
id: this._nextLinkMatcherId++,
regex,
handler,
matchIndex: options.matchIndex,
validationCallback: options.validationCallback,
priority: options.priority || 0
};
this._addLinkMatcherToList(matcher);
return matcher.id;
}
/**
* Inserts a link matcher to the list in the correct position based on the
* priority of each link matcher. New link matchers of equal priority are
* considered after older link matchers.
* @param matcher The link matcher to be added.
*/
private _addLinkMatcherToList(matcher: LinkMatcher): void {
if (this._linkMatchers.length === 0) {
this._linkMatchers.push(matcher);
return;
}
for (let i = this._linkMatchers.length - 1; i >= 0; i--) {
if (matcher.priority <= this._linkMatchers[i].priority) {
this._linkMatchers.splice(i + 1, 0, matcher);
return;
}
}
this._linkMatchers.splice(0, 0, matcher);
}
/**
* Deregisters a link matcher if it has been registered.
* @param {number} matcherId The link matcher's ID (returned after register)
* @return {boolean} Whether a link matcher was found and deregistered.
*/
public deregisterLinkMatcher(matcherId: number): boolean {
// ID 0 is the hypertext link matcher which cannot be deregistered
for (let i = 1; i < this._linkMatchers.length; i++) {
if (this._linkMatchers[i].id === matcherId) {
this._linkMatchers.splice(i, 1);
return true;
}
}
return false;
}
/**
* Linkifies a row.
* @param {number} rowIndex The index of the row to linkify.
*/
private _linkifyRow(rowIndex: number): void {
const row = this._rows[rowIndex];
if (!row) {
return;
}
const text = row.textContent;
for (let i = 0; i < this._linkMatchers.length; i++) {
const matcher = this._linkMatchers[i];
const linkElements = this._doLinkifyRow(row, matcher);
if (linkElements.length > 0) {
// Fire validation callback
if (matcher.validationCallback) {
for (let j = 0; j < linkElements.length; j++) {
const element = linkElements[j];
matcher.validationCallback(element.textContent, element, isValid => {
if (!isValid) {
element.classList.add(INVALID_LINK_CLASS);
}
});
}
}
// Only allow a single LinkMatcher to trigger on any given row.
return;
}
}
}
/**
* Linkifies a row given a specific handler.
* @param {HTMLElement} row The row to linkify.
* @param {LinkMatcher} matcher The link matcher for this line.
* @return The link element(s) that were added.
*/
private _doLinkifyRow(row: HTMLElement, matcher: LinkMatcher): HTMLElement[] {
// Iterate over nodes as we want to consider text nodes
let result = [];
const isHttpLinkMatcher = matcher.id === HYPERTEXT_LINK_MATCHER_ID;
const nodes = row.childNodes;
// Find the first match
let match = row.textContent.match(matcher.regex);
if (!match || match.length === 0) {
return result;
}
let uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
// Set the next searches start index
let rowStartIndex = match.index + uri.length;
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
const searchIndex = node.textContent.indexOf(uri);
if (searchIndex >= 0) {
const linkElement = this._createAnchorElement(uri, matcher.handler, isHttpLinkMatcher);
if (node.textContent.length === uri.length) {
// Matches entire string
if (node.nodeType === 3 /*Node.TEXT_NODE*/) {
this._replaceNode(node, linkElement);
} else {
const element = (<HTMLElement>node);
if (element.nodeName === 'A') {
// This row has already been linkified
return result;
}
element.innerHTML = '';
element.appendChild(linkElement);
}
} else if (node.childNodes.length > 1) {
// Matches part of string in an element with multiple child nodes
for (let j = 0; j < node.childNodes.length; j++) {
const childNode = node.childNodes[j];
const childSearchIndex = childNode.textContent.indexOf(uri);
if (childSearchIndex !== -1) {
// Match found in currentNode
this._replaceNodeSubstringWithNode(childNode, linkElement, uri, childSearchIndex);
// Don't need to count nodesAdded by replacing the node as this
// is a child node, not a top-level node.
break;
}
}
} else {
// Matches part of string in a single text node
const nodesAdded = this._replaceNodeSubstringWithNode(node, linkElement, uri, searchIndex);
// No need to consider the new nodes
i += nodesAdded;
}
result.push(linkElement);
// Find the next match
match = row.textContent.substring(rowStartIndex).match(matcher.regex);
if (!match || match.length === 0) {
return result;
}
uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
rowStartIndex += match.index + uri.length;
}
}
return result;
}
/**
* Creates a link anchor element.
* @param {string} uri The uri of the link.
* @return {HTMLAnchorElement} The link.
*/
private _createAnchorElement(uri: string, handler: LinkMatcherHandler, isHypertextLinkHandler: boolean): HTMLAnchorElement {
const element = this._document.createElement('a');
element.textContent = uri;
element.draggable = false;
if (isHypertextLinkHandler) {
element.href = uri;
// Force link on another tab so work is not lost
element.target = '_blank';
element.addEventListener('click', (event: MouseEvent) => {
if (handler) {
return handler(event, uri);
}
});
} else {
element.addEventListener('click', (event: MouseEvent) => {
// Don't execute the handler if the link is flagged as invalid
if (element.classList.contains(INVALID_LINK_CLASS)) {
return;
}
return handler(event, uri);
});
}
return element;
}
/**
* Replace a node with 1 or more other nodes.
* @param {Node} oldNode The node to replace.
* @param {Node[]} newNodes The new nodes to insert in order.
*/
private _replaceNode(oldNode: Node, ...newNodes: Node[]): void {
const parent = oldNode.parentNode;
for (let i = 0; i < newNodes.length; i++) {
parent.insertBefore(newNodes[i], oldNode);
}
parent.removeChild(oldNode);
}
/**
* Replace a substring within a node with a new node.
* @param {Node} targetNode The target node; either a text node or a <span>
* containing a single text node.
* @param {Node} newNode The new node to insert.
* @param {string} substring The substring to replace.
* @param {number} substringIndex The index of the substring within the string.
* @return The number of nodes to skip when searching for the next uri.
*/
private _replaceNodeSubstringWithNode(targetNode: Node, newNode: Node, substring: string, substringIndex: number): number {
// If the targetNode is a non-text node with a single child, make the child
// the new targetNode.
if (targetNode.childNodes.length === 1) {
targetNode = targetNode.childNodes[0];
}
// The targetNode will be either a text node or a <span>. The text node
// (targetNode or its only-child) needs to be replaced with newNode plus new
// text nodes potentially on either side.
if (targetNode.nodeType !== 3/*Node.TEXT_NODE*/) {
throw new Error('targetNode must be a text node or only contain a single text node');
}
const fullText = targetNode.textContent;
if (substringIndex === 0) {
// Replace with <newNode><textnode>
const rightText = fullText.substring(substring.length);
const rightTextNode = this._document.createTextNode(rightText);
this._replaceNode(targetNode, newNode, rightTextNode);
return 0;
}
if (substringIndex === targetNode.textContent.length - substring.length) {
// Replace with <textnode><newNode>
const leftText = fullText.substring(0, substringIndex);
const leftTextNode = this._document.createTextNode(leftText);
this._replaceNode(targetNode, leftTextNode, newNode);
return 0;
}
// Replace with <textnode><newNode><textnode>
const leftText = fullText.substring(0, substringIndex);
const leftTextNode = this._document.createTextNode(leftText);
const rightText = fullText.substring(substringIndex + substring.length);
const rightTextNode = this._document.createTextNode(rightText);
this._replaceNode(targetNode, leftTextNode, newNode, rightTextNode);
return 1;
}
}
+8 -6
View File
@@ -181,7 +181,7 @@ export class Parser {
*
* @param data The data to parse.
*/
public parse(data: string) {
public parse(data: string): ParserState {
let l = data.length, j, cs, ch, code, low;
this._position = 0;
@@ -471,6 +471,8 @@ export class Parser {
case ParserState.DCS:
if (ch === C0.ESC || ch === C0.BEL) {
if (ch === C0.ESC) this._position++;
let pt;
let valid: boolean;
switch (this._terminal.prefix) {
// User-Defined Keys (DECUDK).
@@ -480,8 +482,8 @@ export class Parser {
// Request Status String (DECRQSS).
// test: echo -e '\eP$q"p\e\\'
case '$q':
let pt = this._terminal.currentParam
, valid = false;
pt = this._terminal.currentParam;
valid = false;
switch (pt) {
// DECSCA
@@ -526,9 +528,8 @@ export class Parser {
// This can cause a small glitch in vim.
// test: echo -ne '\eP+q6b64\e\\'
case '+q':
// TODO: Don't declare pt twice
/*let*/ pt = this._terminal.currentParam
, valid = false;
pt = this._terminal.currentParam;
valid = false;
this._terminal.send(C0.ESC + 'P' + +valid + '+r' + pt + C0.ESC + '\\');
break;
@@ -563,6 +564,7 @@ export class Parser {
break;
}
}
return this._state;
}
/**
+179 -85
View File
@@ -3,6 +3,7 @@
*/
import { ITerminal } from './Interfaces';
import { DomElementObjectPool } from './utils/DomElementObjectPool';
/**
* The maximum number of refresh frames to skip when the write buffer is non-
@@ -30,12 +31,15 @@ export class Renderer {
private _refreshFramesSkipped = 0;
private _refreshAnimationFrame = null;
private _spanElementObjectPool = new DomElementObjectPool('span');
constructor(private _terminal: ITerminal) {
// Figure out whether boldness affects
// the character width of monospace fonts.
if (brokenBold === null) {
brokenBold = checkBoldBroken((<any>this._terminal).document);
brokenBold = checkBoldBroken((<any>this._terminal).element);
}
this._spanElementObjectPool = new DomElementObjectPool('span');
// TODO: Pull more DOM interactions into Renderer.constructor, element for
// example should be owned by Renderer (and also exposed by Terminal due to
@@ -117,9 +121,8 @@ export class Renderer {
* @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
*/
private _refresh(start: number, end: number): void {
let x, y, i, line, out, ch, ch_width, width, data, attr, bg, fg, flags, row, parent, focused = document.activeElement;
// If this is a big refresh, remove the terminal rows from the DOM for faster calculations
let parent;
if (end - start >= this._terminal.rows / 2) {
parent = this._terminal.element.parentNode;
if (parent) {
@@ -127,8 +130,8 @@ export class Renderer {
}
}
width = this._terminal.cols;
y = start;
let width = this._terminal.cols;
let y = start;
if (end >= this._terminal.rows) {
this._terminal.log('`end` is too large. Most likely a bad CSR.');
@@ -136,80 +139,105 @@ export class Renderer {
}
for (; y <= end; y++) {
row = y + this._terminal.ydisp;
let row = y + this._terminal.ydisp;
line = this._terminal.lines.get(row);
if (!line || !this._terminal.children[y]) {
// Continue if the line is not available, this means a resize is currently in progress
continue;
}
out = '';
let line = this._terminal.lines.get(row);
if (this._terminal.y === y - (this._terminal.ybase - this._terminal.ydisp)
&& this._terminal.cursorState
&& !this._terminal.cursorHidden) {
let x;
if (this._terminal.y === y - (this._terminal.ybase - this._terminal.ydisp) &&
this._terminal.cursorState &&
!this._terminal.cursorHidden) {
x = this._terminal.x;
} else {
x = -1;
}
attr = this._terminal.defAttr;
i = 0;
let attr = this._terminal.defAttr;
for (; i < width; i++) {
if (!line[i]) {
// Continue if the character is not available, this means a resize is currently in progress
const documentFragment = document.createDocumentFragment();
let innerHTML = '';
let currentElement;
// Return the row's spans to the pool
while (this._terminal.children[y].children.length) {
const child = this._terminal.children[y].children[0];
this._terminal.children[y].removeChild(child);
this._spanElementObjectPool.release(<HTMLElement>child);
}
for (let i = 0; i < width; i++) {
// TODO: Could data be a more specific type?
let data: any = line[i][0];
const ch = line[i][1];
const ch_width: any = line[i][2];
if (!ch_width) {
continue;
}
data = line[i][0];
ch = line[i][1];
ch_width = line[i][2];
if (!ch_width)
continue;
if (i === x) data = -1;
if (i === x) {
data = -1;
}
if (data !== attr) {
if (attr !== this._terminal.defAttr) {
out += '</span>';
if (innerHTML) {
currentElement.innerHTML = innerHTML;
innerHTML = '';
}
documentFragment.appendChild(currentElement);
currentElement = null;
}
if (data !== this._terminal.defAttr) {
if (innerHTML && !currentElement) {
currentElement = this._spanElementObjectPool.acquire();
}
if (currentElement) {
if (innerHTML) {
currentElement.innerHTML = innerHTML;
innerHTML = '';
}
documentFragment.appendChild(currentElement);
}
currentElement = this._spanElementObjectPool.acquire();
if (data === -1) {
out += '<span class="reverse-video terminal-cursor">';
currentElement.classList.add('reverse-video');
currentElement.classList.add('terminal-cursor');
} else {
let classNames = [];
bg = data & 0x1ff;
fg = (data >> 9) & 0x1ff;
flags = data >> 18;
let bg = data & 0x1ff;
let fg = (data >> 9) & 0x1ff;
let flags = data >> 18;
if (flags & FLAGS.BOLD) {
if (!brokenBold) {
classNames.push('xterm-bold');
currentElement.classList.add('xterm-bold');
}
// See: XTerm*boldColors
if (fg < 8) fg += 8;
if (fg < 8) {
fg += 8;
}
}
if (flags & FLAGS.UNDERLINE) {
classNames.push('xterm-underline');
currentElement.classList.add('xterm-underline');
}
if (flags & FLAGS.BLINK) {
classNames.push('xterm-blink');
currentElement.classList.add('xterm-blink');
}
// If inverse flag is on, then swap the foreground and background variables.
if (flags & FLAGS.INVERSE) {
/* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */
bg = [fg, fg = bg][0];
// Should inverse just be before the
// above boldColors effect instead?
if ((flags & 1) && fg < 8) fg += 8;
let temp = bg;
bg = fg;
fg = temp;
// Should inverse just be before the above boldColors effect instead?
if ((flags & 1) && fg < 8) {
fg += 8;
}
}
if (flags & FLAGS.INVISIBLE) {
classNames.push('xterm-hidden');
currentElement.classList.add('xterm-hidden');
}
/**
@@ -229,55 +257,60 @@ export class Renderer {
}
if (bg < 256) {
classNames.push('xterm-bg-color-' + bg);
currentElement.classList.add(`xterm-bg-color-${bg}`);
}
if (fg < 256) {
classNames.push('xterm-color-' + fg);
currentElement.classList.add(`xterm-color-${fg}`);
}
out += '<span';
if (classNames.length) {
out += ' class="' + classNames.join(' ') + '"';
}
out += '>';
}
}
}
if (ch_width === 2) {
out += '<span class="xterm-wide-char">';
}
switch (ch) {
case '&':
out += '&amp;';
break;
case '<':
out += '&lt;';
break;
case '>':
out += '&gt;';
break;
default:
if (ch <= ' ') {
out += '&nbsp;';
} else {
out += ch;
}
break;
}
if (ch_width === 2) {
out += '</span>';
// Wrap wide characters so they're sized correctly. It's more difficult to release these
// from the object pool so just create new ones via innerHTML.
innerHTML += `<span class="xterm-wide-char">${ch}</span>`;
} else if (ch.charCodeAt(0) > 255) {
// Wrap any non-wide unicode character as some fonts size them badly
innerHTML += `<span class="xterm-normal-char">${ch}</span>`;
} else {
switch (ch) {
case '&':
innerHTML += '&amp;';
break;
case '<':
innerHTML += '&lt;';
break;
case '>':
innerHTML += '&gt;';
break;
default:
if (ch <= ' ') {
innerHTML += '&nbsp;';
} else {
innerHTML += ch;
}
break;
}
}
attr = data;
}
if (attr !== this._terminal.defAttr) {
out += '</span>';
if (innerHTML && !currentElement) {
currentElement = this._spanElementObjectPool.acquire();
}
if (currentElement) {
if (innerHTML) {
currentElement.innerHTML = innerHTML;
innerHTML = '';
}
documentFragment.appendChild(currentElement);
currentElement = null;
}
this._terminal.children[y].innerHTML = out;
this._terminal.children[y].appendChild(documentFragment);
}
if (parent) {
@@ -286,19 +319,80 @@ export class Renderer {
this._terminal.emit('refresh', {element: this._terminal.element, start: start, end: end});
};
/**
* Refreshes the selection in the DOM.
* @param start The selection start.
* @param end The selection end.
*/
public refreshSelection(start: [number, number], end: [number, number]) {
// Remove all selections
while (this._terminal.selectionContainer.children.length) {
this._terminal.selectionContainer.removeChild(this._terminal.selectionContainer.children[0]);
}
// Selection does not exist
if (!start || !end) {
return;
}
// Translate from buffer position to viewport position
const viewportStartRow = start[1] - this._terminal.ydisp;
const viewportEndRow = end[1] - this._terminal.ydisp;
const viewportCappedStartRow = Math.max(viewportStartRow, 0);
const viewportCappedEndRow = Math.min(viewportEndRow, this._terminal.rows - 1);
// No need to draw the selection
if (viewportCappedStartRow >= this._terminal.rows || viewportCappedEndRow < 0) {
return;
}
// Create the selections
const documentFragment = document.createDocumentFragment();
// Draw first row
const startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
const endCol = viewportCappedStartRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow, startCol, endCol));
// Draw middle rows
const middleRowsCount = viewportCappedEndRow - viewportCappedStartRow - 1;
documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow + 1, 0, this._terminal.cols, middleRowsCount));
// Draw final row
if (viewportCappedStartRow !== viewportCappedEndRow) {
// Only draw viewportEndRow if it's not the same as viewporttartRow
const endCol = viewportEndRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
documentFragment.appendChild(this._createSelectionElement(viewportCappedEndRow, 0, endCol));
}
this._terminal.selectionContainer.appendChild(documentFragment);
}
/**
* Creates a selection element at the specified position.
* @param row The row of the selection.
* @param colStart The start column.
* @param colEnd The end columns.
*/
private _createSelectionElement(row: number, colStart: number, colEnd: number, rowCount: number = 1): HTMLElement {
const element = document.createElement('div');
element.style.height = `${rowCount * this._terminal.charMeasure.height}px`;
element.style.top = `${row * this._terminal.charMeasure.height}px`;
element.style.left = `${colStart * this._terminal.charMeasure.width}px`;
element.style.width = `${this._terminal.charMeasure.width * (colEnd - colStart)}px`;
return element;
}
}
// if bold is broken, we can't
// use it in the terminal.
function checkBoldBroken(document) {
const body = document.getElementsByTagName('body')[0];
// If bold is broken, we can't use it in the terminal.
function checkBoldBroken(terminal) {
const document = terminal.ownerDocument;
const el = document.createElement('span');
el.innerHTML = 'hello world';
body.appendChild(el);
const w1 = el.scrollWidth;
terminal.appendChild(el);
const w1 = el.offsetWidth;
const h1 = el.offsetHeight;
el.style.fontWeight = 'bold';
const w2 = el.scrollWidth;
body.removeChild(el);
return w1 !== w2;
const w2 = el.offsetWidth;
const h2 = el.offsetHeight;
terminal.removeChild(el);
return w1 !== w2 || h1 !== h2;
}
+220
View File
@@ -0,0 +1,220 @@
/**
* @license MIT
*/
import jsdom = require('jsdom');
import { assert } from 'chai';
import { ITerminal } from './Interfaces';
import { CharMeasure } from './utils/CharMeasure';
import { CircularList } from './utils/CircularList';
import { SelectionManager } from './SelectionManager';
import { SelectionModel } from './SelectionModel';
class TestSelectionManager extends SelectionManager {
constructor(
terminal: ITerminal,
buffer: CircularList<any>,
rowContainer: HTMLElement,
charMeasure: CharMeasure
) {
super(terminal, buffer, rowContainer, charMeasure);
}
public get model(): SelectionModel { return this._model; }
public selectLineAt(line: number): void { this._selectLineAt(line); }
public selectWordAt(coords: [number, number]): void { this._selectWordAt(coords); }
// Disable DOM interaction
public enable(): void {}
public disable(): void {}
public refresh(): void {}
}
describe('SelectionManager', () => {
let window: Window;
let document: Document;
let terminal: ITerminal;
let buffer: CircularList<any>;
let rowContainer: HTMLElement;
let selectionManager: TestSelectionManager;
beforeEach(done => {
jsdom.env('', (err, w) => {
window = w;
document = window.document;
buffer = new CircularList<any>(100);
terminal = <any>{ cols: 80, rows: 2 };
selectionManager = new TestSelectionManager(terminal, buffer, rowContainer, null);
done();
});
});
function stringToRow(text: string): [number, string, number][] {
let result: [number, string, number][] = [];
for (let i = 0; i < text.length; i++) {
result.push([0, text.charAt(i), 1]);
}
return result;
}
describe('_selectWordAt', () => {
it('should expand selection for normal width chars', () => {
buffer.push(stringToRow('foo bar'));
selectionManager.selectWordAt([0, 0]);
assert.equal(selectionManager.selectionText, 'foo');
selectionManager.selectWordAt([1, 0]);
assert.equal(selectionManager.selectionText, 'foo');
selectionManager.selectWordAt([2, 0]);
assert.equal(selectionManager.selectionText, 'foo');
selectionManager.selectWordAt([3, 0]);
assert.equal(selectionManager.selectionText, ' ');
selectionManager.selectWordAt([4, 0]);
assert.equal(selectionManager.selectionText, 'bar');
selectionManager.selectWordAt([5, 0]);
assert.equal(selectionManager.selectionText, 'bar');
selectionManager.selectWordAt([6, 0]);
assert.equal(selectionManager.selectionText, 'bar');
});
it('should expand selection for whitespace', () => {
buffer.push(stringToRow('a b'));
selectionManager.selectWordAt([0, 0]);
assert.equal(selectionManager.selectionText, 'a');
selectionManager.selectWordAt([1, 0]);
assert.equal(selectionManager.selectionText, ' ');
selectionManager.selectWordAt([2, 0]);
assert.equal(selectionManager.selectionText, ' ');
selectionManager.selectWordAt([3, 0]);
assert.equal(selectionManager.selectionText, ' ');
selectionManager.selectWordAt([4, 0]);
assert.equal(selectionManager.selectionText, 'b');
});
it('should expand selection for wide characters', () => {
// Wide characters use a special format
buffer.push([
[null, '中', 2],
[null, '', 0],
[null, '文', 2],
[null, '', 0],
[null, ' ', 1],
[null, 'a', 1],
[null, '中', 2],
[null, '', 0],
[null, '文', 2],
[null, '', 0],
[null, 'b', 1],
[null, ' ', 1],
[null, 'f', 1],
[null, 'o', 1],
[null, 'o', 1]
]);
// Ensure wide characters take up 2 columns
selectionManager.selectWordAt([0, 0]);
assert.equal(selectionManager.selectionText, '中文');
selectionManager.selectWordAt([1, 0]);
assert.equal(selectionManager.selectionText, '中文');
selectionManager.selectWordAt([2, 0]);
assert.equal(selectionManager.selectionText, '中文');
selectionManager.selectWordAt([3, 0]);
assert.equal(selectionManager.selectionText, '中文');
selectionManager.selectWordAt([4, 0]);
assert.equal(selectionManager.selectionText, ' ');
// Ensure wide characters work when wrapped in normal width characters
selectionManager.selectWordAt([5, 0]);
assert.equal(selectionManager.selectionText, 'a中文b');
selectionManager.selectWordAt([6, 0]);
assert.equal(selectionManager.selectionText, 'a中文b');
selectionManager.selectWordAt([7, 0]);
assert.equal(selectionManager.selectionText, 'a中文b');
selectionManager.selectWordAt([8, 0]);
assert.equal(selectionManager.selectionText, 'a中文b');
selectionManager.selectWordAt([9, 0]);
assert.equal(selectionManager.selectionText, 'a中文b');
selectionManager.selectWordAt([10, 0]);
assert.equal(selectionManager.selectionText, 'a中文b');
selectionManager.selectWordAt([11, 0]);
assert.equal(selectionManager.selectionText, ' ');
// Ensure normal width characters work fine in a line containing wide characters
selectionManager.selectWordAt([12, 0]);
assert.equal(selectionManager.selectionText, 'foo');
selectionManager.selectWordAt([13, 0]);
assert.equal(selectionManager.selectionText, 'foo');
selectionManager.selectWordAt([14, 0]);
assert.equal(selectionManager.selectionText, 'foo');
});
it('should select up to non-path characters that are commonly adjacent to paths', () => {
buffer.push(stringToRow('(cd)[ef]{gh}\'ij"'));
selectionManager.selectWordAt([0, 0]);
assert.equal(selectionManager.selectionText, '(cd');
selectionManager.selectWordAt([1, 0]);
assert.equal(selectionManager.selectionText, 'cd');
selectionManager.selectWordAt([2, 0]);
assert.equal(selectionManager.selectionText, 'cd');
selectionManager.selectWordAt([3, 0]);
assert.equal(selectionManager.selectionText, 'cd)');
selectionManager.selectWordAt([4, 0]);
assert.equal(selectionManager.selectionText, '[ef');
selectionManager.selectWordAt([5, 0]);
assert.equal(selectionManager.selectionText, 'ef');
selectionManager.selectWordAt([6, 0]);
assert.equal(selectionManager.selectionText, 'ef');
selectionManager.selectWordAt([7, 0]);
assert.equal(selectionManager.selectionText, 'ef]');
selectionManager.selectWordAt([8, 0]);
assert.equal(selectionManager.selectionText, '{gh');
selectionManager.selectWordAt([9, 0]);
assert.equal(selectionManager.selectionText, 'gh');
selectionManager.selectWordAt([10, 0]);
assert.equal(selectionManager.selectionText, 'gh');
selectionManager.selectWordAt([11, 0]);
assert.equal(selectionManager.selectionText, 'gh}');
selectionManager.selectWordAt([12, 0]);
assert.equal(selectionManager.selectionText, '\'ij');
selectionManager.selectWordAt([13, 0]);
assert.equal(selectionManager.selectionText, 'ij');
selectionManager.selectWordAt([14, 0]);
assert.equal(selectionManager.selectionText, 'ij');
selectionManager.selectWordAt([15, 0]);
assert.equal(selectionManager.selectionText, 'ij"');
});
});
describe('_selectLineAt', () => {
it('should select the entire line', () => {
buffer.push(stringToRow('foo bar'));
selectionManager.selectLineAt(0);
assert.equal(selectionManager.selectionText, 'foo bar', 'The selected text is correct');
assert.deepEqual(selectionManager.model.finalSelectionStart, [0, 0]);
assert.deepEqual(selectionManager.model.finalSelectionEnd, [terminal.cols, 0], 'The actual selection spans the entire column');
});
});
describe('selectAll', () => {
it('should select the entire buffer, beyond the viewport', () => {
buffer.push(stringToRow('1'));
buffer.push(stringToRow('2'));
buffer.push(stringToRow('3'));
buffer.push(stringToRow('4'));
buffer.push(stringToRow('5'));
selectionManager.selectAll();
terminal.ybase = buffer.length - terminal.rows;
assert.equal(selectionManager.selectionText, '1\n2\n3\n4\n5');
});
});
describe('hasSelection', () => {
it('should return whether there is a selection', () => {
selectionManager.model.selectionStart = [0, 0];
selectionManager.model.selectionStartLength = 0;
assert.equal(selectionManager.hasSelection, false);
selectionManager.model.selectionEnd = [0, 0];
assert.equal(selectionManager.hasSelection, false);
selectionManager.model.selectionEnd = [1, 0];
assert.equal(selectionManager.hasSelection, true);
selectionManager.model.selectionEnd = [0, 1];
assert.equal(selectionManager.hasSelection, true);
selectionManager.model.selectionEnd = [1, 1];
assert.equal(selectionManager.hasSelection, true);
});
});
});
+718
View File
@@ -0,0 +1,718 @@
/**
* @license MIT
*/
import * as Mouse from './utils/Mouse';
import * as Browser from './utils/Browser';
import { CharMeasure } from './utils/CharMeasure';
import { CircularList } from './utils/CircularList';
import { EventEmitter } from './EventEmitter';
import { ITerminal } from './Interfaces';
import { SelectionModel } from './SelectionModel';
/**
* The number of pixels the mouse needs to be above or below the viewport in
* order to scroll at the maximum speed.
*/
const DRAG_SCROLL_MAX_THRESHOLD = 50;
/**
* The maximum scrolling speed
*/
const DRAG_SCROLL_MAX_SPEED = 15;
/**
* The number of milliseconds between drag scroll updates.
*/
const DRAG_SCROLL_INTERVAL = 50;
/**
* The amount of time before mousedown events are no longer stacked to create
* double/triple click events.
*/
const CLEAR_MOUSE_DOWN_TIME = 400;
/**
* The number of pixels in each direction that the mouse must move before
* mousedown events are no longer stacked to create double/triple click events.
*/
const CLEAR_MOUSE_DISTANCE = 10;
/**
* A string containing all characters that are considered word separated by the
* double click to select work logic.
*/
const WORD_SEPARATORS = ' ()[]{}\'"';
// TODO: Move these constants elsewhere, they belong in a buffer or buffer
// data/line class.
const LINE_DATA_CHAR_INDEX = 1;
const LINE_DATA_WIDTH_INDEX = 2;
const NON_BREAKING_SPACE_CHAR = String.fromCharCode(160);
const ALL_NON_BREAKING_SPACE_REGEX = new RegExp(NON_BREAKING_SPACE_CHAR, 'g');
/**
* Represents a position of a word on a line.
*/
interface IWordPosition {
start: number;
length: number;
}
/**
* A selection mode, this drives how the selection behaves on mouse move.
*/
enum SelectionMode {
NORMAL,
WORD,
LINE
}
/**
* A class that manages the selection of the terminal. With help from
* SelectionModel, SelectionManager handles with all logic associated with
* dealing with the selection, including handling mouse interaction, wide
* characters and fetching the actual text within the selection. Rendering is
* not handled by the SelectionManager but a 'refresh' event is fired when the
* selection is ready to be redrawn.
*/
export class SelectionManager extends EventEmitter {
protected _model: SelectionModel;
/**
* The amount to scroll every drag scroll update (depends on how far the mouse
* drag is above or below the terminal).
*/
private _dragScrollAmount: number;
/**
* The last time the mousedown event fired, this is used to track double and
* triple clicks.
*/
private _lastMouseDownTime: number;
/**
* The last position the mouse was clicked [x, y].
*/
private _lastMousePosition: [number, number];
/**
* The number of clicks of the mousedown event. This is used to keep track of
* double and triple clicks.
*/
private _clickCount: number;
/**
* The current selection mode.
*/
private _activeSelectionMode: SelectionMode;
/**
* A setInterval timer that is active while the mouse is down whose callback
* scrolls the viewport when necessary.
*/
private _dragScrollIntervalTimer: NodeJS.Timer;
/**
* The animation frame ID used for refreshing the selection.
*/
private _refreshAnimationFrame: number;
private _bufferTrimListener: any;
private _mouseMoveListener: EventListener;
private _mouseDownListener: EventListener;
private _mouseUpListener: EventListener;
constructor(
private _terminal: ITerminal,
private _buffer: CircularList<any>,
private _rowContainer: HTMLElement,
private _charMeasure: CharMeasure
) {
super();
this._initListeners();
this.enable();
this._model = new SelectionModel(_terminal);
this._lastMouseDownTime = 0;
this._activeSelectionMode = SelectionMode.NORMAL;
}
/**
* Initializes listener variables.
*/
private _initListeners() {
this._bufferTrimListener = (amount: number) => this._onTrim(amount);
this._mouseMoveListener = event => this._onMouseMove(<MouseEvent>event);
this._mouseDownListener = event => this._onMouseDown(<MouseEvent>event);
this._mouseUpListener = event => this._onMouseUp(<MouseEvent>event);
}
/**
* Disables the selection manager. This is useful for when terminal mouse
* are enabled.
*/
public disable() {
this.clearSelection();
this._buffer.off('trim', this._bufferTrimListener);
this._rowContainer.removeEventListener('mousedown', this._mouseDownListener);
}
/**
* Enable the selection manager.
*/
public enable() {
// Only adjust the selection on trim, shiftElements is rarely used (only in
// reverseIndex) and delete in a splice is only ever used when the same
// number of elements was just added. Given this is could actually be
// beneficial to leave the selection as is for these cases.
this._buffer.on('trim', this._bufferTrimListener);
this._rowContainer.addEventListener('mousedown', this._mouseDownListener);
}
/**
* Sets the active buffer, this should be called when the alt buffer is
* switched in or out.
* @param buffer The active buffer.
*/
public setBuffer(buffer: CircularList<any>): void {
this._buffer = buffer;
this.clearSelection();
}
/**
* Gets whether there is an active text selection.
*/
public get hasSelection(): boolean {
const start = this._model.finalSelectionStart;
const end = this._model.finalSelectionEnd;
if (!start || !end) {
return false;
}
return start[0] !== end[0] || start[1] !== end[1];
}
/**
* Gets the text currently selected.
*/
public get selectionText(): string {
const start = this._model.finalSelectionStart;
const end = this._model.finalSelectionEnd;
if (!start || !end) {
return '';
}
// Get first row
const startRowEndCol = start[1] === end[1] ? end[0] : null;
let result: string[] = [];
result.push(this._translateBufferLineToString(this._buffer.get(start[1]), true, start[0], startRowEndCol));
// Get middle rows
for (let i = start[1] + 1; i <= end[1] - 1; i++) {
const bufferLine = this._buffer.get(i);
const lineText = this._translateBufferLineToString(bufferLine, true);
if (bufferLine.isWrapped) {
result[result.length - 1] += lineText;
} else {
result.push(lineText);
}
}
// Get final row
if (start[1] !== end[1]) {
const bufferLine = this._buffer.get(end[1]);
const lineText = this._translateBufferLineToString(bufferLine, true, 0, end[0]);
if (bufferLine.isWrapped) {
result[result.length - 1] += lineText;
} else {
result.push(lineText);
}
}
// Format string by replacing non-breaking space chars with regular spaces
// and joining the array into a multi-line string.
const formattedResult = result.map(line => {
return line.replace(ALL_NON_BREAKING_SPACE_REGEX, ' ');
}).join(Browser.isMSWindows ? '\r\n' : '\n');
return formattedResult;
}
/**
* Clears the current terminal selection.
*/
public clearSelection(): void {
this._model.clearSelection();
this._removeMouseDownListeners();
this.refresh();
}
/**
* Translates a buffer line to a string, with optional start and end columns.
* Wide characters will count as two columns in the resulting string. This
* function is useful for getting the actual text underneath the raw selection
* position.
* @param line The line being translated.
* @param trimRight Whether to trim whitespace to the right.
* @param startCol The column to start at.
* @param endCol The column to end at.
*/
private _translateBufferLineToString(line: any, trimRight: boolean, startCol: number = 0, endCol: number = null): string {
// TODO: This function should live in a buffer or buffer line class
// Get full line
let lineString = '';
let widthAdjustedStartCol = startCol;
let widthAdjustedEndCol = endCol;
for (let i = 0; i < line.length; i++) {
const char = line[i];
lineString += char[LINE_DATA_CHAR_INDEX];
// Adjust start and end cols for wide characters if they affect their
// column indexes
if (char[LINE_DATA_WIDTH_INDEX] === 0) {
if (startCol >= i) {
widthAdjustedStartCol--;
}
if (endCol >= i) {
widthAdjustedEndCol--;
}
}
}
// Calculate the final end col by trimming whitespace on the right of the
// line if needed.
let finalEndCol = widthAdjustedEndCol || line.length;
if (trimRight) {
const rightWhitespaceIndex = lineString.search(/\s+$/);
if (rightWhitespaceIndex !== -1) {
finalEndCol = Math.min(finalEndCol, rightWhitespaceIndex);
}
// Return the empty string if only trimmed whitespace is selected
if (finalEndCol <= widthAdjustedStartCol) {
return '';
}
}
return lineString.substring(widthAdjustedStartCol, finalEndCol);
}
/**
* Queues a refresh, redrawing the selection on the next opportunity.
* @param isNewSelection Whether the selection should be registered as a new
* selection on Linux.
*/
public refresh(isNewSelection?: boolean): void {
// Queue the refresh for the renderer
if (!this._refreshAnimationFrame) {
this._refreshAnimationFrame = window.requestAnimationFrame(() => this._refresh());
}
// If the platform is Linux and the refresh call comes from a mouse event,
// we need to update the selection for middle click to paste selection.
if (Browser.isLinux && isNewSelection) {
const selectionText = this.selectionText;
if (selectionText.length) {
this.emit('newselection', this.selectionText);
}
}
}
/**
* Fires the refresh event, causing consumers to pick it up and redraw the
* selection state.
*/
private _refresh(): void {
this._refreshAnimationFrame = null;
this.emit('refresh', { start: this._model.finalSelectionStart, end: this._model.finalSelectionEnd });
}
/**
* Selects all text within the terminal.
*/
public selectAll(): void {
this._model.isSelectAllActive = true;
this.refresh();
}
/**
* Handle the buffer being trimmed, adjust the selection position.
* @param amount The amount the buffer is being trimmed.
*/
private _onTrim(amount: number) {
const needsRefresh = this._model.onTrim(amount);
if (needsRefresh) {
this.refresh();
}
}
/**
* Gets the 0-based [x, y] buffer coordinates of the current mouse event.
* @param event The mouse event.
*/
private _getMouseBufferCoords(event: MouseEvent): [number, number] {
const coords = Mouse.getCoords(event, this._rowContainer, this._charMeasure, this._terminal.cols, this._terminal.rows, true);
// Convert to 0-based
coords[0]--;
coords[1]--;
// Convert viewport coords to buffer coords
coords[1] += this._terminal.ydisp;
return coords;
}
/**
* Gets the amount the viewport should be scrolled based on how far out of the
* terminal the mouse is.
* @param event The mouse event.
*/
private _getMouseEventScrollAmount(event: MouseEvent): number {
let offset = Mouse.getCoordsRelativeToElement(event, this._rowContainer)[1];
const terminalHeight = this._terminal.rows * this._charMeasure.height;
if (offset >= 0 && offset <= terminalHeight) {
return 0;
}
if (offset > terminalHeight) {
offset -= terminalHeight;
}
offset = Math.min(Math.max(offset, -DRAG_SCROLL_MAX_THRESHOLD), DRAG_SCROLL_MAX_THRESHOLD);
offset /= DRAG_SCROLL_MAX_THRESHOLD;
return (offset / Math.abs(offset)) + Math.round(offset * (DRAG_SCROLL_MAX_SPEED - 1));
}
/**
* Handles te mousedown event, setting up for a new selection.
* @param event The mousedown event.
*/
private _onMouseDown(event: MouseEvent) {
// Only action the primary button
if (event.button !== 0) {
return;
}
// Tell the browser not to start a regular selection
event.preventDefault();
// Reset drag scroll state
this._dragScrollAmount = 0;
this._setMouseClickCount(event);
if (event.shiftKey) {
this._onShiftClick(event);
} else {
if (this._clickCount === 1) {
this._onSingleClick(event);
} else if (this._clickCount === 2) {
this._onDoubleClick(event);
} else if (this._clickCount === 3) {
this._onTripleClick(event);
}
}
this._addMouseDownListeners();
this.refresh(true);
}
/**
* Adds listeners when mousedown is triggered.
*/
private _addMouseDownListeners(): void {
// Listen on the document so that dragging outside of viewport works
this._rowContainer.ownerDocument.addEventListener('mousemove', this._mouseMoveListener);
this._rowContainer.ownerDocument.addEventListener('mouseup', this._mouseUpListener);
this._dragScrollIntervalTimer = setInterval(() => this._dragScroll(), DRAG_SCROLL_INTERVAL);
}
/**
* Removes the listeners that are registered when mousedown is triggered.
*/
private _removeMouseDownListeners(): void {
this._rowContainer.ownerDocument.removeEventListener('mousemove', this._mouseMoveListener);
this._rowContainer.ownerDocument.removeEventListener('mouseup', this._mouseUpListener);
clearInterval(this._dragScrollIntervalTimer);
this._dragScrollIntervalTimer = null;
}
/**
* Performs a shift click, setting the selection end position to the mouse
* position.
* @param event The mouse event.
*/
private _onShiftClick(event: MouseEvent): void {
if (this._model.selectionStart) {
this._model.selectionEnd = this._getMouseBufferCoords(event);
}
}
/**
* Performs a single click, resetting relevant state and setting the selection
* start position.
* @param event The mouse event.
*/
private _onSingleClick(event: MouseEvent): void {
this._model.selectionStartLength = 0;
this._model.isSelectAllActive = false;
this._activeSelectionMode = SelectionMode.NORMAL;
this._model.selectionStart = this._getMouseBufferCoords(event);
if (this._model.selectionStart) {
this._model.selectionEnd = null;
// If the mouse is over the second half of a wide character, adjust the
// selection to cover the whole character
const char = this._buffer.get(this._model.selectionStart[1])[this._model.selectionStart[0]];
if (char[LINE_DATA_WIDTH_INDEX] === 0) {
this._model.selectionStart[0]++;
}
}
}
/**
* Performs a double click, selecting the current work.
* @param event The mouse event.
*/
private _onDoubleClick(event: MouseEvent): void {
const coords = this._getMouseBufferCoords(event);
if (coords) {
this._activeSelectionMode = SelectionMode.WORD;
this._selectWordAt(coords);
}
}
/**
* Performs a triple click, selecting the current line and activating line
* select mode.
* @param event The mouse event.
*/
private _onTripleClick(event: MouseEvent): void {
const coords = this._getMouseBufferCoords(event);
if (coords) {
this._activeSelectionMode = SelectionMode.LINE;
this._selectLineAt(coords[1]);
}
}
/**
* Sets the number of clicks for the current mousedown event based on the time
* and position of the last mousedown event.
* @param event The mouse event.
*/
private _setMouseClickCount(event: MouseEvent): void {
let currentTime = (new Date()).getTime();
if (currentTime - this._lastMouseDownTime > CLEAR_MOUSE_DOWN_TIME || this._distanceFromLastMousePosition(event) > CLEAR_MOUSE_DISTANCE) {
this._clickCount = 0;
}
this._lastMouseDownTime = currentTime;
this._lastMousePosition = [event.pageX, event.pageY];
this._clickCount++;
}
/**
* Gets the maximum number of pixels in each direction the mouse has moved.
* @param event The mouse event.
*/
private _distanceFromLastMousePosition(event: MouseEvent): number {
const result = Math.max(
Math.abs(this._lastMousePosition[0] - event.pageX),
Math.abs(this._lastMousePosition[1] - event.pageY));
return result;
}
/**
* Handles the mousemove event when the mouse button is down, recording the
* end of the selection and refreshing the selection.
* @param event The mousemove event.
*/
private _onMouseMove(event: MouseEvent) {
// Record the previous position so we know whether to redraw the selection
// at the end.
const previousSelectionEnd = this._model.selectionEnd ? [this._model.selectionEnd[0], this._model.selectionEnd[1]] : null;
// Set the initial selection end based on the mouse coordinates
this._model.selectionEnd = this._getMouseBufferCoords(event);
// Select the entire line if line select mode is active.
if (this._activeSelectionMode === SelectionMode.LINE) {
if (this._model.selectionEnd[1] < this._model.selectionStart[1]) {
this._model.selectionEnd[0] = 0;
} else {
this._model.selectionEnd[0] = this._terminal.cols;
}
} else if (this._activeSelectionMode === SelectionMode.WORD) {
this._selectToWordAt(this._model.selectionEnd);
}
// Determine the amount of scrolling that will happen.
this._dragScrollAmount = this._getMouseEventScrollAmount(event);
// If the cursor was above or below the viewport, make sure it's at the
// start or end of the viewport respectively.
if (this._dragScrollAmount > 0) {
this._model.selectionEnd[0] = this._terminal.cols - 1;
} else if (this._dragScrollAmount < 0) {
this._model.selectionEnd[0] = 0;
}
// If the character is a wide character include the cell to the right in the
// selection. Note that selections at the very end of the line will never
// have a character.
if (this._model.selectionEnd[1] < this._buffer.length) {
const char = this._buffer.get(this._model.selectionEnd[1])[this._model.selectionEnd[0]];
if (char && char[2] === 0) {
this._model.selectionEnd[0]++;
}
}
// Only draw here if the selection changes.
if (!previousSelectionEnd ||
previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
this.refresh(true);
}
}
/**
* The callback that occurs every DRAG_SCROLL_INTERVAL ms that does the
* scrolling of the viewport.
*/
private _dragScroll() {
if (this._dragScrollAmount) {
this._terminal.scrollDisp(this._dragScrollAmount, false);
// Re-evaluate selection
if (this._dragScrollAmount > 0) {
this._model.selectionEnd = [this._terminal.cols - 1, this._terminal.ydisp + this._terminal.rows];
} else {
this._model.selectionEnd = [0, this._terminal.ydisp];
}
this.refresh();
}
}
/**
* Handles the mouseup event, removing the mousedown listeners.
* @param event The mouseup event.
*/
private _onMouseUp(event: MouseEvent) {
this._removeMouseDownListeners();
}
/**
* Converts a viewport column to the character index on the buffer line, the
* latter takes into account wide characters.
* @param coords The coordinates to find the 2 index for.
*/
private _convertViewportColToCharacterIndex(bufferLine: any, coords: [number, number]): number {
let charIndex = coords[0];
for (let i = 0; coords[0] >= i; i++) {
const char = bufferLine[i];
if (char[LINE_DATA_WIDTH_INDEX] === 0) {
charIndex--;
}
}
return charIndex;
}
/**
* Gets positional information for the word at the coordinated specified.
* @param coords The coordinates to get the word at.
*/
private _getWordAt(coords: [number, number]): IWordPosition {
const bufferLine = this._buffer.get(coords[1]);
const line = this._translateBufferLineToString(bufferLine, false);
// Get actual index, taking into consideration wide characters
let endIndex = this._convertViewportColToCharacterIndex(bufferLine, coords);
let startIndex = endIndex;
// Record offset to be used later
const charOffset = coords[0] - startIndex;
let leftWideCharCount = 0;
let rightWideCharCount = 0;
if (line.charAt(startIndex) === ' ') {
// Expand until non-whitespace is hit
while (startIndex > 0 && line.charAt(startIndex - 1) === ' ') {
startIndex--;
}
while (endIndex < line.length && line.charAt(endIndex + 1) === ' ') {
endIndex++;
}
} else {
// Expand until whitespace is hit. This algorithm works by scanning left
// and right from the starting position, keeping both the index format
// (line) and the column format (bufferLine) in sync. When a wide
// character is hit, it is recorded and the column index is adjusted.
let startCol = coords[0];
let endCol = coords[0];
// Consider the initial position, skip it and increment the wide char
// variable
if (bufferLine[startCol][LINE_DATA_WIDTH_INDEX] === 0) {
leftWideCharCount++;
startCol--;
}
if (bufferLine[endCol][LINE_DATA_WIDTH_INDEX] === 2) {
rightWideCharCount++;
endCol++;
}
// Expand the string in both directions until a space is hit
while (startIndex > 0 && !this._isCharWordSeparator(line.charAt(startIndex - 1))) {
if (bufferLine[startCol - 1][LINE_DATA_WIDTH_INDEX] === 0) {
// If the next character is a wide char, record it and skip the column
leftWideCharCount++;
startCol--;
}
startIndex--;
startCol--;
}
while (endIndex + 1 < line.length && !this._isCharWordSeparator(line.charAt(endIndex + 1))) {
if (bufferLine[endCol + 1][LINE_DATA_WIDTH_INDEX] === 2) {
// If the next character is a wide char, record it and skip the column
rightWideCharCount++;
endCol++;
}
endIndex++;
endCol++;
}
}
const start = startIndex + charOffset - leftWideCharCount;
const length = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1/*include endIndex char*/, this._terminal.cols);
return {start, length};
}
/**
* Selects the word at the coordinates specified.
* @param coords The coordinates to get the word at.
*/
protected _selectWordAt(coords: [number, number]): void {
const wordPosition = this._getWordAt(coords);
this._model.selectionStart = [wordPosition.start, coords[1]];
this._model.selectionStartLength = wordPosition.length;
}
/**
* Sets the selection end to the word at the coordinated specified.
* @param coords The coordinates to get the word at.
*/
private _selectToWordAt(coords: [number, number]): void {
const wordPosition = this._getWordAt(coords);
this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : (wordPosition.start + wordPosition.length), coords[1]];
}
/**
* Gets whether the character is considered a word separator by the select
* word logic.
* @param char The character to check.
*/
private _isCharWordSeparator(char: string): boolean {
return WORD_SEPARATORS.indexOf(char) >= 0;
}
/**
* Selects the line specified.
* @param line The line index.
*/
protected _selectLineAt(line: number): void {
this._model.selectionStart = [0, line];
this._model.selectionStartLength = this._terminal.cols;
}
}
+131
View File
@@ -0,0 +1,131 @@
/**
* @license MIT
*/
import { assert } from 'chai';
import { ITerminal } from './Interfaces';
import { SelectionModel } from './SelectionModel';
class TestSelectionModel extends SelectionModel {
constructor(
terminal: ITerminal
) {
super(terminal);
}
}
describe('SelectionManager', () => {
let window: Window;
let document: Document;
let terminal: ITerminal;
let model: TestSelectionModel;
beforeEach(() => {
terminal = <any>{ cols: 80, rows: 2, ybase: 0 };
model = new TestSelectionModel(terminal);
});
describe('clearSelection', () => {
it('should clear the final selection', () => {
model.selectionStart = [0, 0];
model.selectionEnd = [10, 2];
assert.deepEqual(model.finalSelectionStart, [0, 0]);
assert.deepEqual(model.finalSelectionEnd, [10, 2]);
model.clearSelection();
assert.deepEqual(model.finalSelectionStart, null);
assert.deepEqual(model.finalSelectionEnd, null);
});
});
describe('areSelectionValuesReversed', () => {
it('should return true when the selection end is before selection start', () => {
model.selectionStart = [1, 0];
model.selectionEnd = [0, 0];
assert.equal(model.areSelectionValuesReversed(), true);
model.selectionStart = [10, 2];
model.selectionEnd = [0, 0];
assert.equal(model.areSelectionValuesReversed(), true);
});
it('should return false when the selection end is after selection start', () => {
model.selectionStart = [0, 0];
model.selectionEnd = [1, 0];
assert.equal(model.areSelectionValuesReversed(), false);
model.selectionStart = [0, 0];
model.selectionEnd = [10, 2];
assert.equal(model.areSelectionValuesReversed(), false);
});
});
describe('onTrim', () => {
it('should trim a portion of the selection when a part of it is trimmed', () => {
model.selectionStart = [0, 0];
model.selectionEnd = [10, 2];
model.onTrim(1);
assert.deepEqual(model.finalSelectionStart, [0, 0]);
assert.deepEqual(model.finalSelectionEnd, [10, 1]);
model.onTrim(1);
assert.deepEqual(model.finalSelectionStart, [0, 0]);
assert.deepEqual(model.finalSelectionEnd, [10, 0]);
});
it('should clear selection when it is trimmed in its entirety', () => {
model.selectionStart = [0, 0];
model.selectionEnd = [10, 0];
model.onTrim(1);
assert.deepEqual(model.finalSelectionStart, null);
assert.deepEqual(model.finalSelectionEnd, null);
});
});
describe('finalSelectionStart', () => {
it('should return the start of the buffer if select all is active', () => {
model.isSelectAllActive = true;
assert.deepEqual(model.finalSelectionStart, [0, 0]);
});
it('should return selection start if there is no selection end', () => {
model.selectionStart = [2, 2];
assert.deepEqual(model.finalSelectionStart, [2, 2]);
});
it('should return selection end if values are reversed', () => {
model.selectionStart = [2, 2];
model.selectionEnd = [3, 2];
assert.deepEqual(model.finalSelectionStart, [2, 2]);
model.selectionEnd = [1, 2];
assert.deepEqual(model.finalSelectionStart, [1, 2]);
});
});
describe('finalSelectionEnd', () => {
it('should return the end of the buffer if select all is active', () => {
model.isSelectAllActive = true;
assert.deepEqual(model.finalSelectionEnd, [80, 1]);
});
it('should return null if there is no selection start', () => {
assert.equal(model.finalSelectionEnd, null);
model.selectionEnd = [1, 2];
assert.equal(model.finalSelectionEnd, null);
});
it('should return selection start + length if there is no selection end', () => {
model.selectionStart = [2, 2];
model.selectionStartLength = 2;
assert.deepEqual(model.finalSelectionEnd, [4, 2]);
});
it('should return selection start + length if values are reversed', () => {
model.selectionStart = [2, 2];
model.selectionStartLength = 2;
model.selectionEnd = [2, 1];
assert.deepEqual(model.finalSelectionEnd, [4, 2]);
});
it('should return selection start + length if selection end is inside the start selection', () => {
model.selectionStart = [2, 2];
model.selectionStartLength = 2;
model.selectionEnd = [3, 2];
assert.deepEqual(model.finalSelectionEnd, [4, 2]);
});
it('should return selection end if selection end is after selection start + length', () => {
model.selectionStart = [2, 2];
model.selectionStartLength = 2;
model.selectionEnd = [5, 2];
assert.deepEqual(model.finalSelectionEnd, [5, 2]);
});
});
});
+128
View File
@@ -0,0 +1,128 @@
/**
* @license MIT
*/
import { ITerminal } from './Interfaces';
/**
* Represents a selection within the buffer. This model only cares about column
* and row coordinates, not wide characters.
*/
export class SelectionModel {
/**
* Whether select all is currently active.
*/
public isSelectAllActive: boolean;
/**
* The [x, y] position the selection starts at.
*/
public selectionStart: [number, number];
/**
* The minimal length of the selection from the start position. When double
* clicking on a word, the word will be selected which makes the selection
* start at the start of the word and makes this variable the length.
*/
public selectionStartLength: number;
/**
* The [x, y] position the selection ends at.
*/
public selectionEnd: [number, number];
constructor(
private _terminal: ITerminal
) {
this.clearSelection();
}
/**
* Clears the current selection.
*/
public clearSelection(): void {
this.selectionStart = null;
this.selectionEnd = null;
this.isSelectAllActive = false;
this.selectionStartLength = 0;
}
/**
* The final selection start, taking into consideration select all.
*/
public get finalSelectionStart(): [number, number] {
if (this.isSelectAllActive) {
return [0, 0];
}
if (!this.selectionEnd || !this.selectionStart) {
return this.selectionStart;
}
return this.areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
}
/**
* The final selection end, taking into consideration select all, double click
* word selection and triple click line selection.
*/
public get finalSelectionEnd(): [number, number] {
if (this.isSelectAllActive) {
return [this._terminal.cols, this._terminal.ybase + this._terminal.rows - 1];
}
if (!this.selectionStart) {
return null;
}
// Use the selection start if the end doesn't exist or they're reversed
if (!this.selectionEnd || this.areSelectionValuesReversed()) {
return [this.selectionStart[0] + this.selectionStartLength, this.selectionStart[1]];
}
// Ensure the the word/line is selected after a double/triple click
if (this.selectionStartLength) {
// Select the larger of the two when start and end are on the same line
if (this.selectionEnd[1] === this.selectionStart[1]) {
return [Math.max(this.selectionStart[0] + this.selectionStartLength, this.selectionEnd[0]), this.selectionEnd[1]];
}
}
return this.selectionEnd;
}
/**
* Returns whether the selection start and end are reversed.
*/
public areSelectionValuesReversed(): boolean {
const start = this.selectionStart;
const end = this.selectionEnd;
return start[1] > end[1] || (start[1] === end[1] && start[0] > end[0]);
}
/**
* Handle the buffer being trimmed, adjust the selection position.
* @param amount The amount the buffer is being trimmed.
* @return Whether a refresh is necessary.
*/
public onTrim(amount: number): boolean {
// Adjust the selection position based on the trimmed amount.
if (this.selectionStart) {
this.selectionStart[1] -= amount;
}
if (this.selectionEnd) {
this.selectionEnd[1] -= amount;
}
// The selection has moved off the buffer, clear it.
if (this.selectionEnd && this.selectionEnd[1] < 0) {
this.clearSelection();
return true;
}
// If the selection start is trimmed, ensure the start column is 0.
if (this.selectionStart && this.selectionStart[1] < 0) {
this.selectionStart[1] = 0;
}
return false;
}
}
+14
View File
@@ -0,0 +1,14 @@
/**
* @license MIT
*/
export type LinkMatcher = {
id: number,
regex: RegExp,
handler: LinkMatcherHandler,
matchIndex?: number,
validationCallback?: LinkMatcherValidationCallback,
priority?: number
};
export type LinkMatcherHandler = (event: MouseEvent, uri: string) => boolean | void;
export type LinkMatcherValidationCallback = (uri: string, element: HTMLElement, callback: (isValid: boolean) => void) => void;
+32 -18
View File
@@ -4,6 +4,7 @@ import { Viewport } from './Viewport';
describe('Viewport', () => {
let terminal;
let viewportElement;
let selectionContainer;
let charMeasure;
let viewport;
let scrollAreaElement;
@@ -20,6 +21,11 @@ describe('Viewport', () => {
style: {
lineHeight: 0
}
},
selectionContainer: {
style: {
height: 0
}
}
};
viewportElement = {
@@ -41,13 +47,17 @@ describe('Viewport', () => {
});
describe('refresh', () => {
it('should set the line-height of the terminal', () => {
assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
charMeasure.height = 1;
viewport.refresh();
assert.equal(viewportElement.style.lineHeight, '1px');
assert.equal(terminal.rowContainer.style.lineHeight, '1px');
it('should set the line-height of the terminal', done => {
// Allow CharMeasure to be initialized
setTimeout(() => {
assert.equal(viewportElement.style.lineHeight, CHARACTER_HEIGHT + 'px');
assert.equal(terminal.rowContainer.style.lineHeight, CHARACTER_HEIGHT + 'px');
charMeasure.height = 1;
viewport.refresh();
assert.equal(viewportElement.style.lineHeight, '1px');
assert.equal(terminal.rowContainer.style.lineHeight, '1px');
done();
}, 0);
});
it('should set the height of the viewport when the line-height changed', () => {
terminal.lines.push('');
@@ -62,17 +72,21 @@ describe('Viewport', () => {
});
describe('syncScrollArea', () => {
it('should sync the scroll area', () => {
terminal.lines.push('');
terminal.rows = 1;
assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
viewport.syncScrollArea();
assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
terminal.lines.push('');
viewport.syncScrollArea();
assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
it('should sync the scroll area', done => {
// Allow CharMeasure to be initialized
setTimeout(() => {
terminal.lines.push('');
terminal.rows = 1;
assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
viewport.syncScrollArea();
assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
terminal.lines.push('');
viewport.syncScrollArea();
assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
done();
}, 0);
});
});
});
+26 -1
View File
@@ -13,6 +13,7 @@ export class Viewport {
private currentRowHeight: number;
private lastRecordedBufferLength: number;
private lastRecordedViewportHeight: number;
private lastTouchY: number;
/**
* Creates a new Viewport.
@@ -35,7 +36,8 @@ export class Viewport {
this.terminal.on('resize', this.syncScrollArea.bind(this));
this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
this.syncScrollArea();
// Perform this async to ensure the CharMeasure is ready.
setTimeout(() => this.syncScrollArea(), 0);
}
/**
@@ -56,6 +58,7 @@ export class Viewport {
if (rowHeightChanged || viewportHeightChanged) {
this.lastRecordedViewportHeight = this.terminal.rows;
this.viewportElement.style.height = this.charMeasure.height * this.terminal.rows + 'px';
this.terminal.selectionContainer.style.height = this.viewportElement.style.height;
}
this.scrollArea.style.height = (this.charMeasure.height * this.lastRecordedBufferLength) + 'px';
}
@@ -119,4 +122,26 @@ export class Viewport {
// Prevent the page from scrolling when the terminal scrolls
ev.preventDefault();
};
/**
* Handles the touchstart event, recording the touch occurred.
* @param ev The touch event.
*/
public onTouchStart(ev: TouchEvent) {
this.lastTouchY = ev.touches[0].pageY;
};
/**
* Handles the touchmove event, scrolling the viewport if the position shifted.
* @param ev The touch event.
*/
public onTouchMove(ev: TouchEvent) {
let deltaY = this.lastTouchY - ev.touches[0].pageY;
this.lastTouchY = ev.touches[0].pageY;
if (deltaY === 0) {
return;
}
this.viewportElement.scrollTop += deltaY;
ev.preventDefault();
};
}
+7 -2
View File
@@ -32,6 +32,9 @@
var exports = {};
exports.proposeGeometry = function (term) {
if (!term.element.parentElement) {
return null;
}
var parentElementStyle = window.getComputedStyle(term.element.parentElement),
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17),
@@ -53,7 +56,7 @@
subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
characterWidth = subjectRow.getBoundingClientRect().width;
subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
characterHeight = parseInt(subjectRow.offsetHeight);
characterHeight = subjectRow.getBoundingClientRect().height;
subjectRow.innerHTML = contentBuffer;
rows = parseInt(availableHeight / characterHeight);
@@ -66,7 +69,9 @@
exports.fit = function (term) {
var geometry = exports.proposeGeometry(term);
term.resize(geometry.cols, geometry.rows);
if (geometry) {
term.resize(geometry.cols, geometry.rows);
}
};
Xterm.prototype.proposeGeometry = function () {
-36
View File
@@ -1,36 +0,0 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="../../src/xterm.css" />
<link rel="stylesheet" href="../../demo/style.css" />
<script src="../../src/xterm.js"></script>
<script src="linkify.js"></script>
<style>
body {
color: #111;
}
#terminal-container {
max-width: 900px;
margin: 0 auto;
}
#terminal-container a {
color: #fff;
}
</style>
</head>
<body>
<div id="terminal-container"></div>
<script>
var term = new Terminal(),
container = document.getElementById('terminal-container');
term.open(container);
term.writeln('Hello, welcome to xterm.js');
term.writeln('');
term.writeln('Check it out at github.com/sourcelair/xterm.js');
term.linkify();
</script>
</body>
</html>
-207
View File
@@ -1,207 +0,0 @@
/**
* Methods for turning URL subscrings in the terminal's content into links (`a` DOM elements).
* @module xterm/addons/linkify/linkify
* @license MIT
*/
(function (linkify) {
if (typeof exports === 'object' && typeof module === 'object') {
/*
* CommonJS environment
*/
module.exports = linkify(require('../../xterm'));
} else if (typeof define == 'function') {
/*
* Require.js is available
*/
define(['../../xterm'], linkify);
} else {
/*
* Plain browser environment
*/
linkify(window.Terminal);
}
})(function (Xterm) {
'use strict';
var exports = {},
protocolClause = '(https?:\\/\\/)',
domainCharacterSet = '[\\da-z\\.-]+',
negatedDomainCharacterSet = '[^\\da-z\\.-]+',
domainBodyClause = '(' + domainCharacterSet + ')',
tldClause = '([a-z\\.]{2,6})',
ipClause = '((\\d{1,3}\\.){3}\\d{1,3})',
portClause = '(:\\d{1,5})',
hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + ')' + portClause + '?',
pathClause = '(\\/[\\/\\w\\.-]*)*',
negatedPathCharacterSet = '[^\\/\\w\\.-]+',
bodyClause = hostClause + pathClause,
start = '(?:^|' + negatedDomainCharacterSet + ')(',
end = ')($|' + negatedPathCharacterSet + ')',
lenientUrlClause = start + protocolClause + '?' + bodyClause + end,
strictUrlClause = start + protocolClause + bodyClause + end,
lenientUrlRegex = new RegExp(lenientUrlClause),
strictUrlRegex = new RegExp(strictUrlClause);
/**
* Converts all valid URLs found in the given terminal line into
* hyperlinks. The terminal line can be either the HTML element itself
* or the index of the termina line in the children of the terminal
* rows container.
*
* @param {Xterm} terminal - The terminal that owns the given line.
* @param {number|HTMLDivElement} line - The terminal line that should get
* "linkified".
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
* @param {string} target - Sets target="" attribute with value provided to links.
* Default doesn't set target attribute
* @emits linkify
* @emits linkify:line
*/
exports.linkifyTerminalLine = function (terminal, line, lenient, target) {
if (typeof line == 'number') {
line = terminal.rowContainer.children[line];
} else if (! (line instanceof HTMLDivElement)) {
var message = 'The "line" argument should be either a number';
message += ' or an HTMLDivElement';
throw new TypeError(message);
}
if (typeof target === 'undefined') {
target = '';
} else {
target = 'target="' + target + '"';
}
var buffer = document.createElement('span'),
nodes = line.childNodes;
for (var j=0; j<nodes.length; j++) {
var node = nodes[j],
match;
/**
* Since we cannot access the TextNode's HTML representation
* from the instance itself, we assign its data as textContent
* to a dummy buffer span, in order to retrieve the TextNode's
* HTML representation from the buffer's innerHTML.
*/
buffer.textContent = node.data;
var nodeHTML = buffer.innerHTML;
/**
* Apply function only on TextNodes
*/
if (node.nodeType != node.TEXT_NODE) {
continue;
}
var url = exports.findLinkMatch(node.data, lenient);
if (!url) {
continue;
}
var startsWithProtocol = new RegExp('^' + protocolClause),
urlHasProtocol = url.match(startsWithProtocol),
href = (urlHasProtocol) ? url : 'http://' + url,
link = '<a href="' + href + '" ' + target + '>' + url + '</a>',
newHTML = nodeHTML.replace(url, link);
line.innerHTML = line.innerHTML.replace(nodeHTML, newHTML);
}
/**
* This event gets emitted when conversion of all URL susbtrings
* to HTML anchor elements (links) has finished, for a specific
* line of the current Xterm instance.
*
* @event linkify:line
*/
terminal.emit('linkify:line', line);
};
/**
* Finds a link within a block of text.
*
* @param {string} text - The text to search .
* @param {boolean} lenient - Whether to use the lenient search.
* @return {string} A URL.
*/
exports.findLinkMatch = function (text, lenient) {
var match = text.match(lenient ? lenientUrlRegex : strictUrlRegex);
if (!match || match.length === 0) {
return null;
}
return match[1];
}
/**
* Converts all valid URLs found in the terminal view into hyperlinks.
*
* @param {Xterm} terminal - The terminal that should get "linkified".
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
* @param {string} target - Sets target="" attribute with value provided to links.
* Default doesn't set target attribute
* @emits linkify
* @emits linkify:line
*/
exports.linkify = function (terminal, lenient, target) {
var rows = terminal.rowContainer.children;
lenient = (typeof lenient == "boolean") ? lenient : true;
for (var i=0; i<rows.length; i++) {
var line = rows[i];
exports.linkifyTerminalLine(terminal, line, lenient, target);
}
/**
* This event gets emitted when conversion of all URL substrings to
* HTML anchor elements (links) has finished for the current Xterm
* instance's view.
*
* @event linkify
*/
terminal.emit('linkify');
};
/**
* Extend Xterm prototype.
*/
/**
* Converts all valid URLs found in the current terminal linte into
* hyperlinks.
*
* @memberof Xterm
* @param {number|HTMLDivElement} line - The terminal line that should get
* "linkified".
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
* @param {string} target - Sets target="" attribute with value provided to links.
* Default doesn't set target attribute
*/
Xterm.prototype.linkifyTerminalLine = function (line, lenient, target) {
return exports.linkifyTerminalLine(this, line, lenient, target);
};
/**
* Converts all valid URLs found in the current terminal into hyperlinks.
*
* @memberof Xterm
* @param {boolean} lenient - The regex type that will be used to identify links. If lenient is
* false, the regex requires a protocol clause. Defaults to true.
* @param {string} target - Sets target="" attribute with value provided to links.
* Default doesn't set target attribute
*/
Xterm.prototype.linkify = function (lenient, target) {
return exports.linkify(this, lenient, target);
};
return exports;
});
-5
View File
@@ -1,5 +0,0 @@
{
"name": "xterm.linkify",
"main": "linkify.js",
"private": true
}
+7 -11
View File
@@ -2,17 +2,13 @@ import { assert } from 'chai';
import * as Terminal from '../xterm';
import * as Clipboard from './Clipboard';
describe('evaluatePastedTextProcessing', function () {
it('should replace carriage return + line feed with line feed on windows', function () {
const pastedText = 'foo\r\nbar\r\n',
processedText = Clipboard.prepareTextForTerminal(pastedText, false),
windowsProcessedText = Clipboard.prepareTextForTerminal(pastedText, true);
describe('evaluateCopiedTextProcessing', function () {
it('should strip trailing whitespaces and replace nbsps with spaces', function () {
let nonBreakingSpace = String.fromCharCode(160),
copiedText = 'echo' + nonBreakingSpace + 'hello' + nonBreakingSpace,
processedText = Clipboard.prepareTextForClipboard(copiedText);
// No trailing spaces
assert.equal(processedText.match(/\s+$/), null);
// No non-breaking space
assert.equal(processedText.indexOf(nonBreakingSpace), -1);
assert.equal(processedText, 'foo\r\nbar\r\n');
assert.equal(windowsProcessedText, 'foo\rbar\r');
});
});
+51 -89
View File
@@ -5,7 +5,7 @@
* @license MIT
*/
import { ITerminal } from '../Interfaces';
import { ITerminal, ISelectionManager } from '../Interfaces';
interface IWindow extends Window {
clipboardData?: {
@@ -17,44 +17,29 @@ interface IWindow extends Window {
declare var window: IWindow;
/**
* Prepares text copied from terminal selection, to be saved in the clipboard by:
* 1. stripping all trailing white spaces
* 2. converting all non-breaking spaces to regular spaces
* @param {string} text The copied text that needs processing for storing in clipboard
* @returns {string}
* Prepares text to be pasted into the terminal by normalizing the line endings
* @param text The pasted text that needs processing before inserting into the terminal
*/
export function prepareTextForClipboard(text: string): string {
let space = String.fromCharCode(32),
nonBreakingSpace = String.fromCharCode(160),
allNonBreakingSpaces = new RegExp(nonBreakingSpace, 'g'),
processedText = text.split('\n').map(function (line) {
// Strip all trailing white spaces and convert all non-breaking spaces
// to regular spaces.
let processedLine = line.replace(/\s+$/g, '').replace(allNonBreakingSpaces, space);
return processedLine;
}).join('\n');
return processedText;
export function prepareTextForTerminal(text: string, isMSWindows: boolean): string {
if (isMSWindows) {
return text.replace(/\r?\n/g, '\r');
}
return text;
}
/**
* Binds copy functionality to the given terminal.
* @param {ClipboardEvent} ev The original copy event to be handled
*/
export function copyHandler(ev: ClipboardEvent, term: ITerminal) {
// We cast `window` to `any` type, because TypeScript has not declared the `clipboardData`
// property that we use below for Internet Explorer.
let copiedText = window.getSelection().toString(),
text = prepareTextForClipboard(copiedText);
export function copyHandler(ev: ClipboardEvent, term: ITerminal, selectionManager: ISelectionManager) {
if (term.browser.isMSIE) {
window.clipboardData.setData('Text', text);
window.clipboardData.setData('Text', selectionManager.selectionText);
} else {
ev.clipboardData.setData('text/plain', text);
ev.clipboardData.setData('text/plain', selectionManager.selectionText);
}
ev.preventDefault(); // Prevent or the original text will be copied.
// Prevent or the original text will be copied.
ev.preventDefault();
}
/**
@@ -68,8 +53,11 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal) {
let text: string;
let dispatchPaste = function(text) {
text = prepareTextForTerminal(text, term.browser.isMSWindows);
term.handler(text);
term.textarea.value = '';
term.emit('paste', text);
return term.cancel(ev);
};
@@ -87,68 +75,42 @@ export function pasteHandler(ev: ClipboardEvent, term: ITerminal) {
}
/**
* Bind to right-click event and allow right-click copy and paste.
*
* **Logic**
* If text is selected and right-click happens on selected text, then
* do nothing to allow seamless copying.
* If no text is selected or right-click is outside of the selection
* area, then bring the terminal's input below the cursor, in order to
* trigger the event on the textarea and allow-right click paste, without
* caring about disappearing selection.
* @param {MouseEvent} ev The original right click event to be handled
* @param {Terminal} term The terminal on which to apply the handled paste event
* Moves the textarea under the mouse cursor and focuses it.
* @param ev The original right click event to be handled.
* @param textarea The terminal's textarea.
*/
export function rightClickHandler(ev: MouseEvent, term: ITerminal) {
let s = document.getSelection(),
selectedText = prepareTextForClipboard(s.toString()),
clickIsOnSelection = false,
x = ev.clientX,
y = ev.clientY;
if (s.rangeCount) {
let r = s.getRangeAt(0),
cr = r.getClientRects();
for (let i = 0; i < cr.length; i++) {
let rect = cr[i];
clickIsOnSelection = (
(x > rect.left) && (x < rect.right) &&
(y > rect.top) && (y < rect.bottom)
);
if (clickIsOnSelection) {
break;
}
}
// If we clicked on selection and selection is not a single space,
// then mark the right click as copy-only. We check for the single
// space selection, as this can happen when clicking on an &nbsp;
// and there is not much pointing in copying a single space.
if (selectedText.match(/^\s$/) || !selectedText.length) {
clickIsOnSelection = false;
}
}
export function moveTextAreaUnderMouseCursor(ev: MouseEvent, textarea: HTMLTextAreaElement) {
// Bring textarea at the cursor position
if (!clickIsOnSelection) {
term.textarea.style.position = 'fixed';
term.textarea.style.width = '20px';
term.textarea.style.height = '20px';
term.textarea.style.left = (x - 10) + 'px';
term.textarea.style.top = (y - 10) + 'px';
term.textarea.style.zIndex = '1000';
term.textarea.focus();
textarea.style.position = 'fixed';
textarea.style.width = '20px';
textarea.style.height = '20px';
textarea.style.left = (ev.clientX - 10) + 'px';
textarea.style.top = (ev.clientY - 10) + 'px';
textarea.style.zIndex = '1000';
// Reset the terminal textarea's styling
setTimeout(function () {
term.textarea.style.position = null;
term.textarea.style.width = null;
term.textarea.style.height = null;
term.textarea.style.left = null;
term.textarea.style.top = null;
term.textarea.style.zIndex = null;
}, 4);
}
textarea.focus();
// Reset the terminal textarea's styling
setTimeout(function () {
textarea.style.position = null;
textarea.style.width = null;
textarea.style.height = null;
textarea.style.left = null;
textarea.style.top = null;
textarea.style.zIndex = null;
}, 4);
}
/**
* Bind to right-click event and allow right-click copy and paste.
* @param ev The original right click event to be handled.
* @param textarea The terminal's textarea.
* @param selectionManager The terminal's selection manager.
*/
export function rightClickHandler(ev: MouseEvent, textarea: HTMLTextAreaElement, selectionManager: ISelectionManager) {
moveTextAreaUnderMouseCursor(ev, textarea);
// Get textarea ready to copy from the context menu
textarea.value = selectionManager.selectionText;
textarea.select();
}
-48
View File
@@ -1,48 +0,0 @@
var assert = require('chai').assert;
var Terminal = require('../../xterm');
var linkify = require('../../addons/linkify/linkify');
describe('linkify addon', function () {
var xterm;
describe('API', function () {
it('should define Terminal.prototype.linkify', function () {
assert.isDefined(Terminal.prototype.linkify);
});
it('should define Terminal.prototype.linkifyTerminalLine', function () {
assert.isDefined(Terminal.prototype.linkifyTerminalLine);
});
});
describe('findUrlMatchOnLine', function () {
describe('strict regex', function () {
it('should match when the entire text is a match', function () {
assert.equal(linkify.findLinkMatch('http://github.com', false), 'http://github.com');
assert.equal(linkify.findLinkMatch('http://127.0.0.1', false), 'http://127.0.0.1');
});
it('should match simple domains', function () {
assert.equal(linkify.findLinkMatch('foo http://github.com bar', false), 'http://github.com');
assert.equal(linkify.findLinkMatch('foo http://www.github.com bar', false), 'http://www.github.com');
assert.equal(linkify.findLinkMatch('foo https://github.com bar', false), 'https://github.com');
assert.equal(linkify.findLinkMatch('foo https://www.github.com bar', false), 'https://www.github.com');
});
it('should match web addresses with alpha paths', function () {
assert.equal(linkify.findLinkMatch('foo http://github.com/a/b/c bar', false), 'http://github.com/a/b/c');
assert.equal(linkify.findLinkMatch('foo http://www.github.com/a/b/c bar', false), 'http://www.github.com/a/b/c');
});
it('should not include whitespace surrounding a match', function () {
assert.equal(linkify.findLinkMatch(' http://github.com', false), 'http://github.com');
assert.equal(linkify.findLinkMatch('http://github.com ', false), 'http://github.com');
assert.equal(linkify.findLinkMatch(' http://github.com ', false), 'http://github.com');
});
it('should match IP addresses', function () {
assert.equal(linkify.findLinkMatch('foo http://127.0.0.1 bar', false), 'http://127.0.0.1');
assert.equal(linkify.findLinkMatch('foo https://127.0.0.1 bar', false), 'https://127.0.0.1');
});
it('should match ports on both domains and IP addresses', function () {
assert.equal(linkify.findLinkMatch('foo http://127.0.0.1:8080 bar', false), 'http://127.0.0.1:8080');
assert.equal(linkify.findLinkMatch('foo http://www.github.com:8080 bar', false), 'http://www.github.com:8080');
});
});
});
});
+28 -6
View File
@@ -21,7 +21,8 @@ describe('xterm.js', function() {
};
xterm.element = {
classList: {
toggle: function(){}
toggle: function(){},
remove: function(){}
}
};
});
@@ -54,6 +55,11 @@ describe('xterm.js', function() {
it('should throw when setting a non-existant option', function() {
assert.throws(xterm.setOption.bind(xterm, 'fake', true));
});
it('should not allow scrollback less than number of rows', function() {
let setOptionCall = xterm.setOption.bind(xterm, 'scrollback', xterm.rows - 1);
assert.equal(setOptionCall(), false);
});
});
describe('clear', function() {
@@ -370,12 +376,17 @@ describe('xterm.js', function() {
});
});
describe('attachCustomEventHandler', function () {
describe('attachCustomKeyEventHandler', function () {
var evKeyDown = {
preventDefault: function() {},
stopPropagation: function() {},
type: 'keydown'
}
var evKeyPress = {
preventDefault: function() {},
stopPropagation: function() {},
type: 'keypress'
}
beforeEach(function() {
xterm.handler = function() {};
@@ -386,29 +397,39 @@ describe('xterm.js', function() {
bind: function() {
return function () { return true; }
}
},
keypress: {
bind: function() {
return function () { return true; }
}
}
}
});
it('should process the keydown event based on what the handler returns', function () {
it('should process the keydown/keypress event based on what the handler returns', function () {
assert.equal(xterm.keyDown(Object.assign({}, evKeyDown, { keyCode: 77 })), true);
xterm.attachCustomKeydownHandler(function (ev) {
assert.equal(xterm.keyPress(Object.assign({}, evKeyPress, { keyCode: 77 })), true);
xterm.attachCustomKeyEventHandler(function (ev) {
return ev.keyCode === 77;
});
assert.equal(xterm.keyDown(Object.assign({}, evKeyDown, { keyCode: 77 })), true);
xterm.attachCustomKeydownHandler(function (ev) {
assert.equal(xterm.keyPress(Object.assign({}, evKeyPress, { keyCode: 77 })), true);
xterm.attachCustomKeyEventHandler(function (ev) {
return ev.keyCode !== 77;
});
assert.equal(xterm.keyDown(Object.assign({}, evKeyDown, { keyCode: 77 })), false);
assert.equal(xterm.keyPress(Object.assign({}, evKeyPress, { keyCode: 77 })), false);
});
it('should alive after reset(ESC c Full Reset (RIS))', function () {
xterm.attachCustomKeydownHandler(function (ev) {
xterm.attachCustomKeyEventHandler(function (ev) {
return ev.keyCode !== 77;
});
assert.equal(xterm.keyDown(Object.assign({}, evKeyDown, { keyCode: 77 })), false);
assert.equal(xterm.keyPress(Object.assign({}, evKeyPress, { keyCode: 77 })), false);
xterm.reset();
assert.equal(xterm.keyDown(Object.assign({}, evKeyDown, { keyCode: 77 })), false);
assert.equal(xterm.keyPress(Object.assign({}, evKeyPress, { keyCode: 77 })), false);
});
});
@@ -550,6 +571,7 @@ describe('xterm.js', function() {
describe('unicode - surrogates', function() {
it('2 characters per cell', function () {
this.timeout(10000); // This is needed because istanbul patches code and slows it down
var high = String.fromCharCode(0xD800);
for (var i=0xDC00; i<=0xDCFF; ++i) {
xterm.write(high + String.fromCharCode(i));
+1
View File
@@ -20,3 +20,4 @@ export const isMac = contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], pla
export const isIpad = platform === 'iPad';
export const isIphone = platform === 'iPhone';
export const isMSWindows = contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
export const isLinux = platform.indexOf('Linux') >= 0;
+77
View File
@@ -0,0 +1,77 @@
/**
* @license MIT
*/
import jsdom = require('jsdom');
import { assert } from 'chai';
import { ICharMeasure, ITerminal } from '../Interfaces';
import { CharMeasure } from './CharMeasure';
describe('CharMeasure', () => {
let window: Window;
let document: Document;
let container: HTMLElement;
let charMeasure: ICharMeasure;
beforeEach(done => {
jsdom.env('', (err, w) => {
window = w;
document = window.document;
container = document.createElement('div');
document.body.appendChild(container);
charMeasure = new CharMeasure(document, container);
done();
});
});
describe('measure', () => {
it('should set _measureElement on first call', () => {
charMeasure.measure();
assert.isDefined((<any>charMeasure)._measureElement, 'CharMeasure.measure should have created _measureElement');
});
it('should be performed async on first call', done => {
assert.equal(charMeasure.width, null);
charMeasure.measure();
// Mock getBoundingClientRect since jsdom doesn't have a layout engine
(<any>charMeasure)._measureElement.getBoundingClientRect = () => {
return { width: 1, height: 1 };
};
assert.equal(charMeasure.width, null);
setTimeout(() => {
assert.equal(charMeasure.width, 1);
done();
}, 0);
});
it('should be performed sync on successive calls', done => {
charMeasure.measure();
// Mock getBoundingClientRect since jsdom doesn't have a layout engine
(<any>charMeasure)._measureElement.getBoundingClientRect = () => {
return { width: 1, height: 1 };
};
setTimeout(() => {
const firstWidth = charMeasure.width;
// Mock getBoundingClientRect since jsdom doesn't have a layout engine
(<any>charMeasure)._measureElement.getBoundingClientRect = () => {
return { width: 2, height: 2 };
};
charMeasure.measure();
assert.equal(charMeasure.width, firstWidth * 2);
done();
}, 0);
});
it('should NOT do a measure when the parent is hidden', done => {
charMeasure.measure();
setTimeout(() => {
const firstWidth = charMeasure.width;
container.style.display = 'none';
container.style.fontSize = '2em';
charMeasure.measure();
assert.equal(charMeasure.width, firstWidth);
done();
}, 0);
});
});
});
+5 -2
View File
@@ -9,13 +9,15 @@ import { EventEmitter } from '../EventEmitter.js';
* Utility class that measures the size of a character.
*/
export class CharMeasure extends EventEmitter {
private _document: Document;
private _parentElement: HTMLElement;
private _measureElement: HTMLElement;
private _width: number;
private _height: number;
constructor(parentElement: HTMLElement) {
constructor(document: Document, parentElement: HTMLElement) {
super();
this._document = document;
this._parentElement = parentElement;
}
@@ -29,11 +31,12 @@ export class CharMeasure extends EventEmitter {
public measure(): void {
if (!this._measureElement) {
this._measureElement = document.createElement('span');
this._measureElement = this._document.createElement('span');
this._measureElement.style.position = 'absolute';
this._measureElement.style.top = '0';
this._measureElement.style.left = '-9999em';
this._measureElement.textContent = 'W';
this._measureElement.setAttribute('aria-hidden', 'true');
this._parentElement.appendChild(this._measureElement);
// Perform _doMeasure async if the element was just attached as sometimes
// getBoundingClientRect does not return accurate values without this.
+22 -4
View File
@@ -4,12 +4,15 @@
* @module xterm/utils/CircularList
* @license MIT
*/
export class CircularList<T> {
import { EventEmitter } from '../EventEmitter';
export class CircularList<T> extends EventEmitter {
private _array: T[];
private _startIndex: number;
private _length: number;
constructor(maxLength: number) {
super();
this._array = new Array<T>(maxLength);
this._startIndex = 0;
this._length = 0;
@@ -43,8 +46,14 @@ export class CircularList<T> {
this._length = newLength;
}
public get forEach(): (callbackfn: (value: T, index: number, array: T[]) => void) => void {
return this._array.forEach;
public get forEach(): (callbackfn: (value: T, index: number) => void) => void {
return (callbackfn: (value: T, index: number) => void) => {
let i = 0;
let length = this.length;
for (let i = 0; i < length; i++) {
callbackfn(this.get(i), i);
}
};
}
/**
@@ -83,6 +92,7 @@ export class CircularList<T> {
if (this._startIndex === this.maxLength) {
this._startIndex = 0;
}
this.emit('trim', 1);
} else {
this._length++;
}
@@ -106,13 +116,16 @@ export class CircularList<T> {
* @param items The items to insert.
*/
public splice(start: number, deleteCount: number, ...items: T[]): void {
// Delete items
if (deleteCount) {
for (let i = start; i < this._length - deleteCount; i++) {
this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
}
this._length -= deleteCount;
}
if (items && items.length) {
// Add items
for (let i = this._length - 1; i >= start; i--) {
this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
}
@@ -120,9 +133,12 @@ export class CircularList<T> {
this._array[this._getCyclicIndex(start + i)] = items[i];
}
// Adjust length as needed
if (this._length + items.length > this.maxLength) {
this._startIndex += (this._length + items.length) - this.maxLength;
const countToTrim = (this._length + items.length) - this.maxLength;
this._startIndex += countToTrim;
this._length = this.maxLength;
this.emit('trim', countToTrim);
} else {
this._length += items.length;
}
@@ -139,6 +155,7 @@ export class CircularList<T> {
}
this._startIndex += count;
this._length -= count;
this.emit('trim', count);
}
public shiftElements(start: number, count: number, offset: number): void {
@@ -162,6 +179,7 @@ export class CircularList<T> {
while (this._length > this.maxLength) {
this._length--;
this._startIndex++;
this.emit('trim', 1);
}
}
} else {
+47
View File
@@ -0,0 +1,47 @@
import { assert } from 'chai';
import { DomElementObjectPool } from './DomElementObjectPool';
class MockDocument {
private _attr: {[key: string]: string} = {};
constructor() {}
public getAttribute(key: string): string { return this._attr[key]; };
public setAttribute(key: string, value: string): void { this._attr[key] = value; }
}
describe('DomElementObjectPool', () => {
let pool: DomElementObjectPool;
beforeEach(() => {
pool = new DomElementObjectPool('span');
(<any>global).document = {
createElement: () => new MockDocument()
};
});
it('should acquire distinct elements', () => {
const element1 = pool.acquire();
const element2 = pool.acquire();
assert.notEqual(element1, element2);
});
it('should acquire released elements', () => {
const element = pool.acquire();
pool.release(element);
assert.equal(pool.acquire(), element);
});
it('should handle a series of acquisitions and releases', () => {
const element1 = pool.acquire();
const element2 = pool.acquire();
pool.release(element1);
assert.equal(pool.acquire(), element1);
pool.release(element1);
pool.release(element2);
assert.equal(pool.acquire(), element2);
assert.equal(pool.acquire(), element1);
});
it('should throw when releasing an element that was not acquired', () => {
assert.throws(() => pool.release(document.createElement('span')));
});
});
+75
View File
@@ -0,0 +1,75 @@
/**
* @module xterm/utils/DomElementObjectPool
* @license MIT
*/
/**
* An object pool that manages acquisition and releasing of DOM elements for
* when reuse is desirable.
*/
export class DomElementObjectPool {
private static readonly OBJECT_ID_ATTRIBUTE = 'data-obj-id';
private static _objectCount = 0;
private _type: string;
private _pool: HTMLElement[];
private _inUse: {[key: string]: HTMLElement};
/**
* @param type The DOM element type (div, span, etc.).
*/
constructor(private type: string) {
this._type = type;
this._pool = [];
this._inUse = {};
}
/**
* Acquire an element from the pool, creating it if the pool is empty.
*/
public acquire(): HTMLElement {
let element: HTMLElement;
if (this._pool.length === 0) {
element = this._createNew();
} else {
element = this._pool.pop();
}
this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)] = element;
return element;
}
/**
* Release an element back into the pool. It's up to the caller of this
* function to ensure that all external references to the element have been
* removed.
* @param element The element being released.
*/
public release(element: HTMLElement): void {
if (!this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)]) {
throw new Error('Could not release an element not yet acquired');
}
delete this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)];
this._cleanElement(element);
this._pool.push(element);
}
/**
* Creates a new element for the pool.
*/
private _createNew(): HTMLElement {
const element = document.createElement(this._type);
const id = DomElementObjectPool._objectCount++;
element.setAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE, id.toString(10));
return element;
}
/**
* Resets an element back to a "clean state".
* @param element The element to be cleaned.
*/
private _cleanElement(element: HTMLElement): void {
element.className = '';
element.innerHTML = '';
}
}
+73
View File
@@ -0,0 +1,73 @@
/**
* @license MIT
*/
import { CharMeasure } from './CharMeasure';
export function getCoordsRelativeToElement(event: MouseEvent, element: HTMLElement): [number, number] {
// Ignore browsers that don't support MouseEvent.pageX
if (event.pageX == null) {
return null;
}
let x = event.pageX;
let y = event.pageY;
// Converts the coordinates from being relative to the document to being
// relative to the terminal.
while (element && element !== self.document.documentElement) {
x -= element.offsetLeft;
y -= element.offsetTop;
element = 'offsetParent' in element ? <HTMLElement>element.offsetParent : <HTMLElement>element.parentElement;
}
return [x, y];
}
/**
* Gets coordinates within the terminal for a particular mouse event. The result
* is returned as an array in the form [x, y] instead of an object as it's a
* little faster and this function is used in some low level code.
* @param event The mouse event.
* @param rowContainer The terminal's row container.
* @param charMeasure The char measure object used to determine character sizes.
* @param colCount The number of columns in the terminal.
* @param rowCount The number of rows n the terminal.
* @param isSelection Whether the request is for the selection or not. This will
* apply an offset to the x value such that the left half of the cell will
* select that cell and the right half will select the next cell.
*/
export function getCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure, colCount: number, rowCount: number, isSelection?: boolean): [number, number] {
const coords = getCoordsRelativeToElement(event, rowContainer);
// Convert to cols/rows.
coords[0] = Math.ceil((coords[0] + (isSelection ? charMeasure.width / 2 : 0)) / charMeasure.width);
coords[1] = Math.ceil(coords[1] / charMeasure.height);
// Ensure coordinates are within the terminal viewport.
coords[0] = Math.min(Math.max(coords[0], 1), colCount + 1);
coords[1] = Math.min(Math.max(coords[1], 1), rowCount + 1);
return coords;
}
/**
* Gets coordinates within the terminal for a particular mouse event, wrapping
* them to the bounds of the terminal and adding 32 to both the x and y values
* as expected by xterm.
* @param event The mouse event.
* @param rowContainer The terminal's row container.
* @param charMeasure The char measure object used to determine character sizes.
* @param colCount The number of columns in the terminal.
* @param rowCount The number of rows in the terminal.
*/
export function getRawByteCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure, colCount: number, rowCount: number): { x: number, y: number } {
const coords = getCoords(event, rowContainer, charMeasure, colCount, rowCount);
let x = coords[0];
let y = coords[1];
// xterm sends raw bytes and starts at 32 (SP) for each.
x += 32;
y += 32;
return { x, y };
}
+48 -20
View File
@@ -41,6 +41,9 @@
font-family: courier-new, courier, monospace;
font-feature-settings: "liga" 0;
position: relative;
user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
}
.terminal.focus,
@@ -71,7 +74,22 @@
resize: none;
}
.terminal:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar) .terminal-cursor {
.terminal a {
color: inherit;
text-decoration: none;
}
.terminal a:hover {
cursor: pointer;
text-decoration: underline;
}
.terminal a.xterm-invalid-link:hover {
cursor: text;
text-decoration: none;
}
.terminal.focus:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar) .terminal-cursor {
background-color: #fff;
color: #000;
}
@@ -82,19 +100,9 @@
background-color: transparent;
}
.terminal:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar).focus.xterm-cursor-blink .terminal-cursor {
animation: xterm-cursor-blink 1.2s infinite step-end;
}
@keyframes xterm-cursor-blink {
0% {
background-color: #fff;
color: #000;
}
50% {
background-color: transparent;
color: #FFF;
}
.terminal:not(.xterm-cursor-style-underline):not(.xterm-cursor-style-bar).focus.xterm-cursor-blink-on .terminal-cursor {
background-color: transparent;
color: inherit;
}
.terminal.xterm-cursor-style-bar .terminal-cursor,
@@ -120,13 +128,13 @@
right: 0;
height: 1px;
}
.terminal.xterm-cursor-style-bar.focus.xterm-cursor-blink.xterm-cursor-blink-on .terminal-cursor::before,
.terminal.xterm-cursor-style-underline.focus.xterm-cursor-blink.xterm-cursor-blink-on .terminal-cursor::before {
background-color: transparent;
}
.terminal.xterm-cursor-style-bar.focus.xterm-cursor-blink .terminal-cursor::before,
.terminal.xterm-cursor-style-underline.focus.xterm-cursor-blink .terminal-cursor::before {
animation: xterm-cursor-non-bar-blink 1.2s infinite step-end;
}
@keyframes xterm-cursor-non-bar-blink {
0% { background-color: #fff; }
50% { background-color: transparent; }
background-color: #fff;
}
.terminal .composition-view {
@@ -148,7 +156,8 @@
overflow-y: scroll;
}
.terminal .xterm-wide-char {
.terminal .xterm-wide-char,
.terminal .xterm-normal-char {
display: inline-block;
}
@@ -174,6 +183,25 @@
left: -9999em;
}
.terminal.enable-mouse-events {
/* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
cursor: default;
}
.terminal .xterm-selection {
position: absolute;
top: 0;
left: 0;
z-index: 1;
opacity: 0.3;
pointer-events: none;
}
.terminal .xterm-selection div {
position: absolute;
background-color: #fff;
}
/*
* Determine default colors for xterm.js
*/
+322 -107
View File
@@ -13,16 +13,19 @@
import { CompositionHelper } from './CompositionHelper';
import { EventEmitter } from './EventEmitter';
import { Viewport } from './Viewport';
import { rightClickHandler, pasteHandler, copyHandler } from './handlers/Clipboard';
import { rightClickHandler, moveTextAreaUnderMouseCursor, pasteHandler, copyHandler } from './handlers/Clipboard';
import { CircularList } from './utils/CircularList';
import { C0 } from './EscapeSequences';
import { InputHandler } from './InputHandler';
import { Parser } from './Parser';
import { Renderer } from './Renderer';
import { Linkifier } from './Linkifier';
import { SelectionManager } from './SelectionManager';
import { CharMeasure } from './utils/CharMeasure';
import * as Browser from './utils/Browser';
import * as Keyboard from './utils/Keyboard';
import * as Mouse from './utils/Mouse';
import { CHARSETS } from './Charsets';
import { getRawByteCoords } from './utils/Mouse';
/**
* Terminal Emulation References:
@@ -51,6 +54,13 @@ var WRITE_BUFFER_PAUSE_THRESHOLD = 5;
*/
var WRITE_BATCH_SIZE = 300;
/**
* The time between cursor blinks. This is driven by JS rather than a CSS
* animation due to a bug in Chromium that causes it to use excessive CPU time.
* See https://github.com/Microsoft/vscode/issues/22900
*/
var CURSOR_BLINK_INTERVAL = 600;
/**
* Terminal
*/
@@ -157,7 +167,8 @@ function Terminal(options) {
this.queue = '';
this.scrollTop = 0;
this.scrollBottom = this.rows - 1;
this.customKeydownHandler = null;
this.customKeyEventHandler = null;
this.cursorBlinkInterval = null;
// modes
this.applicationKeypad = false;
@@ -210,6 +221,8 @@ function Terminal(options) {
this.parser = new Parser(this.inputHandler, this);
// Reuse renderer if the Terminal is being recreated via a Terminal.reset call.
this.renderer = this.renderer || null;
this.selectionManager = this.selectionManager || null;
this.linkifier = this.linkifier || new Linkifier();
// user input states
this.writeBuffer = [];
@@ -238,6 +251,10 @@ function Terminal(options) {
while (i--) {
this.lines.push(this.blankLine());
}
// Ensure the selection manager has the correct buffer
if (this.selectionManager) {
this.selectionManager.setBuffer(this.lines);
}
this.tabs;
this.setupStops();
@@ -402,6 +419,15 @@ Terminal.prototype.setOption = function(key, value) {
}
switch (key) {
case 'scrollback':
if (value < this.rows) {
let msg = 'Setting the scrollback value less than the number of rows ';
msg += `(${this.rows}) is not allowed.`;
console.warn(msg);
return false;
}
if (this.options[key] !== value) {
if (this.lines.length > value) {
const amountToTrim = this.lines.length - value;
@@ -421,7 +447,7 @@ Terminal.prototype.setOption = function(key, value) {
this[key] = value;
this.options[key] = value;
switch (key) {
case 'cursorBlink': this.element.classList.toggle('xterm-cursor-blink', value); break;
case 'cursorBlink': this.setCursorBlinking(value); break;
case 'cursorStyle':
// Style 'block' applies with no class
this.element.classList.toggle(`xterm-cursor-style-underline`, value === 'underline');
@@ -431,6 +457,29 @@ Terminal.prototype.setOption = function(key, value) {
}
};
Terminal.prototype.restartCursorBlinking = function () {
this.setCursorBlinking(this.options.cursorBlink);
};
Terminal.prototype.setCursorBlinking = function (enabled) {
this.element.classList.toggle('xterm-cursor-blink', enabled);
this.clearCursorBlinkingInterval();
if (enabled) {
var self = this;
this.cursorBlinkInterval = setInterval(function () {
self.element.classList.toggle('xterm-cursor-blink-on');
}, CURSOR_BLINK_INTERVAL);
}
};
Terminal.prototype.clearCursorBlinkingInterval = function () {
this.element.classList.remove('xterm-cursor-blink-on');
if (this.cursorBlinkInterval) {
clearInterval(this.cursorBlinkInterval);
this.cursorBlinkInterval = null;
}
};
/**
* Binds the desired focus behavior on a given terminal object.
*
@@ -443,6 +492,7 @@ Terminal.bindFocus = function (term) {
}
term.element.classList.add('focus');
term.showCursor();
term.restartCursorBlinking.apply(term);
Terminal.focus = term;
term.emit('focus', {terminal: term});
});
@@ -467,6 +517,7 @@ Terminal.bindBlur = function (term) {
term.send(C0.ESC + '[O');
}
term.element.classList.remove('focus');
term.clearCursorBlinkingInterval.apply(term);
Terminal.focus = null;
term.emit('blur', {terminal: term});
});
@@ -483,28 +534,43 @@ Terminal.prototype.initGlobal = function() {
Terminal.bindBlur(this);
// Bind clipboard functionality
on(this.element, 'copy', function (ev) {
copyHandler.call(this, ev, term);
});
on(this.textarea, 'paste', function (ev) {
pasteHandler.call(this, ev, term);
});
on(this.element, 'paste', function (ev) {
pasteHandler.call(this, ev, term);
on(this.element, 'copy', event => {
// If mouse events are active it means the selection manager is disabled and
// copy should be handled by the host program.
if (this.mouseEvents) {
return;
}
copyHandler(event, term, this.selectionManager);
});
const pasteHandlerWrapper = event => pasteHandler(event, term);
on(this.textarea, 'paste', pasteHandlerWrapper);
on(this.element, 'paste', pasteHandlerWrapper);
function rightClickHandlerWrapper (ev) {
rightClickHandler.call(this, ev, term);
}
// Handle right click context menus
if (term.browser.isFirefox) {
on(this.element, 'mousedown', function (ev) {
if (ev.button == 2) {
rightClickHandlerWrapper(ev);
// Firefox doesn't appear to fire the contextmenu event on right click
on(this.element, 'mousedown', event => {
if (event.button == 2) {
rightClickHandler(event, this.textarea, this.selectionManager);
}
});
} else {
on(this.element, 'contextmenu', rightClickHandlerWrapper);
on(this.element, 'contextmenu', event => {
rightClickHandler(event, this.textarea, this.selectionManager);
});
}
// Move the textarea under the cursor when middle clicking on Linux to ensure
// middle click to paste selection works. This only appears to work in Chrome
// at the time is writing.
if (term.browser.isLinux) {
// Use auxclick event over mousedown the latter doesn't seem to work. Note
// that the regular click event doesn't fire for the middle mouse button.
on(this.element, 'auxclick', event => {
if (event.button === 1) {
moveTextAreaUnderMouseCursor(event, this.textarea, this.selectionManager);
}
});
}
};
@@ -546,6 +612,9 @@ Terminal.bindKeys = function(term) {
on(term.textarea, 'compositionupdate', term.compositionHelper.compositionupdate.bind(term.compositionHelper));
on(term.textarea, 'compositionend', term.compositionHelper.compositionend.bind(term.compositionHelper));
term.on('refresh', term.compositionHelper.updateCompositionElements.bind(term.compositionHelper));
term.on('refresh', function (data) {
term.queueLinkification(data.start, data.end)
});
};
@@ -569,8 +638,9 @@ Terminal.prototype.insertRow = function (row) {
* Opens the terminal within an element.
*
* @param {HTMLElement} parent The element to create the terminal within.
* @param {boolean} focus Focus the terminal, after it gets instantiated in the DOM
*/
Terminal.prototype.open = function(parent) {
Terminal.prototype.open = function(parent, focus) {
var self=this, i=0, div;
this.parent = parent || this.parent;
@@ -589,9 +659,8 @@ Terminal.prototype.open = function(parent) {
this.element.classList.add('terminal');
this.element.classList.add('xterm');
this.element.classList.add('xterm-theme-' + this.theme);
this.element.classList.toggle('xterm-cursor-blink', this.options.cursorBlink);
this.setCursorBlinking(this.options.cursorBlink);
this.element.style.height
this.element.setAttribute('tabindex', 0);
this.viewportElement = document.createElement('div');
@@ -601,12 +670,18 @@ Terminal.prototype.open = function(parent) {
this.viewportScrollArea.classList.add('xterm-scroll-area');
this.viewportElement.appendChild(this.viewportScrollArea);
// Create the selection container.
this.selectionContainer = document.createElement('div');
this.selectionContainer.classList.add('xterm-selection');
this.element.appendChild(this.selectionContainer);
// Create the container that will hold the lines of the terminal and then
// produce the lines the lines.
this.rowContainer = document.createElement('div');
this.rowContainer.classList.add('xterm-rows');
this.element.appendChild(this.rowContainer);
this.children = [];
this.linkifier.attachToDom(document, this.children);
// Create the container that will hold helpers like the textarea for
// capturing DOM Events. Then produce the helpers.
@@ -641,14 +716,28 @@ Terminal.prototype.open = function(parent) {
}
this.parent.appendChild(this.element);
this.charMeasure = new CharMeasure(this.helperContainer);
this.charMeasure = new CharMeasure(document, this.helperContainer);
this.charMeasure.on('charsizechanged', function () {
self.updateCharSizeCSS();
self.updateCharSizeStyles();
});
this.charMeasure.measure();
this.viewport = new Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
this.renderer = new Renderer(this);
this.selectionManager = new SelectionManager(this, this.lines, this.rowContainer, this.charMeasure);
this.selectionManager.on('refresh', data => {
this.renderer.refreshSelection(data.start, data.end);
});
this.selectionManager.on('newselection', text => {
// If there's a new selection, put it into the textarea, focus and select it
// in order to register it as a selection on the OS. This event is fired
// only on Linux to enable middle click to paste selection.
this.textarea.value = text;
this.textarea.focus();
this.textarea.select();
});
this.on('scroll', () => this.selectionManager.refresh());
this.viewportElement.addEventListener('scroll', () => this.selectionManager.refresh());
// Setup loop that draws to screen
this.refresh(0, this.rows - 1);
@@ -657,8 +746,23 @@ Terminal.prototype.open = function(parent) {
// need to be taken on the document.
this.initGlobal();
// Ensure there is a Terminal.focus.
this.focus();
/**
* Automatic focus functionality.
* TODO: Default to `false` starting with xterm.js 3.0.
*/
if (typeof focus == 'undefined') {
let message = 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
message += 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
message += 'it will default to `false`.';
console.warn(message);
focus = true;
}
if (focus) {
this.focus();
}
on(this.element, 'click', function() {
var selection = document.getSelection(),
@@ -704,8 +808,11 @@ Terminal.loadAddon = function(addon, callback) {
* Updates the helper CSS class with any changes necessary after the terminal's
* character width has been changed.
*/
Terminal.prototype.updateCharSizeCSS = function() {
this.charSizeStyleElement.textContent = '.xterm-wide-char{width:' + (this.charMeasure.width * 2) + 'px;}';
Terminal.prototype.updateCharSizeStyles = function() {
this.charSizeStyleElement.textContent =
`.xterm-wide-char{width:${this.charMeasure.width * 2}px;}` +
`.xterm-normal-char{width:${this.charMeasure.width}px;}` +
`.xterm-rows > div{height:${this.charMeasure.height}px;}`;
}
/**
@@ -732,7 +839,7 @@ Terminal.prototype.bindMouse = function() {
button = getButton(ev);
// get mouse coordinates
pos = getCoords(ev);
pos = getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
if (!pos) return;
sendEvent(button, pos);
@@ -760,7 +867,7 @@ Terminal.prototype.bindMouse = function() {
var button = pressed
, pos;
pos = getCoords(ev);
pos = getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
if (!pos) return;
// buttons marked as motions
@@ -935,52 +1042,6 @@ Terminal.prototype.bindMouse = function() {
return button;
}
// mouse coordinates measured in cols/rows
function getCoords(ev) {
var x, y, w, h, el;
// ignore browsers without pageX for now
if (ev.pageX == null) return;
x = ev.pageX;
y = ev.pageY;
el = self.element;
// should probably check offsetParent
// but this is more portable
while (el && el !== self.document.documentElement) {
x -= el.offsetLeft;
y -= el.offsetTop;
el = 'offsetParent' in el
? el.offsetParent
: el.parentNode;
}
// convert to cols/rows
w = self.element.clientWidth;
h = self.element.clientHeight;
x = Math.ceil((x / w) * self.cols);
y = Math.ceil((y / h) * self.rows);
// be sure to avoid sending
// bad positions to the program
if (x < 0) x = 0;
if (x > self.cols) x = self.cols;
if (y < 0) y = 0;
if (y > self.rows) y = self.rows;
// xterm sends raw bytes and
// starts at 32 (SP) for each.
x += 32;
y += 32;
return {
x: x,
y: y,
type: 'wheel'
};
}
on(el, 'mousedown', function(ev) {
if (!self.mouseEvents) return;
@@ -1034,6 +1095,18 @@ Terminal.prototype.bindMouse = function() {
self.viewport.onWheel(ev);
return self.cancel(ev);
});
on(el, 'touchstart', function(ev) {
if (self.mouseEvents) return;
self.viewport.onTouchStart(ev);
return self.cancel(ev);
});
on(el, 'touchmove', function(ev) {
if (self.mouseEvents) return;
self.viewport.onTouchMove(ev);
return self.cancel(ev);
});
};
/**
@@ -1054,8 +1127,8 @@ Terminal.prototype.destroy = function() {
/**
* Tells the renderer to refresh terminal content between two rows (inclusive) at the next
* opportunity.
* @param {number} start The row to start from (between 0 and terminal's height terminal - 1)
* @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
* @param {number} start The row to start from (between 0 and this.rows - 1).
* @param {number} end The row to end at (between start and this.rows - 1).
*/
Terminal.prototype.refresh = function(start, end) {
if (this.renderer) {
@@ -1063,6 +1136,19 @@ Terminal.prototype.refresh = function(start, end) {
}
};
/**
* Queues linkification for the specified rows.
* @param {number} start The row to start from (between 0 and this.rows - 1).
* @param {number} end The row to end at (between start and this.rows - 1).
*/
Terminal.prototype.queueLinkification = function(start, end) {
if (this.linkifier) {
for (let i = start; i <= end; i++) {
this.linkifier.linkifyRow(i);
}
}
};
/**
* Display the cursor element
*/
@@ -1075,8 +1161,10 @@ Terminal.prototype.showCursor = function() {
/**
* Scroll the terminal down 1 row, creating a blank line.
* @param {boolean} isWrapped Whether the new line is wrapped from the previous
* line.
*/
Terminal.prototype.scroll = function() {
Terminal.prototype.scroll = function(isWrapped) {
var row;
// Make room for the new row in lines
@@ -1103,10 +1191,10 @@ Terminal.prototype.scroll = function() {
if (row === this.lines.length) {
// Optimization: pushing is faster than splicing when they amount to the same behavior
this.lines.push(this.blankLine());
this.lines.push(this.blankLine(undefined, isWrapped));
} else {
// add our new line
this.lines.splice(row, 0, this.blankLine());
this.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
}
if (this.scrollTop !== 0) {
@@ -1141,6 +1229,9 @@ Terminal.prototype.scroll = function() {
*/
Terminal.prototype.scrollDisp = function(disp, suppressScrollEvent) {
if (disp < 0) {
if (this.ydisp === 0) {
return;
}
this.userScrolling = true;
} else if (disp + this.ydisp >= this.ybase) {
this.userScrolling = false;
@@ -1167,25 +1258,25 @@ Terminal.prototype.scrollDisp = function(disp, suppressScrollEvent) {
*/
Terminal.prototype.scrollPages = function(pageCount) {
this.scrollDisp(pageCount * (this.rows - 1));
}
};
/**
* Scrolls the display of the terminal to the top.
*/
Terminal.prototype.scrollToTop = function() {
this.scrollDisp(-this.ydisp);
}
};
/**
* Scrolls the display of the terminal to the bottom.
*/
Terminal.prototype.scrollToBottom = function() {
this.scrollDisp(this.ybase - this.ydisp);
}
};
/**
* Writes text to the terminal.
* @param {string} text The text to write to the terminal.
* @param {string} data The text to write to the terminal.
*/
Terminal.prototype.write = function(data) {
this.writeBuffer.push(data);
@@ -1209,7 +1300,7 @@ Terminal.prototype.write = function(data) {
self.innerWrite();
});
}
}
};
Terminal.prototype.innerWrite = function() {
var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
@@ -1227,7 +1318,13 @@ Terminal.prototype.innerWrite = function() {
this.refreshStart = this.y;
this.refreshEnd = this.y;
this.parser.parse(data);
// HACK: Set the parser state based on it's state at the time of return.
// This works around the bug #662 which saw the parser state reset in the
// middle of parsing escape sequence in two chunks. For some reason the
// state of the parser resets to 0 after exiting parser.parse. This change
// just sets the state back based on the correct return statement.
var state = this.parser.parse(data);
this.parser.setState(state);
this.updateRange(this.y);
this.refresh(this.refreshStart, this.refreshEnd);
@@ -1245,23 +1342,124 @@ Terminal.prototype.innerWrite = function() {
/**
* Writes text to the terminal, followed by a break line character (\n).
* @param {string} text The text to write to the terminal.
* @param {string} data The text to write to the terminal.
*/
Terminal.prototype.writeln = function(data) {
this.write(data + '\r\n');
};
/**
* Attaches a custom keydown handler which is run before keys are processed, giving consumers of
* xterm.js ultimate control as to what keys should be processed by the terminal and what keys
* should not.
* DEPRECATED: only for backward compatibility. Please use attachCustomKeyEventHandler() instead.
* @param {function} customKeydownHandler The custom KeyboardEvent handler to attach. This is a
* function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent
* the default action. The function returns whether the event should be processed by xterm.js.
*/
Terminal.prototype.attachCustomKeydownHandler = function(customKeydownHandler) {
this.customKeydownHandler = customKeydownHandler;
}
let message = 'attachCustomKeydownHandler() is DEPRECATED and will be removed soon. Please use attachCustomKeyEventHandler() instead.';
console.warn(message);
this.attachCustomKeyEventHandler(customKeydownHandler);
};
/**
* Attaches a custom key event handler which is run before keys are processed, giving consumers of
* xterm.js ultimate control as to what keys should be processed by the terminal and what keys
* should not.
* @param {function} customKeyEventHandler The custom KeyboardEvent handler to attach. This is a
* function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent
* the default action. The function returns whether the event should be processed by xterm.js.
*/
Terminal.prototype.attachCustomKeyEventHandler = function(customKeyEventHandler) {
this.customKeyEventHandler = customKeyEventHandler;
};
/**
* Attaches a http(s) link handler, forcing web links to behave differently to
* regular <a> tags. This will trigger a refresh as links potentially need to be
* reconstructed. Calling this with null will remove the handler.
* @param {LinkMatcherHandler} handler The handler callback function.
*/
Terminal.prototype.setHypertextLinkHandler = function(handler) {
if (!this.linkifier) {
throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
}
this.linkifier.setHypertextLinkHandler(handler);
// Refresh to force links to refresh
this.refresh(0, this.rows - 1);
};
/**
* Attaches a validation callback for hypertext links. This is useful to use
* validation logic or to do something with the link's element and url.
* @param {LinkMatcherValidationCallback} callback The callback to use, this can
* be cleared with null.
*/
Terminal.prototype.setHypertextValidationCallback = function(callback) {
if (!this.linkifier) {
throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
}
this.linkifier.setHypertextValidationCallback(callback);
// Refresh to force links to refresh
this.refresh(0, this.rows - 1);
};
/**
* Registers a link matcher, allowing custom link patterns to be matched and
* handled.
* @param {RegExp} regex The regular expression to search for, specifically
* this searches the textContent of the rows. You will want to use \s to match
* a space ' ' character for example.
* @param {LinkMatcherHandler} handler The callback when the link is called.
* @param {LinkMatcherOptions} [options] Options for the link matcher.
* @return {number} The ID of the new matcher, this can be used to deregister.
*/
Terminal.prototype.registerLinkMatcher = function(regex, handler, options) {
if (this.linkifier) {
var matcherId = this.linkifier.registerLinkMatcher(regex, handler, options);
this.refresh(0, this.rows - 1);
return matcherId;
}
};
/**
* Deregisters a link matcher if it has been registered.
* @param {number} matcherId The link matcher's ID (returned after register)
*/
Terminal.prototype.deregisterLinkMatcher = function(matcherId) {
if (this.linkifier) {
if (this.linkifier.deregisterLinkMatcher(matcherId)) {
this.refresh(0, this.rows - 1);
}
}
};
/**
* Gets whether the terminal has an active selection.
*/
Terminal.prototype.hasSelection = function() {
return this.selectionManager.hasSelection;
};
/**
* Gets the terminal's current selection, this is useful for implementing copy
* behavior outside of xterm.js.
*/
Terminal.prototype.getSelection = function() {
return this.selectionManager.selectionText;
};
/**
* Clears the current terminal selection.
*/
Terminal.prototype.clearSelection = function() {
this.selectionManager.clearSelection();
};
/**
* Selects all text within the terminal.
*/
Terminal.prototype.selectAll = function() {
this.selectionManager.selectAll();
};
/**
* Handle a keydown event
@@ -1270,10 +1468,12 @@ Terminal.prototype.attachCustomKeydownHandler = function(customKeydownHandler) {
* @param {KeyboardEvent} ev The keydown event to be handled.
*/
Terminal.prototype.keyDown = function(ev) {
if (this.customKeydownHandler && this.customKeydownHandler(ev) === false) {
if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
return false;
}
this.restartCursorBlinking();
if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) {
if (this.ybase !== this.ydisp) {
this.scrollToBottom();
@@ -1592,6 +1792,10 @@ Terminal.prototype.evaluateKeyEscapeSequence = function(ev) {
} else if (ev.keyCode >= 48 && ev.keyCode <= 57) {
result.key = C0.ESC + (ev.keyCode - 48);
}
} else if (this.browser.isMac && !ev.altKey && !ev.ctrlKey && ev.metaKey) {
if (ev.keyCode === 65) { // cmd + a
this.selectAll();
}
}
break;
}
@@ -1629,6 +1833,10 @@ Terminal.prototype.setgCharset = function(g, charset) {
Terminal.prototype.keyPress = function(ev) {
var key;
if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
return false;
}
this.cancel(ev);
if (ev.charCode) {
@@ -1654,7 +1862,7 @@ Terminal.prototype.keyPress = function(ev) {
this.showCursor();
this.handler(key);
return false;
return true;
};
/**
@@ -1719,6 +1927,10 @@ Terminal.prototype.resize = function(x, y) {
return;
}
if (y > this.getOption('scrollback')) {
this.setOption('scrollback', y)
}
var line
, el
, i
@@ -1743,14 +1955,8 @@ Terminal.prototype.resize = function(x, y) {
this.lines.get(i).push(ch);
}
}
} else { // (j > x)
i = this.lines.length;
while (i--) {
while (this.lines.get(i).length > x) {
this.lines.get(i).pop();
}
}
}
this.cols = x;
this.setupStops(this.cols);
@@ -1766,7 +1972,7 @@ Terminal.prototype.resize = function(x, y) {
// There is room above the buffer and there are no empty elements below the line,
// scroll up
this.ybase--;
addToY++
addToY++;
if (this.ydisp > 0) {
// Viewport is at the top of the buffer, must increase downwards
this.ydisp--;
@@ -1967,8 +2173,9 @@ Terminal.prototype.eraseLine = function(y) {
/**
* Return the data array of a blank line
* @param {number} cur First bunch of data for each "blank" character.
* @param {boolean} isWrapped Whether the new line is wrapped from the previous line.
*/
Terminal.prototype.blankLine = function(cur) {
Terminal.prototype.blankLine = function(cur, isWrapped) {
var attr = cur
? this.eraseAttr()
: this.defAttr;
@@ -1977,6 +2184,12 @@ Terminal.prototype.blankLine = function(cur) {
, line = []
, i = 0;
// TODO: It is not ideal that this is a property on an array, a buffer line
// class should be added that will hold this data and other useful functions.
if (isWrapped) {
line.isWrapped = isWrapped;
}
for (; i < this.cols; i++) {
line[i] = ch;
}
@@ -2086,9 +2299,11 @@ Terminal.prototype.reverseIndex = function() {
Terminal.prototype.reset = function() {
this.options.rows = this.rows;
this.options.cols = this.cols;
var customKeydownHandler = this.customKeydownHandler;
var customKeyEventHandler = this.customKeyEventHandler;
var cursorBlinkInterval = this.cursorBlinkInterval;
Terminal.call(this, this.options);
this.customKeydownHandler = customKeydownHandler;
this.customKeyEventHandler = customKeyEventHandler;
this.cursorBlinkInterval = cursorBlinkInterval;
this.refresh(0, this.rows - 1);
this.viewport.syncScrollArea();
};
+1 -8
View File
@@ -12,13 +12,6 @@
"src/**/*"
],
"exclude": [
"src/addons/**/*",
"build",
"demo",
"dist",
"out",
"test",
"node_modules",
"docs"
"src/addons/**/*"
]
}