OSDN Git Service

[Refactor] #2138 Separated input_repeat_num() from request_command()
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 19 Feb 2022 09:00:38 +0000 (18:00 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 20 Feb 2022 14:51:52 +0000 (23:51 +0900)
src/io/input-key-requester.cpp
src/io/input-key-requester.h

index 5c8d06f..835d3b9 100644 (file)
@@ -77,25 +77,7 @@ void InputKeyRequestor::request_command()
             auto old_arg = command_arg;
             command_arg = 0;
             prt(_("回数: ", "Count: "), 0, 0);
-            while (true) {
-                cmd = inkey();
-                if ((cmd == 0x7F) || (cmd == KTRL('H'))) {
-                    command_arg = command_arg / 10;
-                    prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
-                } else if (cmd >= '0' && cmd <= '9') {
-                    if (command_arg >= 1000) {
-                        bell();
-                        command_arg = 9999;
-                    } else {
-                        command_arg = command_arg * 10 + D2I(cmd);
-                    }
-
-                    prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
-                } else {
-                    break;
-                }
-            }
-
+            cmd = this->input_repeat_num();
             if (command_arg == 0) {
                 command_arg = 99;
                 prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
@@ -377,3 +359,29 @@ char InputKeyRequestor::inkey_from_menu()
 
     return command;
 }
+
+char InputKeyRequestor::input_repeat_num()
+{
+    while (true) {
+        auto cmd = inkey();
+        if ((cmd == 0x7F) || (cmd == KTRL('H'))) {
+            command_arg = command_arg / 10;
+            prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
+            continue;
+        }
+
+        if ((cmd >= '0') && (cmd <= '9')) {
+            if (command_arg >= 1000) {
+                bell();
+                command_arg = 9999;
+            } else {
+                command_arg = command_arg * 10 + D2I(cmd);
+            }
+
+            prt(format(_("回数: %d", "Count: %d"), command_arg), 0, 0);
+            continue;
+        }
+
+        return cmd;
+    }
+}
index 8b78e95..4b6a488 100644 (file)
@@ -29,4 +29,5 @@ private:
 
     short get_command(const keymap_mode mode);
     char inkey_from_menu();
+    char input_repeat_num();
 };