@@ -25,13 +25,15 @@ type line struct {
2525 TotalNanos int64 `json:"totalNanos"`
2626 Total string `json:"total,omitempty"`
2727 Text string `json:"text,omitempty"`
28+ Previous string `json:"previous,omitempty"`
2829}
2930
3031type configuration struct {
3132 timeFormat string // -timeformat="..."
3233 template string // -template="..."
3334 plain bool // -plain
3435 version string
36+ previous bool
3537}
3638
3739var config = configuration {}
@@ -88,6 +90,7 @@ func init() {
8890 flag .StringVar (& config .template , "template" , "" , "go template (https://golang.org/pkg/text/template)" )
8991 flag .StringVar (& config .timeFormat , "timeformat" , "RFC3339" , timeFormatsHelp ())
9092 flag .BoolVar (& config .plain , "plain" , false , "-template='{{.Time}} +{{.DeltaNanos}} {{.Text}}'" )
93+ flag .BoolVar (& config .previous , "previous" , false , "include previous line" )
9194 flag .Parse ()
9295 if knownFormat , ok := timeFormats [config .timeFormat ]; ok {
9396 config .timeFormat = knownFormat
@@ -108,6 +111,7 @@ func main() {
108111 line := line {}
109112 last := now
110113 first := now
114+ previous := ""
111115 i := uint64 (0 )
112116 for scanner .Scan () {
113117 now = time .Now ()
@@ -126,6 +130,10 @@ func main() {
126130 line .TimeString = now .Format (config .timeFormat )
127131 line .Text = scanner .Text ()
128132 line .I = i
133+ if config .previous {
134+ line .Previous = previous
135+ previous = line .Text
136+ }
129137 if err := printer (& line ); err != nil {
130138 fmt .Fprintln (os .Stderr , "output error:" , err )
131139 }
0 commit comments