Class Nano

java.lang.Object
org.jline.builtins.Nano
All Implemented Interfaces:
Editor

public class Nano extends Object implements Editor
A terminal text editor similar to the 'nano' Unix command.

This class provides a text editor with features including:

  • File editing with save functionality
  • Cut, copy, and paste operations
  • Search and replace functionality
  • Syntax highlighting
  • Undo/redo support
  • Line numbering

The implementation supports many of the key bindings and features of the traditional Unix 'nano' editor, adapted for JLine's terminal handling. It implements the JLine Editor interface for integration with other components.

  • Field Details

    • terminal

      protected final Terminal terminal
    • display

      protected final Display display
    • bindingReader

      protected final BindingReader bindingReader
    • size

      protected final Size size
    • root

      protected final Path root
    • vsusp

      protected final int vsusp
    • syntaxFiles

      private final List<Path> syntaxFiles
    • keys

      protected KeyMap<Nano.Operation> keys
    • title

      public String title
    • printLineNumbers

      public boolean printLineNumbers
    • wrapping

      public boolean wrapping
    • smoothScrolling

      public boolean smoothScrolling
    • mouseSupport

      public boolean mouseSupport
    • mouseTracking

      public Terminal.MouseTracking mouseTracking
    • oneMoreLine

      public boolean oneMoreLine
    • constantCursor

      public boolean constantCursor
    • quickBlank

      public boolean quickBlank
    • tabs

      public int tabs
    • brackets

      public String brackets
    • matchBrackets

      public String matchBrackets
    • punct

      public String punct
    • quoteStr

      public String quoteStr
    • restricted

      private boolean restricted
    • syntaxName

      private String syntaxName
    • writeBackup

      private boolean writeBackup
    • atBlanks

      private boolean atBlanks
    • view

      private boolean view
    • cut2end

      private boolean cut2end
    • tempFile

      private boolean tempFile
    • historyLog

      private String historyLog
    • tabsToSpaces

      private boolean tabsToSpaces
    • autoIndent

      private boolean autoIndent
    • buffers

      protected final List<Nano.Buffer> buffers
    • bufferIndex

      protected int bufferIndex
    • buffer

      protected Nano.Buffer buffer
    • message

      protected String message
    • errorMessage

      protected String errorMessage
    • nbBindings

      protected int nbBindings
    • shortcuts

      protected LinkedHashMap<String,String> shortcuts
    • editMessage

      protected String editMessage
    • editBuffer

      protected final StringBuilder editBuffer
    • searchCaseSensitive

      protected boolean searchCaseSensitive
    • searchRegexp

      protected boolean searchRegexp
    • searchBackwards

      protected boolean searchBackwards
    • searchTerm

      protected String searchTerm
    • matchedLength

      protected int matchedLength
    • patternHistory

      protected Nano.PatternHistory patternHistory
    • writeMode

      protected Nano.WriteMode writeMode
    • cutbuffer

      protected List<String> cutbuffer
    • mark

      protected boolean mark
    • highlight

      protected boolean highlight
    • searchToReplace

      private boolean searchToReplace
    • readNewBuffer

      protected boolean readNewBuffer
    • nanorcIgnoreErrors

      private boolean nanorcIgnoreErrors
    • windowsTerminal

      private final boolean windowsTerminal
    • insertHelp

      private boolean insertHelp
    • help

      private boolean help
    • suggestionBox

      private Nano.Box suggestionBox
    • suggestions

      private Map<AttributedString,List<AttributedString>> suggestions
    • mouseX

      private int mouseX
    • mouseY

      private int mouseY
  • Constructor Details

  • Method Details

    • usage

      public static String[] usage()
    • parseConfig

      private void parseConfig(Path file) throws IOException
      Throws:
      IOException
    • setRestricted

      public void setRestricted(boolean restricted)
      Description copied from interface: Editor
      Sets whether the editor should run in restricted mode.

      In restricted mode, the editor may have limited functionality or access to certain features or files. This is typically used for security reasons when the application needs to limit what the user can do in the editor.

      Specified by:
      setRestricted in interface Editor
      Parameters:
      restricted - true to enable restricted mode, false otherwise
    • open

      public void open(String... files) throws IOException
      Throws:
      IOException
    • open

      public void open(List<String> files) throws IOException
      Description copied from interface: Editor
      Opens the specified files in the external editor.

      This method launches the external editor with the given files as arguments. The behavior depends on the specific editor implementation and configuration.

      Specified by:
      open in interface Editor
      Parameters:
      files - the list of files to open in the editor
      Throws:
      IOException - if an I/O error occurs while launching the editor
    • run

      public void run() throws IOException
      Description copied from interface: Editor
      Runs the editor process.

      This method starts the editor process and typically waits for it to complete. The specific behavior depends on the editor implementation.

      Specified by:
      run in interface Editor
      Throws:
      IOException - if an I/O error occurs while running the editor
    • resetSuggestion

      private void resetSuggestion()
    • editInputBuffer

      private int editInputBuffer(Nano.Operation operation, int curPos)
    • write

      boolean write() throws IOException
      Throws:
      IOException
    • readOperation

      private Nano.Operation readOperation(KeyMap<Nano.Operation> keymap)
    • save

      private boolean save(String name) throws IOException
      Throws:
      IOException
    • getYNC

      private Nano.Operation getYNC(String message)
    • getYNC

      private Nano.Operation getYNC(String message, boolean andAll)
    • getWriteMessage

      private String getWriteMessage()
    • read

      void read()
    • getReadMessage

      private String getReadMessage()
    • gotoLine

      void gotoLine()
    • gotoShortcuts

      private LinkedHashMap<String,String> gotoShortcuts()
    • readShortcuts

      private LinkedHashMap<String,String> readShortcuts()
    • writeShortcuts

      private LinkedHashMap<String,String> writeShortcuts()
    • helpShortcuts

      private LinkedHashMap<String,String> helpShortcuts()
    • searchShortcuts

      private LinkedHashMap<String,String> searchShortcuts()
    • replaceShortcuts

      private LinkedHashMap<String,String> replaceShortcuts()
    • standardShortcuts

      private LinkedHashMap<String,String> standardShortcuts()
    • help

      void help(String help)
    • searchAndReplace

      void searchAndReplace()
    • search

      void search() throws IOException
      Throws:
      IOException
    • replace

      String replace()
    • getSearchMessage

      private String getSearchMessage()
    • computeCurPos

      String computeCurPos()
    • curPos

      void curPos()
    • prevBuffer

      void prevBuffer() throws IOException
      Throws:
      IOException
    • nextBuffer

      void nextBuffer() throws IOException
      Throws:
      IOException
    • setMessage

      void setMessage(String message)
    • quit

      boolean quit() throws IOException
      Throws:
      IOException
    • numbers

      void numbers()
    • smoothScrolling

      void smoothScrolling()
    • mouseSupport

      void mouseSupport()
    • constantCursor

      void constantCursor()
    • oneMoreLine

      void oneMoreLine()
    • wrap

      void wrap()
    • clearScreen

      void clearScreen()
    • mouseEvent

      void mouseEvent()
    • enableSuspension

      void enableSuspension()
    • toggleSuspension

      void toggleSuspension()
    • getTitle

      public String getTitle()
    • resetDisplay

      void resetDisplay()
    • display

      void display()
    • display

      void display(Integer editCursor)
    • insertHelp

      protected void insertHelp(int selected)
      Inserts the selected suggestion into the text.

      This method is called when a suggestion is selected and should be inserted into the text. Subclasses should override this method to implement the insertion logic based on the selected suggestion index.

      The selected suggestion can be retrieved from the suggestions map using: new ArrayList<>(suggestions.keySet()).get(selected)

      Parameters:
      selected - the index of the selected suggestion in the suggestions list
    • showCompletion

      private void showCompletion(List<AttributedString> newLines)
    • computeSuggestions

      protected LinkedHashMap<AttributedString,List<AttributedString>> computeSuggestions()
      Initializes the suggestions map.

      This method is called when suggestions need to be displayed. Subclasses should override this method to return a map of suggestions to their documentation.

      The keys in the map are AttributedString objects representing the available suggestions. The values are lists of AttributedString objects containing the documentation lines for each suggestion.

      It is recommended to use a LinkedHashMap to preserve the order of suggestions, as this order will be used when displaying the suggestions to the user.

      The default implementation returns an empty map, indicating no suggestions are available.

      Returns:
      a map of suggestions to their documentation, or an empty map if no suggestions are available
    • computeDiagnostic

      protected List<Nano.Diagnostic> computeDiagnostic()
      Computes the list of diagnostics for the current buffer.

      This method is called when rendering the buffer to determine if there are any diagnostics (errors, warnings, etc.) that should be displayed. Subclasses should override this method to provide diagnostics based on the current buffer content.

      Diagnostics are used to highlight issues in the code and display tooltips with error messages or warnings when hovering over the highlighted regions.

      Returns:
      a list of Diagnostic objects, or an empty list if there are no diagnostics
    • initBoxes

      private void initBoxes(List<AttributedString> screenLines)
    • buildSuggestionBox

      private Nano.Box buildSuggestionBox(List<AttributedString> suggestions, List<AttributedString> screenLines)
    • buildDocumentationBox

      private Nano.Box buildDocumentationBox(List<AttributedString> screenLines, Nano.Box suggestionBox, List<AttributedString> documentation)
    • adjustLines

      private List<AttributedString> adjustLines(List<AttributedString> lines, int max, int boxLength)
    • computeFooter

      protected List<AttributedString> computeFooter()
    • handle

      protected void handle(Terminal.Signal signal)
    • bindKeys

      protected void bindKeys()