ng-console
v1.7.3
Published
Small directive for angular, to implement a console that's able to execute commands.
Downloads
10
Maintainers
Readme
ngConsole
Small directive for angular, to implement a console that's able to execute commands. You can see a demo here.
With this directive, developers can avoid to design and create a user interface for small tasks like cleaning server cache, restart some backend tasks and so on. Just create the logic, and ngConsole will allow you to execute all these actions from the same place.
Installation
To install ngConsole on your project, follow these steps:
- Make a npm install ng-console.
- Copy the file node_modules/ng-console/build/ngConsole.js to your project's folder.
- Declare ngConsole as a dependency for your module angular.module('myApp' ['ngConsole'])
- Save it. You are done!
Use
Now, you just have to write <ng-console></ng-console> on your code, and that's it, you already have a console installed on your Angular website.
You can use different attributes to customize it:
- open: Open by default (boolean)
- fixed: Embeded in your HTML, or fixed and hidden (boolean)
- If it's fixed, you should press º to open it.
- fullsize: When fixed, filling the entire screen (boolean)
- custom-height: Set a custom height, this will be ignored if fullsize is true (number).
- custom-prefix: The prefix displayed (string)
- custom-commands: An array with commands that you wanna add to the console. (boolean)
Custom commands
Custom commands must have particular properties to make them work. Each command must have:
- name: The keyword used to execute the command (string)
- description: A short description to show with help command (string)
- params: A list of parameters that can be used with this command (Object: {name: "string", description: "string"})
- action: The function that's gonna be executed (function(printLn, params){ whatever(); }).
If user wants to use parameters, he/she can use any of these combinations:
- say --text Hello world
- say --text "Hello world"
- say --text=Hello world
- say --text="Hello world"
In our live example, our custom command say accepts params, so if you execute say --text Something, it's going to prompt you "something". And we are able to get it by doing this: function(printLn, params){ if(params && params.text){ printLn(params.text); } }
Custom theme
If you want to customize ngConsole's default colors, you can specify a customTheme on your options object.
- If you want to use a stock theme, just write its name, like this: $scope.options.customTheme = "light"
- If you want to create a new theme, that's going to be available on your console, write this:
$scope.options.customTheme = { name: "my theme name", data:{ bg: "any-css-color", color: "any-css-color", boldColor: "any-css-color", fontfamily: number, fontsize: "string-font-name" }, labels:{ bg: "The color name that's going to be displayed", color: "The color name that's going to be displayed", boldColor: "The color name that's going to be displayed" } } }