From 2521d3e693e7453eabc2e93ef3c33d86dfbb3a8c Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Mon, 8 Oct 2007 23:22:04 +0000 Subject: [PATCH] added flags to vimperator.commandline.echo() --- content/bookmarks.js | 8 ++++---- content/buffers.js | 2 +- content/commands.js | 9 ++++----- content/events.js | 2 +- content/find.js | 2 +- content/hints.js | 4 ++-- content/mappings.js | 4 ++-- content/modes.js | 4 ++-- content/options.js | 2 +- content/ui.js | 34 +++++++++++++++++++++++++--------- content/vimperator.js | 4 ++-- 11 files changed, 45 insertions(+), 30 deletions(-) diff --git a/content/bookmarks.js b/content/bookmarks.js index 80497479..674ea69c 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -277,7 +277,7 @@ function Bookmarks() //{{{ } list += ""; - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, true); + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); } } } @@ -501,7 +501,7 @@ function History() //{{{ } list += ""; - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, true); + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); } } } @@ -758,7 +758,7 @@ function Marks() //{{{ } list += ""; - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, true); // TODO: force of multiline widget a better way + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); // TODO: force of multiline widget a better way } //}}} } //}}} @@ -850,7 +850,7 @@ function QuickMarks() //{{{ } list += ""; - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, true); // TODO: force of multiline widget a better way + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); // TODO: force of multiline widget a better way } this.destroy = function() diff --git a/content/buffers.js b/content/buffers.js index 6f661722..0c345797 100644 --- a/content/buffers.js +++ b/content/buffers.js @@ -253,7 +253,7 @@ function Buffer() //{{{ } list += ""; - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, true); + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); } } diff --git a/content/commands.js b/content/commands.js index 46f0d0ae..3a35e5f8 100644 --- a/content/commands.js +++ b/content/commands.js @@ -284,11 +284,10 @@ function Commands() //{{{ result.title = result.url; vimperator.bookmarks.add(result.title, result.url); - vimperator.echo("Bookmark `" + result.title + "' added with url `" + result.url + "'"); + vimperator.echo("Bookmark `" + result.title + "' added with url `" + result.url + "'", vimperator.commandline.FORCE_SINGLELINE); } else { - //vimperator.echo("Usage: :bmark [-t \"My Title\"] [-T tag1,tag2] "); vimperator.echoerr("E474: Invalid argument"); } }, @@ -385,7 +384,7 @@ function Commands() //{{{ result.url = vimperator.buffer.URL; var deleted_count = vimperator.bookmarks.remove(result.url); - vimperator.echo(deleted_count + " bookmark(s) with url `" + result.url + "' deleted"); + vimperator.echo(deleted_count + " bookmark(s) with url `" + result.url + "' deleted", vimperator.commandline.FORCE_SINGLELINE); } else { @@ -680,7 +679,7 @@ function Commands() //{{{ str += "" + i + "" + prefix + value + "\n"; } if (str) - vimperator.echo("" + str + "
", true); + vimperator.echo("" + str + "
", vimperator.commandline.FORCE_MULTILINE); else vimperator.echo("No variables found"); return; @@ -1471,7 +1470,7 @@ function Commands() //{{{ "" + total + "" + ""; - vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, true); + vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); } else { diff --git a/content/events.js b/content/events.js index 2c0e74af..b19cb5f7 100644 --- a/content/events.js +++ b/content/events.js @@ -845,7 +845,7 @@ function Events() //{{{ if (ssli == 1) vimperator.statusline.updateUrl("Link: " + link); else if (ssli == 2) - vimperator.echo("Link: " + link); + vimperator.echo("Link: " + link, vimperator.commandline.DISALLOW_MULTILINE); } if (link == "") diff --git a/content/find.js b/content/find.js index 2109030f..9a2ded79 100644 --- a/content/find.js +++ b/content/find.js @@ -168,7 +168,7 @@ function Search() //{{{ } else { - vimperator.echo((up ? "?" : "/") + last_search_pattern); + vimperator.echo((up ? "?" : "/") + last_search_pattern, null, vimperator.commandline.FORCE_SINGLELINE); if (vimperator.options["hlsearch"]) this.highlight(last_search_string); diff --git a/content/hints.js b/content/hints.js index 4a4d34bb..dfd0a7d8 100644 --- a/content/hints.js +++ b/content/hints.js @@ -520,7 +520,7 @@ function Hints() //{{{ this.disableHahMode(null, true); vimperator.copyToClipboard(loc); - vimperator.echo("Yanked " + loc); + vimperator.echo("Yanked " + loc, vimperator.commandline.FORCE_SINGLELINE); }; this.yankTextHints = function() @@ -543,7 +543,7 @@ function Hints() //{{{ this.disableHahMode(null, true); vimperator.copyToClipboard(loc); - vimperator.echo("Yanked " + loc); + vimperator.echo("Yanked " + loc, vimperator.commandline.FORCE_SINGLELINE); }; function setMouseOverElement(elem) diff --git a/content/mappings.js b/content/mappings.js index 51fe9b37..6eef277d 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -295,7 +295,7 @@ function Mappings() //{{{ } list += ""; - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, true); // TODO: force of multiline widget a better way + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); } /////////////////////////////////////////////////////////////////////////////}}} @@ -678,7 +678,7 @@ function Mappings() //{{{ { var url = vimperator.buffer.URL; vimperator.copyToClipboard(url); - vimperator.echo("Yanked " + url); + vimperator.echo("Yanked " + url, vimperator.commandline.FORCE_SINGLELINE); }, { short_help: "Yank current location to the clipboard", diff --git a/content/modes.js b/content/modes.js index 35c894bc..003d2a33 100644 --- a/content/modes.js +++ b/content/modes.js @@ -150,9 +150,9 @@ vimperator.modes = (function() var msg = getModeMessage(); if (msg) - vimperator.commandline.echo("-- " + getModeMessage() + " --", vimperator.commandline.HL_MODEMSG); + vimperator.commandline.echo("-- " + getModeMessage() + " --", vimperator.commandline.HL_MODEMSG, vimperator.commandline.DISALLOW_MULTILINE); else - vimperator.commandline.echo(""); + vimperator.commandline.echo("", null, vimperator.commandline.DISALLOW_MULTILINE); }, // helper function to set both modes in one go diff --git a/content/options.js b/content/options.js index 29f743e0..1a71eeb6 100644 --- a/content/options.js +++ b/content/options.js @@ -326,7 +326,7 @@ function Options() //{{{ list += ""; - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, true); + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); } // TODO: separate Preferences from Options? Would these utility functions diff --git a/content/ui.js b/content/ui.js index 1d1c95e6..842f2b1f 100644 --- a/content/ui.js +++ b/content/ui.js @@ -251,9 +251,12 @@ function CommandLine() //{{{ this.HL_WARNING = "hl-Warning"; // not yet used - this.FORCE_MULTILINE = 1 << 0; - this.FORCE_SINGLELINE = 1 << 1; - this.FORCE_ECHO = 1 << 2; // also echoes if the commandline has focus + this.FORCE_MULTILINE = 1 << 0; + this.FORCE_SINGLELINE = 1 << 1; + this.DISALLOW_MULTILINE = 1 << 2; // if an echo() should try to use the single line, + // but output nothing when the MOW is open; when also + // FORCE_MULTILINE is given, FORCE_MULTILINE takes precedence + this.APPEND_TO_MESSAGES = 1 << 3; // will show the string in :messages this.getCommand = function() { @@ -292,8 +295,8 @@ function CommandLine() //{{{ this.clear(); } - // FIXME: flags not yet really functional --mst - // multiline string don't obey highlight_group + // TODO: add :messages entry + // vimperator.echo uses different order of flags as it omits the hightlight group, change v.commandline.echo argument order? --mst this.echo = function(str, highlight_group, flags) { var focused = document.commandDispatcher.focusedElement; @@ -302,10 +305,23 @@ function CommandLine() //{{{ highlight_group = highlight_group || this.HL_NORMAL; - if (flags || !multiline_output_widget.collapsed || /\n|/.test(str)) - setMultiline(str, highlight_group); - else - setLine(str, highlight_group); + var where = setLine; + if (flags & this.FORCE_MULTILINE) + where = setMultiline; + else if (flags & this.FORCE_SINGLELINE) + where = setLine; + else if (!multiline_output_widget.collapsed) + { + if (flags & this.DISALLOW_MULTILINE) + where = null; + else + where = setMultiline; + } + else if (/\n|/.test(str)) + where = setMultiline; + + if (where) + where(str, highlight_group); cur_extended_mode = null; diff --git a/content/vimperator.js b/content/vimperator.js index a3b628de..164f37c6 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -743,8 +743,8 @@ const vimperator = (function() //{{{ vimperator.hints = new Hints(); vimperator.log("All modules loaded", 3); - vimperator.echo = function(str) { vimperator.commandline.echo(str); } - vimperator.echoerr = function(str) { vimperator.commandline.echo(str, vimperator.commandline.HL_ERRORMSG); } + vimperator.echo = function(str, flags) { vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, flags); } + vimperator.echoerr = function(str, flags) { vimperator.commandline.echo(str, vimperator.commandline.HL_ERRORMSG, flags); } vimperator.globalVariables = {};