You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-38
Original file line number
Diff line number
Diff line change
@@ -10,49 +10,53 @@ Only works on the `extensions` branch of https://github.com/dvkt/ldpl
10
10
Usage
11
11
-----
12
12
13
-
For readline-like behavior, first set the `RL-PROMPT` text variable to a prompt then call the `RL-ACCEPT` subroutine:
13
+
Any LDPL program using this extension must declare these three variables, even if you're not going to use them:
14
14
15
-
STORE "Type something: " IN RL-PROMPT
16
-
CALL RL-ACCEPT
17
-
18
-
What the user inputs will be put into the `RL-INPUT` text variable:
19
-
20
-
DISPLAY "You entered: " RL-INPUT CRLF
15
+
DATA:
16
+
RL-INPUT is TEXT
17
+
RL-PROMPT is TEXT
18
+
RL-HISTORY-FILE is TEXT
21
19
22
-
To save and load history, 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 and the `RL-ADD-HISTORY` subroutine to add the value of `RL-INPUT` to the current history:
20
+
-`RL-INPUT` will be filled with the user's input after prompting them.
21
+
-`RL-PROMPT` will default to `> ` and allows you to customize the prompt shown to users. Optional.
22
+
-`RL-HISTORY-FILE` can be set by you to the location of the history file for this program. Optional.
23
23
24
-
STORE "history.txt" IN RL-HISTORY
25
-
CALL RL-LOAD-HISTORY
26
-
# code that calls RL-ACCEPT
27
-
CALL RL-ADD-HISTORY
28
-
# then, before you exit:
29
-
CALL RL-SAVE-HISTORY
24
+
To actually use the library, call the `RL-ACCEPT` subroutine to prompt the user for input:
30
25
31
-
Setup
32
-
-----
26
+
STORE "Type something: " IN RL-PROMPT
27
+
CALL EXTERNAL RL-ACCEPT
33
28
34
-
To build a static archive for your platform, cd into this repo and run:
29
+
What the user inputs will be put into the `RL-INPUT` text variable:
35
30
36
-
make
31
+
DISPLAY "You entered: " RL-INPUT CRLF
37
32
38
-
This will create `ldplnoise.a`. Copy that file and `ldplnoise.h` into your LDPL project's root directory.
33
+
So the above will print:
39
34
40
-
Then compile your LDPL project:
35
+
Type something: <user types Dave and presses >
36
+
You entered: Dave
41
37
42
-
ldpl -i=ldplnoise.h your-code.ldpl
38
+
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.
43
39
44
-
You can test that the archive was created correctly by compiling `test.lsc` in this repo:
40
+
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:
45
41
46
-
ldpl -i=ldplnoise.h test.lsc
47
-
./test-bin
42
+
# ...program starts...
43
+
STORE "history.txt" IN RL-HISTORY
44
+
CALL EXTERNAL RL-LOAD-HISTORY
45
+
# ...main program code...
46
+
CALL EXTERNAL RL-ACCEPT
47
+
CALL EXTERNAL RL-ADD-HISTORY
48
+
# ...before the program exits...
49
+
CALL EXTERNAL RL-SAVE-HISTORY
48
50
49
-
Most likely you'll want to include this entire repo in your LDPL project and, in your build process, create an archive using the following commands:
51
+
Setup
52
+
-----
50
53
51
-
c++ -c linenoise.hpp -std=gnu++11 -o linenoise.o
52
-
c++ -c ldplnoise.cpp -std=gnu++11 -o ldplnoise.o
53
-
ar -cvq ldplnoise.a ldplnoise.o linenoise.o
54
+
The easy way to include LDPLNOISE in your project is to just clone this repo into it and tell the the `ldpl` compiler where to find `ldplnoise.cpp`:
54
55
55
-
Then pass -i=ldplnoise.h to `ldpl` when compiling your project.
56
+
cd my-great-ldpl-project
57
+
git clone https://github.com/dvkt/ldplnoise
58
+
ldpl -i=ldplnoise/ldplnoise.cpp my-code.ldpl
59
+
./my-code-bin
56
60
57
61
Example
58
62
-------
@@ -63,21 +67,21 @@ Example
63
67
64
68
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.
65
69
66
-
Check out `test.lsc` to see an example of using the extension.
70
+
Check out `test.ldpl` to see an example of using the extension.
67
71
68
72
LDPL API
69
73
--------
70
74
71
75
Variables:
72
76
73
-
RL-PROMPT is TEXT
74
-
RL-INPUT is TEXT
75
-
RL-HISTORY-FILE is TEXT
77
+
RL-PROMPT is TEXT # prompt shown to user
78
+
RL-INPUT is TEXT # the user's input after a RL-ACCEPT
79
+
RL-HISTORY-FILE is TEXT # path to history file
76
80
77
81
Subroutines:
78
82
79
-
RL-ACCEPT
80
-
RL-LOAD-HISTORY
81
-
RL-SAVE-HISTORY
82
-
RL-ADD-HISTORY
83
-
83
+
RL-ACCEPT # main readline()-like prompt function.
84
+
RL-LOAD-HISTORY # load command history from RL-HISTORY-FILE
85
+
RL-SAVE-HISTORY # save command history to RL-HISTORY-FFILE
86
+
RL-ADD-HISTORY # add content of RL-INPUT to the history
0 commit comments