You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by ahgittin <gi...@git.apache.org> on 2016/11/07 15:31:20 UTC

[GitHub] brooklyn-docs pull request #123: Remove bash prompt chars

GitHub user ahgittin opened a pull request:

    https://github.com/apache/brooklyn-docs/pull/123

    Remove bash prompt chars

    inspired by #97 (and replacing it) this uses the proper multi-line bash char, and ensures these chars are removed on copy-paste
    
    uses a nice JS `oncopy` trick mentioned in the comments on that PR

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ahgittin/brooklyn-docs remove-bash-prompt-chars

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-docs/pull/123.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #123
    
----
commit f25797de3a87514bf373679a6714fa7542518783
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date:   2016-11-07T15:28:18Z

    improve how we remove prompt chars when copy-pasting bash
    
    now applies to cmd-c as well as flash, and feedback is clearer too (for both)

commit 68291a398f4205b79af8021744db9ca0d081e46a
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date:   2016-11-07T15:29:33Z

    tidies for prompt chars, esp multi-line
    
    and fix broken link
    
    cf https://github.com/apache/brooklyn-docs/pull/97

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-docs pull request #123: Remove bash prompt chars

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-docs/pull/123#discussion_r86802168
  
    --- Diff: _layouts/base.html ---
    @@ -65,32 +63,70 @@
         }
     });
     
    -<!-- Clipboard support -->
    -  ZeroClipboard.config({ moviePath: '{{ site.path.style }}/js/zeroclipboard/ZeroClipboard.swf' });
    +<!-- Copying and clipboard support -->
    +
    +// first make the $% line starts not selectable 
    +
    +$(function() {
    +  $('div.highlight').attr('oncopy', 'handleHideCopy(this)');
    +  $('div.highlight').each(function(index,target) {
    +    if ($(target).find('code.bash')) {
    +      // Mark bash prompts from the start of each line (i.e. '$' or '%' characters
    +      // at the very start, or immediately following any newline) as not-selectable. 
    +      // Handle continuation lines where a leading '$' or '%' is *not* a prompt character.
    +      // (If example wants to exclude output, it can manually use class="nocopy".)
    +      target.innerHTML = target.innerHTML.replace(/(^\s*|[^\\]\n)(<.*>)?([$%]|&gt;) /g, '$1$2<span class="nocopy bash_prompt">$3 </span>');
    +    }
    +  });
    +});
    +
    +// normal cmd-C (non-icon) copying
    +
    +function handleHideCopy(el) {
    +//    var origHtml = $(el).clone();
    +    console.log("handling copy", el);
    +    $(el).addClass('copying');
    +    $(el).find('.nocopy').hide();
    +    $(el).find('.clipboard_button').addClass('manual-clipboard-is-active');
    +    setTimeout(function(){
    +        $(el).removeClass('copying');
    +        $(el).find('.clipboard_button').removeClass('manual-clipboard-is-active');
    +        $(el).find('.nocopy').show();
    +//        $(el).html(origHtml);
    +    }, 600);
    +}
    +
    +// and icon (flash) copying
    +
    +</script>
    +
    +<script src="{{ site.path.style }}/js/zeroclipboard/ZeroClipboard.min.js"></script>
    +
    +<script language="JavaScript" type="application/javascript">
    +
    +ZeroClipboard.config({ moviePath: '{{ site.path.style }}/js/zeroclipboard/ZeroClipboard.swf' });
     
     $(function() {
       $('div.highlight').prepend(
    -  $('<div class="clipboard_container" title="Copy to Clipboard">'+
    -    '<div class="fa clipboard_button">'+
    -    '<div class="on-active"><div>Copied to Clipboard</div></div>'+
    -  '</div></div>'));
    +    $('<div class="clipboard_container" title="Copy to Clipboard">'+
    +      '<div class="fa clipboard_button">'+
    +      '<div class="on-active"><div>Copied to Clipboard</div></div>'+
    +    '</div></div>'));
       $('div.clipboard_container').each(function(index) {
         var clipboard = new ZeroClipboard();
         clipboard.clip( $(this).find(":first")[0], $(this)[0] );
    -    var target = $(this).next();
    -    var txt = target.text().trim();
    -    if (target.find('code.bash')) {
    -      // Strip out bash prompts from the start of each line (i.e. '$' or '%' characters
    -      // at the very start, or immediately following any newline). Correctly handles continuation
    -      // lines, where a leading '$' or '%' is *not* a prompt character.
    -      txt = txt.replace(/(^|[^\\]\n)[$%] /g, "$1");
    -    }
    +    var target0 = $(this).next();
    +    var target = target0.clone();
    +    target.find('.nocopy').remove();
    +    var txt = target.text();
         clipboard.on( 'dataRequested', function (client, args) {
    +      handleHideCopy( target0.closest('div.highlight') );  //not necessary but nicer feedback
    --- End diff --
    
    This won't be called if zeroclipboard is not active (no flash installed for example). Could use [`user-select`](https://developer.mozilla.org/en-US/docs/Web/CSS/user-select) for a similar effect.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-docs pull request #123: Remove bash prompt chars

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/brooklyn-docs/pull/123#discussion_r86807790
  
    --- Diff: _layouts/base.html ---
    @@ -65,32 +63,70 @@
         }
     });
     
    -<!-- Clipboard support -->
    -  ZeroClipboard.config({ moviePath: '{{ site.path.style }}/js/zeroclipboard/ZeroClipboard.swf' });
    +<!-- Copying and clipboard support -->
    +
    +// first make the $% line starts not selectable 
    +
    +$(function() {
    +  $('div.highlight').attr('oncopy', 'handleHideCopy(this)');
    +  $('div.highlight').each(function(index,target) {
    +    if ($(target).find('code.bash')) {
    +      // Mark bash prompts from the start of each line (i.e. '$' or '%' characters
    +      // at the very start, or immediately following any newline) as not-selectable. 
    +      // Handle continuation lines where a leading '$' or '%' is *not* a prompt character.
    +      // (If example wants to exclude output, it can manually use class="nocopy".)
    +      target.innerHTML = target.innerHTML.replace(/(^\s*|[^\\]\n)(<.*>)?([$%]|&gt;) /g, '$1$2<span class="nocopy bash_prompt">$3 </span>');
    +    }
    +  });
    +});
    +
    +// normal cmd-C (non-icon) copying
    +
    +function handleHideCopy(el) {
    +//    var origHtml = $(el).clone();
    +    console.log("handling copy", el);
    +    $(el).addClass('copying');
    +    $(el).find('.nocopy').hide();
    +    $(el).find('.clipboard_button').addClass('manual-clipboard-is-active');
    +    setTimeout(function(){
    +        $(el).removeClass('copying');
    +        $(el).find('.clipboard_button').removeClass('manual-clipboard-is-active');
    +        $(el).find('.nocopy').show();
    +//        $(el).html(origHtml);
    +    }, 600);
    +}
    +
    +// and icon (flash) copying
    +
    +</script>
    +
    +<script src="{{ site.path.style }}/js/zeroclipboard/ZeroClipboard.min.js"></script>
    +
    +<script language="JavaScript" type="application/javascript">
    +
    +ZeroClipboard.config({ moviePath: '{{ site.path.style }}/js/zeroclipboard/ZeroClipboard.swf' });
     
     $(function() {
       $('div.highlight').prepend(
    -  $('<div class="clipboard_container" title="Copy to Clipboard">'+
    -    '<div class="fa clipboard_button">'+
    -    '<div class="on-active"><div>Copied to Clipboard</div></div>'+
    -  '</div></div>'));
    +    $('<div class="clipboard_container" title="Copy to Clipboard">'+
    +      '<div class="fa clipboard_button">'+
    +      '<div class="on-active"><div>Copied to Clipboard</div></div>'+
    +    '</div></div>'));
       $('div.clipboard_container').each(function(index) {
         var clipboard = new ZeroClipboard();
         clipboard.clip( $(this).find(":first")[0], $(this)[0] );
    -    var target = $(this).next();
    -    var txt = target.text().trim();
    -    if (target.find('code.bash')) {
    -      // Strip out bash prompts from the start of each line (i.e. '$' or '%' characters
    -      // at the very start, or immediately following any newline). Correctly handles continuation
    -      // lines, where a leading '$' or '%' is *not* a prompt character.
    -      txt = txt.replace(/(^|[^\\]\n)[$%] /g, "$1");
    -    }
    +    var target0 = $(this).next();
    +    var target = target0.clone();
    +    target.find('.nocopy').remove();
    +    var txt = target.text();
         clipboard.on( 'dataRequested', function (client, args) {
    +      handleHideCopy( target0.closest('div.highlight') );  //not necessary but nicer feedback
    --- End diff --
    
    yeah the `oncopy` handler solves the no-flash case.  would be nice if we didn't even show the clipboard on no-flash but didn't do that.
    
    i have added `user-select` in a follow-up PR, but note it doesn't always do what one might expect, so this code is worth having in addition


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-docs issue #123: Remove bash prompt chars

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-docs/pull/123
  
    LGTM


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-docs pull request #123: Remove bash prompt chars

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-docs/pull/123


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---