Class LineEditor
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.AbstractEditor
-
- edu.uiuc.ncsa.security.util.cli.editing.LineEditor
-
public class LineEditor extends AbstractEditor
Since it is close to impossible to get consistent behavior at the command line between different JVM hosts, the only reasonable way to edit things at the command line is going to be with some form of line editor. Rather than be clever and create one, this is a basic port of the tried and true Unix line editor, ed.Usage
You use this by creating an instance with either a buffer of lines or a string which is parsed simply into lines (this is not perfect since there can be some cross-platform issues -- better to roll it yourself). You then invokeexecute()
and this runs the editor. When done, this method exist and you check theisSaved()
flag. If true, then the user saved the buffer and wants to keep it, so you can either get the buffer and process the lines or invoke thebufferToString()
method.Created by Jeff Gaynor
on 8/30/18 at 11:23 AM
-
-
Field Summary
-
Fields inherited from class edu.uiuc.ncsa.security.util.cli.AbstractEditor
HELP_COMMAND, isDone, PROMPT, QUIT_COMMAND, QUIT_COMMAND_LONG, VERBOSE_COMMAND, VERBOSE_COMMAND_LONG, verboseOn
-
-
Constructor Summary
Constructors Constructor Description LineEditor(String rawText)
This will split the text at new lines and put it in the buffer.LineEditor(StringBuffer buffer)
LineEditor(List<String> buffer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
allHelp()
String
bufferToString()
Reconstruct the input as a string with new line characters.protected void
doAppend(LineEditorInputLine eil)
protected void
doAppendtHelp()
protected void
doCopy(LineEditorInputLine eil)
protected void
doCopyHelp()
protected void
doCut(LineEditorInputLine eil)
protected void
doCutHelp()
protected void
doDelete(LineEditorInputLine eil)
protected void
doDeleteHelp()
protected void
doEditLines(LineEditorInputLine eil)
protected void
doEditLinesHelp()
protected void
doFind(LineEditorInputLine eil)
protected void
doFindHelp()
protected void
doInsert(LineEditorInputLine eil)
Insert lines until a single period is entered.protected void
doInsertHelp()
protected void
doMove(LineEditorInputLine eil)
protected void
doMoveHelp()
protected void
doPaste(LineEditorInputLine eil)
protected void
doPasteHelp()
protected void
doPrint(LineEditorInputLine eil)
protected void
doPrintHelp()
protected void
doRead(LineEditorInputLine eil)
Read a file into this buffer at a possible starting index.protected void
doReadHelp()
protected void
doSubstitute(LineEditorInputLine eil)
protected void
doSubstituteHelp()
protected void
doViewClipboard(LineEditorInputLine eil)
protected void
doViewClipboardHelp()
protected void
doWrite(LineEditorInputLine eil)
protected void
doWriteHelp()
void
execute()
List<String>
getBuffer()
List<String>
getClipboard()
protected int[]
getRange(LineEditorInputLine eil)
File
getTargetFile()
This sets a target file.boolean
isSaved()
static void
main(String[] args)
protected void
parseLine(String lineIn)
The form of the line is command [x,y,z] arg0 arg1 arg2...void
setClipboard(List<String> clipboard)
void
setTargetFile(File targetFile)
protected LineEditorInputLine
toInputLine(String x)
protected void
verboseHelp()
-
Methods inherited from class edu.uiuc.ncsa.security.util.cli.AbstractEditor
getIoInterface, readline, say, sayi, sayv, setIoInterface, showHelp
-
-
-
-
Field Detail
-
END_COMMAND
public static final String END_COMMAND
- See Also:
- Constant Field Values
-
APPEND_COMMAND
public static final String APPEND_COMMAND
- See Also:
- Constant Field Values
-
APPEND_COMMAND_LONG
public static final String APPEND_COMMAND_LONG
- See Also:
- Constant Field Values
-
VIEW_CLIPBOARD_COMMAND
public static final String VIEW_CLIPBOARD_COMMAND
- See Also:
- Constant Field Values
-
VIEW_CLIPBOARD_COMMAND_LONG
public static final String VIEW_CLIPBOARD_COMMAND_LONG
- See Also:
- Constant Field Values
-
COPY_COMMAND
public static final String COPY_COMMAND
- See Also:
- Constant Field Values
-
COPY_COMMAND_LONG
public static final String COPY_COMMAND_LONG
- See Also:
- Constant Field Values
-
DELETE_COMMAND
public static final String DELETE_COMMAND
- See Also:
- Constant Field Values
-
DELETE_COMMAND_LONG
public static final String DELETE_COMMAND_LONG
- See Also:
- Constant Field Values
-
EDIT_A_LINE_COMMAND
public static final String EDIT_A_LINE_COMMAND
- See Also:
- Constant Field Values
-
EDIT_A_LINE_COMMAND_LONG
public static final String EDIT_A_LINE_COMMAND_LONG
- See Also:
- Constant Field Values
-
INSERT_COMMAND
public static final String INSERT_COMMAND
- See Also:
- Constant Field Values
-
INSERT_COMMAND_LONG
public static final String INSERT_COMMAND_LONG
- See Also:
- Constant Field Values
-
FIND_COMMAND
public static final String FIND_COMMAND
- See Also:
- Constant Field Values
-
FIND_COMMAND_LONG
public static final String FIND_COMMAND_LONG
- See Also:
- Constant Field Values
-
CLEAR_COMMAND
public static final String CLEAR_COMMAND
- See Also:
- Constant Field Values
-
CLEAR_COMMAND_LONG
public static final String CLEAR_COMMAND_LONG
- See Also:
- Constant Field Values
-
MOVE_COMMAND
public static final String MOVE_COMMAND
- See Also:
- Constant Field Values
-
MOVE_COMMAND_LONG
public static final String MOVE_COMMAND_LONG
- See Also:
- Constant Field Values
-
PRINT_COMMAND
public static final String PRINT_COMMAND
- See Also:
- Constant Field Values
-
PRINT_COMMAND_LONG
public static final String PRINT_COMMAND_LONG
- See Also:
- Constant Field Values
-
READ_COMMAND
public static final String READ_COMMAND
- See Also:
- Constant Field Values
-
READ_COMMAND_LONG
public static final String READ_COMMAND_LONG
- See Also:
- Constant Field Values
-
SUBSITUTE_COMMAND
public static final String SUBSITUTE_COMMAND
- See Also:
- Constant Field Values
-
SUBSITUTE_COMMAND_LONG
public static final String SUBSITUTE_COMMAND_LONG
- See Also:
- Constant Field Values
-
PASTE_COMMAND
public static final String PASTE_COMMAND
- See Also:
- Constant Field Values
-
PASTE_COMMAND_LONG
public static final String PASTE_COMMAND_LONG
- See Also:
- Constant Field Values
-
CUT_COMMAND
public static final String CUT_COMMAND
- See Also:
- Constant Field Values
-
CUT_COMMAND_LONG
public static final String CUT_COMMAND_LONG
- See Also:
- Constant Field Values
-
WRITE_COMMAND
public static final String WRITE_COMMAND
- See Also:
- Constant Field Values
-
WRITE_COMMAND_LONG
public static final String WRITE_COMMAND_LONG
- See Also:
- Constant Field Values
-
SIZE_COMMAND
public static final String SIZE_COMMAND
- See Also:
- Constant Field Values
-
SIZE_COMMAND_LONG
public static final String SIZE_COMMAND_LONG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LineEditor
public LineEditor(StringBuffer buffer)
-
LineEditor
public LineEditor(String rawText)
This will split the text at new lines and put it in the buffer.- Parameters:
rawText
-
-
-
Method Detail
-
isSaved
public boolean isSaved()
-
bufferToString
public String bufferToString()
Reconstruct the input as a string with new line characters.- Returns:
-
allHelp
protected void allHelp()
-
execute
public void execute() throws Throwable
- Overrides:
execute
in classAbstractEditor
- Throws:
Throwable
-
doFindHelp
protected void doFindHelp()
-
doFind
protected void doFind(LineEditorInputLine eil)
-
doSubstituteHelp
protected void doSubstituteHelp()
-
getRange
protected int[] getRange(LineEditorInputLine eil)
-
doSubstitute
protected void doSubstitute(LineEditorInputLine eil)
-
doCutHelp
protected void doCutHelp()
-
doCut
protected void doCut(LineEditorInputLine eil)
-
doDeleteHelp
protected void doDeleteHelp()
-
doDelete
protected void doDelete(LineEditorInputLine eil)
-
doMoveHelp
protected void doMoveHelp()
-
doMove
protected void doMove(LineEditorInputLine eil)
-
doViewClipboardHelp
protected void doViewClipboardHelp()
-
doViewClipboard
protected void doViewClipboard(LineEditorInputLine eil)
-
doWriteHelp
protected void doWriteHelp()
-
getTargetFile
public File getTargetFile()
This sets a target file. If none is specified in the write command, this is used.- Returns:
-
setTargetFile
public void setTargetFile(File targetFile)
-
doWrite
protected void doWrite(LineEditorInputLine eil)
-
doAppendtHelp
protected void doAppendtHelp()
-
doAppend
protected void doAppend(LineEditorInputLine eil) throws IOException
- Throws:
IOException
-
doInsertHelp
protected void doInsertHelp()
-
doInsert
protected void doInsert(LineEditorInputLine eil) throws IOException
Insert lines until a single period is entered.- Parameters:
eil
-- Throws:
IOException
-
doEditLinesHelp
protected void doEditLinesHelp()
-
doEditLines
protected void doEditLines(LineEditorInputLine eil)
-
verboseHelp
protected void verboseHelp()
- Overrides:
verboseHelp
in classAbstractEditor
-
doPrintHelp
protected void doPrintHelp()
-
doPrint
protected void doPrint(LineEditorInputLine eil)
-
doReadHelp
protected void doReadHelp()
-
doRead
protected void doRead(LineEditorInputLine eil)
Read a file into this buffer at a possible starting index.- Parameters:
eil
-
-
doCopyHelp
protected void doCopyHelp()
-
doCopy
protected void doCopy(LineEditorInputLine eil)
-
doPasteHelp
protected void doPasteHelp()
-
doPaste
protected void doPaste(LineEditorInputLine eil)
-
parseLine
protected void parseLine(String lineIn)
The form of the line is command [x,y,z] arg0 arg1 arg2... So for instance
>m [2,5,15]
would move lines 2,3,4 and 5 to before line 15, this implies that lines 2,3,4 and 5 are removed from their original location. Another example might be>s [1,6] "fnord" "baz"
Replaces every instance of "baz" by "fnord" in the range of lines 1 through 6.- Parameters:
lineIn
-
-
toInputLine
protected LineEditorInputLine toInputLine(String x)
-
main
public static void main(String[] args)
-
-