This commit is contained in:
Maximilian Hils 2015-11-26 14:58:08 +01:00
parent 354f84c4c8
commit 5d332e7218
2 changed files with 26 additions and 11 deletions

View File

@ -1,8 +1,9 @@
from __future__ import absolute_import from __future__ import absolute_import, division
import os import os
import traceback import traceback
import sys import sys
import math
import urwid import urwid
from netlib import odict from netlib import odict
@ -207,10 +208,26 @@ class FlowView(tabs.Tabs):
if description == "No content" and isinstance(message, HTTPRequest): if description == "No content" and isinstance(message, HTTPRequest):
description = "No request content (press tab to view response)" 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 = [] text_objects = []
for line in lines: for line in lines:
text_objects.append(urwid.Text(line)) txt = []
if len(text_objects) == max_lines: 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([ text_objects.append(urwid.Text([
("highlight", "Stopped displaying data after %d lines. Press " % max_lines), ("highlight", "Stopped displaying data after %d lines. Press " % max_lines),
("key", "f"), ("key", "f"),

View File

@ -17,18 +17,15 @@ import json
import logging import logging
import subprocess import subprocess
import sys import sys
import lxml.html import lxml.html
import lxml.etree import lxml.etree
from PIL import Image from PIL import Image
from PIL.ExifTags import TAGS from PIL.ExifTags import TAGS
import html2text import html2text
import six import six
from netlib.odict import ODict from netlib.odict import ODict
from netlib import encoding from netlib import encoding
from netlib.utils import clean_bin, hexdump, urldecode, multipartdecode, parse_content_type from netlib.utils import clean_bin, hexdump, urldecode, multipartdecode, parse_content_type
from . import utils from . import utils
from .exceptions import ContentViewException from .exceptions import ContentViewException
from .contrib import jsbeautifier from .contrib import jsbeautifier
@ -485,6 +482,12 @@ content_types_map = {}
view_prompts = [] view_prompts = []
def get(name):
for i in views:
if i.name == name:
return i
def get_by_shortcut(c): def get_by_shortcut(c):
for i in views: for i in views:
if i.prompt[1] == c: if i.prompt[1] == c:
@ -543,11 +546,6 @@ if pyamf:
if ViewProtobuf.is_available(): if ViewProtobuf.is_available():
add(ViewProtobuf()) add(ViewProtobuf())
def get(name):
for i in views:
if i.name == name:
return i
def safe_to_print(lines, encoding="utf8"): def safe_to_print(lines, encoding="utf8"):
""" """