Commit Graph

47 Commits

Author SHA1 Message Date
Qi Xiao
42867d56ba Remove the -bin flag.
Always determine it with os.Executable() instead.
2021-06-27 23:12:09 +01:00
Qi Xiao
d6464280f2 Remove direct dependency of pkg/shell on the daemon implementation.
The dependency is injected via a field in shell.Program.

Also add an alternative entrypoint, cmd/nodaemon/elvish, which does not include
the daemon server or client.
2021-06-19 01:43:30 +01:00
Qi Xiao
cfb6134236 Remove daemon:spawn.
The daemon module has never been documented and is not used by any code on GitHub:
https://github.com/search?q=%22use+daemon%22+extension%3Aelv&type=Code&ref=advsearch&l=&l=
arch&l=&l=
2021-06-19 01:07:29 +01:00
Qi Xiao
27eec7c8ee Reorganize the daemon module.
* Move client, spawning and activation code into pkg/daemon/client.

* Move API types into pkg/daemon/daemondefs.
2021-06-19 01:06:11 +01:00
Kurtis Rader
e2f810048e Add $edit:after-command and $edit:command-duration
The `edit:after-command` hooks are called with a single argument:
a pseudo-map with these keys:

    "command": the command line that was run
    "duration": the execution duration in seconds
    "error": any error that occurred ($nil if no error occurred)

The `edit:command-duration` variable is the elapsed seconds (as a
float64) of the most recently run interactive command.

Resolves #1029
2021-05-05 22:17:19 +01:00
Qi Xiao
42d6e94dd7 Remove support for $-exports-. 2021-04-09 00:02:40 +01:00
Supreet
77c40b9abb Links file module, marks fopen and fclose deprecation in compiler.go
aand builtin_fn_io.go
2021-04-08 22:45:16 +01:00
Qi Xiao
0427c536d0 Simplify the API of pkg/cli.
* Move all widget types to a new pkg/cli/tk.

* Move Mode{Line Prompt} to a new pkg/cli/mode.

* Move all packages in pkg/cli/addons to pkg/cli/mode.

* Remove WriteListing.

* Remove StdTTY.

* Rename GetCodeBuffer to CodeBuffer.
2021-02-11 19:24:37 +00:00
Qi Xiao
72fc2dbe4a Copy and trim down the net/rpc package.
In particular, the dependency on net/http is removed, which removes a
bunch of transitive dependencies.
2021-01-30 23:56:58 +00:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
de562f84d4 Deprecate the $-exports- mechanism in 0.15. 2021-01-19 23:28:38 +00:00
Kurtis Rader
be712d5405
Introduce the path: module (#1203)
* Introduce the `path:` module

This is based on https://github.com/elves/elvish/pull/1084 by @kolbycrouch
submitted five months ago. It addresses all of the feedback on that
change and includes other documentation and unit test improvements. It
also includes a couple of extensions to the original P.R., such as a
`path:is-abs` command.

I decided to resurrect that change because I want better support for
filesystem path manipulation so that users can replace non-portable
external commands such as `realpath` and `find` with Elvish builtins. This
is a baby step towards that goal.

Related #849

* Add a `path:is-regular` command

This adds a `path:is-regular` command.  This is for symmetry with the
`path:is-dir` command and the glob `[type:regular]` modifier.

It also adds support for symlinks in the `testutil.Applydir` function
and change the path unit test to use it.

* Rename path:real to path:eval-symlinks
2021-01-16 23:21:33 +00:00
Kurtis Rader
d241243fdf Ensure the daemon doesn't have fds open on the tty
The Elvish daemon should not inherit file descriptors open on the tty.
Make the daemon's stdin open on the null device and its stdout/stderr
open on a predictable file.

Fixes #1191
2021-01-16 23:18:38 +00:00
Qi Xiao
75baa0b5a2 pkg/eval: Remove (*Ns).Append.
This change makes Ns immutable from the exposed API. Internally there is exactly
one place that still mutates Ns, in scopeOp; this will be addressed later.
2021-01-05 01:09:04 +00:00
Qi Xiao
a2790af67a pkg/eval: Clean up the structure and methods of Evaler and Frame.
- Make Evaler mostly thread-safe. The only remaining thread-unsafe part is the
  modules field, which is more tricky than other fields.

- Remove the state and evalerScopes type, and move their fields into Evaler.

- Expose valuePrefix via a get method, and change PortsFromFiles to take the
  prefix instead of a *Evaler. Also expose a PortsFromStdFiles.

- Make Evaler a normal field of Frame, instead of an embedded field. This makes
  access to global states more explicit.
2021-01-05 00:22:09 +00:00
Qi Xiao
086038fa0f pkg/eval: Remove (*Evaler).Close. 2021-01-03 20:55:04 +00:00
Qi Xiao
3f6b5da2b9 pkg/shell: Print both parse and compile errors when using -compileonly -json.
The new (*Evaler).Check method allows the implementation to be simpler.

Also test the JSON format feature in an integration test instead of unit test;
this makes it unnecessary for the eval package to expose NewCompilationError.
2021-01-03 16:32:04 +00:00
Qi Xiao
7663d9a0ce pkg/eval: Replace the NoExecute option of (*Evaler).Eval with a new Check method.
This method has the property that it always tries to compile the code even if
there is a parse failure. This is the more desirable behavior when checking
code: if there is a parse failure near the end of a chunk of code, the user may
like to learn about compile errors earlier in the code.
2021-01-03 16:01:24 +00:00
Qi Xiao
dc59cbfeb4 pkg/eval: Make (*Evaler).Eval accept a Source instead of an Op.
Most callers can now call it with the source to evaluate, without having to call
ParseAndCompile first themselves.
2021-01-02 00:10:26 +00:00
Qi Xiao
7584319b69 pkg/parse: MultiError -> Error; add a GetError function. 2021-01-01 23:19:03 +00:00
Qi Xiao
41bed735e7 pkg/shell: Install the edit module in the builtin namespace.
Installing it in the global namespace doesn't work, since modules may use the
edit namespace.
2020-12-25 21:01:47 +00:00
Qi Xiao
6419f4524a Implement namespaces using slices instead of maps.
More related improvements and cleanups will be done in followup commits.

This fixes #1139.
2020-12-25 17:46:46 +00:00
Kurtis Rader
9c7c9cf7d9 [cleanup] trivial golint suggested changes
As with commit #eb2a792 I acknowledge that `golint` recommendations are
controversial and should not automatically be acted on. Nonetheless,
this change fixes legitimate lint issues such as copy/paste cleanups,
style problems I introduced (`i += 1` versus `i++`) or method/var comments
that are not in the preferred form.
2020-12-25 01:11:33 +00:00
Qi Xiao
27fa20d65e pkg/eval: Move ChopLineEnding to the strutil package.
Also add unit tests.
2020-09-04 21:16:06 +01:00
Qi Xiao
11898f763a pkg/util: Break into fsutil/ and logutil/. 2020-09-03 05:27:18 +01:00
Qi Xiao
48919bcb24 pkg/: Move test utilities from util/ to testutil/. 2020-09-03 04:55:16 +01:00
Qi Xiao
eb9638fc16 pkg/eval: Move modules into a mods directory. 2020-09-03 04:31:04 +01:00
Qi Xiao
8f410a24be pkg/util: Move environment variable names to a new package.
Also document that this package should be broken up.
2020-08-16 14:12:48 +01:00
Kurtis Rader
30d1161ded Replace "USERNAME" literals with a constant 2020-08-16 14:05:13 +01:00
Kurtis Rader
947ac39876 Replace "XDG_RUNTIME_DIR" literals with a constant 2020-08-16 14:05:13 +01:00
Kurtis Rader
f656f9511b Replace "HOME" literals with a constant 2020-08-16 14:05:13 +01:00
Kurtis Rader
ade5fa6c76 Fix exec handling of $E:SHLVL
Fixes #1091
2020-08-16 14:05:13 +01:00
Kurtis Rader
3643f252f3 Verify stdout and stderr in shell tests
While working on my next commit, to prevent I/O deadlocks, I experienced
some problems because I had a syntax error in the Elvish code to generate
the output. That wasn't immediately obvious because I had copied another
test that only tested the stdout of the shell and the syntax error was
written to stderr. This change modifies existing tests to verify both
stdout and stderr have the expected content.

Note that there are three interactive tests for which we still do not
verify the content of stderr. That's because stderr for those tests only
contains a shell prompt whose content changes each time the test is run.
TBD is modifying the interactive tests to have a predictable prompt.
2020-08-11 15:58:20 +01:00
Kurtis Rader
9858d5a545 Add missing deprecation text for explode
Also, fix trivial typo in a comment as reported at
https://goreportcard.com/report/github.com/elves/elvish
2020-07-21 22:51:53 +01:00
Qi Xiao
8995bc5663 Fix build. 2020-07-11 14:26:30 +01:00
Kurtis Rader
c30a9ff9ad Tell external cmds to ignore job control signals
Since elvish does not support job control it should run all external
commands with the tty job control signals set to be ignored. See "APUE",
third edition, page 379.

This doesn't actually fix the problem in the case of broken programs
like vim which blindly assume the parent process implements job control.
But there isn't much we can do about that other than try to get those
programs to pay attention to being told to ignore SIGTSTP.

Fixes #988
2020-07-11 14:18:42 +01:00
Kurtis Rader
1045fa3d1f Panic during shell unit tests should be failures
While debugging my fix for issue #661 I noticed that a panic that invokes
the `rescue` function causes Go to think the test passed due to launching
a rescue shell. This introduces a mechanism for elvish unit tests to
request that panics be fatal; i.e., exit with a non-zero status rather
than launch a rescue shell.

This also changes the behavior of panics by non-interactive elvish
shells to no longer launch an unexpected rescue shell.
2020-07-11 14:16:48 +01:00
Qi Xiao
e9b4035896 pkg/eval: Move the show command into the builtin namespace.
This will likely become a basic operation in future that can support more types
than exceptions, so putting it in the builtin namespace is appropriate.

Also remove the exc: module altogether as it contains nothing now. All the
introspection features are now implemented as fields of the exception values and
the reason values.
2020-06-30 22:36:27 +01:00
Qi Xiao
eb37f92300 pkg/eval: Use eval.ChopLineEnding everywhere for removing line ending. 2020-05-06 23:10:57 +01:00
Qi Xiao
0b5b210d24 Add exc:show for showing exceptions.
This addresses #945.
2020-05-02 23:28:42 +01:00
Qi Xiao
bffb74f90a pkg/shell: Use fmt.Println to print the recovered value.
The println function does not handle interface values correctly.
2020-05-02 19:28:46 +01:00
Qi Xiao
52bd0aef41 pkg/shell: Do not spawn the daemon when running a script. 2020-04-28 23:41:34 +01:00
Qi Xiao
c767f92d01 Support compile-time deprecation.
This fixes #898.
2020-04-26 13:14:51 +01:00
Qi Xiao
20979b44a2 pkg/parse: Use Source values, not pointers.
The Source type is small enough that using values is likely more efficient.
2020-04-25 19:22:38 +01:00
Qi Xiao
b8505c7065 pkg/eval/source.go -> pkg/parse/source.go. 2020-04-25 18:26:17 +01:00
Qi Xiao
53a1eca9af pkg/eval: Remove New*Source functions.
All call sites of such functions are replaced with simple &Source{...}
expressions.
2020-04-25 13:22:07 +01:00
Qi Xiao
78cae6a695 pkg/prog/{shell,web} -> pkg/{shell,web}. 2020-04-25 00:12:18 +01:00