Git Product home page Git Product logo

embeddedcli's Introduction

Embedded CLI

Embedded CLI Logo

Embedded CLI is a library for providing usable command line interfaces for embedded systems. It supports history and command line editing. It is designed to use no dynamic memory, and provide an easy to integrate API.

GitHub Actions

License: BSD 0-Clause

Features

  • Cursor support (left/right/up/down)
  • Searchable history (^R to start search)
  • No dynamic allocation
    • Base structure has a fixed size, with compile time size limitations
  • Comprehensive test suite, including fuzz testing for memory safety
  • Command line comprehension
    • Support for parsing the command line into an argc/argv pair
    • Handling of quoted strings, escaped characters etc...

Works well in conjunction with the Simple Options library to provide quick & easy argument parsing in embedded environments. Using this combination makes it simple to create an extensible CLI interface, with easy argument parsing/usage/help support.

Platform support & requirements

Embedded CLI makes very few assumptions about the platform. Data input/output is abstracted in call backs.

Examples are provided for a posix simulator, STM32

No 3rd party libraries are assumed beyond the following standard C library functions:

  • memcpy
  • memmove
  • memset
  • strcmp
  • strlen
  • strncpy
  • strcpy

All code is C99 compliant.

Memory usage

Memory usage is configurable by adjusting the internal buffering. In the default configuration, it will consume approximately 1.5kB of RAM, most of which is in the history buffer, and 2kB of code space (ARM Thumb2). The easiest way to reduce memory consumption is to drop the support for the history buffer. In this configuration it will consume approximately 200B of RAM, and approximately 1kB of code space (ARM Thumb2).

Thanks

Icon terminal by Ashwin Dinesh from the Noun Project

embeddedcli's People

Contributors

andrerenaud avatar dhylands avatar dwhinham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

embeddedcli's Issues

Doesn't work with real serial terminals

When you press ENTER (or RETURN) on a serial terminal, it generates a CR and not NL.

I noticed that the posix demo works because it doesn't use raw mode, and leaves the CR->NL translation turned on.

If you use screen under linux over a serial port, it sends a CR when you press ENTER, and the embedded CLI doesn't recognize it as an end of line.

Similarly, on the output side, the code currently only generates a NL at the end of the line, and it really needs to generate a CR NL.

I can work around these things by translating CR to NL on the input side and translate NL to CR NL on the putchar side, but I thought I would report it as an issue, since if it were fixed then it would work properly with most of the terminal programs out there. Yes most terminal programs have the option to do this translation for you, but my thinking is that you shouldn't need to rely on the terminal program.

Perhaps it should be a configuration option?

I'm happy to code up a PR for your consideration.

Embedded CLI becomes unresponsive when line buffer is full

Thank you for this clean and simple CLI library!

One thing I noticed while testing it, is that when EMBEDDED_CLI_MAX_LINE - 1 characters are typed into the CLI, the CLI is no longer able to process any further characters (including backspace or movement), putting it into an unrecoverable state.

The range checks in embedded_cli_insert_char() probably just need to account for characters that will not increase the usage of the buffer.

putch callback

Hi,

It would be advantageous for the callback for putch to have a additional parameter that indicates whether the character is the last byte in the transmission.

As an example, the usage case where the transport is over USB, single byte transfers are an expensive operation. With an additional parameter that either tells us that this is the last byte allows flushing to be handled in the call-back directly without needing other solutions or the parameter saying "you can flush now" would make better use of the USB bus.

Prompt argument is not const

void embedded_cli_init(struct embedded_cli *cli, char *prompt,
                       void (*putchar)(void *data, char ch), void *cb_data)

The prompt argument to this function should be const.

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.