Closed pires closed 8 years ago
Returning an internal slice is not safe, even if you take the requisite mutex.
I recommend using a bytes.Buffer with the existing WriteHistory to retrieve the current history state.
@peterh so instead of returning int, error
it could return int, bytes.Buffer, error
or just bytes.Buffer, error
?
I mean instead of adding a function to liner (which already has too many functions), you could add an example to the documentation.
So in line_test.go you could add
func ExampleWriteHistory() {
// Untested, please test and fix before submitting patch
buf := new(bytes.Buffer)
_, err := line.WriteHistory(buf)
if err != nil {
history := strings.Split(buf.String(), "\n")
for i, line := range history {
fmt.Println("History entry ", i, ": ", line)
}
}
}
and that example would show up in the documentation. See https://blog.golang.org/examples
@peterh WriteHistory didn't seem like the method to use but it is and it was right in my face. Thanks for doing most of the work for me. PR on the way.
Fixes #56