[tor-commits] [nyx/master] Make max torrc line wrapping configurable
atagar at torproject.org
atagar at torproject.org
Sun Feb 14 02:55:49 UTC 2016
commit dda12b882596593c3e559ee200c12b4604387a55
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Feb 8 17:48:44 2016 -0800
Make max torrc line wrapping configurable
Log panel has a config option for this so might as well mirror it here.
---
nyx/log_panel.py | 6 +++---
nyx/torrc_panel.py | 37 ++++++++++++++++++-------------------
nyxrc.sample | 4 +++-
3 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/nyx/log_panel.py b/nyx/log_panel.py
index 258d7a7..e1c79af 100644
--- a/nyx/log_panel.py
+++ b/nyx/log_panel.py
@@ -20,7 +20,7 @@ from nyx.util import join, panel, tor_controller, ui_tools
def conf_handler(key, value):
- if key == 'features.log.maxLinesPerEntry':
+ if key == 'features.log.maxLineWrap':
return max(1, value)
elif key == 'features.log.prepopulateReadLimit':
return max(0, value)
@@ -33,7 +33,7 @@ def conf_handler(key, value):
CONFIG = conf.config_dict('nyx', {
'features.logFile': '',
'features.log.showDuplicateEntries': False,
- 'features.log.maxLinesPerEntry': 6,
+ 'features.log.maxLineWrap': 6,
'features.log.prepopulate': True,
'features.log.prepopulateReadLimit': 5000,
'features.log.maxRefreshRate': 300,
@@ -380,7 +380,7 @@ class LogPanel(panel.Panel, threading.Thread):
while msg:
x, msg = draw_line(x, y, width, msg, *attr)
- if (y - orig_y + 1) >= CONFIG['features.log.maxLinesPerEntry']:
+ if (y - orig_y + 1) >= CONFIG['features.log.maxLineWrap']:
break # filled up the maximum number of lines we're allowing for
if msg:
diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py
index ffe7b9b..21d5576 100644
--- a/nyx/torrc_panel.py
+++ b/nyx/torrc_panel.py
@@ -9,9 +9,17 @@ from nyx.util import expand_path, msg, panel, tor_controller, ui_tools
from stem import ControllerError
from stem.control import State
-from stem.util import str_tools
+from stem.util import conf, str_tools
-MAX_WRAP_PER_LINE = 8
+
+def conf_handler(key, value):
+ if key == 'features.log.maxLineWrap':
+ return max(1, value)
+
+
+CONFIG = conf.config_dict('nyx', {
+ 'features.torrc.maxLineWrap': 8,
+}, conf_handler)
class TorrcPanel(panel.Panel):
@@ -122,21 +130,14 @@ class TorrcPanel(panel.Panel):
self.addstr(1, 0, self._torrc_load_error, 'red', curses.A_BOLD)
return
- # restricts scroll location to valid bounds
-
self._scroll = max(0, min(self._scroll, self._last_content_height - height + 1))
- # offset to make room for the line numbers
-
- line_number_offset = 0
-
- if self._show_line_numbers:
- if len(self._torrc_content) == 0:
- line_number_offset = 2
- else:
- line_number_offset = int(math.log10(len(self._torrc_content))) + 2
-
- # draws left-hand scroll bar if content's longer than the height
+ if not self._show_line_numbers:
+ line_number_offset = 0
+ elif len(self._torrc_content) == 0:
+ line_number_offset = 2
+ else:
+ line_number_offset = int(math.log10(len(self._torrc_content))) + 2
scroll_offset = 0
@@ -147,9 +148,7 @@ class TorrcPanel(panel.Panel):
display_line = -self._scroll + 1 # line we're drawing on
is_multiline = False # true if we're in the middle of a multiline torrc entry
- for line_number in range(0, len(self._torrc_content)):
- line = self._torrc_content[line_number]
-
+ for line_number, line in enumerate(self._torrc_content):
if self._strip_comments:
line = line[:line.find('#')].rstrip() if '#' in line else line.rstrip()
@@ -215,7 +214,7 @@ class TorrcPanel(panel.Panel):
if len(label) >= max_msg_size:
# message is too long - break it up
- if line_offset == MAX_WRAP_PER_LINE - 1:
+ if line_offset == CONFIG['features.log.maxLineWrap'] - 1:
label = str_tools.crop(label, max_msg_size)
else:
include_break = True
diff --git a/nyxrc.sample b/nyxrc.sample
index 186df2b..dfb9873 100644
--- a/nyxrc.sample
+++ b/nyxrc.sample
@@ -73,13 +73,15 @@ features.confirmQuit true
# preconfigured regular expression pattern, up to five will be loaded
features.log.showDuplicateEntries false
-features.log.maxLinesPerEntry 6
+features.log.maxLineWrap 6
features.log.prepopulate true
features.log.prepopulateReadLimit 5000
features.log.maxRefreshRate 300
#features.log.regex My First Regex Pattern
#features.log.regex ^My Second Regex Pattern$
+features.torrc.maxLineWrap 8
+
# Paremters for the config panel
# ---------------------------
# order
More information about the tor-commits
mailing list