[tor-commits] [nyx/master] Move input_prompt() to controller

atagar at torproject.org atagar at torproject.org
Mon Apr 18 20:23:16 UTC 2016


commit 2d2e0c4435dda692c97a895ece690cf6b11f04db
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Apr 18 12:02:07 2016 -0700

    Move input_prompt() to controller
    
    The controller already proxies this, so might as well move the implementation
    over too. It's tiny.
    
    Also dropping a duplicate redraw() call.
---
 nyx/controller.py   | 18 +++++++++++++++++-
 nyx/panel/header.py | 20 +-------------------
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/nyx/controller.py b/nyx/controller.py
index 3336837..1957770 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -66,7 +66,23 @@ def show_message(message = None, *attr, **kwargs):
 
 
 def input_prompt(msg, initial_value = ''):
-  return get_controller().header_panel().input_prompt(msg, initial_value)
+  """
+  Prompts the user for input.
+
+  :param str message: prompt for user input
+  :param str initial_value: initial value of the prompt
+
+  :returns: **str** with the user input, this is **None** if the prompt is
+    canceled
+  """
+
+  header_panel = get_controller().header_panel()
+
+  header_panel.show_message(msg)
+  user_input = nyx.curses.str_input(len(msg), header_panel.get_height() - 1, initial_value)
+  header_panel.show_message()
+
+  return user_input
 
 
 class Controller(object):
diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 897ffbc..a9712b4 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -77,24 +77,6 @@ class HeaderPanel(nyx.panel.DaemonPanel):
       self.show_message()  # clear override
       return user_input
 
-  def input_prompt(self, message, initial_value = ''):
-    """
-    Prompts the user for input.
-
-    :param str message: prompt for user input
-    :param str initial_value: initial value of the prompt
-
-    :returns: **str** with the user input, this is **None** if the prompt is
-      canceled
-    """
-
-    self.show_message(message)
-    self.redraw(True)
-    user_input = nyx.curses.str_input(len(message), self.get_height() - 1, initial_value)
-    self.show_message()
-
-    return user_input
-
   def is_wide(self):
     """
     True if we should show two columns of information, False otherwise.
@@ -143,7 +125,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
         try:
           controller.reconnect(chroot_path = CONFIG['tor.chroot'])
         except stem.connection.MissingPassword:
-          password = self.input_prompt('Controller Password: ')
+          password = nyx.controller.input_prompt('Controller Password: ')
 
           if password:
             controller.authenticate(password)





More information about the tor-commits mailing list