Giter VIP home page Giter VIP logo

dotnet-repl's Introduction

dotnet-repl

REPL preview in C# and F#

This project is an experiment using .NET Interactive 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

You can use a notebook file (either .ipynb or .dib) as an initialization script for the REPL.

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

Run a notebook as a script

You might also want to just use a notebook as a non-interactive script. You can do this by adding the --exit-after-run flag.

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

Both .ipynb and .dib files are supported.

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

image

๐Ÿ’โ€โ™€๏ธ Ask for help

You can see help for the REPL by running the #!help magic command. I won't print it 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.

dotnet-repl's People

Contributors

jonsequitur avatar patriksvensson avatar whiteblackgoose avatar happypig375 avatar michaeloyer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.