scryglass 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.tool-versions +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +21 -0
- data/README.md +252 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example_config.rb +30 -0
- data/lib/example_material.rb +97 -0
- data/lib/hexes.rb +135 -0
- data/lib/prog.rb +89 -0
- data/lib/refinements/ansiless_string_refinement.rb +11 -0
- data/lib/refinements/array_fit_to_refinement.rb +67 -0
- data/lib/refinements/clip_string_refinement.rb +27 -0
- data/lib/refinements/constant_defined_string_refinement.rb +11 -0
- data/lib/scryglass.rb +177 -0
- data/lib/scryglass/config.rb +103 -0
- data/lib/scryglass/lens_helper.rb +22 -0
- data/lib/scryglass/lens_panel.rb +140 -0
- data/lib/scryglass/ro.rb +237 -0
- data/lib/scryglass/ro_builder.rb +402 -0
- data/lib/scryglass/session.rb +514 -0
- data/lib/scryglass/tree_panel.rb +122 -0
- data/lib/scryglass/version.rb +3 -0
- data/lib/scryglass/view_panel.rb +91 -0
- data/lib/scryglass/view_wrapper.rb +23 -0
- data/scryglass.gemspec +46 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ba13f5c4e89b1e2750fd307557d9093cbc8194fa3696fc314515011322786cf
|
4
|
+
data.tar.gz: 853762f415aada3e416f20beb12b1033620d60747a5ca49c76a1f4ab53af7073
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c58c3f36b278b03c0ab7105eb7e72eb6ae0db614945623752096ce07e5ca8401b03d3e23761fc79336f335d63d4ee9ef9dc12a3c9ede29121e74cf966124940a
|
7
|
+
data.tar.gz: 1f80a280e9a45cf1407377bf5128c222c4384154b9971992c68b98c8ba02128132d7424c7c12672c4dacf6a22b34616e5630b4ce5b27492580a684e0fb231db8
|
data/.gitignore
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.4.4
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
scryglass (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.2.4.4)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
concurrent-ruby (1.1.7)
|
15
|
+
i18n (1.8.5)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
minitest (5.14.2)
|
18
|
+
rake (12.3.3)
|
19
|
+
thread_safe (0.3.6)
|
20
|
+
tzinfo (1.2.7)
|
21
|
+
thread_safe (~> 0.1)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
activesupport (~> 5.0)
|
28
|
+
bundler (~> 2.1)
|
29
|
+
rake (~> 12.0)
|
30
|
+
scryglass!
|
31
|
+
|
32
|
+
BUNDLED WITH
|
33
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Gavin Myers
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
# 🔮 Scryglass
|
2
|
+
|
3
|
+
Scryglass is a ruby console tool for visualizing and actively exploring objects (large, nested, interrelated, or unfamiliar). You can navigate nested arrays, hashes, instance variables, ActiveRecord
|
4
|
+
relations, and unknown Enumerable types like an expandable/collapsable file tree in an intuitive UI.
|
5
|
+
|
6
|
+
Objects and child objects can also be inspected through a variety of display lenses, returned directly to the console, and more!
|
7
|
+
|
8
|
+
`scry` is quick to use and useful for both experienced developers and those very new to ruby, rails, or coding.
|
9
|
+
It facilitates:
|
10
|
+
- Debugging/Investigating
|
11
|
+
- Education, learning the structure of objects and their relationships
|
12
|
+
- Comparing/Scanning sub-items in an Enumerable (e.g. Person.first.library_records.scry)
|
13
|
+
|
14
|
+
## ⚡️ tl;dr SUPER Quick Start
|
15
|
+
|
16
|
+
If you're in a real hurry to get your hands in it (though not necessarily in the most efficient way), here are the quickest steps!
|
17
|
+
|
18
|
+
| Quick Step | Alternative |
|
19
|
+
|-----------------------------------------|------------------------------------------------------|
|
20
|
+
| 1. **Install:** Add to your Gemfile | *(OR `gem install scryglass`)* |
|
21
|
+
| 2. **Enable in console:** `Scryglass.load` | *(Please consider adding to `.irbrc` & `.pryrc`)* |
|
22
|
+
| 3. **Run in console:** `my_object.scry` | *(OR `scry my_object`)* |
|
23
|
+
| 4. **You're there! Use arrow keys,** and use '?' To learn more. | |
|
24
|
+
|
25
|
+
## Installing Scryglass
|
26
|
+
|
27
|
+
Add the following, with whatever version specifics you like, to your Gemfile, if you use Bundler:
|
28
|
+
```ruby
|
29
|
+
gem 'scryglass'
|
30
|
+
```
|
31
|
+
And then execute:
|
32
|
+
```
|
33
|
+
$ bundle install
|
34
|
+
```
|
35
|
+
If you don't have a Gemfile, you can simply install from RubyGems:
|
36
|
+
```
|
37
|
+
$ gem install scryglass
|
38
|
+
```
|
39
|
+
## Enabling Scryglass
|
40
|
+
|
41
|
+
For the `scry` method syntax to work as cleanly as it does, Scryglass needs to add the method to the Kernel module. While this is safe, it was safest to have this only happen on a console session basis. To enable the `scry` method, call `Scryglass.load`. Thus, to automatically enable Scryglass when opening a console, you add one of the following lines to your `./irbrc` (and `./pryrc` for rails or pry sessions):
|
42
|
+
```ruby
|
43
|
+
Scryglass.load
|
44
|
+
```
|
45
|
+
...Which will print the success or failure of loading Scryglass, along with a note of which file loaded it, or
|
46
|
+
```ruby
|
47
|
+
Scryglass.load_silently
|
48
|
+
```
|
49
|
+
...Which will never print anything upon loading the tool.
|
50
|
+
|
51
|
+
And then you're good to go – the syntax is loaded!
|
52
|
+
|
53
|
+
## Launching a `scry` Session
|
54
|
+
In console (Ruby||Rails), you can get some help information with `Scryglass.help`.
|
55
|
+
Among other things, it will tell you:
|
56
|
+
```
|
57
|
+
[...]
|
58
|
+
|
59
|
+
To start a Scry Session, call:
|
60
|
+
> scry my_object OR
|
61
|
+
> my_object.scry
|
62
|
+
|
63
|
+
[...]
|
64
|
+
```
|
65
|
+
**A note about passing an argument without parentheses:**
|
66
|
+
> The arg syntax (`scry my_object`) will get confused if it's given a hash direcly (`scry {a: [1, 2] }`), thinking you're trying to pass a block, unless you use parentheses (`scry({a: [1, 2] })`).
|
67
|
+
|
68
|
+
**A note about using the resume session command, while in a pry:**
|
69
|
+
> The straight resume command, the bare `scry`, relies on the assumption that the method receiver is `main`. When your console is a pry in some other code, `self` is no longer `main`, but some other object, and so you are actually calling `scry` on that, overwriting your previous session. If you still want to resume session in that context, you can use `scry_resume`.
|
70
|
+
|
71
|
+
## Basic Usage
|
72
|
+
|
73
|
+
Use the arrow keys to move around and open/close known Enumerable types! Hit `'?'` to view all the controls and learn how to do much much more.
|
74
|
+
|
75
|
+
## Reading the UI
|
76
|
+
|
77
|
+
Every object (or key-value pair) is one row. Nested objects will be displayed under their parent object, with one more layer of indentation. The cursor will generally look like a horizontal line.
|
78
|
+
|
79
|
+
This default view is the Tree View. You can seitch between that and Lens View with `SPACEBAR`.
|
80
|
+
|
81
|
+
### Tree View (default) row sample strings
|
82
|
+
Each row has either an object or a key-value pair. The objects are given a sample representation in the Tree View using `inspect`, and long ones are cut off and marked with `'……'`. For display purposes, newlines (`"\n"`) are removed from these strings, but remain untouched on the object, including in Lens View.
|
83
|
+
|
84
|
+
### Known Enumerables
|
85
|
+
If the object (or the value in a key-value pair) is one of the known Enumerable types, it will display with one of the following wrappers:
|
86
|
+
|
87
|
+
| Wrapper | Indicates... |
|
88
|
+
|:-------:|--------------|
|
89
|
+
| `[]` | Array |
|
90
|
+
| `{}` | Hash |
|
91
|
+
| `<>` | ActiveRecord Relation *(if ActiveRecord is being used)* |
|
92
|
+
| `‹›` | ActiveRecord CollectionProxy *(if ActiveRecord is being used)* |
|
93
|
+
|
94
|
+
The known Enumerable will also indicate its state:
|
95
|
+
| Wrapper | Indicates... |
|
96
|
+
|:-------:|--------------|
|
97
|
+
| `[]` | Empty |
|
98
|
+
| `[•••]` | Closed with hidden contents |
|
99
|
+
| `[` | Open |
|
100
|
+
|
101
|
+
However, some objects (both known and unknown Enumerable types) have sub-items that can be calculated and opened on the spot.
|
102
|
+
|
103
|
+
### The Cursor, and Unknown Enumerables
|
104
|
+
The cursor, movable by arrow keys, is represented by a straight line (`––––`). It may overlap with a selection marker (`->`), if the current row is also a selected row. The left two characters of the cursor serve as gentle indicators of how objects of an unknown Enumerable type might be opened:
|
105
|
+
|
106
|
+
| Cursor | The smart opener detects... |
|
107
|
+
|:------:|-----------------------------|
|
108
|
+
| `––––` | ...no secret contents |
|
109
|
+
| `(–––` | ...a non-empty Enumerable of an unknown type (openable with `'('`) |
|
110
|
+
| `–@––` | ...instance variables on the object (openable with `'@'`) |
|
111
|
+
| `(@––` | ...both! ***Generally* instance variables yield more sub-items with more info.** |
|
112
|
+
|
113
|
+
ActiveRecord objects are no secret; you can press `'.'` on them to build their AR Association sub-items.
|
114
|
+
|
115
|
+
A single `•` will mark the presence of user-added rows when they are hidden.
|
116
|
+
|
117
|
+
### Waiting!
|
118
|
+
Scryglass has two features to make wait time a little easier:
|
119
|
+
- If any process takes longer than 4 seconds between you pressing a key and the process completing, it **makes a beep sound!** This means if something seems like it might take a bit, you can switch to another tab or window without worry, and it will tell you when to check back.
|
120
|
+
- While there are no time estimates (for a number of reasons), many subprocesses are linked to a **progress bar**, which will display at the bottom of the screen. If multiple nested processes are running one within another, the progress bar will divide itself into parts to show each process. The leftmost bar is the base level iteration task.
|
121
|
+
|
122
|
+
## In-Depth Control Rundown
|
123
|
+
|
124
|
+
| Key | Help Screen Snippet | Verbose Description |
|
125
|
+
|:---:|---------------------|---------------------|
|
126
|
+
| `?` | Press '?' for controls | `?` will cycle through the help panels, then back to the scry session. |
|
127
|
+
| `q` | Quit Scry | Exits the scry session, returning nil. The cursor (and exit message) is then placed below the last line console line with content in order to take up no more space than needed. |
|
128
|
+
| `UP`/`DOWN` | Navigate (You can type a number first) | Moves the cursor one step upward or downward in the tree view (this can be done while in lens view). If a number (of any number of digits) is typed out before pressing `UP` or `DOWN`, then the cursor will move that many steps in that direction. If the number of steps goes past the edge of the list, the cursor will sit safely at that edge. |
|
129
|
+
| `RIGHT` | Expand current or selected row(s) | If any rows are *selected* this attempts to expand all of them, and will expand the ones it can. If none are selected, then it will attempt to expand the current row where the cursor is. If the current row has preexisting sub-items, but they are hidden because the current ro is collapsed, this will reveal them in the tree view. |
|
130
|
+
| `LEFT` | Collapse current or selected row(s) | If any rows are *selected* this attempts to collapse all of them, and will collapse the ones it can. If none are selected, then it will attempt to collapse the current row where the cursor is. If the current row either has no sub-items or is already collapsed, this action will collapse its parent row instead and place the cursor there. |
|
131
|
+
| `ENTER` | Close Scry, returning current or selected object(s) (Key or Value) | Returns the subject object (based on current subject type, :value or :key) of the current item, or, if any items are selected (`->`), it returns all of those in an array. The order matches the order in which they were marked as selected. In the case of \| and \*, the order of the array will be top to bottom. If the current Subject Type (toggled by `L`) is :key, rows without "keys" will return `nil`. |
|
132
|
+
| `SPACEBAR` | Toggle Lens View | Switches between Tree View and Lens View. This will not change the view position of the lens view, but the view position of the tree view will still follow the cursor if the cursor moves while in lens view. |
|
133
|
+
| `l` | Cycle through lens types | Cycles through the different lens types in the lens view. These all take the current row, at either the "key" or the "value" object depending on the current subject type (toggled by `L`), and display a string of it, transformed through that particular lens. New lenses can be written in the config. |
|
134
|
+
| `L` | Toggle subject (Key/Value of row) | This change is only perceptible in the lens view, but does also change which objects are returned by `ENTER`. Any objects without "keys" will return nil for their :key if they don't have one. |
|
135
|
+
| `w`/`a`/`s`/`d` | Move view window (ALT increases speed) | The W/A/S/D keys form a second set of arrow keys for moving around the "screen" through which you view the tree view and the lens view, when the contents don't all fit on the screen at once. They move 5 cells in the specificied direction, or 50 if ALT is held before pressing. Can be held down for continuous movement. |
|
136
|
+
| `0` | Reset view location (Press again: reset cursor) | This resets/zeros the current view (tree or lens). If you are in the tree view, and the view is in the zero (top left) position, then this will instead move the cursor there. |
|
137
|
+
| `@` | Build instance variable sub-rows for current or selected row(s) | Identifies all instance variables on the object (or value of a key-value pair) of the current or selected rows. Then these instance variables are turned into a list of keys, called on the original object, and then paired with the resulting objects. Known Enumerables are recursively navigable as always. |
|
138
|
+
| `.` | Build ActiveRecord association sub-rows for current or selected row(s) | If the `ActiveRecord` constant is not defined by the system, this will do nothing. If it is, this will navigate the reflections of the the class of the object (or value of a key-value pair) in order to find its AR Associations and turn them into key-value sub-items. Note: With the default configuration, the way it uses reflections *purposefully ignores `:through` relations and `scope`d relations (e.g. the extraneous `CURRENT_phone_numbers`).* |
|
139
|
+
| `(` | Attempt to smart-build sub-rows for current or selected row(s), if Enumerable. Usually '@' is preferable | Attempts a "smart reading" of the object (or value of a key-value pair) of the current or selected rows. If the object is an Enumerable, it will attempt to parse it into sub-items. if the object has keys, it will be parsed as key-value pairs like a hash, otherwise singular objects like an array. This can sometimes create sub-items that would otherwise be more neatly accesible under a single instance variable if instance variables are built instead, so default to trying that first. |
|
140
|
+
| `*` | Select/Deselect ALL rows | This includes hidden rows. If all rows are already selected, they will be unselected, regardless of how they became selected. |
|
141
|
+
| `\|` | Select/Deselect every sibling row under the same parent row | If all siblings under that parent row are already selected, they will be unselected, regardless of how they became selected. |
|
142
|
+
| `-` | Select/Deselect current row | If these objects are later returned, the order in which they were selected will determine their order in the returned array. |
|
143
|
+
| `/` | Begin a text search (in tree view) | Begins a case-sensitive regex search of all items, in a loop, starting with just below the current row. For a matching object to be found, the search must match its *truncated sample string in tree view* (regardless of what is on or off screen) (it must match either the key or the value, not the full line they create) (known enumerable types, like `[•••]`, may count as a match if they contain the string in the backend). |
|
144
|
+
| `n` | Move to next search result | Will, using the most recent search entry, move the cursor on to the next match downward, cycling through all rows. This follows the same matching rules as the original search. |
|
145
|
+
|
146
|
+
## Configuration / Customization (all optional)
|
147
|
+
|
148
|
+
Scry is (optionally) configured with a `configure` method on the `Scryglass` module, allowing you to overwrite default attributes of the Config object, like so:
|
149
|
+
```ruby
|
150
|
+
Scryglass.configure do |config|
|
151
|
+
config.tab_length = 3
|
152
|
+
# config... etc
|
153
|
+
end
|
154
|
+
```
|
155
|
+
This can be placed in any loaded path of your system, including `.irbrc` and `.pryrc`, or directly into the ruby||rails console itself to quickly experiment with settings. But the ideal place for it in an application is likely your own `config/initializers/scryglass.rb` or `config/scryglass.rb`.
|
156
|
+
|
157
|
+
Here is a commented-out config file template (you can uncomment and alter things as you wish):
|
158
|
+
(Found in *example_config.rb*)
|
159
|
+
```ruby
|
160
|
+
Scryglass.configure do |config|
|
161
|
+
## Display
|
162
|
+
# config.tab_length = 2 # Default: 2
|
163
|
+
# config.tree_view_key_string_clip_length = 200 # Default: 200
|
164
|
+
# config.tree_view_value_string_clip_length = 500 # Default: 500
|
165
|
+
# config.dot_coloring = true # Default: true
|
166
|
+
|
167
|
+
## UX
|
168
|
+
# config.cursor_tracking = [:flexible_range, :dead_center][0] # Default: [0]
|
169
|
+
# config.lenses = [ # Custom lenses can easily be added as name+lambda hashes! Or comment some out to turn them off.
|
170
|
+
# { name: 'Pretty Print (`pp`)',
|
171
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { pp o } } },
|
172
|
+
# { name: 'Inspect (`.inspect`)',
|
173
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { puts o.inspect } } },
|
174
|
+
# { name: 'Yaml Print (`y`)',
|
175
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { y o } } }, # OR: `puts o.to_yaml`
|
176
|
+
# { name: 'Puts (`puts`)',
|
177
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { puts o } } },
|
178
|
+
# # { name: 'Method Showcase', # Not included by default
|
179
|
+
# # lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o) } },
|
180
|
+
# ]
|
181
|
+
|
182
|
+
## Building ActiveRecord association sub-rows:
|
183
|
+
# config.include_empty_associations = true # Default: true
|
184
|
+
# config.include_through_associations = false # Default: false
|
185
|
+
# config.include_scoped_associations = false # Default: false
|
186
|
+
# config.show_association_types = true # Default: true
|
187
|
+
end
|
188
|
+
```
|
189
|
+
|
190
|
+
If you ever wish to restore the "factory" default config settings for a particular console session, you can run:
|
191
|
+
```ruby
|
192
|
+
Scryglass.reset_config
|
193
|
+
```
|
194
|
+
|
195
|
+
Here are some explanations of some less obvious configurations:
|
196
|
+
`show_association_types`, when true, will show association types indicators:
|
197
|
+
`(HM)` : has_many
|
198
|
+
`(HO)` : has_one
|
199
|
+
`(BT)` : belongs_to
|
200
|
+
|
201
|
+
`(t)` : `:through` (if through relations are enabled)
|
202
|
+
`(s)` : `scoped` (if scoped relations are enabled)
|
203
|
+
|
204
|
+
### A note on adding your own lenses
|
205
|
+
|
206
|
+
For properly capturing out*put* methods of various kinds, and for the ability to truncate strings of cosmic scale before they've been *entirely* printed to the invisible IO (can be minutes and trillions of characters), we highly recommend using the `Hexes.capture_io` method with the `char_limit:` keyword argument as seen in the template config file (and Scryglass code). `capture_io` captures console output as a string; `char_limit:` will run the capture in a separate thread which can be truncated before it finishes printing.
|
207
|
+
|
208
|
+
## Controlling how some objects are displayed in tree view / Using Scryglass as the UI for another tool
|
209
|
+
|
210
|
+
Scryglass originally started as a small subtool to be used as the UI for another console project, which, in short, would output a large branching hash which was then to be navigated. To have more control over the tree panel display, you can wrap objects in a Scryglass::ViewWrapper. For example, by default, this array item: `[unsightly_object]` will appear in the tree view in its `inspect`ed form, "#<UnsightlyObject:0x00007f9ac8224e78>". But say you want it to show it's best face to the user, using the sightly return of it's `best_face` method. You can instead hand scryglass the following item:
|
211
|
+
```ruby
|
212
|
+
Scryglass::ViewWrapper.new(unsightly_object,
|
213
|
+
string: unsightly_object.best_face)
|
214
|
+
```
|
215
|
+
Scryglass will use the original object as usual in every way, except the tree view will display it according to your nicer string:
|
216
|
+
```
|
217
|
+
[
|
218
|
+
Unsightly Object (id:55)
|
219
|
+
```
|
220
|
+
This can be used for "key" objects in your hashes just as easily. For example, Scryglass itself, when generating instance variable subitems, uses the following ViewWrapper to make them display a little more naturally, without the colon:
|
221
|
+
```ruby
|
222
|
+
iv_key = Scryglass::ViewWrapper.new(iv_name,
|
223
|
+
string: iv_name.to_s) # to_s removes ':'
|
224
|
+
```
|
225
|
+
So
|
226
|
+
```
|
227
|
+
:@attributes : {...}
|
228
|
+
```
|
229
|
+
|
230
|
+
becomes, just in the tree view:
|
231
|
+
```
|
232
|
+
@attributes : {...}
|
233
|
+
```
|
234
|
+
And if it's useful, a `string_lambda:` argument can be passed instead, and the string will be generated once from the lambda, in context, when the session is first built.
|
235
|
+
|
236
|
+
## Miscellaneous troubleshooting notes:
|
237
|
+
|
238
|
+
If you ever use the search function (`'/'`), press enter, and the only thing that happens is you add a `'^M'` to your entry text: Go back to your shell and run:
|
239
|
+
```
|
240
|
+
$ stty sane
|
241
|
+
```
|
242
|
+
Or you can try from your ruby console:
|
243
|
+
```
|
244
|
+
system('stty sane')
|
245
|
+
```
|
246
|
+
And that should do the trick.
|
247
|
+
|
248
|
+
## Contributing
|
249
|
+
|
250
|
+
Scryglass is being released as a relatively mature piece of software, with smaller improvements to be made over time. As such, we're not looking for contributors at the moment. However:
|
251
|
+
- Please feel free to use a fork and modify it to your heart's content!
|
252
|
+
- Please feel free to open a github issue for any problems you run into, or any ideas for possible improvements!
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "scryglass"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/example_config.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Scryglass.configure do |config|
|
4
|
+
## Display
|
5
|
+
# config.tab_length = 2 # Default: 2
|
6
|
+
# config.tree_view_key_string_clip_length = 200 # Default: 200
|
7
|
+
# config.tree_view_value_string_clip_length = 500 # Default: 500
|
8
|
+
# config.dot_coloring = true # Default: true
|
9
|
+
|
10
|
+
## UX
|
11
|
+
# config.cursor_tracking = [:flexible_range, :dead_center][0] # Default: [0]
|
12
|
+
# config.lenses = [ # Custom lenses can easily be added as name+lambda hashes! Or comment some out to turn them off.
|
13
|
+
# { name: 'Pretty Print (`pp`)',
|
14
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { pp o } } },
|
15
|
+
# { name: 'Inspect (`.inspect`)',
|
16
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { puts o.inspect } } },
|
17
|
+
# { name: 'Yaml Print (`y`)',
|
18
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { y o } } }, # OR: `puts o.to_yaml`
|
19
|
+
# { name: 'Puts (`puts`)',
|
20
|
+
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { puts o } } },
|
21
|
+
# # { name: 'Method Showcase', # Not included by default
|
22
|
+
# # lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o) } },
|
23
|
+
# ]
|
24
|
+
|
25
|
+
## Building ActiveRecord association sub-rows:
|
26
|
+
# config.include_empty_associations = true # Default: true
|
27
|
+
# config.include_through_associations = false # Default: false
|
28
|
+
# config.include_scoped_associations = false # Default: false
|
29
|
+
# config.show_association_types = true # Default: true
|
30
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
## Purely for use by Scryglass.demo_hash
|
4
|
+
class ScryExampleClass
|
5
|
+
attr_accessor :instance_variable_1, :instance_variable_2, :instance_variable_3, :instance_variable_4
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
self.instance_variable_1 = nil
|
9
|
+
self.instance_variable_2 = true
|
10
|
+
self.instance_variable_3 = {:test => true, :not_test => false}
|
11
|
+
self.instance_variable_4 = 'Scrying is fun!'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Scryglass
|
16
|
+
def self.test_hash
|
17
|
+
{
|
18
|
+
:move_into_this_sub_item_with_down_arrow => "I'm just a string",
|
19
|
+
:disclaimer => 'This giant playground object is still no substitute for just pressing `?`...',
|
20
|
+
:an_empty_array => [],
|
21
|
+
:an_array_you_can_open_with_right_arrow => [
|
22
|
+
1,
|
23
|
+
1.0,
|
24
|
+
'You can close this array, anywhere here, with left arrow',
|
25
|
+
:an_empty_hash => {},
|
26
|
+
:some_more_advanced_stuff => {
|
27
|
+
'What about lens view?' => [
|
28
|
+
"I'm a string, but you can prove it by pressing spacebar to toggle lens view",
|
29
|
+
"There's lots to do with lens view, but the help screens ('?') are really best."
|
30
|
+
],
|
31
|
+
'What is my cursor telling me about this Range object?' => (1...12),
|
32
|
+
nil => "this line is so long you should use the w/a/s/d ('d' in particular) to see more. If you can see the whole line all at once, your text/screen ratio might need some balancing..." * 10,
|
33
|
+
[1,2,3] => "Can't expand/collapse keys, sorry...",
|
34
|
+
Scryglass::ViewWrapper.new('the actual string', string: 'This key appears differently in the tree view!') => Scryglass::ViewWrapper.new(24601, string: 'So do this integer!'),
|
35
|
+
"A lambda" => ->(o) { puts o.inspect.upcase.reverse },
|
36
|
+
"\n\n\n" => "If you want to know what that lambda does, move your cursor to it, press ENTER, and it will be returned to your console for you to play with!",
|
37
|
+
'Allll the coolest stuff' => [
|
38
|
+
Scryglass::ViewWrapper.new('TODO add link', string: '...Is really in the help screens (`?`) and the README. Press spacebar for README link in lens view'),
|
39
|
+
],
|
40
|
+
:delicious_data => {
|
41
|
+
:whoa_now => ([1]*800).map { rand(2) }.insert($stdout.winsize.first, 'Press zero to reset view position, then again to reset cursor there!'),
|
42
|
+
999 => {
|
43
|
+
4.1 => [4,1],
|
44
|
+
5.1 => [5,1],
|
45
|
+
6.1 => [6,1],
|
46
|
+
7.1 => [7,1],
|
47
|
+
8.1 => [8,1],
|
48
|
+
9.1 => [9,1],
|
49
|
+
0.1 => [0,1],
|
50
|
+
1.1 => [1,1],
|
51
|
+
},
|
52
|
+
Array => [1,2, [1,2,[3]], [3, 88, [99, 100]], 0],
|
53
|
+
'Some test classes with instance variables' => [
|
54
|
+
ScryExampleClass.new,
|
55
|
+
ScryExampleClass.new,
|
56
|
+
ScryExampleClass.new,
|
57
|
+
ScryExampleClass.new,
|
58
|
+
],
|
59
|
+
},
|
60
|
+
},
|
61
|
+
],
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.demo_hash
|
66
|
+
{
|
67
|
+
:time => Time.now,
|
68
|
+
:temperature => 'Just right',
|
69
|
+
:data => [
|
70
|
+
[
|
71
|
+
ScryExampleClass.new,
|
72
|
+
ScryExampleClass.new,
|
73
|
+
],
|
74
|
+
[
|
75
|
+
ScryExampleClass.new,
|
76
|
+
ScryExampleClass.new,
|
77
|
+
],
|
78
|
+
[
|
79
|
+
ScryExampleClass.new,
|
80
|
+
ScryExampleClass.new,
|
81
|
+
],
|
82
|
+
[
|
83
|
+
ScryExampleClass.new,
|
84
|
+
ScryExampleClass.new,
|
85
|
+
],
|
86
|
+
[
|
87
|
+
ScryExampleClass.new,
|
88
|
+
ScryExampleClass.new,
|
89
|
+
],
|
90
|
+
[
|
91
|
+
ScryExampleClass.new,
|
92
|
+
ScryExampleClass.new,
|
93
|
+
],
|
94
|
+
]
|
95
|
+
}
|
96
|
+
end
|
97
|
+
end
|