diff --git a/builtins/src/main/java/org/jline/builtins/Commands.java b/builtins/src/main/java/org/jline/builtins/Commands.java index 25d5cb1a5..fcf157b4e 100644 --- a/builtins/src/main/java/org/jline/builtins/Commands.java +++ b/builtins/src/main/java/org/jline/builtins/Commands.java @@ -110,6 +110,22 @@ public static void nano(Terminal terminal, PrintStream out, PrintStream err, "nano - edit files", "Usage: nano [OPTIONS] [FILES]", " -? --help Show help", + " -B --backup When saving a file, back up the previous version of it, using the current filename", + " suffixed with a tilde (~)." , + " -I --ignorercfiles Don't look at the system's nanorc nor at the user's nanorc." , + " -Q --quotestr=regex Set the regular expression for matching the quoting part of a line. The default value", + " is \"^([ \t]*([!#%:;>|}]|//))+\".", + " -T --tabsize=number Set the size (width) of a tab to number columns.", + " -U --quickblank Do quick status-bar blanking: status-bar messages will disappear after 1 keystroke", + " instead of 25.", + " -c --constantshow Constantly show the cursor position on the status bar.", + " -e --emptyline Do not use the line below the title bar, leaving it entirely blank.", + " -j --jumpyscrolling Scroll the buffer contents per half-screen instead of per line.", + " -l --linenumbers Display line numbers to the left of the text area.", + " -m --mouse Enable mouse support, if available for your system. When enabled, mouse clicks can be", + " used to place the cursor, set the mark (with a double click), and execute shortcuts.", + " -$ --softwrap Enable 'soft wrapping'. This will make nano attempt to display the entire contents of any", + " line, even if it is longer than the screen width, by continuing it over multiple screen lines.", " -R --restricted Restricted mode: don't allow suspending; don't allow a file to be appended to,", " prepended to, or saved under a different name if it already has one;", " and don't use backup files.", @@ -149,7 +165,8 @@ public static void less(Terminal terminal, InputStream in, PrintStream out, Prin " -N --LINE-NUMBERS Display line number for each line", " -Y --syntax=name The name of the syntax highlighting to use.", " --no-init Disable terminal initialization", - " --no-keypad Disable keypad handling" + " --no-keypad Disable keypad handling", + " --ignorercfiles Don't look at the system's lessrc nor at the user's lessrc." }; diff --git a/builtins/src/main/java/org/jline/builtins/Less.java b/builtins/src/main/java/org/jline/builtins/Less.java index c52e9456f..4b21dd4ca 100644 --- a/builtins/src/main/java/org/jline/builtins/Less.java +++ b/builtins/src/main/java/org/jline/builtins/Less.java @@ -108,7 +108,7 @@ public class Less { protected String displayPattern; protected final Size size = new Size(); - + SyntaxHighlighter syntaxHighlighter; private List syntaxFiles = new ArrayList<>(); private boolean highlight = true; @@ -123,13 +123,14 @@ public Less(Terminal terminal, Path currentDir, Options opts, Path lessrc) { this.display = new Display(terminal, true); this.bindingReader = new BindingReader(terminal.reader()); this.currentDir = currentDir; - if (lessrc != null && lessrc.toFile().exists()) { + boolean ignorercfiles = opts!=null && opts.isSet("ignorercfiles"); + if (lessrc != null && lessrc.toFile().exists() && !ignorercfiles) { try { parseConfig(lessrc); } catch (IOException e) { errorMessage = "Encountered error while reading config file: " + lessrc; } - } else if (new File("/usr/share/nano").exists()) { + } else if (new File("/usr/share/nano").exists() && !ignorercfiles) { PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:/usr/share/nano/*.nanorc"); try { Files.find(Paths.get("/usr/share/nano"), Integer.MAX_VALUE, (path, f) -> pathMatcher.matches(path)) @@ -180,7 +181,7 @@ public Less(Terminal terminal, Path currentDir, Options opts, Path lessrc) { } } } - + private void parseConfig(Path file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(file.toFile())); String line = reader.readLine(); @@ -200,23 +201,23 @@ private void parseConfig(Path file) throws IOException { && (parts.get(0).equals("set") || parts.get(0).equals("unset"))) { String option = parts.get(1); boolean val = parts.get(0).equals("set"); - if (option.equals("quitatfirsteof")) { + if (option.equals("QUIT-AT-EOF")) { quitAtFirstEof = val; - } else if (option.equals("quitatsecondeof")) { + } else if (option.equals("quit-at-eof")) { quitAtSecondEof = val; - } else if (option.equals("quitifonescreen")) { + } else if (option.equals("quit-if-one-screen")) { quitIfOneScreen = val; - } else if (option.equals("quiet")) { + } else if (option.equals("quiet") || option.equals("silent")) { quiet = val; - } else if (option.equals("veryquiet")) { + } else if (option.equals("QUIET") || option.equals("SILENT")) { veryQuiet = val; - } else if (option.equals("choplonglines")) { + } else if (option.equals("chop-long-lines")) { chopLongLines = val; - } else if (option.equals("ignorecaseallways")) { + } else if (option.equals("IGNORE-CASE")) { ignoreCaseAlways = val; - } else if (option.equals("ignorecasecond")) { + } else if (option.equals("ignore-case")) { ignoreCaseCond = val; - } else if (option.equals("linenumbers")) { + } else if (option.equals("LINE-NUMBERS")) { printLineNumbers = val; } else { errorMessage = "Less config: Unknown or unsupported configuration option " + option; diff --git a/builtins/src/main/java/org/jline/builtins/Nano.java b/builtins/src/main/java/org/jline/builtins/Nano.java index b9b8bf636..bf8126258 100644 --- a/builtins/src/main/java/org/jline/builtins/Nano.java +++ b/builtins/src/main/java/org/jline/builtins/Nano.java @@ -82,21 +82,21 @@ public class Nano implements Editor { // Configuration public String title = "JLine Nano 3.0.0"; - public boolean printLineNumbers = true; - public boolean wrapping = true; + public boolean printLineNumbers = false; + public boolean wrapping = false; public boolean smoothScrolling = true; public boolean mouseSupport = false; public boolean oneMoreLine = true; - public boolean constantCursor; + public boolean constantCursor = false; public boolean quickBlank = false; public int tabs = 1; // tabs are not currently supported! public String brackets = "\"’)>]}"; public String matchBrackets = "(<[{)>]}"; public String punct = "!.?"; public String quoteStr = "^([ \\t]*[#:>\\|}])+"; - private boolean restricted; + private boolean restricted = false; private String syntaxName; - private List syntaxFiles = new ArrayList<>(); + private boolean writeBackup = false; // Input protected final List buffers = new ArrayList<>(); @@ -104,6 +104,7 @@ public class Nano implements Editor { protected Buffer buffer; protected String message; + protected String errorMessage = null; protected int nbBindings = 0; protected LinkedHashMap shortcuts; @@ -118,14 +119,13 @@ public class Nano implements Editor { protected List searchTerms = new ArrayList<>(); protected int searchTermId = -1; protected WriteMode writeMode = WriteMode.WRITE; - protected boolean writeBackup; protected List cutbuffer = new ArrayList<>(); protected boolean cut2end = false; protected boolean mark = false; protected boolean highlight = true; + private List syntaxFiles = new ArrayList<>(); protected boolean readNewBuffer = true; - protected String errorMessage = null; protected enum WriteMode { WRITE, @@ -1583,13 +1583,14 @@ public Nano(Terminal terminal, Path root, Options opts, Path nanorc) { this.size = new Size(); this.vsusp = terminal.getAttributes().getControlChar(ControlChar.VSUSP); bindKeys(); - if (nanorc != null && nanorc.toFile().exists()) { + boolean ignorercfiles = opts!=null && opts.isSet("ignorercfiles"); + if (nanorc != null && nanorc.toFile().exists() && !ignorercfiles) { try { parseConfig(nanorc); } catch (IOException e) { errorMessage = "Encountered error while reading config file: " + nanorc; } - } else if (new File("/usr/share/nano").exists()) { + } else if (new File("/usr/share/nano").exists() && !ignorercfiles) { PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:/usr/share/nano/*.nanorc"); try { Files.find(Paths.get("/usr/share/nano"), Integer.MAX_VALUE, (path, f) -> pathMatcher.matches(path)) @@ -1601,6 +1602,36 @@ public Nano(Terminal terminal, Path root, Options opts, Path nanorc) { if (opts != null) { this.restricted = opts.isSet("restricted"); this.syntaxName = opts.isSet("syntax") ? opts.get("syntax") : null; + if (opts.isSet("backup")) { + writeBackup = true; + } + if (opts.isSet("quotestr")) { + quoteStr = opts.get("quotestr"); + } + if (opts.isSet("tabsize")) { + tabs = opts.getNumber("tabsize"); + } + if (opts.isSet("quickblank")) { + quickBlank = true; + } + if (opts.isSet("constantshow")) { + constantCursor = true; + } + if (opts.isSet("emptyline")) { + oneMoreLine = false; + } + if (opts.isSet("jumpyscrolling")) { + smoothScrolling = false; + } + if (opts.isSet("linenumbers")) { + printLineNumbers = true; + } + if (opts.isSet("mouse")) { + mouseSupport = true; + } + if (opts.isSet("softwrap")) { + wrapping = true; + } } } @@ -2393,6 +2424,9 @@ void help(String help) { this.printLineNumbers = false; this.constantCursor = false; this.buffer = newBuf; + if (!oldWrapping) { + buffer.computeAllOffsets(); + } try { this.message = null; terminal.puts(Capability.cursor_invisible); @@ -2438,6 +2472,9 @@ void help(String help) { this.constantCursor = oldConstantCursor; this.shortcuts = oldShortcuts; terminal.puts(Capability.cursor_visible); + if (!oldWrapping) { + buffer.computeAllOffsets(); + } } } diff --git a/demo/src/main/java/org/apache/felix/gogo/jline/Posix.java b/demo/src/main/java/org/apache/felix/gogo/jline/Posix.java index 8f5de3a59..ccc044a2a 100644 --- a/demo/src/main/java/org/apache/felix/gogo/jline/Posix.java +++ b/demo/src/main/java/org/apache/felix/gogo/jline/Posix.java @@ -865,6 +865,22 @@ protected void nano(final CommandSession session, Process process, String[] argv "nano - edit files", "Usage: nano [OPTIONS] [FILES]", " -? --help Show help", + " -B --backup When saving a file, back up the previous version of it, using the current filename", + " suffixed with a tilde (~)." , + " -I --ignorercfiles Don't look at the system's nanorc nor at the user's nanorc." , + " -Q --quotestr=regex Set the regular expression for matching the quoting part of a line. The default value", + " is \"^([ \t]*([!#%:;>|}]|//))+\".", + " -T --tabsize=number Set the size (width) of a tab to number columns.", + " -U --quickblank Do quick status-bar blanking: status-bar messages will disappear after 1 keystroke", + " instead of 25.", + " -c --constantshow Constantly show the cursor position on the status bar.", + " -e --emptyline Do not use the line below the title bar, leaving it entirely blank.", + " -j --jumpyscrolling Scroll the buffer contents per half-screen instead of per line.", + " -l --linenumbers Display line numbers to the left of the text area.", + " -m --mouse Enable mouse support, if available for your system. When enabled, mouse clicks can be", + " used to place the cursor, set the mark (with a double click), and execute shortcuts.", + " -$ --softwrap Enable 'soft wrapping'. This will make nano attempt to display the entire contents of any", + " line, even if it is longer than the screen width, by continuing it over multiple screen lines.", " -R --restricted Restricted mode: don't allow suspending; don't allow a file to be appended to,", " prepended to, or saved under a different name if it already has one;", " and don't use backup files.", @@ -950,7 +966,9 @@ protected void less(CommandSession session, Process process, String[] argv) thro " -N --LINE-NUMBERS Display line number for each line", " -Y --syntax=name The name of the syntax highlighting to use.", " --no-init Disable terminal initialization", - " --no-keypad Disable keypad handling" + " --no-keypad Disable keypad handling", + " --ignorercfiles Don't look at the system's lessrc nor at the user's lessrc." + }; try { Less.class.getField("quitIfOneScreen");