-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
34 lines (31 loc) · 1.2 KB
/
util.py
File metadata and controls
34 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from typing import List
from wcwidth import wcswidth
def format_output_info(output:List[str], width:int)->str:
'''format the output info like
+---------------------------------+
|              |
|   info          |
|              |
+---------------------------------+
Parameters
----------
output : List[str]
The output info
width : int
The width of the output info
Returns
-------
str
The formatted output info
'''
terminal_width = os.get_terminal_size().columns
max_width = wcswidth(max(*output, key=wcswidth))
width = width if width > max_width else max_width
line_spcace = int((width - max_width)/2)
format_space = int((terminal_width - width - 10)/2)
ans = f'{" "*format_space}+{"-"*width}+\n'
for item in output:
ans += f'{" "*format_space}|{" "*(line_spcace) + item + " "*(width-line_spcace-wcswidth(item))}|\n'
ans += f'{" "*format_space}+{"-"*width}+\n'
return ans