From 5d332e7218eaa6d23f3bfdb99038730274648f23 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 26 Nov 2015 14:58:08 +0100 Subject: fix #842 --- libmproxy/console/flowview.py | 23 ++++++++++++++++++++--- libmproxy/contentviews.py | 14 ++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 4304afb5..0038558b 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -1,8 +1,9 @@ -from __future__ import absolute_import +from __future__ import absolute_import, division import os import traceback import sys +import math import urwid from netlib import odict @@ -207,10 +208,26 @@ class FlowView(tabs.Tabs): if description == "No content" and isinstance(message, HTTPRequest): description = "No request content (press tab to view response)" + # If the users has a wide terminal, he gets fewer lines; this should not be an issue. + chars_per_line = 80 + max_chars = max_lines * chars_per_line + total_chars = 0 text_objects = [] for line in lines: - text_objects.append(urwid.Text(line)) - if len(text_objects) == max_lines: + txt = [] + for (style, text) in line: + if total_chars + len(text) > max_chars: + text = text[:max_chars-total_chars] + txt.append((style, text)) + total_chars += len(text) + if total_chars == max_chars: + break + + # round up to the next line. + total_chars = int(math.ceil(total_chars / chars_per_line) * chars_per_line) + + text_objects.append(urwid.Text(txt)) + if total_chars == max_chars: text_objects.append(urwid.Text([ ("highlight", "Stopped displaying data after %d lines. Press " % max_lines), ("key", "f"), diff --git a/libmproxy/contentviews.py b/libmproxy/contentviews.py index b2459563..eaab8169 100644 --- a/libmproxy/contentviews.py +++ b/libmproxy/contentviews.py @@ -17,18 +17,15 @@ import json import logging import subprocess import sys - import lxml.html import lxml.etree from PIL import Image from PIL.ExifTags import TAGS import html2text import six - from netlib.odict import ODict from netlib import encoding from netlib.utils import clean_bin, hexdump, urldecode, multipartdecode, parse_content_type - from . import utils from .exceptions import ContentViewException from .contrib import jsbeautifier @@ -485,6 +482,12 @@ content_types_map = {} view_prompts = [] +def get(name): + for i in views: + if i.name == name: + return i + + def get_by_shortcut(c): for i in views: if i.prompt[1] == c: @@ -543,11 +546,6 @@ if pyamf: if ViewProtobuf.is_available(): add(ViewProtobuf()) -def get(name): - for i in views: - if i.name == name: - return i - def safe_to_print(lines, encoding="utf8"): """ -- cgit v1.2.3