Package: devtodo / 0.1.20+git20200830.0ad52b0-3

020_use-libedit-readline-compat-layer.patch Patch series | download
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
From: Carlos Henrique Lima Melara <charlesmelara@outlook.com>
Date: Wed, 9 Nov 2022 16:19:45 -0300
Subject: Removes libreadline dependency. Uses libedit compatibility layer
 instead

Author: Carlos Henrique Lima Melara <charlesmelara@outlook.com>
Bug: https://github.com/alecthomas/devtodo/issues/4
Applied-Upstream: 0.1.21, https://github.com/alecthomas/devtodo/commit/afac3bf6670d25684a6a9aac6e05480d3aa67643
Last-Update: 2022-11-09
---
 src/TodoDB.cc  |  2 +-
 src/main.cc    |  2 +-
 src/support.cc | 37 +++++++++----------------------------
 src/support.h  |  2 +-
 src/todorl.h   | 26 --------------------------
 5 files changed, 12 insertions(+), 57 deletions(-)
 delete mode 100644 src/todorl.h

diff --git a/src/TodoDB.cc b/src/TodoDB.cc
index 000ae7b..94e9b67 100644
--- a/src/TodoDB.cc
+++ b/src/TodoDB.cc
@@ -502,7 +502,7 @@ string priority;
 		if (isatty(0)) {
 			if (options.verbose)
 				cout << info << "Enter a priority from those listed above." << normal << endl;
-			priority = readText("priority> ", current, true);
+			priority = readText("priority [" + current + "] > ", "");
 		} else
 			priority = current;
 		priority = trim(priority);
diff --git a/src/main.cc b/src/main.cc
index f3cbafd..da3e61a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,7 +1,7 @@
+#include <readline/readline.h>
 #include "TodoDB.h"
 #include "support.h"
 #include "config.h"
-#include "todorl.h"
 
 void joinArgs(TodoDB &todo, vector<string> const &args, int argc, char const **argv) {
 char const *av[args.size() + argc];
diff --git a/src/support.cc b/src/support.cc
index 8922d0c..2e1db56 100644
--- a/src/support.cc
+++ b/src/support.cc
@@ -4,16 +4,16 @@
 #include <cstdio>
 #include <sstream>
 #include <stdexcept>
+#include <readline/readline.h>
+#include <readline/history.h>
 #include "support.h"
 #include "TodoDB.h"
 #include "Strings.h"
 #include "CommandArgs.h"
 #include "todoterm.h"
 #include "config.h"
-#include "todorl.h"
 
 using namespace str;
-static bool nukeonhit = false;
 
 Options options;
 
@@ -693,7 +693,6 @@ string out = ctime(&date);
 /* Readline support */
 string const *rl_buffer;
 
-static char *getMatches(char *text, int state) {
 static char const *list[] = {
 	"veryhigh",
 	"high",
@@ -702,6 +701,8 @@ static char const *list[] = {
 	"verylow",
 	0
 };
+
+static char *getMatches(const char *text, int state) {
 static int i, len;
 char const *t;
 
@@ -718,42 +719,22 @@ char const *t;
 	return 0;
 }
 
-static char **completion(char *text, int start, int end) {
+static char **completion(const char *text, int start, int end) {
 	if (start == 0)
-		return completion_matches(text, (char*(*)(...))getMatches);
+		return rl_completion_matches(text, (char*(*)(const char*, int))getMatches);
 	return 0;
 }
 
 static int init_rl() {
 	rl_insert_text(const_cast<char*>(rl_buffer->c_str()));
-	rl_attempted_completion_function = (char **(*)(...))completion;
+	rl_attempted_completion_function = (char **(*)(const char*, int, int))completion;
 	return 0;
 }
 
-static int nuke_on_hit() {
-int c = rl_getc(stdin);
-
-	if (nukeonhit && c != 13) {
-		rl_delete_text(0, rl_end);
-		rl_end = rl_mark = rl_point = 0;
-		rl_redisplay();
-		rl_clear_message();
-		nukeonhit = false;
-	}
-	if (c == 14) {
-		rl_insert_text(const_cast<char*>("\n"));
-		return 0;
-	}
-	return c;
-}
-
-string readText(string const &prompt, string existing, bool nuke) {
+string readText(string const &prompt, string existing) {
 string out;
 
-	rl_startup_hook = (int(*)(...))init_rl;
-	rl_getc_function = (int(*)())nuke_on_hit;
-
-	nukeonhit = nuke;
+	rl_startup_hook = (int(*)(const char*, int))init_rl;
 
 	rl_buffer = &existing;
 char const *tmp = readline(const_cast<char*>(prompt.c_str()));
diff --git a/src/support.h b/src/support.h
index adadbda..d1b94c3 100644
--- a/src/support.h
+++ b/src/support.h
@@ -57,7 +57,7 @@ string symbolisePriority(Todo::Priority sym);
 Todo::Priority desymbolisePriority(string sym);
 
 // text input
-string readText(string const &prompt, string existing = "", bool nuke = false);
+string readText(string const &prompt, string existing = "");
 void addHistory(string text);
 
 // Parse command line arguments
diff --git a/src/todorl.h b/src/todorl.h
deleted file mode 100644
index 1b2b5ae..0000000
--- a/src/todorl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef TODORL_H__
-#define TODORL_H__
-
-/*	
-	Explicitly declare readline functions because on several distributions
-	the readline headers do NOT compile under C++ at all due to a lack of
-	function parameters.
-*/
-typedef int intfunc ();
-
-extern "C" int rl_initialize();
-extern "C" char *rl_readline_name;
-extern "C" char **completion_matches(char*, char*(*)(...));
-extern "C" void rl_insert_text(char*);
-extern "C" char **(*rl_attempted_completion_function)(...);
-extern "C" int (*rl_startup_hook)(...);
-extern "C" char *readline(char*);
-extern "C" void add_history(char*);
-extern "C" int rl_getc(FILE *);
-extern "C" int rl_point, rl_end, rl_mark;
-extern "C" int rl_delete_text(int, int);
-extern "C" void rl_redisplay();
-extern "C" void rl_clear_message();
-extern "C" intfunc *rl_getc_function;
-
-#endif