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 TypeClassDescription(package private) classA class representing a box to be drawn on the screen.protected classprotected static enumstatic interfaceInterface representing a diagnostic message for code in the editor.protected static enumprotected static classprotected static enumprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprotected final BindingReaderprotected Nano.Bufferprotected intprotected final List<Nano.Buffer> booleanprivate booleanprotected final Displayprotected final StringBuilderprotected Stringprotected Stringprivate booleanprotected booleanprivate Stringprivate booleanprotected KeyMap<Nano.Operation> protected booleanprotected intprotected Stringbooleanprivate intprivate intprivate booleanprotected intbooleanprotected Nano.PatternHistorybooleanbooleanprotected booleanprivate booleanprotected final Pathprotected booleanprotected booleanprotected booleanprotected Stringprivate booleanprotected LinkedHashMap<String, String> protected final Sizebooleanprivate Nano.Boxprivate Map<AttributedString, List<AttributedString>> private Stringintprivate booleanprivate booleanprotected final Terminalprivate booleanprotected final intprivate final booleanbooleanprivate booleanprotected Nano.WriteMode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate List<AttributedString> adjustLines(List<AttributedString> lines, int max, int boxLength) protected voidbindKeys()private Nano.BoxbuildDocumentationBox(List<AttributedString> screenLines, Nano.Box suggestionBox, List<AttributedString> documentation) private Nano.BoxbuildSuggestionBox(List<AttributedString> suggestions, List<AttributedString> screenLines) (package private) void(package private) Stringprotected List<Nano.Diagnostic> Computes the list of diagnostics for the current buffer.protected List<AttributedString> protected LinkedHashMap<AttributedString, List<AttributedString>> Initializes the suggestions map.(package private) void(package private) voidcurPos()(package private) voiddisplay()(package private) voidprivate inteditInputBuffer(Nano.Operation operation, int curPos) (package private) voidprivate Stringprivate StringgetTitle()private Stringprivate Nano.Operationprivate Nano.Operation(package private) voidgotoLine()private LinkedHashMap<String, String> protected voidhandle(Terminal.Signal signal) (package private) voidprivate LinkedHashMap<String, String> private voidinitBoxes(List<AttributedString> screenLines) protected voidinsertHelp(int selected) Inserts the selected suggestion into the text.(package private) void(package private) void(package private) void(package private) voidnumbers()(package private) voidvoidvoidOpens the specified files in the external editor.private voidparseConfig(Path file) (package private) void(package private) booleanquit()(package private) voidread()private Nano.OperationreadOperation(KeyMap<Nano.Operation> keymap) private LinkedHashMap<String, String> (package private) Stringreplace()private LinkedHashMap<String, String> (package private) voidprivate voidvoidrun()Runs the editor process.private boolean(package private) voidsearch()(package private) voidprivate LinkedHashMap<String, String> (package private) voidsetMessage(String message) voidsetRestricted(boolean restricted) Sets whether the editor should run in restricted mode.private voidshowCompletion(List<AttributedString> newLines) (package private) voidprivate LinkedHashMap<String, String> (package private) voidstatic String[]usage()(package private) voidwrap()(package private) booleanwrite()private LinkedHashMap<String, String>
-
Field Details
-
terminal
-
display
-
bindingReader
-
size
-
root
-
vsusp
protected final int vsusp -
syntaxFiles
-
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
-
restricted
private boolean restricted -
syntaxName
-
writeBackup
private boolean writeBackup -
atBlanks
private boolean atBlanks -
view
private boolean view -
cut2end
private boolean cut2end -
tempFile
private boolean tempFile -
historyLog
-
tabsToSpaces
private boolean tabsToSpaces -
autoIndent
private boolean autoIndent -
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 -
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
-
suggestions
-
mouseX
private int mouseX -
mouseY
private int mouseY
-
-
Constructor Details
-
Nano
-
Nano
-
Nano
-
Nano
-
-
Method Details
-
usage
-
parseConfig
- Throws:
IOException
-
setRestricted
public void setRestricted(boolean restricted) Description copied from interface:EditorSets 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:
setRestrictedin interfaceEditor- Parameters:
restricted- true to enable restricted mode, false otherwise
-
open
- Throws:
IOException
-
open
Description copied from interface:EditorOpens 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:
openin 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:EditorRuns 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:
runin interfaceEditor- Throws:
IOException- if an I/O error occurs while running the editor
-
resetSuggestion
private void resetSuggestion() -
editInputBuffer
-
write
- Throws:
IOException
-
readOperation
-
save
- Throws:
IOException
-
getYNC
-
getYNC
-
getWriteMessage
-
read
void read() -
getReadMessage
-
gotoLine
void gotoLine() -
gotoShortcuts
-
readShortcuts
-
writeShortcuts
-
helpShortcuts
-
searchShortcuts
-
replaceShortcuts
-
standardShortcuts
-
help
-
searchAndReplace
void searchAndReplace() -
search
- Throws:
IOException
-
replace
String replace() -
getSearchMessage
-
computeCurPos
String computeCurPos() -
curPos
void curPos() -
prevBuffer
- Throws:
IOException
-
nextBuffer
- Throws:
IOException
-
setMessage
-
quit
- 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
-
resetDisplay
void resetDisplay() -
display
void display() -
display
-
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
-
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
-
initBoxes
-
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
-
handle
-
bindKeys
protected void bindKeys()
-