jline / jline3

JLine is a Java library for handling console input.
Other
1.46k stars 215 forks source link

No history in terminal after auto-truncation of the history file #149

Closed sdht0 closed 7 years ago

sdht0 commented 7 years ago

Hi,

JLine version: compile 'org.jline:jline:3.3.1'

I have enabled history using:

lineReader = LineReaderBuilder.builder()
            .terminal(TerminalBuilder.builder().build())
            .variable(LineReader.HISTORY_FILE,historyFile)
            .variable(LineReader.HISTORY_FILE_SIZE,2)
            .history(new DefaultHistory())

and then executing lineReader.getHistory().save() in the main loop after each input. The HISTORY_FILE_SIZE value of 2 is to test truncation.

The issue is, whenever the file is truncated, the history stops working in the terminal (up arrow does not fill in the earlier commands). It might be a configuration bug on my end, as I hacked this together by reading the interfaces (the wiki entry for history is still incomplete).

Kindly take a look.

gnodet commented 7 years ago

You don't have to call lineReader.getHistory().save() explicitely. The default behavior is controlled by the LineReader.Option.HISTORY_INCREMENTAL option which is on by default, and when on, will automatically save the history when an item is added, which is done by the reader. I'll fix the index issue which is the problem you actually report.