Skip to content

Commit 7b09c15

Browse files
Driegermmarchini
authored andcommitted
src: colorize output for findjsinstances
To make visualization easier, objects types, properties and addresses will be colorized. Using `rang` library color pallete, the current definition is: * cyan for addresses * magenta for objects being inspected * yellow for types * bold yellow for objects properties Fixes: #179 Colorize findrefs output PR-URL: #225 Reviewed-By: Matheus Marchini <[email protected]>
1 parent 411ba51 commit 7b09c15

File tree

12 files changed

+1122
-112
lines changed

12 files changed

+1122
-112
lines changed

binding.gyp

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"src/llscan.cc",
8080
"src/node.cc",
8181
"src/node-constants.cc",
82+
"src/settings.cc",
8283
],
8384
"conditions": [
8485
[ "OS == 'win'", {
@@ -97,7 +98,7 @@
9798
"include_dirs": [
9899
"<!@(node -p \"require('node-addon-api').include\")"
99100
],
100-
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
101+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS", "NO_COLOR_OUTPUT" ],
101102
"sources": [
102103
"src/addon.cc",
103104
"src/llnode_module.cc",
@@ -108,6 +109,7 @@
108109
"src/llv8-constants.cc",
109110
"src/llscan.cc",
110111
"src/node-constants.cc",
112+
"src/settings.cc",
111113
],
112114
"cflags!": [ "-fno-exceptions" ],
113115
"cflags_cc!": [ "-fno-exceptions" ],

deps/rang/LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org>

deps/rang/README.md

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# rang [![Build Status](https://travis-ci.org/agauniyal/rang.svg?branch=master)](https://travis-ci.org/agauniyal/rang) [![Build status](https://ci.appveyor.com/api/projects/status/jqpdoelli38h2a7w?svg=true)](https://ci.appveyor.com/project/agauniyal/rang) [![codecov](https://codecov.io/gh/agauniyal/rang/branch/master/graph/badge.svg)](https://codecov.io/gh/agauniyal/rang) [ ![Download](https://api.bintray.com/packages/agauniyal/rang/rang%3Arang/images/download.svg) ](https://bintray.com/agauniyal/rang/rang%3Arang/_latestVersion)
2+
3+
##### Colors for your Terminal.
4+
5+
![rang-demo](https://cloud.githubusercontent.com/assets/7630575/13501282/0bd00074-e18c-11e5-9848-5bd1f20566d9.gif)
6+
<details>
7+
<summary>Windows Demo</summary>
8+
9+
![rang-windows-demo](https://cloud.githubusercontent.com/assets/11349690/19836886/8134975e-9ebe-11e6-9ee4-c4657784ff3b.gif)
10+
</details>
11+
12+
13+
Example usage
14+
-------------
15+
16+
```c++
17+
#include "rang.hpp"
18+
19+
using namespace std;
20+
using namespace rang;
21+
22+
int main()
23+
{
24+
cout << "Plain old text"
25+
<< style::bold << "Rang styled text!!"
26+
<< style::reset << endl;
27+
}
28+
```
29+
30+
Dependencies
31+
------------
32+
*rang* only depends on [C++ standard library](http://en.cppreference.com/w/cpp/header), `unistd.h` system header on unix and `windows.h` & `io.h` system headers on windows based systems. In other words, you don't need any 3rd party dependencies.
33+
34+
35+
Installation
36+
------------
37+
38+
*rang* is a single header-only library. Put `rang.hpp` in the [include](include) folder directly into the project source tree or somewhere reachable from your project.
39+
40+
Or, if you use the [conan package manager](https://www.conan.io/), follow these steps:
41+
42+
1. Add a reference to *rang* to the *requires* section of your project's `conanfile.txt` file:
43+
44+
[requires]
45+
rang/3.1.0@rang/stable
46+
47+
2. Run conan's install command:
48+
49+
conan install
50+
51+
52+
## How to use
53+
54+
*Rang* uses iostream objects - `cout`/`clog`/`cerr` to apply attributes to output text. Since *rang* aims to support both windows and unix like systems, it takes care of the os specific details and tries to provide a uniform interface. Due to incompatiblities b/w different OS versions, not all kinds of attributes are supported on every system so rang will try to skip the ones which might produce garbage(instead of pushing random ANSI escape codes on your streams). Detection of tty is also handled internally so you don't need to check if application user might redirect output to a file.
55+
56+
> **Need support for non-ansi terminals? Check out [Termdb](https://github.com/agauniyal/termdb) which supports virtually all terminals and their capablities.**
57+
58+
Apart from setting text attributes, you can also ask rang to override its default behaviour through these methods -
59+
```cpp
60+
void rang::setControlMode(rang::control);
61+
```
62+
where `rang::control` takes
63+
- `control::Auto` - Automatically detects whether terminal supports color or not(**Default**)
64+
- `control::Off` - Turn off colors completely
65+
- `control::Force` - Force colors even if terminal doesn't supports them or output is redirected to non-terminal
66+
67+
```cpp
68+
void rang::setWinTermMode(rang::winTerm);
69+
```
70+
where `rang::winTerm` takes
71+
- `winTerm::Auto` - Checks for newer windows and picks Ansi otherwise falls back to Native(**Default**)
72+
- `winTerm::Native` - This method is supported in all versions of windows but supports less attributes
73+
- `winTerm::Ansi` - This method is supported in newer versions of windows and supports rich variety of attributes
74+
75+
76+
Supported attributes with their compatiblity are listed below -
77+
78+
**Text Styles**:
79+
80+
| Code | Linux/Win/Others | Old Win
81+
| ---- | --------- | ------ |
82+
| `rang::style::bold` | yes | yes |
83+
| `rang::style::dim` | yes | no |
84+
| `rang::style::italic` | yes | no |
85+
| `rang::style::underline` | yes | no |
86+
| `rang::style::blink` | no | no |
87+
| `rang::style::rblink` | no | no |
88+
| `rang::style::reversed` | yes | yes |
89+
| `rang::style::conceal` | maybe | yes |
90+
| `rang::style::crossed` | yes | no |
91+
92+
**Text Color**:
93+
94+
| Code | Linux/Win/Others | Old Win
95+
| ---- | --------- | ------ |
96+
| `rang::fg::black` | yes | yes |
97+
| `rang::fg::red` | yes | yes |
98+
| `rang::fg::green` | yes | yes |
99+
| `rang::fg::yellow` | yes | yes |
100+
| `rang::fg::blue` | yes | yes |
101+
| `rang::fg::magenta` | yes | yes |
102+
| `rang::fg::cyan` | yes | yes |
103+
| `rang::fg::gray` | yes | yes |
104+
105+
**Background Color**:
106+
107+
| Code | Linux/Win/Others | Old Win
108+
| ---- | --------- | ------ |
109+
| `rang::bg::black` | yes | yes |
110+
| `rang::bg::red` | yes | yes |
111+
| `rang::bg::green` | yes | yes |
112+
| `rang::bg::yellow` | yes | yes |
113+
| `rang::bg::blue` | yes | yes |
114+
| `rang::bg::magenta` | yes | yes |
115+
| `rang::bg::cyan` | yes | yes |
116+
| `rang::bg::gray` | yes | yes |
117+
118+
**Bright Foreground Color**:
119+
120+
| Code | Linux/Win/Others | Old Win
121+
| ---- | --------- | ------ |
122+
| `rang::fgB::black` | yes | yes |
123+
| `rang::fgB::red` | yes | yes |
124+
| `rang::fgB::green` | yes | yes |
125+
| `rang::fgB::yellow` | yes | yes |
126+
| `rang::fgB::blue` | yes | yes |
127+
| `rang::fgB::magenta` | yes | yes |
128+
| `rang::fgB::cyan` | yes | yes |
129+
| `rang::fgB::gray` | yes | yes |
130+
131+
**Bright Background Color**:
132+
133+
| Code | Linux/Win/Others | Old Win
134+
| ---- | --------- | ------ |
135+
| `rang::bgB::black` | yes | yes |
136+
| `rang::bgB::red` | yes | yes |
137+
| `rang::bgB::green` | yes | yes |
138+
| `rang::bgB::yellow` | yes | yes |
139+
| `rang::bgB::blue` | yes | yes |
140+
| `rang::bgB::magenta` | yes | yes |
141+
| `rang::bgB::cyan` | yes | yes |
142+
| `rang::bgB::gray` | yes | yes |
143+
144+
**Reset Styles/Colors**:
145+
146+
| Code | Linux/Win/Others | Old Win
147+
| ---- | --------- | ------ |
148+
| `rang::style::reset` | yes | yes |
149+
| `rang::fg::reset` | yes | yes |
150+
| `rang::bg::reset` | yes | yes |
151+
152+
-----
153+
## My terminal is not detected/gets garbage output!
154+
155+
Check your env variable `TERM`'s value. Then open an issue [here](https://github.com/agauniyal/rang/issues/new) and make sure to mention `TERM`'s value along with your terminal name.
156+
157+
## Redirecting `cout`/`cerr`/`clog` rdbuf?
158+
159+
Rang doesn't interfere if you try to redirect `cout`/`cerr`/`clog` to somewhere else and leaves the decision to the library user. Make sure you've read this [conversation](https://github.com/agauniyal/rang/pull/77#issuecomment-360991652) and check out the example code [here](https://gist.github.com/kingseva/a918ec66079a9475f19642ec31276a21).

0 commit comments

Comments
 (0)