Skip to content

Commit

Permalink
Merge pull request #1 from jievince/append-history-tofile
Browse files Browse the repository at this point in the history
append history items to history file
  • Loading branch information
jievince authored Jul 30, 2021
2 parents 1c3aa69 + 40cebc1 commit 27aa20d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type commonState struct {
outputRedirected bool
inputRedirected bool
history []string
newlyAddedHistory []string
historyMutex sync.RWMutex
completer WordCompleter
columns int
Expand Down Expand Up @@ -118,7 +119,7 @@ func (s *State) WriteHistory(w io.Writer) (num int, err error) {
s.historyMutex.RLock()
defer s.historyMutex.RUnlock()

for _, item := range s.history {
for _, item := range s.newlyAddedHistory {
_, err := fmt.Fprintln(w, item)
if err != nil {
return num, err
Expand All @@ -140,6 +141,7 @@ func (s *State) AppendHistory(item string) {
}
}
s.history = append(s.history, item)
s.newlyAddedHistory = append(s.newlyAddedHistory, item)
if len(s.history) > HistoryLimit {
s.history = s.history[1:]
}
Expand Down

0 comments on commit 27aa20d

Please sign in to comment.