@@ 3,6 3,7 @@ package format
import (
"fmt"
"strings"
+ "unicode"
"github.com/fatih/color"
"github.com/mattn/go-tty"
@@ 42,6 43,18 @@ func center(s string, l, w int) string {
return strings.Repeat(" ", lp) + s + strings.Repeat(" ", ls)
}
+func abbreviate(s string) string {
+ prev := ' '
+ return strings.Map(func(r rune) rune {
+ res := rune(-1)
+ if unicode.IsSpace(prev) {
+ res = r
+ }
+ prev = r
+ return res
+ }, s)
+}
+
// PrettyFormatter is a pretty time table formatter.
type PrettyFormatter struct {
tables []prettyTable
@@ 115,8 128,10 @@ func (t *prettyTable) format(width int) []string {
func (f *PrettyFormatter) Add(tt *fav.TimeTable) {
t := prettyTable{}
- t.headerLength = len([]rune(fmt.Sprintf("[%s] %s → %s", tt.LineNumber, tt.StopName, tt.Direction)))
- t.header = prettyLineNumber.Sprintf("[%s]", tt.LineNumber)
+ lineName := abbreviate(tt.LineNumber)
+
+ t.headerLength = len([]rune(fmt.Sprintf("[%s] %s → %s", lineName, tt.StopName, tt.Direction)))
+ t.header = prettyLineNumber.Sprintf("[%s]", lineName)
t.header += " " + prettyStopName.Sprint(tt.StopName)
t.header += " → " + prettyDirection.Sprint(tt.Direction)