All Projects → jonsequitur → dotnet-repl

jonsequitur / dotnet-repl

Licence: MIT license
A polyglot REPL built on .NET Interactive

Programming Languages

C#
18002 projects
Jupyter Notebook
11667 projects
powershell
5483 projects

Projects that are alternatives of or similar to dotnet-repl

Alive Progress
A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
Stars: ✭ 2,940 (+463.22%)
Mutual labels:  repl
Codi.vim
📔 The interactive scratchpad for hackers.
Stars: ✭ 2,464 (+372.03%)
Mutual labels:  repl
Tslab
Interactive JavaScript and TypeScript programming with Jupyter
Stars: ✭ 240 (-54.02%)
Mutual labels:  repl
Charly
🐈 The Charly Programming Language | Written by @KCreate
Stars: ✭ 185 (-64.56%)
Mutual labels:  repl
Gluon
A static, type inferred and embeddable language written in Rust.
Stars: ✭ 2,457 (+370.69%)
Mutual labels:  repl
Unrepl
A common ground for better Clojure REPLs
Stars: ✭ 222 (-57.47%)
Mutual labels:  repl
Jupyter Php
A PHP Kernel for Jupyter
Stars: ✭ 179 (-65.71%)
Mutual labels:  repl
swiftreplmadness
Example of using your own packages in the Swift REPL
Stars: ✭ 18 (-96.55%)
Mutual labels:  repl
Ldb
A C++ REPL / CLI for LevelDB
Stars: ✭ 201 (-61.49%)
Mutual labels:  repl
Mond
A scripting language for .NET Core
Stars: ✭ 237 (-54.6%)
Mutual labels:  repl
Lgo
Interactive Go programming with Jupyter
Stars: ✭ 2,225 (+326.25%)
Mutual labels:  repl
Blazorrepl
Write, compile, execute and share Blazor components entirely in the browser
Stars: ✭ 196 (-62.45%)
Mutual labels:  repl
Lfortran
Official mirror of https://gitlab.com/lfortran/lfortran. Please submit pull requests (PR) there. Any PR sent here will be closed automatically.
Stars: ✭ 220 (-57.85%)
Mutual labels:  repl
Fridayuserbot
A Pluggable And Powerful Telegram Manager Bot
Stars: ✭ 183 (-64.94%)
Mutual labels:  repl
Go Pry
An interactive REPL for Go that allows you to drop into your code at any point.
Stars: ✭ 2,747 (+426.25%)
Mutual labels:  repl
Calvin
A minimalistic build tool for clojurescript projects that does not require the jvm
Stars: ✭ 181 (-65.33%)
Mutual labels:  repl
Vsh
vsh - HashiCorp Vault interactive shell and cli tool
Stars: ✭ 209 (-59.96%)
Mutual labels:  repl
sliver
REPL for SilverStripe, powered by Psysh. Interactively debug and tinker with a sliver of your code.
Stars: ✭ 17 (-96.74%)
Mutual labels:  repl
Ipython
Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
Stars: ✭ 15,107 (+2794.06%)
Mutual labels:  repl
Box
A mruby-based Builder for Docker Images
Stars: ✭ 236 (-54.79%)
Mutual labels:  repl

dotnet-repl

REPL preview in C# and F#

This project is an experiment using .NET Interactive / Polyglot Notebooks and Spectre.Console to create a polyglot .NET REPL for use on the command line.

This is a personal project. Hopefully you enjoy it and find it useful. Contributions are welcome.

NuGet Status Build status

Installation

To install dotnet-repl, run the following in your terminal:

> dotnet tool install -g dotnet-repl

Features

Here's what you can do with it:

Code in C#

You can start dotnet-repl in one of a number of different language modes. The default is C#, so the following two commands are equivalent:

> dotnet repl --default-kernel csharp
> dotnet repl

Once the REPL has started, you can type C# code at the prompt and run it by pressing Enter. (Note that this is the C# scripting dialect, which is also used in Visual Studio's C# Interactive Window and in .NET Interactive Notebooks.)

One notable feature of C# scripting is the ability to specify a return value for a code submission using a "trailing expression":

Code in F#

You can also start up the REPL in F# mode with --default-kernel or set the environment variable DOTNET_REPL_DEFAULT_KERNEL to fsharp:

> dotnet repl --default-kernel fsharp
# DOTNET_REPL_DEFAULT_KERNEL=fsharp
> dotnet repl

📝 Submit multi-line entries

By pressing Shift-Enter, you can add multiple lines before running your code using Enter. This can be useful for creating multi-line code constructs, including declaring classes.

Another handy aspect of multi-line entries is that you no longer need to use the the F# Interactive convention of terminating a line with ;; to indicate that the accumulated submission should be run. Pressing Enter will submit the code, and if you need more than one line of code at a time, you can use Shift-Enter to add lines before submitting.

🚥 Switch languages within the same session

🎁 Add NuGet packages

You can use #r nuget to install a package for the duration of the current session.

🌱 Initialize your REPL session using a notebook, script, or code file

You can use a file containing code as an initialization script for the REPL.

> dotnet repl --run /path/to/notebook.ipynb

The following file types are supported

🏃🏽 Run a notebook, script, or code file and then exit

You might also want to just use a notebook or other file containing code as a non-interactive script. You can do this by adding the --exit-after-run flag. As long as the file extension indicates a language understood by .NET Interactive, it will try to run it.

> dotnet repl --run /path/to/notebook.ipynb --exit-after-run

File formats currently supported are:

  • .ipynb: A Jupyter notebook, which can contain code cells in multiple different languages understood by .NET Interactive.
  • .dib: A .NET Interactive script file.
  • .cs: A C# source code file. (Some language constructs, such as namespaces, are not supported, so this one is extra experimental.)
  • .csx: A C# script file.
  • .fs: An F# source code file.
  • .fsx: An F# script file.
  • .ps1: A PowerShell script.
  • .html: An HTML file. (This will render in an external browser window.)
  • .js: A JavaScript file. (This will render in an external browser window.)

If all of the notebook's cells execute successfully, a 0 exit code is returned. Otherwise, 2 is returned. This can be used as a way to test notebooks.

image

If you also want to capture the notebook output when it runs, you can do so by specifying the --output-path and --output-format options. --output-path should be the file name you would like to write to. --output-format can be either ipynb or trx. ipynb is the default and will write a Jupyter notebook file with the outputs captured from the run. You can open this file using the .NET Interactive Notebooks extension in Visual Studio Code, or any number of other Jupyter readers, and it can be displayed in GitHub. The trx format is a .NET test result file and can be useful in CI pipelines such as Azure DevOps, or can be opened with Visual Studio, or read with the t-rex tool.

🛳️ Import a notebook or script and run it

If the REPL is already running, you can import a file into it and run it immediately using the #!import magic command. All of the same file types that --run supports are supported by #!import.

🏀 Pass parameters when running a notebook or script

If a notebook contains magic commands with @input tokens, running them in a notebook editor like .NET Interactive Notebooks will create a prompt for user input. Values for these inputs can provided on the command line using the --input option.

For example, let's say you have a notebook called notebook.ipynb containing the following magic commnand:

#!connect mssql --kernel-name mydatabase @input:connectionString

You can pass in the connection string from the command line like this:

> dotnet repl --run notebook.ipynb --input connectionString="Persist Security Info=False; Integrated Security=true; Initial Catalog=MyDatabase; Server=localhost"

💁‍♀️ Ask for help

You can see help for the REPL by running the #!help magic command. I won't print it all here because it's a work in progress. Just give it a try.

Keyboard shortcuts

dotnet-repl supports a number of keyboard shortcuts. These will evolve over time but for now, here they are:

Keybinding What it does
Enter Submit and run the current code
Shift+Enter Inserts a newline without submitting the current code
Tab Show next completion
Shift+Tab Show previous completion
Ctrl+C Exit the REPL
Ctrl+Up Go back through your submission history (current session only)
Ctrl+Down Go forward through your submission history (current session only)

🧙‍♂️ Magic commands

Because dotnet-repl is built on .NET Interactive, it supports "magic commands". You can recognize a magic command by the #! at the start of a line.

You can see the list of supported magic commands by running the #!help magic command.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].