Don't format the prompt.

pull/9/head
Joshua Potter 2023-11-25 12:48:21 -07:00
parent ef2bb9cc1f
commit 27c097eb72
2 changed files with 11 additions and 7 deletions

View File

@ -27,7 +27,7 @@ We start with an example. Consider the following *spec*, which we'll name
{
"filename": {
"type": "STRING",
"prompt": "What file should I create for you?"
"prompt": "What file should I create for you? "
}
}
```
@ -43,12 +43,15 @@ Running `bootstrap` with these two files configured will invoke the following
interactive script:
```bash
> bootstrap example
What file should I create for you? hello-world.txt
Creating hello-world.txt
I: What file should I create for you? hello-world.txt
O: Creating hello-world.txt
>
```
You should now see a new `hello-world.txt` file in the current directory.
Here the line prefixed with `I:` indicates a prompt that must be answered by
the user. The line prefixed with `O:` indicates the output of the builder
script. You should now see a new `hello-world.txt` file in your current working
directory.
## Usage

View File

@ -46,9 +46,10 @@ static const char *prompt_field(struct Field *field) {
switch (field->type) {
case FT_STRING:
printf("%s> ", field->prompt);
char *input = calloc(1, 256);
if (fgets(input, 256, stdin)) {
printf("%s", field->prompt);
// TODO: Probably want this buffer size to be a bit more dynamic.
char *input = calloc(1, 1024);
if (fgets(input, 1024, stdin)) {
size_t len = strlen(input);
if (len > 0 && input[len - 1] == '\n') {
input[len - 1] = '\0';