Giter Site home page Giter Site logo

ldplnoise's Introduction

LDPLNOISE

LDPL 4.3 extension with linenoise support. linenoise is a lite version of readline, originally at https://github.com/antirez/linenoise.

This version wraps https://github.com/yhirose/cpp-linenoise.

Usage

There's only one required variable: RL-INPUT. You must declare it before using this extension:

DATA:
RL-INPUT is EXTERNAL TEXT

The optional variables are:

  • RL-PROMPT
    • Defaults to > and allows you to customize the prompt shown to users.
  • RL-HISTORY-FILE
    • Can be set to the path to the history file for this program.

To actually use the library, call the RL-ACCEPT subroutine to prompt the user for input:

STORE "Type something: " IN RL-PROMPT
CALL EXTERNAL RL-ACCEPT

What the user inputs will be put into the RL-INPUT text variable:

DISPLAY "You entered: " RL-INPUT CRLF

So the above will print:

Type something: <user types Dave and presses >
You entered: Dave

To record history for a single session, call RL-ADD-HISTORY after calling RL-ACCEPT. The content of the RL-INPUT variable will be added to the history.

To persist history across sessions, you need to save and load a history file. To do so, first set the RL-HISTORY-FILE text variable to the location of your history file, then use the RL-LOAD-HISTORY and RL-SAVE-HISTORY subroutines to load/save the history when your LDPL program begins and ends:

# ...program starts...
STORE "history.txt" IN RL-HISTORY
CALL EXTERNAL RL-LOAD-HISTORY
# ...main program code...
CALL EXTERNAL RL-ACCEPT
CALL EXTERNAL RL-ADD-HISTORY
# ...before the program exits...
CALL EXTERNAL RL-SAVE-HISTORY

Setup

The easy way to include LDPLNOISE in your project is to clone this repo into it and tell the the ldpl compiler where to find ldplnoise.cpp:

cd my-great-ldpl-project
git clone https://github.com/xvxx/ldplnoise
ldpl -i=ldplnoise/ldplnoise.cpp my-code.ldpl
./my-code-bin

You can also use the EXTENSION statement in your LDPL files:

EXTENSION "ldplnoise.cpp"

Example

git clone https://github.com/xvxx/ldplnoise
cd ldplnoise
make example

This should launch you into a basic prompt that echos what you type and remembers you history for that session. To exit, just type "quit" or "exit", submit an empty line, or hit Ctrl-C.

Check out example.ldpl to see an example of using the extension.

LDPL API

Variables:

RL-INPUT          # text entered by the user during RL-ACCEPT
RL-PROMPT         # text prompt shown to user. optional
RL-HISTORY-FILE   # text path to history file

Subroutines:

RL-ACCEPT                # main readline()-like prompt function.
RL-LOAD-HISTORY          # load command history from RL-HISTORY-FILE
RL-SAVE-HISTORY          # save command history to RL-HISTORY-FFILE
RL-ADD-HISTORY           # add content of RL-INPUT to the history
                         # should be called after RL-ACCEPT

ldplnoise's People

Contributors

xvxx avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lartu

ldplnoise's Issues

Add to base LDPL

Hi hi, I was wondering, what if we added this to the base LDPL input command? It would be nice to have the features LDPLNoise has, and incorporating it into the main codebase doesn't seem to be complicated nor to add any dependencies that are not part of this repo ๐Ÿค”

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.