Class Nano
- java.lang.Object
-
- org.jline.builtins.Nano
-
- All Implemented Interfaces:
org.jline.reader.Editor
public class Nano extends java.lang.Object implements org.jline.reader.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
Nano.Buffer
protected static class
Nano.CursorMovement
static interface
Nano.Diagnostic
Interface representing a diagnostic message for code in the editor.protected static class
Nano.Operation
protected static class
Nano.PatternHistory
protected static class
Nano.WriteFormat
protected static class
Nano.WriteMode
-
Field Summary
Fields Modifier and Type Field Description protected org.jline.keymap.BindingReader
bindingReader
java.lang.String
brackets
protected Nano.Buffer
buffer
protected int
bufferIndex
protected java.util.List<Nano.Buffer>
buffers
boolean
constantCursor
protected java.util.List<java.lang.String>
cutbuffer
protected org.jline.utils.Display
display
protected java.lang.StringBuilder
editBuffer
protected java.lang.String
editMessage
protected java.lang.String
errorMessage
protected boolean
highlight
protected org.jline.keymap.KeyMap<Nano.Operation>
keys
protected boolean
mark
java.lang.String
matchBrackets
protected int
matchedLength
protected java.lang.String
message
boolean
mouseSupport
org.jline.terminal.Terminal.MouseTracking
mouseTracking
protected int
nbBindings
boolean
oneMoreLine
protected Nano.PatternHistory
patternHistory
boolean
printLineNumbers
java.lang.String
punct
boolean
quickBlank
java.lang.String
quoteStr
protected boolean
readNewBuffer
protected java.nio.file.Path
root
protected boolean
searchBackwards
protected boolean
searchCaseSensitive
protected boolean
searchRegexp
protected java.lang.String
searchTerm
protected java.util.LinkedHashMap<java.lang.String,java.lang.String>
shortcuts
protected org.jline.terminal.Size
size
boolean
smoothScrolling
int
tabs
protected org.jline.terminal.Terminal
terminal
java.lang.String
title
protected int
vsusp
boolean
wrapping
protected Nano.WriteMode
writeMode
-
Constructor Summary
Constructors Constructor Description Nano(org.jline.terminal.Terminal terminal, java.io.File root)
Nano(org.jline.terminal.Terminal terminal, java.nio.file.Path root)
Nano(org.jline.terminal.Terminal terminal, java.nio.file.Path root, Options opts)
Nano(org.jline.terminal.Terminal terminal, java.nio.file.Path root, Options opts, ConfigurationPath configPath)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
bindKeys()
protected java.util.List<Nano.Diagnostic>
computeDiagnostic()
Computes the list of diagnostics for the current buffer.protected java.util.List<org.jline.utils.AttributedString>
computeFooter()
protected java.util.LinkedHashMap<org.jline.utils.AttributedString,java.util.List<org.jline.utils.AttributedString>>
computeSuggestions()
Initializes the suggestions map.java.lang.String
getTitle()
protected void
handle(org.jline.terminal.Terminal.Signal signal)
protected void
insertHelp(int selected)
Inserts the selected suggestion into the text.void
open(java.lang.String... files)
void
open(java.util.List<java.lang.String> files)
void
run()
void
setRestricted(boolean restricted)
static java.lang.String[]
usage()
-
-
-
Field Detail
-
terminal
protected final org.jline.terminal.Terminal terminal
-
display
protected final org.jline.utils.Display display
-
bindingReader
protected final org.jline.keymap.BindingReader bindingReader
-
size
protected final org.jline.terminal.Size size
-
root
protected final java.nio.file.Path root
-
vsusp
protected final int vsusp
-
keys
protected org.jline.keymap.KeyMap<Nano.Operation> keys
-
title
public java.lang.String title
-
printLineNumbers
public boolean printLineNumbers
-
wrapping
public boolean wrapping
-
smoothScrolling
public boolean smoothScrolling
-
mouseSupport
public boolean mouseSupport
-
mouseTracking
public org.jline.terminal.Terminal.MouseTracking mouseTracking
-
oneMoreLine
public boolean oneMoreLine
-
constantCursor
public boolean constantCursor
-
quickBlank
public boolean quickBlank
-
tabs
public int tabs
-
brackets
public java.lang.String brackets
-
matchBrackets
public java.lang.String matchBrackets
-
punct
public java.lang.String punct
-
quoteStr
public java.lang.String quoteStr
-
buffers
protected final java.util.List<Nano.Buffer> buffers
-
bufferIndex
protected int bufferIndex
-
buffer
protected Nano.Buffer buffer
-
message
protected java.lang.String message
-
errorMessage
protected java.lang.String errorMessage
-
nbBindings
protected int nbBindings
-
shortcuts
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> shortcuts
-
editMessage
protected java.lang.String editMessage
-
editBuffer
protected final java.lang.StringBuilder editBuffer
-
searchCaseSensitive
protected boolean searchCaseSensitive
-
searchRegexp
protected boolean searchRegexp
-
searchBackwards
protected boolean searchBackwards
-
searchTerm
protected java.lang.String searchTerm
-
matchedLength
protected int matchedLength
-
patternHistory
protected Nano.PatternHistory patternHistory
-
writeMode
protected Nano.WriteMode writeMode
-
cutbuffer
protected java.util.List<java.lang.String> cutbuffer
-
mark
protected boolean mark
-
highlight
protected boolean highlight
-
readNewBuffer
protected boolean readNewBuffer
-
-
Constructor Detail
-
Nano
public Nano(org.jline.terminal.Terminal terminal, java.io.File root)
-
Nano
public Nano(org.jline.terminal.Terminal terminal, java.nio.file.Path root)
-
Nano
public Nano(org.jline.terminal.Terminal terminal, java.nio.file.Path root, Options opts)
-
Nano
public Nano(org.jline.terminal.Terminal terminal, java.nio.file.Path root, Options opts, ConfigurationPath configPath)
-
-
Method Detail
-
usage
public static java.lang.String[] usage()
-
setRestricted
public void setRestricted(boolean restricted)
- Specified by:
setRestricted
in interfaceorg.jline.reader.Editor
-
open
public void open(java.lang.String... files) throws java.io.IOException
- Throws:
java.io.IOException
-
open
public void open(java.util.List<java.lang.String> files) throws java.io.IOException
- Specified by:
open
in interfaceorg.jline.reader.Editor
- Throws:
java.io.IOException
-
run
public void run() throws java.io.IOException
- Specified by:
run
in interfaceorg.jline.reader.Editor
- Throws:
java.io.IOException
-
getTitle
public java.lang.String 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
protected java.util.LinkedHashMap<org.jline.utils.AttributedString,java.util.List<org.jline.utils.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 java.util.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
-
computeFooter
protected java.util.List<org.jline.utils.AttributedString> computeFooter()
-
handle
protected void handle(org.jline.terminal.Terminal.Signal signal)
-
bindKeys
protected void bindKeys()
-
-