@@ -748,6 +748,7 @@ def __init__(
748
748
column_borders : bool = True ,
749
749
padding : int = 1 ,
750
750
border_fg : Optional [ansi .FgColor ] = None ,
751
+ border_bg : Optional [ansi .BgColor ] = None ,
751
752
header_bg : Optional [ansi .BgColor ] = None ,
752
753
data_bg : Optional [ansi .BgColor ] = None ,
753
754
) -> None :
@@ -762,6 +763,7 @@ def __init__(
762
763
a row's cells. (Defaults to True)
763
764
:param padding: number of spaces between text and left/right borders of cell
764
765
:param border_fg: optional foreground color for borders (defaults to None)
766
+ :param border_bg: optional background color for borders (defaults to None)
765
767
:param header_bg: optional background color for header cells (defaults to None)
766
768
:param data_bg: optional background color for data cells (defaults to None)
767
769
:raises: ValueError if tab_width is less than 1
@@ -776,18 +778,19 @@ def __init__(
776
778
self .padding = padding
777
779
778
780
self .border_fg = border_fg
781
+ self .border_bg = border_bg
779
782
self .header_bg = header_bg
780
783
self .data_bg = data_bg
781
784
782
- def apply_border_fg (self , value : Any ) -> str :
785
+ def apply_border_color (self , value : Any ) -> str :
783
786
"""
784
- If defined, apply the border foreground color to border text
787
+ If defined, apply the border foreground and background colors
785
788
:param value: object whose text is to be colored
786
789
:return: formatted text
787
790
"""
788
- if self .border_fg is None :
791
+ if self .border_fg is None and self . border_bg is None :
789
792
return str (value )
790
- return ansi .style (value , fg = self .border_fg )
793
+ return ansi .style (value , fg = self .border_fg , bg = self . border_bg )
791
794
792
795
def apply_header_bg (self , value : Any ) -> str :
793
796
"""
@@ -853,10 +856,10 @@ def generate_table_top_border(self) -> str:
853
856
854
857
return self .generate_row (
855
858
row_data = self .empty_data ,
856
- fill_char = self .apply_border_fg (fill_char ),
857
- pre_line = self .apply_border_fg (pre_line ),
858
- inter_cell = self .apply_border_fg (inter_cell ),
859
- post_line = self .apply_border_fg (post_line ),
859
+ fill_char = self .apply_border_color (fill_char ),
860
+ pre_line = self .apply_border_color (pre_line ),
861
+ inter_cell = self .apply_border_color (inter_cell ),
862
+ post_line = self .apply_border_color (post_line ),
860
863
)
861
864
862
865
def generate_header_bottom_border (self ) -> str :
@@ -874,32 +877,32 @@ def generate_header_bottom_border(self) -> str:
874
877
875
878
return self .generate_row (
876
879
row_data = self .empty_data ,
877
- fill_char = self .apply_border_fg (fill_char ),
878
- pre_line = self .apply_border_fg (pre_line ),
879
- inter_cell = self .apply_border_fg (inter_cell ),
880
- post_line = self .apply_border_fg (post_line ),
880
+ fill_char = self .apply_border_color (fill_char ),
881
+ pre_line = self .apply_border_color (pre_line ),
882
+ inter_cell = self .apply_border_color (inter_cell ),
883
+ post_line = self .apply_border_color (post_line ),
881
884
)
882
885
883
886
def generate_row_bottom_border (self ) -> str :
884
887
"""Generate a border which appears at the bottom of rows"""
885
- fill_char = self . apply_data_bg ( '─' )
888
+ fill_char = '─'
886
889
887
- pre_line = '╟' + self .apply_data_bg ( self . padding * '─' )
890
+ pre_line = '╟' + self .padding * '─'
888
891
889
892
inter_cell = self .padding * '─'
890
893
if self .column_borders :
891
894
inter_cell += '┼'
892
895
inter_cell += self .padding * '─'
893
- inter_cell = self . apply_data_bg ( inter_cell )
896
+ inter_cell = inter_cell
894
897
895
- post_line = self .apply_data_bg ( self . padding * '─' ) + '╢'
898
+ post_line = self .padding * '─' + '╢'
896
899
897
900
return self .generate_row (
898
901
row_data = self .empty_data ,
899
- fill_char = self .apply_border_fg (fill_char ),
900
- pre_line = self .apply_border_fg (pre_line ),
901
- inter_cell = self .apply_border_fg (inter_cell ),
902
- post_line = self .apply_border_fg (post_line ),
902
+ fill_char = self .apply_border_color (fill_char ),
903
+ pre_line = self .apply_border_color (pre_line ),
904
+ inter_cell = self .apply_border_color (inter_cell ),
905
+ post_line = self .apply_border_color (post_line ),
903
906
)
904
907
905
908
def generate_table_bottom_border (self ) -> str :
@@ -917,25 +920,24 @@ def generate_table_bottom_border(self) -> str:
917
920
918
921
return self .generate_row (
919
922
row_data = self .empty_data ,
920
- fill_char = self .apply_border_fg (fill_char ),
921
- pre_line = self .apply_border_fg (pre_line ),
922
- inter_cell = self .apply_border_fg (inter_cell ),
923
- post_line = self .apply_border_fg (post_line ),
923
+ fill_char = self .apply_border_color (fill_char ),
924
+ pre_line = self .apply_border_color (pre_line ),
925
+ inter_cell = self .apply_border_color (inter_cell ),
926
+ post_line = self .apply_border_color (post_line ),
924
927
)
925
928
926
929
def generate_header (self ) -> str :
927
930
"""Generate table header"""
928
931
fill_char = self .apply_header_bg (SPACE )
929
932
930
- pre_line = self .apply_border_fg ('║' ) + self .apply_header_bg (self .padding * SPACE )
933
+ pre_line = self .apply_border_color ('║' ) + self .apply_header_bg (self .padding * SPACE )
931
934
932
- inter_cell = self .padding * SPACE
935
+ inter_cell = self .apply_header_bg ( self . padding * SPACE )
933
936
if self .column_borders :
934
- inter_cell += self .apply_border_fg ('│' )
935
- inter_cell += self .padding * SPACE
936
- inter_cell = self .apply_header_bg (inter_cell )
937
+ inter_cell += self .apply_border_color ('│' )
938
+ inter_cell += self .apply_header_bg (self .padding * SPACE )
937
939
938
- post_line = self .apply_header_bg (self .padding * SPACE ) + self .apply_border_fg ('║' )
940
+ post_line = self .apply_header_bg (self .padding * SPACE ) + self .apply_border_color ('║' )
939
941
940
942
# Apply background color to header text in Columns which allow it
941
943
to_display : List [Any ] = []
@@ -968,15 +970,14 @@ def generate_data_row(self, row_data: Sequence[Any]) -> str:
968
970
"""
969
971
fill_char = self .apply_data_bg (SPACE )
970
972
971
- pre_line = self .apply_border_fg ('║' ) + self .apply_data_bg (self .padding * SPACE )
973
+ pre_line = self .apply_border_color ('║' ) + self .apply_data_bg (self .padding * SPACE )
972
974
973
- inter_cell = self .padding * SPACE
975
+ inter_cell = self .apply_data_bg ( self . padding * SPACE )
974
976
if self .column_borders :
975
- inter_cell += self .apply_border_fg ('│' )
976
- inter_cell += self .padding * SPACE
977
- inter_cell = self .apply_data_bg (inter_cell )
977
+ inter_cell += self .apply_border_color ('│' )
978
+ inter_cell += self .apply_data_bg (self .padding * SPACE )
978
979
979
- post_line = self .apply_data_bg (self .padding * SPACE ) + self .apply_border_fg ('║' )
980
+ post_line = self .apply_data_bg (self .padding * SPACE ) + self .apply_border_color ('║' )
980
981
981
982
# Apply background color to data text in Columns which allow it
982
983
to_display : List [Any ] = []
@@ -1041,6 +1042,7 @@ def __init__(
1041
1042
column_borders : bool = True ,
1042
1043
padding : int = 1 ,
1043
1044
border_fg : Optional [ansi .FgColor ] = None ,
1045
+ border_bg : Optional [ansi .BgColor ] = None ,
1044
1046
header_bg : Optional [ansi .BgColor ] = None ,
1045
1047
odd_bg : Optional [ansi .BgColor ] = None ,
1046
1048
even_bg : Optional [ansi .BgColor ] = ansi .Bg .DARK_GRAY ,
@@ -1058,14 +1060,21 @@ def __init__(
1058
1060
a row's cells. (Defaults to True)
1059
1061
:param padding: number of spaces between text and left/right borders of cell
1060
1062
:param border_fg: optional foreground color for borders (defaults to None)
1063
+ :param border_bg: optional background color for borders (defaults to None)
1061
1064
:param header_bg: optional background color for header cells (defaults to None)
1062
1065
:param odd_bg: optional background color for odd numbered data rows (defaults to None)
1063
1066
:param even_bg: optional background color for even numbered data rows (defaults to StdBg.DARK_GRAY)
1064
1067
:raises: ValueError if tab_width is less than 1
1065
1068
:raises: ValueError if padding is less than 0
1066
1069
"""
1067
1070
super ().__init__ (
1068
- cols , tab_width = tab_width , column_borders = column_borders , padding = padding , border_fg = border_fg , header_bg = header_bg
1071
+ cols ,
1072
+ tab_width = tab_width ,
1073
+ column_borders = column_borders ,
1074
+ padding = padding ,
1075
+ border_fg = border_fg ,
1076
+ border_bg = border_bg ,
1077
+ header_bg = header_bg ,
1069
1078
)
1070
1079
self .row_num = 1
1071
1080
self .odd_bg = odd_bg
0 commit comments