Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for 16-color and 1-color tty #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"description": "A terminal client for slack",
"main": "main.js",
"dependencies": {
"ws": "^0.7.1",
"blessed": "^0.1.56",
"request": "^2.55.0",
"blessed": "^0.1.56"
"supports-color": "^3.2.3",
"ws": "^0.7.1"
},
"devDependencies": {
"eslint": "^3.9.1",
Expand All @@ -16,6 +17,7 @@
"eslint-plugin-react": "^6.5.0"
},
"scripts": {
"start": "node .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand Down
47 changes: 47 additions & 0 deletions themes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@


module.exports = {

default: {
name: "Default color theme",
level: 3, // 16 milion colors
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in milion here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll fix that!

palette: {
fg: '#bbb',
bg: '#1d1f21',
boxBorderFG: '#888',
searchFG: '#cc6666',
listSelectedItemFG: '#c5c8c6',
listSelectedItemBG: '#373b41',
focusBorder: '#cc6666'
}
},

tty16Default: {
name: "TTY 16-color theme",
level: 1, // 16 colors
palette: {
fg: 'white',
bg: 'black',
boxBorderFG: 'white',
searchFG: 'cyan',
listSelectedItemFG: 'yellow',
listSelectedItemBG: 'black',
focusBorder: 'red'
}
},

tty1Default: {
name: "TTY no color theme",
level: 0, // 1 color
palette: {
fg: 'white',
bg: 'black',
boxBorderFG: 'white',
searchFG: 'white',
listSelectedItemFG: 'white',
listSelectedItemBG: 'black',
focusBorder: 'white'
}
}
};

94 changes: 55 additions & 39 deletions userInterface.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
var blessed = require('blessed');
var colorPal = require('./themes.js');
var supportsColor = require('supports-color');

// Colors
var colorSupportLevel = supportsColor ? supportsColor.level : 0;
var defaultThemesByColorLevel = {
3: colorPal.default,
2: colorPal.default, // Not tested yet
1: colorPal.tty16Default,
0: colorPal.tty1Default // Can be "tested" by passing --no-color argument
};

var theme = defaultThemesByColorLevel[colorSupportLevel];
var colors = theme.palette;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the above (L6 - L15) be pulled into another module to import? Also, I think it would be clearer to use the supportsColor.has256, supportsColor.has16m, etc. rather than doing it by level.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Yes, this could be in its own little module
  • I also prefer the has256 and has16m. The thing is that they are "independant" flags which doesn't fit very well the idea of having a single "supported color" field that we can compare, filter, sort... What if I turn it into constants instead? For instance: COLORLEVEL_MONO, COLORLEVEL_16, COLORLEVEL_256, COLORLEVEL_16M or any similar names. The level field in the themes could be turned into something like color: "mono" | "16" | "256" | "16m" so the theme designers would find it very easy to understand. Tell me your idea about this
  • For the commas, I can revert the change. I was not expecting ending up in a pull request :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if the logic for choosing the color level were in its own module, the module should be able to just return the theme object. That way we don't have to deal with importing/choosing themes here (i.e. the module would just export what the colors variable is right now).

If you prefer to use constants, I think that's okay. I also think it would work to just use the independent flags right now similar to the first usage example they have on https://www.npmjs.com/package/supports-color. If people wanted to create themes, you would have to check what color level the terminal supports anyway.



// UI
var keyBindings = {};

module.exports = {
init: function () {
var screen = blessed.screen({
autopadding: true,
smartCSR: true,
title: 'Slack',
title: 'Slack'
});

var container = blessed.box({
width: '100%',
height: '100%',
style: {
fg: '#bbb',
bg: '#1d1f21',
},
fg: colors.fg,
bg: colors.bg
}
});

var sideBar = blessed.box({
width: '30%',
height: '100%',
height: '100%'
});

var mainWindow = blessed.box({
Expand All @@ -30,18 +46,18 @@ module.exports = {
left: '30%',
// scrollable: true,
border: {
type: 'line',
type: 'line'
},
style: {
border: {
fg: '#888',
},
},
fg: colors.boxBorderFG
}
}
});

var mainWindowTitle = blessed.text({
width: '90%',
tags: true,
tags: true
});

var chatWindow = blessed.box({
Expand All @@ -53,7 +69,7 @@ module.exports = {
vi: true,
scrollable: true,
alwaysScroll: true,
tags: true,
tags: true
});

var messageInput = blessed.textbox({
Expand All @@ -64,8 +80,8 @@ module.exports = {
vi: true,
inputOnFocus: true,
border: {
type: 'line',
},
type: 'line'
}
});

function searchChannels(searchCallback) {
Expand All @@ -74,7 +90,7 @@ module.exports = {
left: '5%',
align: 'left',
content: '{bold}Search{/bold}',
tags: true,
tags: true
});
var searchBox = blessed.textbox({
width: '90%',
Expand All @@ -85,9 +101,9 @@ module.exports = {
vi: true,
inputOnFocus: true,
border: {
fg: '#cc6666',
type: 'line',
},
fg: colors.searchFG,
type: 'line'
}
});
function removeSearchBox() {
mainWindow.remove(searchBox);
Expand Down Expand Up @@ -124,21 +140,21 @@ module.exports = {
width: '100%',
height: '60%',
border: {
type: 'line',
type: 'line'
},
style: {
border: {
fg: '#888',
},
},
fg: colors.boxBorderFG
}
}
});

var channelsTitle = blessed.text({
width: '90%',
left: '5%',
align: 'center',
content: '{bold}Channels{/bold}',
tags: true,
tags: true
});

var channelList = blessed.list({
Expand All @@ -151,33 +167,33 @@ module.exports = {
search: searchChannels,
style: {
selected: {
bg: '#373b41',
fg: '#c5c8c6',
},
bg: colors.listSelectedItemBG,
fg: colors.listSelectedItemFG
}
},
tags: true,
tags: true
});

var usersBox = blessed.box({
width: '100%',
height: '40%',
top: '60%',
border: {
type: 'line',
type: 'line'
},
style: {
border: {
fg: '#888',
},
},
fg: colors.boxBorderFG
}
}
});

var usersTitle = blessed.text({
width: '90%',
left: '5%',
align: 'center',
content: '{bold}Users{/bold}',
tags: true,
tags: true
});

var userList = blessed.list({
Expand All @@ -190,11 +206,11 @@ module.exports = {
search: searchChannels,
style: {
selected: {
bg: '#373b41',
fg: '#c5c8c6',
},
bg: colors.listSelectedItemBG,
fg: colors.listSelectedItemFG
}
},
tags: true,
tags: true
});

channelsBox.append(channelsTitle);
Expand Down Expand Up @@ -249,11 +265,11 @@ module.exports = {

// event handlers for focus and blur of inputs
var onFocus = function (component) {
component.style.border = { fg: '#cc6666' }; // eslint-disable-line no-param-reassign
component.style.border = { fg: colors.focusBorder }; // eslint-disable-line no-param-reassign
screen.render();
};
var onBlur = function (component) {
component.style.border = { fg: '#888' }; // eslint-disable-line no-param-reassign
component.style.border = { fg: colors.boxBorderFG }; // eslint-disable-line no-param-reassign
screen.render();
};
userList.on('focus', onFocus.bind(null, usersBox));
Expand All @@ -276,7 +292,7 @@ module.exports = {
mainWindow: mainWindow,
mainWindowTitle: mainWindowTitle,
chatWindow: chatWindow,
messageInput: messageInput,
messageInput: messageInput
};
},
}
};