Wednesday, February 20, 2019

A CLI in CircuitPython

In a recent guide we had a look at CircuitScheme: a Scheme-like Lisp dialect implemented in CircuitPython. One area of improvement that was mentioned was the improvement of the REPL.

A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple, interactive programming environment that takes single user inputs (i.e., single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise.

The prior REPL in CircuitScheme was just a way to enter code via the console. It simply reads characters and tried to evaluate what you entered when you ended the line.

This guide walks through a more feature complete REPL for CircuitScheme. Even though it was written for CircuitScheme, it's completely independent except for 2 function calls. This means that it's quite general and can easily be adapted to most situations where you need to enter keyboard commands to a CircuitPython app.

In CPython there is the readline module that pulls in GNU readline. readline provides a very feature-rich line editor.  That's not an option for CircuitPython, but we can do much the same thing in pure Python.

No comments:

Post a Comment