├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── cli.js ├── license ├── media ├── logo.ai ├── logo.png └── logo.svg ├── package.json ├── readme.md ├── screenshot.png └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.ai binary 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | const brightness = require('brightness'); 4 | const meow = require('meow'); 5 | const progressControl = require('progress-control'); 6 | const chalk = require('chalk'); 7 | const cliCursor = require('cli-cursor'); 8 | const firstRun = require('first-run'); 9 | const indentString = require('indent-string'); 10 | 11 | const cli = meow(` 12 | Example 13 | $ brightness 14 | $ brightness 0.8 15 | `); 16 | 17 | const updateBar = (val, bar) => brightness.set(val).then(() => { 18 | const str = `${(val * 100)}%`; 19 | const maxLength = 4; 20 | 21 | bar.update(val, {val: indentString(str, maxLength - str.length, ' ')}); 22 | }); 23 | 24 | const getBar = (val, text) => { 25 | const bar = progressControl(text, {total: 10}, { 26 | up() { 27 | val = Math.min(Math.round((val + 0.1) * 10) / 10, 1); 28 | updateBar(val, bar); 29 | }, 30 | down() { 31 | val = Math.max(Math.round((val - 0.1) * 10) / 10, 0); 32 | updateBar(val, bar); 33 | } 34 | }); 35 | 36 | return bar; 37 | }; 38 | 39 | const main = val => { 40 | if (!process.stdout.isTTY) { 41 | console.log(val); 42 | return; 43 | } 44 | 45 | val = Math.round((val) * 10) / 10; 46 | 47 | let text = '[:bar] :val'; 48 | 49 | if (firstRun()) { 50 | text += ` ${chalk.dim('Use up/down arrows')}`; 51 | } 52 | 53 | const bar = getBar(val, text); 54 | 55 | cliCursor.hide(); 56 | updateBar(val, bar); 57 | }; 58 | 59 | try { 60 | if (cli.input.length === 0) { 61 | brightness.get().then(val => main(val)); 62 | } else { 63 | brightness.set(parseFloat(cli.input[0], 10)); 64 | } 65 | } catch (err) { 66 | console.error(err.message); 67 | process.exit(1); 68 | } 69 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Kevin Mårtensson (github.com/kevva) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /media/logo.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/brightness-cli/925cca4b6cd28c6118555614b7e0dcdcf86503a7/media/logo.ai -------------------------------------------------------------------------------- /media/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/brightness-cli/925cca4b6cd28c6118555614b7e0dcdcf86503a7/media/logo.png -------------------------------------------------------------------------------- /media/logo.svg: -------------------------------------------------------------------------------- 1 | brightness -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "brightness-cli", 3 | "version": "2.4.0", 4 | "description": "Change the screen brightness", 5 | "license": "MIT", 6 | "repository": "kevva/brightness-cli", 7 | "author": { 8 | "email": "kevinmartensson@gmail.com", 9 | "name": "Kevin Mårtensson", 10 | "url": "github.com/kevva" 11 | }, 12 | "bin": { 13 | "brightness": "cli.js" 14 | }, 15 | "engines": { 16 | "node": ">=4" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava" 20 | }, 21 | "files": [ 22 | "cli.js" 23 | ], 24 | "keywords": [ 25 | "app", 26 | "brightness", 27 | "cli", 28 | "cli-app", 29 | "interactive", 30 | "linux", 31 | "osx", 32 | "screen", 33 | "windows", 34 | "xdg" 35 | ], 36 | "dependencies": { 37 | "brightness": "^3.0.0", 38 | "chalk": "^2.0.1", 39 | "cli-cursor": "^2.1.0", 40 | "first-run": "^1.0.0", 41 | "indent-string": "^3.1.0", 42 | "meow": "^3.3.0", 43 | "progress-control": "^1.0.0" 44 | }, 45 | "devDependencies": { 46 | "ava": "*", 47 | "execa": "^0.7.0", 48 | "xo": "*" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |

2 |
3 | brightness 4 |
5 |
6 |
7 |

8 | 9 | > Change the screen brightness 10 | 11 | [![Build Status](https://travis-ci.org/kevva/brightness-cli.svg?branch=master)](https://travis-ci.org/kevva/brightness-cli) 12 | 13 | 14 | ## Install 15 | 16 | ``` 17 | $ npm install --global brightness-cli 18 | ``` 19 | 20 | 21 | ## Usage 22 | 23 | 24 | 25 | ``` 26 | $ brightness --help 27 | 28 | Example 29 | $ brightness 30 | $ brightness 0.8 31 | ``` 32 | 33 | 34 | ## Related 35 | 36 | * [brightness](https://github.com/kevva/brightness) - API for this module 37 | 38 | 39 | ## License 40 | 41 | MIT © [Kevin Mårtensson](https://github.com/kevva) 42 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/brightness-cli/925cca4b6cd28c6118555614b7e0dcdcf86503a7/screenshot.png -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import execa from 'execa'; 2 | import test from 'ava'; 3 | 4 | test('doesn\'t throw', async t => { 5 | await t.notThrows(execa.stdout('./cli.js')); 6 | }); 7 | 8 | test('should set brightness', async t => { 9 | await t.notThrows(execa.stdout('./cli.js', [0.8])); 10 | }); 11 | --------------------------------------------------------------------------------