-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprompt.h
85 lines (77 loc) · 3.12 KB
/
prompt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (C) 2015 Richard Burke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef WED_PROMPT_H
#define WED_PROMPT_H
#include "buffer.h"
#include "list.h"
/* Max length of prompt text */
#define MAX_CMD_PROMPT_LENGTH 50
typedef enum {
PT_SAVE_FILE,
PT_OPEN_FILE,
PT_FIND,
PT_REPLACE,
PT_COMMAND,
PT_GOTO,
PT_BUFFER,
PT_ENTRY_NUM
} PromptType;
/* Prompt configuration */
typedef struct {
PromptType prompt_type; /* Specify prompt type */
const char *prompt_text; /* Prompt text to display */
List *history; /* List to use for prompt history */
int show_last_entry; /* Populate prompt with last history entry */
int select_last_entry; /* Select prompt text if populated with
last entry */
} PromptOpt;
/* Structure for controlling prompt */
typedef struct {
Buffer *prompt_buffer; /* Used for prompt input e.g. Find & Replace,
file name input, etc... */
char *prompt_text; /* Prompt message presented to user
e.g. Find, Replace, Save As, ... */
int cancelled; /* Did the user quit the last prompt */
List *history; /* Stores previous user entries */
size_t history_index; /* Index of previous entry shown */
PromptType prompt_type; /* This is used to drive prompt completion */
List *suggestions; /* Stores suggested prompt completions
e.g. completed file path, buffer name */
size_t suggestion_index; /* Currently displayed suggestion */
int show_suggestion_prompt; /* True if suggestions should be shown */
} Prompt;
Prompt *pr_new(Buffer *prompt_buffer);
void pr_free(Prompt *, int free_prompt_buffer);
Status pr_reset_prompt(Prompt *, const PromptOpt *prompt_opt);
Status pr_set_prompt_text(Prompt *, const char *prompt_text);
Buffer *pr_get_prompt_buffer(const Prompt *);
PromptType pr_get_prompt_type(const Prompt *);
const char *pr_get_prompt_text(const Prompt *);
char *pr_get_prompt_content(const Prompt *);
int pr_prompt_cancelled(const Prompt *);
void pr_prompt_set_cancelled(Prompt *, int cancelled);
void pr_show_suggestion_prompt(Prompt *);
void pr_hide_suggestion_prompt(Prompt *);
Status pr_previous_entry(Prompt *);
Status pr_next_entry(Prompt *);
size_t pr_suggestion_num(const Prompt *);
void pr_clear_suggestions(Prompt *);
Status pr_show_next_suggestion(Prompt *);
Status pr_show_previous_suggestion(Prompt *);
Status pr_show_suggestion(Prompt *, size_t suggestion_index);
#endif