@@ -8,49 +8,54 @@ import (
88 core "github.com/statloc/core"
99)
1010
11- func GetTable (items map [string ]* core.TableItem ) string {
11+ func GetTable (
12+ items map [string ]* core.TableItem ,
13+ titleLength int ,
14+ LOCLength int ,
15+ filesLength int ,
16+ ) string {
1217 // im sorry for that
13- maxTitleLength , maxLOCLength , maxFilesLength := 5 , 3 , 5
18+ column1width , column2width , column3width := titleLength , LOCLength , filesLength
1419 for title , item := range items {
15- if len (title ) > maxTitleLength {
16- maxTitleLength = len (title )
20+ if len (title ) > int ( column1width ) {
21+ column1width = len (title )
1722 }
1823
1924 LOC := strconv .FormatUint (item .LOC , 10 )
20- if len (LOC ) > maxLOCLength {
21- maxLOCLength = len (LOC )
25+ if len (LOC ) > column2width {
26+ column2width = len (LOC )
2227 }
2328
2429 files := strconv .FormatUint (item .Files , 10 )
25- if len (files ) > maxFilesLength {
26- maxFilesLength = len (files )
30+ if len (files ) > column3width {
31+ column3width = len (files )
2732 }
2833 }
2934
3035 separator := fmt .Sprintf (
3136 "+-%s-+-%s-+-%s-+\n " ,
32- strings .Repeat ("-" , maxTitleLength ),
33- strings .Repeat ("-" , maxLOCLength ),
34- strings .Repeat ("-" , maxFilesLength ),
37+ strings .Repeat ("-" , column1width ),
38+ strings .Repeat ("-" , column2width ),
39+ strings .Repeat ("-" , column3width ),
3540 )
3641
3742 result := fmt .Sprint (
3843 separator ,
3944 fmt .Sprintf (
4045 "| Title%s | LOC%s | Files%s |\n " ,
41- strings .Repeat (" " , maxTitleLength - 5 ),
42- strings .Repeat (" " , maxLOCLength - 3 ),
43- strings .Repeat (" " , maxFilesLength - 5 ),
46+ strings .Repeat (" " , column1width - titleLength ),
47+ strings .Repeat (" " , column2width - LOCLength ),
48+ strings .Repeat (" " , column3width - filesLength ),
4449 ),
4550 separator ,
4651 )
4752
4853 for title , item := range items {
4954 result += fmt .Sprintf (
5055 "| %s%s | %d%s | %d%s |\n " ,
51- title , strings .Repeat (" " , maxTitleLength - len (title )),
52- item .LOC , strings .Repeat (" " , maxLOCLength - len (strconv .FormatUint (item .LOC , 10 ))),
53- item .Files , strings .Repeat (" " , maxFilesLength - len (strconv .FormatUint (item .Files , 10 ))),
56+ title , strings .Repeat (" " , column1width - len (title )),
57+ item .LOC , strings .Repeat (" " , column2width - len (strconv .FormatUint (item .LOC , 10 ))),
58+ item .Files , strings .Repeat (" " , column3width - len (strconv .FormatUint (item .Files , 10 ))),
5459 )
5560 }
5661
0 commit comments