Skip to content

Commit

Permalink
Add --no-hborder (#476)
Browse files Browse the repository at this point in the history
* Add --no-hborder

This removes the horizontal border lines, making for more compact
output.

For example:

	% scc --min-gen --no-complexity --no-cocomo --no-size
	───────────────────────────────────────────────────────────────────────────────
	Language                     Files       Lines     Blanks    Comments      Code
	───────────────────────────────────────────────────────────────────────────────
	Go                              10        1374        114         199      1061
	License                          1          20          4           0        16
	Markdown                         1          94         23           0        71
	YAML                             1           1          0           0         1
	───────────────────────────────────────────────────────────────────────────────
	Total                           13        1489        141         199      1149
	───────────────────────────────────────────────────────────────────────────────

	% scc --min-gen --no-complexity --no-cocomo --no-size --no-hborder
	Language                     Files       Lines     Blanks    Comments      Code
	Go                              10        1374        114         199      1061
	License                          1          20          4           0        16
	Markdown                         1          94         23           0        71
	YAML                             1           1          0           0         1
	Total                           13        1489        141         199      1149

Removing those four lines makes a relatively large difference.

I named it "hborder" so that it won't be problematic with any potential
future vertical borders. Maybe at some point an option for something
like this will be added:

	Language │ Files │  Lines │ Blanks │ Comments  │ Code
	─────────┼───────┼────────┼────────┼───────────┼─────
	Go       │    10 │   1374 │    114 │      199  │ 1061
	License  │     1 │     20 │      4 │        0  │   16
	Markdown │     1 │     94 │     23 │        0  │   71
	YAML     │     1 │      1 │      0 │        0  │    1
	─────────┼───────┼────────┼────────┼───────────┼─────
	Total    │    13 │   1489 │    141 │      199  │ 1149

Or something along those lines.

* Don't print trailing blank line
  • Loading branch information
arp242 committed Jun 10, 2024
1 parent 9251957 commit b630cad
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ func main() {
false,
"remove size calculation output",
)
flags.BoolVar(
&processor.HBorder,
"no-hborder",
false,
"remove horizontal borders between sections",
)
flags.StringVar(
&processor.SizeUnit,
"size-unit",
Expand Down
8 changes: 8 additions & 0 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ type languageReportEnd struct {
}

func getTabularShortBreak() string {
if HBorder {
return ""
}

if Ci {
return tabularShortBreakCi
}
Expand All @@ -150,6 +154,10 @@ func getTabularShortBreak() string {
}

func getTabularWideBreak() string {
if HBorder {
return ""
}

if Ci {
return tabularWideBreakCi
}
Expand Down
42 changes: 29 additions & 13 deletions processor/formatters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
package processor

import (
"github.com/mattn/go-runewidth"
"strings"
"testing"

"github.com/mattn/go-runewidth"
)

func TestPrintTrace(t *testing.T) {
Expand Down Expand Up @@ -1316,21 +1317,36 @@ func TestGetTabularShortBreak(t *testing.T) {
}

func TestGetTabularWideBreak(t *testing.T) {
Ci = false
r := getTabularWideBreak()

if !strings.Contains(r, "─") {
t.Errorf("Expected to have box line")
{
Ci, HBorder = false, false
r := getTabularWideBreak()
if !strings.Contains(r, "─") {
t.Errorf("Expected to have box line")
}
}

Ci = true
r = getTabularWideBreak()

if !strings.Contains(r, "-") {
t.Errorf("Expected to have hyphen")
{
Ci, HBorder = false, true
r := getTabularWideBreak()
if strings.Contains(r, "─") {
t.Errorf("Didn't expect to have box line")
}
}
{
Ci, HBorder = true, false
r := getTabularWideBreak()
if !strings.Contains(r, "-") {
t.Errorf("Expected to have hyphen")
}
}
{
Ci, HBorder = true, true
r := getTabularWideBreak()
if strings.Contains(r, "-") {
t.Errorf("Didn't expect to have hyphen")
}
}

Ci = false
Ci, HBorder = false, false
}

func TestToHTML(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ var CocomoProjectType = "organic"
// Size toggles the Size calculation
var Size = false

// Draw horizontal borders between sections.
var HBorder = false

// SizeUnit determines what size calculation is used for megabytes
var SizeUnit = "si"

Expand Down Expand Up @@ -656,7 +659,7 @@ func Process() {

result := fileSummarize(fileSummaryJobQueue)
if FileOutput == "" {
fmt.Println(result)
fmt.Print(result)
} else {
_ = os.WriteFile(FileOutput, []byte(result), 0644)
fmt.Println("results written to " + FileOutput)
Expand Down

0 comments on commit b630cad

Please sign in to comment.