diff --git a/README.md b/README.md index bb87f9db..835c51f1 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ Nope. There are no cons cells here. ### Is this a Clojure port? -No. It's similar to Clojure superficially because I like Lisps and I like the asthetics. +No. It's similar to Clojure superficially because I like Lisps and I like the aesthetics. Internally, Janet is not at all like Clojure. ### Are the immutable data structures (tuples and structs) implemented as hash tries? diff --git a/examples/urlloader.janet b/examples/urlloader.janet index 75cf82c0..507987dc 100644 --- a/examples/urlloader.janet +++ b/examples/urlloader.janet @@ -1,10 +1,10 @@ -# An example of using Janet's extensible module system -# to import files from URL. To try this, run `janet -l examples/urlloader.janet` -# from the repl, and then: +# An example of using Janet's extensible module system to import files from +# URL. To try this, run `janet -l ./examples/urlloader.janet` from the command +# line, and then at the REPL type: # # (import https://raw.githubusercontent.com/janet-lang/janet/master/examples/colors.janet :as c) # -# This will import a file using curl. You can then try +# This will import a file using curl. You can then try: # # (print (c/color :green "Hello!")) # @@ -13,9 +13,9 @@ (defn- load-url [url args] - (def f (file/popen (string "curl " url))) - (def res (dofile f :source url ;args)) - (try (file/close f) ([err] nil)) + (def p (os/spawn ["curl" url "-s"] :p {:out :pipe})) + (def res (dofile (p :out) :source url ;args)) + (:wait p) res) (defn- check-http-url diff --git a/src/core/os.c b/src/core/os.c index 752e1dd1..9e479405 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -544,7 +544,7 @@ JANET_CORE_FN(os_proc_wait, JANET_CORE_FN(os_proc_kill, "(os/proc-kill proc &opt wait)", "Kill a subprocess by sending SIGKILL to it on posix systems, or by closing the process " - "handle on windows. If wait is truthy, will wait for the process to finsih and " + "handle on windows. If wait is truthy, will wait for the process to finish and " "returns the exit code. Otherwise, returns proc.") { janet_arity(argc, 1, 2); JanetProc *proc = janet_getabstract(argv, 0, &ProcAT); @@ -689,6 +689,12 @@ static int janet_proc_get(void *p, Janet key, Janet *out) { *out = (NULL == proc->err) ? janet_wrap_nil() : janet_wrap_abstract(proc->err); return 1; } + #ifndef JANET_WINDOWS + if (janet_keyeq(key, "pid")) { + *out = janet_wrap_number(proc->pid); + return 1; + } + #endif if ((-1 != proc->return_code) && janet_keyeq(key, "return-code")) { *out = janet_wrap_integer(proc->return_code); return 1; @@ -1057,7 +1063,9 @@ JANET_CORE_FN(os_execute, JANET_CORE_FN(os_spawn, "(os/spawn args &opt flags env)", "Execute a program on the system and return a handle to the process. Otherwise, the " - "same arguments as os/execute. Does not wait for the process.") { + "same arguments as os/execute. Does not wait for the process. " + "The returned value has the fields :in, :out, :err, :return-code and " + "the additional field :pid on unix like platforms.") { return os_execute_impl(argc, argv, 1); } diff --git a/src/mainclient/shell.c b/src/mainclient/shell.c index 396c6762..8e68fc51 100644 --- a/src/mainclient/shell.c +++ b/src/mainclient/shell.c @@ -136,7 +136,6 @@ static JANET_THREAD_LOCAL int gbl_cols = 80; static JANET_THREAD_LOCAL char *gbl_history[JANET_HISTORY_MAX]; static JANET_THREAD_LOCAL int gbl_history_count = 0; static JANET_THREAD_LOCAL int gbl_historyi = 0; -static JANET_THREAD_LOCAL int gbl_sigint_flag = 0; static JANET_THREAD_LOCAL struct termios gbl_termios_start; static JANET_THREAD_LOCAL JanetByteView gbl_matches[JANET_MATCH_MAX]; static JANET_THREAD_LOCAL int gbl_match_count = 0; @@ -758,9 +757,8 @@ static int line() { kleft(); break; case 3: /* ctrl-c */ - clearlines(); - gbl_sigint_flag = 1; - return -1; + kill(getpid(), SIGINT); + /* fallthrough */ case 17: /* ctrl-q */ gbl_cancel_current_repl_form = 1; clearlines(); @@ -962,11 +960,7 @@ void janet_line_get(const char *p, JanetBuffer *buffer) { } if (line()) { norawmode(); - if (gbl_sigint_flag) { - raise(SIGINT); - } else { - fputc('\n', out); - } + fputc('\n', out); return; } fflush(stdin);