Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

from __future__ import print_function

from terminaltables import AsciiTable, DoubleTable, SingleTable
from terminaltables import AsciiTable, DoubleTable, SingleTable, UnicodeSingleTable
try:
from imp import reload
except:
pass # python 2 has it built-in

TABLE_DATA = (
('Platform', 'Years', 'Notes'),
Expand Down Expand Up @@ -37,6 +41,20 @@ def main():
print(table_instance.table)
print()

# UnicodeTable
table_instance = UnicodeSingleTable(TABLE_DATA, title)
table_instance.justify_columns[2] = 'right'
# table_instance.inner_row_border = True
print(table_instance.table)
print()


if __name__ == '__main__':
try:
import sys
reload(sys)
sys.setdefaultencoding('utf8')
except:
pass

main()
3 changes: 3 additions & 0 deletions terminaltables/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Generate simple tables in terminals from a nested list of strings.

Use SingleTable or DoubleTable instead of AsciiTable for box-drawing characters.
Expand All @@ -10,8 +11,10 @@
from terminaltables.github_table import GithubFlavoredMarkdownTable # noqa
from terminaltables.other_tables import DoubleTable # noqa
from terminaltables.other_tables import SingleTable # noqa
from terminaltables.other_tables import UnicodeSingleTable # noqa
from terminaltables.other_tables import PorcelainTable # noqa


__author__ = '@Robpol86'
__license__ = 'MIT'
__version__ = '3.1.0'
1 change: 1 addition & 0 deletions terminaltables/ascii_table.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""AsciiTable is the main table class. To be inherited by other tables. Define convenience methods here."""

from terminaltables.base_table import BaseTable
Expand Down
1 change: 1 addition & 0 deletions terminaltables/base_table.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Base table class. Define just the bare minimum to build tables."""

from terminaltables.build import build_border, build_row, flatten
Expand Down
1 change: 1 addition & 0 deletions terminaltables/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Combine cells into rows."""

from terminaltables.width_and_alignment import visible_width
Expand Down
1 change: 1 addition & 0 deletions terminaltables/github_table.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""GithubFlavoredMarkdownTable class."""

from terminaltables.ascii_table import AsciiTable
Expand Down
51 changes: 51 additions & 0 deletions terminaltables/other_tables.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
# coding=UTF-8
"""Additional simple tables defined here."""

from terminaltables.ascii_table import AsciiTable
from terminaltables.terminal_io import IS_WINDOWS


class UnicodeSingleTable(AsciiTable):
"""Draw a table using UTF-8 border characters. Table borders won't have any gaps between lines.

Similar to the tables shown on PC BIOS boot messages, but not double-lined.

For Python 2.7 and before you might need to force the encoding on stdout to be UTF-8.
That can be done with the following commands, although they are not recommended.
reload(sys)
sys.setdefaultencoding('utf8')

"""

CHAR_F_INNER_HORIZONTAL = u'─'
CHAR_F_INNER_INTERSECT = u'┼'
CHAR_F_INNER_VERTICAL = u'│'
CHAR_F_OUTER_LEFT_INTERSECT = u'├'
CHAR_F_OUTER_LEFT_VERTICAL = u'┌'
CHAR_F_OUTER_RIGHT_INTERSECT = u'┤'
CHAR_F_OUTER_RIGHT_VERTICAL = u'┐'
CHAR_H_INNER_HORIZONTAL = u'─'
CHAR_H_INNER_INTERSECT = u'┼'
CHAR_H_INNER_VERTICAL = '│'
CHAR_H_OUTER_LEFT_INTERSECT = u'├'
CHAR_H_OUTER_LEFT_VERTICAL = u'│'
CHAR_H_OUTER_RIGHT_INTERSECT = u'┤'
CHAR_H_OUTER_RIGHT_VERTICAL = u'│'
CHAR_INNER_HORIZONTAL = u'─'
CHAR_INNER_INTERSECT = u'┼'
CHAR_INNER_VERTICAL = u'│'
CHAR_OUTER_BOTTOM_HORIZONTAL = u'─'
CHAR_OUTER_BOTTOM_INTERSECT = u'┴'
CHAR_OUTER_BOTTOM_LEFT = u'└'
CHAR_OUTER_BOTTOM_RIGHT = u'┘'
CHAR_OUTER_LEFT_INTERSECT = u'├'
CHAR_OUTER_LEFT_VERTICAL = u'│'
CHAR_OUTER_RIGHT_INTERSECT = u'┤'
CHAR_OUTER_RIGHT_VERTICAL = u'│'
CHAR_OUTER_TOP_HORIZONTAL = u'─'
CHAR_OUTER_TOP_INTERSECT = u'┬'
CHAR_OUTER_TOP_LEFT = u'┌'
CHAR_OUTER_TOP_RIGHT = u'┐'

@property
def table(self):
"""Return a large string of the entire table ready to be printed to the terminal."""
ascii_table = super(UnicodeSingleTable, self).table
optimized = ascii_table.replace('\033(B\033(0', '')
return optimized


class UnixTable(AsciiTable):
"""Draw a table using box-drawing characters on Unix platforms. Table borders won't have any gaps between lines.

Expand Down
1 change: 1 addition & 0 deletions terminaltables/terminal_io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Get info about the current terminal window/screen buffer."""

import ctypes
Expand Down
1 change: 1 addition & 0 deletions terminaltables/width_and_alignment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Functions that handle alignment, padding, widths, etc."""

import re
Expand Down