From ade5216f685e75d48f1c6e99327e380b96b650ea Mon Sep 17 00:00:00 2001
From: Issam Maghni <me@concati.me>
Date: Sat, 14 Sep 2019 11:25:45 -0400
Subject: Support RET to set the todo item priority to 0

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/ui-todo.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/ui-todo.c b/src/ui-todo.c
index cc186df..6b20621 100644
--- a/src/ui-todo.c
+++ b/src/ui-todo.c
@@ -35,6 +35,7 @@
  */
 
 #include "calcurse.h"
+#include <ctype.h>
 
 static unsigned ui_todo_view = 0;
 
@@ -55,7 +56,7 @@ static void ui_todo_set_selitem(struct todo *todo)
 /* Request user to enter a new todo item. */
 void ui_todo_add(void)
 {
-	int ch = 0;
+	int ch;
 	const char *mesg = _("Enter the new TODO item:");
 	const char *mesg_id =
 	    _("Enter the TODO priority [0 (none), 1 (highest) - 9 (lowest)]:");
@@ -64,10 +65,12 @@ void ui_todo_add(void)
 	status_mesg(mesg, "");
 	if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) ==
 	    GETSTRING_VALID) {
-		while ((ch < '0') || (ch > '9')) {
+		do {
 			status_mesg(mesg_id, "");
-			ch = keys_wgetch(win[KEY].p);
-		}
+			if ((ch = keys_wgetch(win[KEY].p)) == RETURN) {
+				ch = '0';
+			}
+		} while (!isdigit(ch));
 		struct todo *todo = todo_add(todo_input, ch - '0', 0, NULL);
 		ui_todo_load_items();
 		io_set_modified();
-- 
cgit v1.2.3-70-g09d2