mirror of https://github.com/Hilbis/Hilbish
refactor: panic in history.go for more context
parent
23902ea25c
commit
0e4f552be2
|
@ -12,11 +12,11 @@ type fileHistory struct {
|
||||||
f *os.File
|
f *os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFileHistory() (*fileHistory, error) {
|
func newFileHistory() *fileHistory {
|
||||||
data, err := os.ReadFile(defaultHistPath)
|
data, err := os.ReadFile(defaultHistPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, fs.ErrNotExist) {
|
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)
|
f, err := os.OpenFile(defaultHistPath, os.O_APPEND | os.O_WRONLY | os.O_CREATE, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fh := &fileHistory{
|
fh := &fileHistory{
|
||||||
|
@ -38,7 +38,7 @@ func newFileHistory() (*fileHistory, error) {
|
||||||
f: f,
|
f: f,
|
||||||
}
|
}
|
||||||
|
|
||||||
return fh, nil
|
return fh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *fileHistory) Write(line string) (int, error) {
|
func (h *fileHistory) Write(line string) (int, error) {
|
||||||
|
|
6
rl.go
6
rl.go
|
@ -20,11 +20,7 @@ func newLineReader(prompt string, noHist bool) *lineReader {
|
||||||
// we don't mind hilbish.read rl instances having completion,
|
// we don't mind hilbish.read rl instances having completion,
|
||||||
// but it cant have shared history
|
// but it cant have shared history
|
||||||
if !noHist {
|
if !noHist {
|
||||||
fh, err := newFileHistory()
|
fileHist = newFileHistory()
|
||||||
fileHist = fh // go stupid
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
rl.SetHistoryCtrlR("file", fileHist)
|
rl.SetHistoryCtrlR("file", fileHist)
|
||||||
rl.HistoryAutoWrite = false
|
rl.HistoryAutoWrite = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue