Skip to content

Commit

Permalink
devtools: introduce printing the Dirac welcome message
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Jun 1, 2016
1 parent d790e80 commit 981962b
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 15 deletions.
98 changes: 83 additions & 15 deletions resources/unpacked/devtools/front_end/console/ConsoleView.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,21 +827,22 @@ WebInspector.ConsoleView.prototype = {
* @param {!WebInspector.ConsoleMessage} message
* @return {!WebInspector.ConsoleViewMessage}
*/
_createViewMessage2: function(message)
{
_createViewMessage2: function(message) {
var nestingLevel = this._currentGroup.nestingLevel();
switch (message.type) {
case WebInspector.ConsoleMessage.MessageType.Command:
return new WebInspector.ConsoleCommand(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.DiracCommand:
return new WebInspector.ConsoleDiracCommand(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.Result:
return new WebInspector.ConsoleCommandResult(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed:
case WebInspector.ConsoleMessage.MessageType.StartGroup:
return new WebInspector.ConsoleGroupViewMessage(message, this._linkifier, nestingLevel);
default:
return new WebInspector.ConsoleViewMessage(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.Command:
return new WebInspector.ConsoleCommand(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.DiracCommand:
return new WebInspector.ConsoleDiracCommand(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.DiracMarkup:
return new WebInspector.ConsoleDiracMarkup(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.Result:
return new WebInspector.ConsoleCommandResult(message, this._linkifier, nestingLevel);
case WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed:
case WebInspector.ConsoleMessage.MessageType.StartGroup:
return new WebInspector.ConsoleGroupViewMessage(message, this._linkifier, nestingLevel);
default:
return new WebInspector.ConsoleViewMessage(message, this._linkifier, nestingLevel);
}
},

Expand Down Expand Up @@ -1072,6 +1073,37 @@ WebInspector.ConsoleView.prototype = {
this._prompt.setText("");
},

appendDiracMarkup: function (markup) {
const executionContext = WebInspector.context.flavor(WebInspector.ExecutionContext);
if (!executionContext) {
return false;
}

const target = executionContext.target();
const source = WebInspector.ConsoleMessage.MessageSource.Other;
const level = WebInspector.ConsoleMessage.MessageLevel.Log;
const type = WebInspector.ConsoleMessage.MessageType.DiracMarkup;
const message = new WebInspector.ConsoleMessage(target, source, level, markup, type);
message.setExecutionContextId(executionContext.id);
target.consoleModel.addMessage(message);
},

displayWelcomeMessage: function() {
dirac.feedback('displayWelcomeMessage');
const wrapCode = (text) => {
return "<code style='background-color:rgba(0, 0, 0, 0.08);padding:0 2px;border-radius:1px'>" + text + "</code>";
};
const wrapBold = (text) => {
return "<b>" + text + "</b>";
};

var markup = [
"Welcome to " + wrapBold("Dirac DevTools") + " hosted in " + wrapBold("Dirac Chrome Extension v" + dirac.getVersion()) + ".",
"Use " + wrapCode("CTRL+,") + " and " + wrapCode("CTRL+.") + " to switch between Javascript and Dirac prompts.",
"In connected Dirac prompt, you can enter " + wrapCode("(dirac! :help)") + " for more info."];
this.appendDiracMarkup(markup.join("\n"));
},

_normalizePromptIndex: function(index) {
var count = this._prompts.length;
while (index<0) {
Expand Down Expand Up @@ -1700,7 +1732,7 @@ WebInspector.ConsoleCommand.prototype = {
WebInspector.ConsoleDiracCommand = function(message, linkifier, nestingLevel)
{
WebInspector.ConsoleCommand.call(this, message, linkifier, nestingLevel);
}
};

WebInspector.ConsoleDiracCommand.prototype = {

Expand All @@ -1725,7 +1757,43 @@ WebInspector.ConsoleDiracCommand.prototype = {
},

__proto__: WebInspector.ConsoleCommand.prototype
}
};

/**
* @constructor
* @extends {WebInspector.ConsoleViewMessage}
* @param {!WebInspector.ConsoleMessage} message
* @param {!WebInspector.Linkifier} linkifier
* @param {number} nestingLevel
*/
WebInspector.ConsoleDiracMarkup = function(message, linkifier, nestingLevel)
{
WebInspector.ConsoleViewMessage.call(this, message, linkifier, nestingLevel);
};

WebInspector.ConsoleDiracMarkup.prototype = {

/**
* @override
* @return {!Element}
*/
contentElement: function()
{
if (!this._element) {
this._element = createElementWithClass("div", "console-message console-dirac-markup");
this._element.message = this;

this._formattedCommand = createElementWithClass("span", "console-message-text source-code");
this._formattedCommand.innerHTML = this._message.messageText;
this._element.appendChild(this._formattedCommand);

this.element().classList.add("dirac-flavor"); // applied to wrapper element
}
return this._element;
},

__proto__: WebInspector.ConsoleViewMessage.prototype
};


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
-webkit-filter: hue-rotate(280deg);
}

.console-dirac-markup {
line-height: 14px;
}

.console-message, .console-user-command {
padding-left: 4px !important;
padding-right: 4px !important;
Expand Down
1 change: 1 addition & 0 deletions resources/unpacked/devtools/front_end/sdk/ConsoleModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ WebInspector.ConsoleMessage.MessageType = {
Profile: "profile",
ProfileEnd: "profileEnd",
DiracCommand: "diracCommand",
DiracMarkup: "diracMarkup",
Command: "command"
}

Expand Down
1 change: 1 addition & 0 deletions test/browser/transcripts/expected/suite01-completions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ devtools #1 console initialized
devtools #1 adopt-prompt-element use-parinfer? true
devtools #1 setDiracPromptMode('status')
devtools #1 ConsoleView constructed
devtools #1 displayWelcomeMessage
devtools #1 setCurrentPanel: console
automate #1 switch-prompt-to-dirac!
devtools #1 switched console prompt to 'dirac'
Expand Down
1 change: 1 addition & 0 deletions test/browser/transcripts/expected/suite01-console.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ devtools #1 console initialized
devtools #1 adopt-prompt-element use-parinfer? true
devtools #1 setDiracPromptMode('status')
devtools #1 ConsoleView constructed
devtools #1 displayWelcomeMessage
devtools #1 setCurrentPanel: console
automate #1 enable-console-feedback!
automate #1 simulate-console-action! ["CTRL+."]
Expand Down
1 change: 1 addition & 0 deletions test/browser/transcripts/expected/suite01-dirac-eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ devtools #1 console initialized
devtools #1 adopt-prompt-element use-parinfer? true
devtools #1 setDiracPromptMode('status')
devtools #1 ConsoleView constructed
devtools #1 displayWelcomeMessage
devtools #1 setCurrentPanel: console
automate #1 switch-prompt-to-dirac!
devtools #1 switched console prompt to 'dirac'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ devtools #1 console initialized
devtools #1 adopt-prompt-element use-parinfer? false
devtools #1 setDiracPromptMode('status')
devtools #1 ConsoleView constructed
devtools #1 displayWelcomeMessage
devtools #1 setCurrentPanel: console
automate #1 switch-prompt-to-dirac!
devtools #1 switched console prompt to 'dirac'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ devtools #1 console initialized
devtools #1 adopt-prompt-element use-parinfer? true
devtools #1 setDiracPromptMode('status')
devtools #1 ConsoleView constructed
devtools #1 displayWelcomeMessage
devtools #1 setCurrentPanel: console
automate #1 switch-prompt-to-dirac!
devtools #1 switched console prompt to 'dirac'
Expand Down

0 comments on commit 981962b

Please sign in to comment.