Class Nano
- All Implemented Interfaces:
Editor
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
protected static enum
static interface
Interface representing a diagnostic message for code in the editor.protected static enum
protected static class
protected static enum
protected static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BindingReader
protected Nano.Buffer
protected int
protected final List
<Nano.Buffer> boolean
protected final Display
protected final StringBuilder
protected String
protected String
protected boolean
protected KeyMap
<Nano.Operation> protected boolean
protected int
protected String
boolean
protected int
boolean
protected Nano.PatternHistory
boolean
boolean
protected boolean
protected final Path
protected boolean
protected boolean
protected boolean
protected String
protected LinkedHashMap
<String, String> protected final Size
boolean
int
protected final Terminal
protected final int
boolean
protected Nano.WriteMode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
bindKeys()
protected List
<Nano.Diagnostic> Computes the list of diagnostics for the current buffer.protected List
<AttributedString> protected LinkedHashMap
<AttributedString, List<AttributedString>> Initializes the suggestions map.getTitle()
protected void
handle
(Terminal.Signal signal) protected void
insertHelp
(int selected) Inserts the selected suggestion into the text.void
void
Opens the specified files in the external editor.void
run()
Runs the editor process.void
setRestricted
(boolean restricted) Sets whether the editor should run in restricted mode.static String[]
usage()
-
Field Details
-
terminal
-
display
-
bindingReader
-
size
-
root
-
vsusp
protected final int vsusp -
keys
-
title
-
printLineNumbers
public boolean printLineNumbers -
wrapping
public boolean wrapping -
smoothScrolling
public boolean smoothScrolling -
mouseSupport
public boolean mouseSupport -
mouseTracking
-
oneMoreLine
public boolean oneMoreLine -
constantCursor
public boolean constantCursor -
quickBlank
public boolean quickBlank -
tabs
public int tabs -
brackets
-
matchBrackets
-
punct
-
quoteStr
-
buffers
-
bufferIndex
protected int bufferIndex -
buffer
-
message
-
errorMessage
-
nbBindings
protected int nbBindings -
shortcuts
-
editMessage
-
editBuffer
-
searchCaseSensitive
protected boolean searchCaseSensitive -
searchRegexp
protected boolean searchRegexp -
searchBackwards
protected boolean searchBackwards -
searchTerm
-
matchedLength
protected int matchedLength -
patternHistory
-
writeMode
-
cutbuffer
-
mark
protected boolean mark -
highlight
protected boolean highlight -
readNewBuffer
protected boolean readNewBuffer
-
-
Constructor Details
-
Nano
-
Nano
-
Nano
-
Nano
-
-
Method Details
-
usage
-
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 interfaceEditor
- Parameters:
restricted
- true to enable restricted mode, false otherwise
-
open
- Throws:
IOException
-
open
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 interfaceEditor
- Parameters:
files
- the list of files to open in the editor- Throws:
IOException
- if an I/O error occurs while launching the editor
-
run
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 interfaceEditor
- Throws:
IOException
- if an I/O error occurs while running the editor
-
getTitle
-
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
-
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
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
-
handle
-
bindKeys
protected void bindKeys()
-