Package org.jline.shell.widget
Class AutopairWidgets
java.lang.Object
org.jline.shell.widget.AutopairWidgets
Provides intelligent auto-pairing of matching delimiters in the command line.
When enabled, this widget automatically:
- Inserts closing delimiters when an opening delimiter is typed
(e.g., typing
(inserts()) - Deletes matching pairs when backspace is pressed between them
- Skips over closing delimiters when typed and already present
The default paired delimiters are: () [] "" '' `` " " (space).
Curly braces {} can be optionally enabled.
Inspired by zsh-autopair.
Example:
AutopairWidgets autopair = new AutopairWidgets(reader); autopair.enable();
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAutopairWidgets(LineReader reader) Creates autopair widgets without curly brace support.AutopairWidgets(LineReader reader, boolean addCurlyBrackets) Creates autopair widgets with optional curly brace support. -
Method Summary
-
Field Details
-
reader
-
-
Constructor Details
-
AutopairWidgets
Creates autopair widgets without curly brace support.- Parameters:
reader- the line reader
-
AutopairWidgets
Creates autopair widgets with optional curly brace support.- Parameters:
reader- the line readeraddCurlyBrackets- true to include{}as a paired delimiter
-
-
Method Details
-
enable
public void enable()Enables auto-pairing if not already enabled. -
disable
public void disable()Disables auto-pairing if currently enabled. -
toggle
public boolean toggle()Toggles auto-pairing on or off.- Returns:
- true if auto-pairing is now enabled
-
autopairInsert
public boolean autopairInsert() -
autopairClose
public boolean autopairClose() -
autopairDelete
public boolean autopairDelete() -
toggleKeyBindings
public boolean toggleKeyBindings()
-