Class AutopairWidgets


  • public class AutopairWidgets
    extends java.lang.Object
    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
    • 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 reader
        addCurlyBrackets - 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()