Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
binwalk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
binwalk
Commits
4db37f29
Commit
4db37f29
authored
Feb 21, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug in terminal line wrapping output.
parent
153a2fc9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
18 deletions
+34
-18
display.py
src/binwalk/core/display.py
+34
-18
No files found.
src/binwalk/core/display.py
View file @
4db37f29
...
...
@@ -131,29 +131,45 @@ class Display(object):
Formats a line of text to fit in the terminal window.
For Tim.
'''
delim
=
'
\n
'
offset
=
0
space_offset
=
0
self
.
string_parts
=
[]
delim
=
'
\n
'
if
self
.
fit_to_screen
and
len
(
line
)
>
self
.
SCREEN_WIDTH
:
# Split the line into an array of columns, e.g., ['0', '0x00000000', 'Some description here']
line_columns
=
line
.
split
(
None
,
self
.
num_columns
-
1
)
if
line_columns
:
delim
=
'
\n
'
+
' '
*
line
.
rfind
(
line_columns
[
-
1
])
while
len
(
line
[
offset
:])
>
self
.
SCREEN_WIDTH
:
space_offset
=
line
[
offset
:
offset
+
self
.
HEADER_WIDTH
]
.
rfind
(
' '
)
if
space_offset
==
-
1
or
space_offset
==
0
:
space_offset
=
self
.
SCREEN_WIDTH
self
.
_append_to_data_parts
(
line
,
offset
,
offset
+
space_offset
)
offset
+=
space_offset
self
.
_append_to_data_parts
(
line
,
offset
,
offset
+
len
(
line
[
offset
:]))
return
delim
.
join
(
self
.
string_parts
)
# Find where the start of the last column (description) starts in the line of text.
# All line wraps need to be aligned to this offset.
offset
=
line
.
rfind
(
line_columns
[
-
1
])
# The delimiter will be a newline followed by spaces padding out the line wrap to the alignment offset.
delim
+=
' '
*
offset
# Calculate the maximum length that each wrapped line can be
max_line_wrap_length
=
self
.
SCREEN_WIDTH
-
offset
# Append all but the last column to formatted_line
formatted_line
=
line
[:
offset
]
# Loop to split up line into multiple max_line_wrap_length pieces
while
len
(
line
[
offset
:])
>
max_line_wrap_length
:
# Find the nearest space to wrap the line at (so we don't split a word across two lines)
split_offset
=
line
[
offset
:
offset
+
max_line_wrap_length
]
.
rfind
(
' '
)
# If there were no good places to split the line, just truncate it at max_line_wrap_length
if
split_offset
<
1
:
split_offset
=
max_line_wrap_length
self
.
_append_to_data_parts
(
line
,
offset
,
offset
+
split_offset
)
offset
+=
split_offset
# Add any remaining data (guarunteed to be max_line_wrap_length long or shorter) to self.string_parts
self
.
_append_to_data_parts
(
line
,
offset
,
offset
+
len
(
line
[
offset
:]))
# Append self.string_parts to formatted_line; each part seperated by delim
formatted_line
+=
delim
.
join
(
self
.
string_parts
)
else
:
# Line fits on screen as-is, no need to format it
formatted_line
=
line
return
formatted_line
def
_configure_formatting
(
self
):
'''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment