D3650: serve: add an option to open in the default browser

2020-01-24 Thread baymax (Baymax, Your Personal Patch-care Companion)
This revision now requires changes to proceed.
baymax added a comment.
baymax requested changes to this revision.


  There seems to have been no activities on this Diff for the past 3 Months.
  
  By policy, we are automatically moving it out of the `need-review` state.
  
  Please, move it back to `need-review` without hesitation if this diff should 
still be discussed.
  
  :baymax:need-review-idle:

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D3650/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

To: nspanti-logilab, #hg-reviewers, baymax
Cc: yuja, pulkit, av6, durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3650: serve: add an option to open in the default browser

2018-06-16 Thread yuja (Yuya Nishihara)
yuja added a comment.


  (Resend because I forgot to remove the "someone wrote:" line again, sorry.)
  
  >   For laziness,  this patch could be also useful. It is also better for 
text shell beginners, because they may not know that they can combine commands 
like that (even if it is basic).
  
  For laziness, we can add it to `[alias]`. I'm not a fan of adding lots of
  one-off options since that's the source of man page bloat.
  
  How about document the xdg-open example in `hg help serve -v`?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

To: nspanti-logilab, #hg-reviewers
Cc: yuja, pulkit, av6, durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D3650: serve: add an option to open in the default browser

2018-06-16 Thread Yuya Nishihara
(Resend because I forgot to remove the "someone wrote:" line again, sorry.)

>   For laziness,  this patch could be also useful. It is also better for text 
> shell beginners, because they may not know that they can combine commands 
> like that (even if it is basic).

For laziness, we can add it to `[alias]`. I'm not a fan of adding lots of
one-off options since that's the source of man page bloat.

How about document the xdg-open example in `hg help serve -v`?
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D3650: serve: add an option to open in the default browser

2018-06-15 Thread Yuya Nishihara
On Fri, 15 Jun 2018 08:40:33 +, nspanti-logilab (Nicola Spanti) wrote:
>   For laziness,  this patch could be also useful. It is also better for text 
> shell beginners, because they may not know that they can combine commands 
> like that (even if it is basic). Moreover, you can still use `hg serve` in 
> foreground or use it in background and give the result of `--print-url` to a 
> non web browser application (but I imagine that there is a way to duplicate 
> stdout to multiple programs). These are the advantages of this patch that I 
> see over `--print-url` of https://phab.mercurial-scm.org/D3649. It is better 
> for convenience and require less knowledge for the user, but it is not a 
> need. https://phab.mercurial-scm.org/D3649 was precisely suggested to me 
> because it can fulfill the functionality of the current patch and is more 
> versatile.

For laziness, we can add it to `[alias]`. I'm not a fan of adding lots of
one-off options since that's the source of man page bloat.

How about document the xdg-open example in `hg help serve -v`?
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3650: serve: add an option to open in the default browser

2018-06-15 Thread nspanti-logilab (Nicola Spanti)
nspanti-logilab added a comment.


  For laziness,  this patch could be also useful. It is also better for text 
shell beginners, because they may not know that they can combine commands like 
that (even if it is basic). Moreover, you can still use `hg serve` in 
foreground or use it in background and give the result of `--print-url` to a 
non web browser application (but I imagine that there is a way to duplicate 
stdout to multiple programs). These are the advantages of this patch that I see 
over `--print-url` of https://phab.mercurial-scm.org/D3649. It is better for 
convenience and require less knowledge for the user, but it is not a need. 
https://phab.mercurial-scm.org/D3649 was precisely suggested to me because it 
can fulfill the functionality of the current patch and is more versatile.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

To: nspanti-logilab, #hg-reviewers
Cc: pulkit, av6, durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3650: serve: add an option to open in the default browser

2018-06-14 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  Do we need this patch any more since https://phab.mercurial-scm.org/D3649 has 
landed and we can do `xdg-open "$(hg serve --print-url)"`?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

To: nspanti-logilab, #hg-reviewers
Cc: pulkit, av6, durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3650: serve: add an option to open in the default browser

2018-06-02 Thread av6 (Anton Shestakov)
av6 added a comment.


  https://phab.mercurial-scm.org/D3649 mentions `xdg-open "$(hg serve 
--print-url)"`, which shows that --print-url can nearly replace --graphical and 
is more versatile.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

To: nspanti-logilab, #hg-reviewers
Cc: av6, durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3650: serve: add an option to open in the default browser

2018-05-31 Thread durin42 (Augie Fackler)
durin42 added a comment.


  I don't love the flag name, and am -0 on the feature in general. All terminal 
emulators I've used in the last 10 years have URL detection logic and make 
clicking the link trivial...

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

To: nspanti-logilab, #hg-reviewers
Cc: durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3650: serve: add an option to open in the default browser

2018-05-24 Thread nspanti-logilab (Nicola Spanti)
nspanti-logilab created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It is inspired by a similar functionality in pydoc.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

AFFECTED FILES
  mercurial/commands.py
  mercurial/hgweb/__init__.py
  tests/test-completion.t

CHANGE DETAILS

diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -239,7 +239,7 @@
   pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
   push: force, rev, bookmark, branch, new-branch, pushvars, ssh, remotecmd, 
insecure
   remove: after, force, subrepos, include, exclude, dry-run
-  serve: accesslog, daemon, daemon-postexec, errorlog, port, address, prefix, 
name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, 
ipv6, certificate, subrepos
+  serve: accesslog, daemon, daemon-postexec, graphical, errorlog, port, 
address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, 
templates, style, ipv6, certificate, subrepos
   status: all, modified, added, removed, deleted, clean, unknown, ignored, 
no-status, terse, copies, print0, rev, change, include, exclude, subrepos, 
template
   summary: remote
   update: clean, check, merge, date, rev, tool
diff --git a/mercurial/hgweb/__init__.py b/mercurial/hgweb/__init__.py
--- a/mercurial/hgweb/__init__.py
+++ b/mercurial/hgweb/__init__.py
@@ -9,6 +9,7 @@
 from __future__ import absolute_import
 
 import os
+import webbrowser
 
 from ..i18n import _
 
@@ -60,6 +61,25 @@
 if self.opts['port'] and not self.ui.verbose:
 return
 
+bindaddr = self._getbindaddr()
+
+if self.opts['port']:
+write = self.ui.status
+else:
+write = self.ui.write
+write(_('listening at %s (bound to %s:%d)\n') %
+  (self._geturl(), pycompat.sysbytes(bindaddr), self.httpd.port))
+self.ui.flush()  # avoid buffering of status message
+
+def _getbindaddr(self):
+bindaddr = self.httpd.addr
+if bindaddr == r'0.0.0.0':
+bindaddr = r'*'
+elif r':' in bindaddr: # IPv6
+bindaddr = r'[%s]' % bindaddr
+return bindaddr
+
+def _geturl(self):
 if self.httpd.prefix:
 prefix = self.httpd.prefix.strip('/') + '/'
 else:
@@ -69,25 +89,18 @@
 if port == r':80':
 port = r''
 
-bindaddr = self.httpd.addr
-if bindaddr == r'0.0.0.0':
-bindaddr = r'*'
-elif r':' in bindaddr: # IPv6
-bindaddr = r'[%s]' % bindaddr
+bindaddr = self._getbindaddr()
 
 fqaddr = self.httpd.fqaddr
 if r':' in fqaddr:
 fqaddr = r'[%s]' % fqaddr
-if self.opts['port']:
-write = self.ui.status
-else:
-write = self.ui.write
-write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
-  (pycompat.sysbytes(fqaddr), pycompat.sysbytes(port),
-   prefix, pycompat.sysbytes(bindaddr), self.httpd.port))
-self.ui.flush()  # avoid buffering of status message
+
+return 'http://%s%s/%s' % (
+pycompat.sysbytes(fqaddr), pycompat.sysbytes(port), prefix)
 
 def run(self):
+if self.opts.pop('gui', None):
+webbrowser.open(self._geturl())
 self.httpd.serve_forever()
 
 def createapp(baseui, repo, webconf):
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4747,6 +4747,7 @@
  _('FILE')),
 ('d', 'daemon', None, _('run server in background')),
 ('', 'daemon-postexec', [], _('used internally by daemon mode')),
+('g', 'gui', None, _('open in default web browser')),
 ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')),
 # use string type, then we can check if something was passed
 ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')),



To: nspanti-logilab, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel