Skip to content

Commit

Permalink
[Windows] Fix broken table structure for non-unicode code page
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerCD authored and muesli committed Oct 9, 2020
1 parent f726dea commit 7e705b8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
github.com/jedib0t/go-pretty/v6 v6.0.5
github.com/mattn/go-runewidth v0.0.9
github.com/muesli/termenv v0.7.2
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
sortBy = flag.String("sort", "mountpoint", "sort output by: "+strings.Join(columnIDs(), ", "))
width = flag.Uint("width", 0, "max output width")
themeOpt = flag.String("theme", defaultThemeName(), "color themes: dark, light")
styleOpt = flag.String("style", "unicode", "style: unicode, ascii")
styleOpt = flag.String("style", defaultStyleName(), "style: unicode, ascii")

inodes = flag.Bool("inodes", false, "list inode information instead of block usage")
jsonOutput = flag.Bool("json", false, "output all devices in JSON format")
Expand Down
7 changes: 7 additions & 0 deletions style_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !windows

package main

func defaultStyleName() string {
return "unicode"
}
17 changes: 17 additions & 0 deletions style_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build windows

package main

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

func defaultStyleName() string {
/*
Due to a bug in github.com/mattn/go-runewidth v0.0.9, the width of unicode rune(such as '╭') could not be correctly
calculated. Degrade to ascii to prevent broken table structure. Remove this once the bug is fixed.
*/
if runewidth.RuneWidth('╭') > 1 {
return "ascii"
}

return "unicode"
}

0 comments on commit 7e705b8

Please sign in to comment.