refactor: panic in history.go for more context

windows-fixes
TorchedSammy 2022-03-12 21:43:02 -04:00
parent 23902ea25c
commit 0e4f552be2
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 5 additions and 9 deletions

View File

@ -12,11 +12,11 @@ type fileHistory struct {
f *os.File
}
func newFileHistory() (*fileHistory, error) {
func newFileHistory() *fileHistory {
data, err := os.ReadFile(defaultHistPath)
if err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return nil, err
panic(err)
}
}
@ -30,7 +30,7 @@ func newFileHistory() (*fileHistory, error) {
}
f, err := os.OpenFile(defaultHistPath, os.O_APPEND | os.O_WRONLY | os.O_CREATE, 0755)
if err != nil {
return nil, err
panic(err)
}
fh := &fileHistory{
@ -38,7 +38,7 @@ func newFileHistory() (*fileHistory, error) {
f: f,
}
return fh, nil
return fh
}
func (h *fileHistory) Write(line string) (int, error) {

6
rl.go
View File

@ -20,11 +20,7 @@ func newLineReader(prompt string, noHist bool) *lineReader {
// we don't mind hilbish.read rl instances having completion,
// but it cant have shared history
if !noHist {
fh, err := newFileHistory()
fileHist = fh // go stupid
if err != nil {
panic(err)
}
fileHist = newFileHistory()
rl.SetHistoryCtrlR("file", fileHist)
rl.HistoryAutoWrite = false
}