aboutsummaryrefslogtreecommitdiff
path: root/src/console
diff options
context:
space:
mode:
Diffstat (limited to 'src/console')
-rw-r--r--src/console/actions/console.js14
-rw-r--r--src/console/actions/index.js5
-rw-r--r--src/console/components/console.js31
-rw-r--r--src/console/index.html4
-rw-r--r--src/console/index.js27
-rw-r--r--src/console/reducers/index.js26
-rw-r--r--src/console/site.scss10
7 files changed, 69 insertions, 48 deletions
diff --git a/src/console/actions/console.js b/src/console/actions/console.js
index 01d9a9b..0d891bb 100644
--- a/src/console/actions/console.js
+++ b/src/console/actions/console.js
@@ -14,9 +14,16 @@ const showError = (text) => {
};
};
-const hide = () => {
+const showInfo = (text) => {
return {
- type: actions.CONSOLE_HIDE
+ type: actions.CONSOLE_SHOW_INFO,
+ text: text
+ };
+};
+
+const hideCommand = () => {
+ return {
+ type: actions.CONSOLE_HIDE_COMMAND,
};
};
@@ -40,5 +47,6 @@ const completionPrev = () => {
};
export {
- showCommand, showError, hide, setCompletions, completionNext, completionPrev
+ showCommand, showError, showInfo, hideCommand,
+ setCompletions, completionNext, completionPrev
};
diff --git a/src/console/actions/index.js b/src/console/actions/index.js
index a5d03bc..c4f88cd 100644
--- a/src/console/actions/index.js
+++ b/src/console/actions/index.js
@@ -1,9 +1,10 @@
export default {
// console commands
CONSOLE_SHOW_COMMAND: 'console.show.command',
- CONSOLE_SET_COMPLETIONS: 'console.set.completions',
CONSOLE_SHOW_ERROR: 'console.show.error',
- CONSOLE_HIDE: 'console.hide',
+ CONSOLE_SHOW_INFO: 'console.show.info',
+ CONSOLE_HIDE_COMMAND: 'console.hide.command',
+ CONSOLE_SET_COMPLETIONS: 'console.set.completions',
CONSOLE_COMPLETION_NEXT: 'console.completion.next',
CONSOLE_COMPLETION_PREV: 'console.completion.prev',
};
diff --git a/src/console/components/console.js b/src/console/components/console.js
index 9023d91..93802f8 100644
--- a/src/console/components/console.js
+++ b/src/console/components/console.js
@@ -16,7 +16,7 @@ export default class ConsoleComponent {
input.addEventListener('keyup', this.onKeyUp.bind(this));
this.hideCommand();
- this.hideError();
+ this.hideMessage();
}
onBlur() {
@@ -72,17 +72,16 @@ export default class ConsoleComponent {
update() {
let state = this.store.getState();
- if (!this.prevState.commandShown && state.commandShown) {
+ if (this.prevState.mode !== 'command' && state.mode === 'command') {
this.showCommand(state.commandText);
- } else if (!state.commandShown) {
+ } else if (state.mode !== 'command') {
this.hideCommand();
}
- if (state.errorShown) {
- this.setErrorText(state.errorText);
- this.showError();
+ if (state.mode === 'error' || state.mode === 'info') {
+ this.showMessage(state.mode, state.messageText);
} else {
- this.hideError();
+ this.hideMessage();
}
if (state.groupSelection >= 0 && state.itemSelection >= 0) {
@@ -128,21 +127,21 @@ export default class ConsoleComponent {
input.value = this.completionOrigin;
}
- setErrorText(text) {
+ showMessage(mode, text) {
let doc = this.wrapper.ownerDocument;
- let error = doc.querySelector('#vimvixen-console-error');
+ let error = doc.querySelector('#vimvixen-console-message');
+ error.classList.remove(
+ 'vimvixen-console-info',
+ 'vimvixen-console-error'
+ );
+ error.classList.add('vimvixen-console-' + mode);
error.textContent = text;
- }
-
- showError() {
- let doc = this.wrapper.ownerDocument;
- let error = doc.querySelector('#vimvixen-console-error');
error.style.display = 'block';
}
- hideError() {
+ hideMessage() {
let doc = this.wrapper.ownerDocument;
- let error = doc.querySelector('#vimvixen-console-error');
+ let error = doc.querySelector('#vimvixen-console-message');
error.style.display = 'none';
}
}
diff --git a/src/console/index.html b/src/console/index.html
index 4222f12..f41a8dc 100644
--- a/src/console/index.html
+++ b/src/console/index.html
@@ -6,8 +6,8 @@
<script src='console.js'></script>
</head>
<body class='vimvixen-console'>
- <p id='vimvixen-console-error'
- class='vimvixen-console-error'></p>
+ <p id='vimvixen-console-message'
+ class='vimvixen-console-message'></p>
<div id='vimvixen-console-command'>
<ul id='vimvixen-console-completion' class='vimvixen-console-completion'></ul>
<div class='vimvixen-console-command'>
diff --git a/src/console/index.js b/src/console/index.js
index 7396a96..895fcc2 100644
--- a/src/console/index.js
+++ b/src/console/index.js
@@ -17,18 +17,25 @@ window.addEventListener('load', () => {
consoleComponent = new ConsoleComponent(document.body, store);
});
+const onMessage = (message) => {
+ switch (message.type) {
+ case messages.CONSOLE_SHOW_COMMAND:
+ return store.dispatch(consoleActions.showCommand(message.command));
+ case messages.CONSOLE_SHOW_ERROR:
+ return store.dispatch(consoleActions.showError(message.text));
+ case messages.CONSOLE_SHOW_INFO:
+ return store.dispatch(consoleActions.showInfo(message.text));
+ case messages.CONSOLE_HIDE_COMMAND:
+ return store.dispatch(consoleActions.hideCommand());
+ }
+};
+
store.subscribe(() => {
completionComponent.update();
consoleComponent.update();
});
-browser.runtime.onMessage.addListener((action) => {
- switch (action.type) {
- case messages.CONSOLE_SHOW_COMMAND:
- return store.dispatch(consoleActions.showCommand(action.command));
- case messages.CONSOLE_SHOW_ERROR:
- return store.dispatch(consoleActions.showError(action.text));
- case messages.CONSOLE_HIDE:
- return store.dispatch(consoleActions.hide(action.command));
- }
-});
+browser.runtime.onMessage.addListener(onMessage);
+window.addEventListener('message', (message) => {
+ onMessage(JSON.parse(message.data));
+}, false);
diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js
index ee9c691..d4affa7 100644
--- a/src/console/reducers/index.js
+++ b/src/console/reducers/index.js
@@ -1,9 +1,8 @@
import actions from 'console/actions';
const defaultState = {
- errorShown: false,
- errorText: '',
- commandShown: false,
+ mode: '',
+ messageText: '',
commandText: '',
completions: [],
groupSelection: -1,
@@ -48,25 +47,24 @@ export default function reducer(state = defaultState, action = {}) {
switch (action.type) {
case actions.CONSOLE_SHOW_COMMAND:
return Object.assign({}, state, {
- commandShown: true,
+ mode: 'command',
commandText: action.text,
errorShown: false,
completions: []
});
case actions.CONSOLE_SHOW_ERROR:
return Object.assign({}, state, {
- errorText: action.text,
- errorShown: true,
- commandShown: false,
+ mode: 'error',
+ messageText: action.text,
});
- case actions.CONSOLE_HIDE:
- if (state.errorShown) {
- // keep error message if shown
- return state;
- }
+ case actions.CONSOLE_SHOW_INFO:
return Object.assign({}, state, {
- errorShown: false,
- commandShown: false
+ mode: 'info',
+ messageText: action.text,
+ });
+ case actions.CONSOLE_HIDE_COMMAND:
+ return Object.assign({}, state, {
+ mode: state.mode === 'command' ? '' : state.mode,
});
case actions.CONSOLE_SET_COMPLETIONS:
return Object.assign({}, state, {
diff --git a/src/console/site.scss b/src/console/site.scss
index 5823dce..e5cb2df 100644
--- a/src/console/site.scss
+++ b/src/console/site.scss
@@ -64,12 +64,20 @@ body {
}
}
+ &-message {
+ @include consoole-font;
+ }
+
&-error {
background-color: red;
font-weight: bold;
color: white;
+ }
- @include consoole-font;
+ &-info {
+ background-color: white;
+ font-weight: normal;
+ color: green;
}
&-command {