Skip to content

Commit

Permalink
bump player dependency, refactor components to separate view from logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ewnd9 committed Jan 17, 2016
1 parent 93f4ebf commit a5aa0c7
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 179 deletions.
8 changes: 8 additions & 0 deletions lab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node

var intel = require('intel');
intel.addHandler(new intel.handlers.File(process.env.HOME + '/.badtaste-npm-lab.log'));
global.Logger = intel;

require('babel/register')();
require('./test/lab');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"intel": "^1.0.2",
"lodash": "^3.10.1",
"meow": "^3.4.1",
"player": "git://github.com/ewnd9/player.git#600fce7cacc5276e0b9fa1b34674681aca94c677",
"player": "^0.6.1",
"playmusic": "^2.1.0",
"split-tracklist": "^1.1.1",
"update-notifier": "^0.5.0",
Expand Down
6 changes: 0 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ setupCredentials(cli.flags.setup).then(() => {

screen.key(['/', '?', '.', ','], () => storage.emit(SHOW_HELP));

screen.key(['escape', 'q', 'C-c'], () => {
if (!screen.blockEsc) {
process.exit(0);
}
});

screen.title = 'badtaste';
screen.render();

Expand Down
37 changes: 37 additions & 0 deletions src/tui/components/file-manager-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import blessed from 'blessed';

export const Layout = screen => blessed.box({
parent: screen,
top: 'center',
left: 'center',
width: '90%',
height: '90%',
tags: true,
border: {
type: 'line'
}
});

export const FileManager = () => blessed.filemanager({
border: 'line',
style: {
selected: {
bg: 'blue'
}
},
height: '100%-3',
label: ' {blue-fg}%path{/blue-fg} ',
cwd: process.env.HOME,
keys: true,
vi: true,
scrollbar: {
bg: 'white',
ch: ' '
}
});

export const Text = () => blessed.text({
content: 'Press "s" to play directory',
top: '100%-3',
align: 'middle'
});
15 changes: 15 additions & 0 deletions src/tui/components/help-box-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import blessed from 'blessed';

export const HelpBox = screen => blessed.message({
parent: screen,
border: 'line',
height: 'shrink',
width: 'half',
top: 'center',
left: 'center',
label: ' {blue-fg}Help{/blue-fg}',
tags: true,
keys: true,
hidden: true,
vi: true
});
12 changes: 12 additions & 0 deletions src/tui/components/line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import blessed from 'blessed';

export default (parent, params) => blessed.line({
...params,
parent: parent,
type: 'line',
orientation: 'horizontal',
top: 0,
style: {
fg: 'green'
}
});
55 changes: 55 additions & 0 deletions src/tui/components/lists-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import blessed from 'blessed';

const basicList = {
top: 1,
bottom: 1,
tags: true,
padding: {
left: 1,
right: 1
},
input: true,
scrollable: true,
keys: true,
vi: true,
mouse: true,
alwaysScroll: true,
scrollbar: {
ch: ' ',
inverse: true,
fg: 'red'
},
style: {
selected: {
fg: 'grey',
bg: 'white'
}
}
};

export const LeftPane = parent => blessed.list({
...basicList,
parent: parent,
left: 0,
width: '30%',
items: ['Loading']
});

export const RightPane = parent => blessed.list({
...basicList,
parent: parent,
left: '30%',
width: '70%',
items: ['{bold}Loading{/bold}, please wait']
});

export const SelectList = () => blessed.list({
...basicList,
top: 'center',
left: 'center',
width: '50%',
height: '50%',
border: {
type: 'line'
}
});
28 changes: 28 additions & 0 deletions src/tui/components/tracklist-prompt-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import blessed from 'blessed';

export const Layout = screen => blessed.box({
parent: screen,
top: 'center',
left: 'center',
width: '50%',
height: '50%',
tags: true,
border: {
type: 'line'
}
});

export const TextArea = () => blessed.textarea({
inputOnFocus: true,
style: {
bg: 'black'
},
keys: true,
height: '100%-6'
});

export const Text = () => blessed.text({
content: 'Paste tracklist, press esc.\nUnfortunately there is large input lag before text is actually pasted in form, don\'t close it',
top: '100%-6',
align: 'middle'
});
51 changes: 12 additions & 39 deletions src/tui/file-manager.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
import blessed from 'blessed';
import Promise from 'bluebird';

export default (screen) => {
let layout = blessed.box({
parent: screen,
top: 'center',
left: 'center',
width: '90%',
height: '90%',
tags: true,
border: {
type: 'line'
}
});

let fm = blessed.filemanager({
border: 'line',
style: {
selected: {
bg: 'blue'
}
},
height: '100%-3',
label: ' {blue-fg}%path{/blue-fg} ',
cwd: process.env.HOME,
keys: true,
vi: true,
scrollbar: {
bg: 'white',
ch: ' '
}
});
import {
Layout,
FileManager,
Text
} from './components/file-manager-components';

let text = blessed.text({
content: 'Press "s" to play directory',
top: '100%-3',
align: 'middle'
});
export default (screen) => {
const layout = Layout(screen);
const fm = FileManager();
const text = Text();

layout.append(fm);
layout.append(text);
Expand All @@ -54,9 +27,9 @@ export default (screen) => {
screen.key(['s'], function(ch, key) {
layout.destroy();

let content = fm.items[fm.selected].content;
let escaped = content.replace(/\{[^{}]+\}/g, '').replace(/@$/, '');
let result = lastCd + '/' + escaped;
const content = fm.items[fm.selected].content;
const escaped = content.replace(/\{[^{}]+\}/g, '').replace(/@$/, '');
const result = lastCd + '/' + escaped;

return resolve(result);
});
Expand Down
20 changes: 5 additions & 15 deletions src/tui/help-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@ import blessed from 'blessed';
import _ from 'lodash';
import storage from './../storage';

import { HelpBox } from './components/help-box-components';

export default (screen) => {
var msg = blessed.message({
parent: screen,
border: 'line',
height: 'shrink',
width: 'half',
top: 'center',
left: 'center',
label: ' {blue-fg}Help{/blue-fg}',
tags: true,
keys: true,
hidden: true,
vi: true
});
const msg = HelpBox(screen);

var lines = [];
var addHotkey = (key, description) => lines.push(_.padRight(key, 8) + description);
const lines = [];
const addHotkey = (key, description) => lines.push(_.padRight(key, 8) + description);

addHotkey('f', 'local search');
addHotkey('space', 'play/stop');
Expand Down
2 changes: 1 addition & 1 deletion src/tui/info-box.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import blessed from 'blessed';

export default (screen, message) => {
var msg = blessed.message({
const msg = blessed.message({
parent: screen,
border: 'line',
height: 'shrink',
Expand Down
26 changes: 5 additions & 21 deletions src/tui/left-pane.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
import blessed from 'blessed';
import style from './list-style';

export default (parent) => {
let box = blessed.list({
...style,
left: 0,
width: '30%',
items: ['Loading']
});

let line = blessed.line({
parent: parent,
type: 'line',
orientation: 'horizontal',
left: 1,
width: '30%-3',
top: 0,
style: {
fg: 'green'
}
});
import { LeftPane } from './components/lists-components';
import Line from './components/line';

parent.append(box);
export default (parent) => {
const box = LeftPane(parent);
const line = Line(parent, { left: 1, width: '30%-3' });

return {
box,
Expand Down
26 changes: 0 additions & 26 deletions src/tui/list-style.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/tui/loading-spinner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import blessed from 'blessed';

export default (screen, message, lockKeys = true, label = ' {blue-fg}Loading{/blue-fg} ') => {
var loader = blessed.loading({
const loader = blessed.loading({
parent: screen,
border: 'line',
height: 'shrink',
Expand All @@ -20,7 +20,7 @@ export default (screen, message, lockKeys = true, label = ' {blue-fg}Loading{/bl
screen.lockKeys = lockKeys;
screen.key(['z'], (ch, key) => loader.stop());

var superStop = loader.stop;
const superStop = loader.stop;
loader.stop = () => {
superStop.call(loader);
screen.removeKey(['z'], (ch, key) => loader.stop());
Expand Down
2 changes: 1 addition & 1 deletion src/tui/prompt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import blessed from 'blessed';

export default (screen, label, question, cb) => {
let prompt = blessed.prompt({
const prompt = blessed.prompt({
parent: screen,
border: 'line',
height: 'shrink',
Expand Down
Loading

0 comments on commit a5aa0c7

Please sign in to comment.