mirror of https://github.com/curusarn/resh
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
700 B
26 lines
700 B
package searchapp
|
|
|
|
import (
|
|
"github.com/curusarn/resh/internal/histcli"
|
|
"github.com/curusarn/resh/internal/msg"
|
|
"github.com/curusarn/resh/internal/recio"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// LoadHistoryFromFile ...
|
|
func LoadHistoryFromFile(sugar *zap.SugaredLogger, historyPath string, numLines int) msg.CliResponse {
|
|
rio := recio.New(sugar)
|
|
recs, _, err := rio.ReadFile(historyPath)
|
|
if err != nil {
|
|
sugar.Panicf("failed to read hisotry file: %w", err)
|
|
}
|
|
if numLines != 0 && numLines < len(recs) {
|
|
recs = recs[:numLines]
|
|
}
|
|
cliRecords := histcli.New(sugar)
|
|
for i := len(recs) - 1; i >= 0; i-- {
|
|
rec := recs[i]
|
|
cliRecords.AddRecord(&rec)
|
|
}
|
|
return msg.CliResponse{Records: cliRecords.Dump()}
|
|
}
|
|
|