webbrowser: open url's in your webbrowser.

db4
John Benediktsson 2011-11-12 16:18:52 -08:00
parent 340e69aef3
commit e10e019f9f
10 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1 @@
John Benediktsson

View File

@ -0,0 +1,13 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: formatting io.launcher present system urls webbrowser ;
IN: webbrowser.unix
M: unix open-file ( path -- )
"gnome-open \"%s\"" sprintf try-process ;
M: unix open-url ( url -- )
>url present open-file ;

View File

@ -0,0 +1 @@
linux

View File

@ -0,0 +1,15 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: formatting io.encodings.ascii io.launcher present system
urls webbrowser ;
IN: webbrowser.macosx
M: macosx open-file ( path -- )
"open \"%s\"" sprintf try-process ;
M: macosx open-url ( url -- )
>url present "osascript" ascii [
"open location \"%s\"" printf
] with-process-writer ;

View File

@ -0,0 +1 @@
macosx

View File

@ -0,0 +1 @@
Open URLs in your web browser

View File

@ -0,0 +1,19 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: help.markup help.syntax strings webbrowser ;
IN: webbrowser
HELP: open-file
{ $values { "path" string } }
{ $description
"Open a specified file or directory using the default "
"application, similar to double-clicking the file's icon."
} ;
HELP: open-url
{ $values { "url" string } }
{ $description
"Open a specified url in the default web browser."
} ;

View File

@ -0,0 +1,18 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: combinators system ui.operations urls vocabs ;
IN: webbrowser
HOOK: open-file os ( path -- )
HOOK: open-url os ( url -- )
{
{ [ os macosx? ] [ "webbrowser.macosx" ] }
{ [ os linux? ] [ "webbrowser.linux" ] }
{ [ os windows? ] [ "webbrowser.windows" ] }
} cond require
[ url? ] \ open-url H{ } define-operation

View File

@ -0,0 +1 @@
windows

View File

@ -0,0 +1,13 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: present urls webbrowser windows.shell32 windows.user32 ;
IN: webbrowser.windows
M: windows open-file ( path -- )
[ f "open" ] dip f f SW_SHOWNORMAL ShellExecute drop ;
M: windows open-url ( url -- )
>url present open-file ;