Package org.jline.shell.widget
Class AutopairWidgets
- java.lang.Object
-
- org.jline.shell.widget.AutopairWidgets
-
public class AutopairWidgets extends java.lang.ObjectProvides 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
- Inserts closing delimiters when an opening delimiter is typed
(e.g., typing
-
-
Field Summary
Fields Modifier and Type Field Description protected LineReaderreader
-
Constructor Summary
Constructors Constructor Description AutopairWidgets(LineReader reader)Creates autopair widgets without curly brace support.AutopairWidgets(LineReader reader, boolean addCurlyBrackets)Creates autopair widgets with optional curly brace support.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanautopairClose()booleanautopairDelete()booleanautopairInsert()voiddisable()Disables auto-pairing if currently enabled.voidenable()Enables auto-pairing if not already enabled.booleantoggle()Toggles auto-pairing on or off.booleantoggleKeyBindings()
-
-
-
Field Detail
-
reader
protected final LineReader reader
-
-
Constructor Detail
-
AutopairWidgets
public AutopairWidgets(LineReader reader)
Creates autopair widgets without curly brace support.- Parameters:
reader- the line reader
-
AutopairWidgets
public AutopairWidgets(LineReader reader, boolean addCurlyBrackets)
Creates autopair widgets with optional curly brace support.- Parameters:
reader- the line readeraddCurlyBrackets- true to include{}as a paired delimiter
-
-
Method Detail
-
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()
-
-