Module nh_console

The remote console NervesHub attaches to.

Description

The remote console NervesHub attaches to.

nerves_hub_link on Nerves answers the console channel with a real IEx session over ExTTY, so an operator gets the language. AtomVM has no shell and no ExTTY, so this is a debug terminal instead: a fixed set of commands that answer the questions a console is usually opened to answer.

That difference is worth being plain about. This will not evaluate Erlang, and it is not a way in to a running system — it reports, and it reboots.

The protocol

NervesHub drives it over the console topic:

  dn           %{"data" => Keystrokes}    server -> device
  window_size  %{"height" =>, "width" =>} server -> device
  restart                                 server -> device
  up           %{"data" => Output}        device -> server

Keystrokes arrive as they are typed, so this echoes them back: nothing else is going to, and a terminal that shows nothing while you type reads as broken. restart clears the session the way it restarts IEx on Nerves — it does not restart the device, which is what reboot is for.

File transfer is declined. file-data/* exists to push a file onto a device with a filesystem to put it in, and this one has partitions.

Data Types

state()

state() = #{line := binary(), mode := input | escape | escape_bracket}

Function Index

banner/0What to send when someone first attaches.
commands/0The commands and what each is for.
handle_input/2Feed keystrokes in, get terminal output back.
new/0A console session with nothing typed.
parse/1Split a line into a command and its arguments.
prompt/0
restart/1Reset the session, as restart does to IEx on Nerves.

Function Details

banner/0

banner() -> binary()

What to send when someone first attaches.

A console that says nothing until you type looks like one that is not working, and the commands here are not guessable.

commands/0

commands() -> [{binary(), binary()}]

The commands and what each is for.

handle_input/2

handle_input(Data::binary(), State::state()) -> {state(), binary()}

Feed keystrokes in, get terminal output back.

Returns everything to send in one up, so a line that runs a command echoes the newline, the output and the next prompt together.

new/0

new() -> state()

A console session with nothing typed.

parse/1

parse(Line::binary()) -> {binary(), [binary()]} | empty

Split a line into a command and its arguments.

prompt/0

prompt() -> binary()

restart/1

restart(State::state()) -> {state(), binary()}

Reset the session, as restart does to IEx on Nerves.


Generated by EDoc