-
Notifications
You must be signed in to change notification settings - Fork 17
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
allow styling of output lines by non-path patterns and styles.less #36
base: master
Are you sure you want to change the base?
Conversation
I used traditional kind of building the HTML for the styling, because I'm still not familiar with atom's way (and could not get it to work). |
Hi @hg42 This is a very innovative feature! I'll be happy to merge it in. There's just two thing I'll have to run by you first. First, on line 189 you have
, but the style Second, the following unfortunately introduces a bug:
The culprit is the Atom uses space-pen for constructing its UI. The original code was
When you look at What the .html() does is it converts it to plain text. It therefore loses the click behaviour. The path is still shown with an underline, but clicking on it has no effect. |
this assigns a class to all lines matching a path pattern. I thought it might be useful to someone to be able to style such lines. |
I managed to find an implementation using space-pen, but I have one remaining problem. I used this to output a matching line wrapped with a
This works, but if I have something like:
those special characters are converted to
In Developer Tools they are shown (optically) as expected:
but copying the element gives:
so it seems all the I will start digging into the documentation of space-pen to find a solution. |
ok, I guess I found a solution using
|
I actually don't have a solution nor a hint. Sorry... I personally didn't find space-pen to be very intuitive nor its documentation very insightful. Even Google-ing for examples doesn't yield much. I'm sure you'll get it right, but I'll also look into it a bit myself. As for the special characters. I don't know if you saw it, but these are actually handled in the method called |
Thanks for the quick answer, however I already found a solution...see above. Thanks for the hint to the other PR, ansi sequences are useful for shell commands. I didn't notice that coloring is possible, because commands like |
I added a |
re-thinking the whole matching:
in fact each line pattern could be transformed:
In general, patterns could match whatever they want and add a But:
I'm not sure if I should complete this PR now or better try a bit more to implement these ideas. What do you think? |
After thinking some time about generalization, I feel it would lead to much more complications and more complex configuration than being useful:
So, I would conclude, let's better keep it simple. The current implementation should be sufficient for line based matching and works well for my needs. At least it's already better than the SciTE way with it's non-configurable expressions. What about documentation...where and how much should I add some? Btw., I also would like to change the default to enabled for all patterns, because it's uncomfortable to enable all these patterns for new commands, at least for line patterns. The default However the something like:
written multi-line with space in front of "|", to make it more clear. Perhaps it should be a multi-line setting for user convenience and lines joined by "|" afterwards. I also think, there is a mistake in the current default path regex itself and also in the function (without having tested). I will probably add an issue and may be a PR after some testing. |
Just a note, what's going on... I had some problems with detection of path patterns and rendering. python generates messages like: The quotes were "sanitized" by outputToPanel, so the regex did not match the Additionally, the local file name without directory wasn't matched. Apart from that, I had more than one path pattern in a single line. I also noticed something similar before: |
to test multi-part output I wrote this shell script:
with my styling pattern of |
Hi @hg42 Sorry for being so quiet. I haven't had much free time lately. It looks like you've been quite busy! By now you seem to have a more comprehensive grasp of the styling than me in general. I agree that we should try and keep things simple. When I originally started with the pattern matching I kept it simple by just trying to match one pattern per line. I suppose that is perhaps too simple, but it helped me to get something out that works for, I guess, most use cases. When it comes to enabling all patterns by default, I think I'll add a setting so that one can choose if that should be the case and rather have it disabled by default. When I release updates I try to keep the default behaviour as-is so that existing users aren't affected, or surprised, too much. The path expression can become a global setting. I think, though, that it should only serve as a default so that one can always override it on a per-command basis. I also agree that the path expression can be improved on like you suggested. I'll try to look at the changes you've made in more detail soon, but I can at least say that I won't release another update until this PR has been merged. |
Hi @morassman, I already assumed you were very busy....so I had more time to go forward. Because of multiple path patterns in a single line and the way I am already matching the rest of the line recursively, I think it's more complicated than what I described before. I currently think it's better to separate whole-line expressions from part-of-line expressions.
btw. can I redefine RegExPattern and PathPattern, so that RegExPattern is used for regex expressions and PathPattern is used for path expressions? |
I agree with you that separating whole-line and part-of-line expressions would be better. Most of your points make sense to me. I'm not 100% sure what the collected array is for as apposed to just writing directly to the output, but I'm sure it'll make sense when I see the implementation. Don't worry about preserving RegExPattern and PathPattern. You can change them as you see fit. |
Thanks for all that. The array is needed, because the line pattern is tested after converting subexpressions to objects and then wraps all this in a span. |
there are now four passes:
Because of that strategy inline expressions can not match over paths. I added a global setting I had several problems with space-pen.
But I wasn't able to drop it. This does not affect functionality, but it is sub-optimal. I think this could be accepted now (may be after some tests by others). |
as an example, I currently use this in my process-palette.json:
and these in styles.less:
|
Hi @hg42 I started looking at your implementation and testing it. It's looking very good. I think the concept of defaultPatterns isn't very obvious though. At the moment there isn't a place in the UI where default patterns are configured, so one needs to know about it and edit it directly in the process-palette.json file. (Unless I'm missing something?) Tell me if you think this is a good idea. I'd like to add a column to the 'Edit Patterns' part of the config editor called 'Default'. This column will have a checkbox so that one can choose which of the patterns should be a default pattern. This will be a simple way of showing the concept of a default pattern to the user and making it editable from the UI at the same time. |
hi @morassman, I'm on vacations now, so this is from memory only. You wanted to keep it compatible, so I added defaultPatterns. I thought, a GUI wouldn't be necessary. defaultPatterns defines the processing sequence of patterns for all commands where not configured individual (meaning no pattern enabled for the command). With defaultPatterns, you don't need individual sequences for each command, if you always want the same. If you want a GUI for that, it would be just like the individual setting (the one with the little arrows) but only a single global setting. A more intuitive way would be to be able to sort patterns in "Edit Patterns" and may be a single check box for each command saying something like "choose sequence individually" or "use default sequence". |
Styles how do you use the patterns? look pattern selection in command editor Please don't remove the list. Whether there is a CSV text field or a list comes down to the same thing, but I would like to keep the list. I think a middle ground would be to keep the list, but only show the patterns that were actually chosen. The button you mentioned can then be added so that one can use it to choose the patterns that one wants for that command. If you don't like the arrows then you're welcome to remove them and make them draggable like you did for the table. For the list, though, you won't need checkboxes to select them. Since the pattern names aren't editable in that context one can just click and drag from the pattern name. When it comes to a command one should be able to either choose:
Migration I've done migrations in my other package. What I did was to add a The migration is straight forward, but I think leave it to me. I'd like to implement it in the same way that I did for my other package. |
I commited to my master branch, you can test it now Styles look pattern selection in command editor
sure...I can imagine such cases. For this I would ideally prefer pattern groups. May be a command could use several groups. But ok, let's keep it as it is.
my only concern is the size of the list. Perhaps it could be shown horizontally (floating checkbox items). Eventually I'll try at some time later on another PR.
so you still think they are necessary?
ok, so simple solution is:
Migration
ok, less work :-)
ok
ok, but this has influence to the other code, because defaultPatterns can be extracted from the patterns list (all or only checked if we add a checkbox for that, but IMHO this should simply be all patterns). |
I tend to fix things when they get in the way, at least in smaller projects. |
ok, I found it myself. |
Hi. My comments:
I'll change it later myself so that there is an
Once drag-and-drop behaviour has been added to the list the arrow buttons won't be necessary. Until then they will be needed.
This might be the case for how you plan on using the patterns, but I don't think we should assume it would be the case for others. The user should be able to choose what behaviour they want. The order in the patterns editor should only apply to the default patterns. If that is the order that should be applied to a command then one should choose to use the default patterns. The per-command selection and order of patterns should remain so that one has the option to use a command specific list and order instead of the global list and order. The per-command list of patterns should remain. Especially for backwards compatibility and those people that use it in that way.
I think rather focus on the things that are needed for this feature. If there is a small issue or change you think would be beneficial then rather log a separate issue for it. I know it can be annoying when there are little things that one just wants to take care of, but I'd prefer to keep PRs focused on one thing. |
I looked at the code for pattern loading and usage regarding the conversion to a list. Assuming that all patterns are used for defaultPatterns and because you want to keep the command specific pattern lists with their own sequences, I think it would indeed be better what you suggested before: keeping current structures and simply use defaultPatterns for it's sequence. If defaultPatterns does not exist it will be created out of the "patterns" map (the current behavior is to use a for loop over the keys and values to create the table view, so this would keep the current sequence). Editing the patterns would additionally save defaultPatterns. When the map and the list don't match:
But, if you want to allow disabling some patterns in defaultPatterns it becomes a bit more complicated.
|
Hmmm... I don't fully understand. I think that, as part of the migration, the map should be converted to an array. The order in the array would then imply the order of the default patterns. Each pattern can then get a string field for its name and a boolean to indicate if it is a default pattern. This way one only needs to maintain the array and not multiple maps and lists. Would this work? |
I am trying to use the table view more generally with options selectable, deletable, draggable |
Ok. I didn't realise you went with the idea to kept the definition of the patterns (the map) separate from default patterns (array). |
that was the plan... but -- the container used in the package has to be a map anyways, because the names of the command patterns are looked up. defaultPatterns needs to remain a list internally, because it's handled just like the command patterns. So as a conclusion, I think it's not worth migrating to a structure not representing the real situation. Btw. I got tricked by coffeescript in my last commit, |
I fixed a remaining bug in pattern detection, just the same I fixed for inline patterns some time ago. |
Working on the fix I got into messing with regexps again. I tried several regexp libraries available for node.js, to solve the index problem. For the record and my motivation to look into other regexp libraries: I am refering to my comment above: To summarize the problem in short:
In our case we need pre and post to find other patterns in those strings. But, javascript does not provide the index of the group but only the index of the whole match, as you can see here. When switching the regexp engines, you see that javascript is the only one that has Unfortunately any prefixing expression is part of the whole match (even non-capturing groups) and thus you don't have any chance to find the matched group itself. Searching Using a better regexp library with named groups would simplify life for the user:
allowing complex expressions defining what should surrounding the match or be somewhere else in the line, and simply marking the right one with the name (here Having extended regexps with insignificant whitespace and comments would allow even more clarity. E.g. Path expressions like this one:
could be written like this:
Then e.g.
which would allow extracting the path from the regexp result simply by
note that some libraries don't allow multiple sub-expressions with the same name. Named expressions would also allow to remove the "Path Regex" column. The user could simply use a group named A good library also allows to include flags in the regexp, so The libraries I found are split in two categories:
So, before fixing the interface by releasing the package, I want to try these:
|
this thread describes the misery: current state:
but there is some silver lining on the horizon:
now the only problem is to combine them => not trivial... They are not designed to be used as a chain or can be easily chained automatically. I am currently eliminating the false candidates. |
status update: I have found a really nice library called My current plan:
I currently have each part of the match in an array of strings and objects for named and numbered groups. Nested groups come after the enclosing group. |
That sound promising. I also came across XRegExp when I added patterns, but it didn't do what I was looking for either. You remember that quote I made of solving things with regular expressions? What made me think of it was when I realised that what you're bordering on is the need for a proper parser. Regular expressions are powerful, but has their limits. I hope regexp-tree allows you to do what you need with regular expressions. We should try to avoid getting to the point where a language specification for each pattern would be better suited than a regex :) |
basically the same what I do now but without javascript problems :-) regexp-tree is only used to transform an extended regexp into javascript regexp. |
I just want to say, I am not dead :-) |
Note, the above example (
where I wanted to style only the function result / func ( x=1 y=2 z=3 ) = "some result of func" This was impossible with javascript regexps, because I cannot get the character index (position in line) of the group. I had to use a trick, which is visible to the user, using three groups instead of one and determining the position of the second group by looking at the length of the first group. This is not intuitive and the user can easily create a non-working configuration. Now with regexp-tree, I can parse the regexp configured by the user, wrap all non-grouped parts in groups and calculate the positions in the match result by cumulating the lengths of each detected group result.
which is a number preceded somewhere by "abc" and followed somewhere by a "xyz".
returns:
So, you only get the position of "a" in the line ( With this result, you have no way to determine the position of the number. foo abc test 123 test xyz bar but it should look like this: foo abc test 123 test xyz bar With regexp-tree I can parse the regexp convert it to:
and remember the group numbers of the original groups.
I get:
So I can split the pre and post parts of the result as usual ( Generally all grouped elements should be styled and the surrounding strings should not.
should style the first number and the second number or word including @morassman I also want to replace the regexp for paths etc. with named groups:
would then look like this:
advantages:
Is this ok for you? |
btw. I am not sure how to handle my new regexp module (codename XRE). On the other hand, the code for process-palette can be left simple, while I would want the module to get some more features in future. I am currently planning to include the XRE code in With XRE I have more possibilities to split the line into parts. |
just a quick update... I am near to releasing my regexp module (code name XRE above) to the public, because I think it is mature enough now. But I am waiting for a pull request to be accepted for the underlying regexp parser to fix a bug. I have already integrated this regexp module into process-palette with x-flag and named groups for path and line as described above. No algorithmic changes in the three processing loops for now. I'll push the new changes for testing, when the pull request has been accepted and I have released the module. |
I published the npm module: uxregexp I merged all my local commits to process-palette into a single commit on the pull request and cleaned some differences in my working tree. I hope there's nothing missing. There is an "interesting" conflict between the ansi colors and patterns: Probably, the solution would be to move the ansi conversion directly in front of the pattern conversion. I am currently using atom 1.17.0-beta4. However, almost all changes were implemented and tested with 1.16.0. |
I had to fix an error in uxregexp... |
I wouldn't be too worried about the conflict with ansi colours. If people use the patterns for styling the way your code intends then the pattern should determine the colour and not the ansi codes. I may be wrong, but from my experience not many command line tools produce ansi codes, or at least not the ones I've been using. Also, it may even be that the average user won't use the patterns in the first place, so it might be a bit of a corner case if someone experiences a problem. |
yes, I don't worry much about that, because there are not many chances they conflict. But I ran into it myself: |
I wonder if we should provide default patterns, so the average user can take advantage of the feature without configuring anything. |
Process palette has an example configuration file built in. It's very easy to get access to it. Any configuration examples such as these should go into that file. |
coming from scite and loving process-palette, I thought, I'll extend the functionality a bit.
This PR implements styling the output lines via pattern expressions and the user's styles.less.
snippet from process-palette.json:
snippet from styles.less:
Patterns not using "(path)" will be used as line expression and if matching the line will be wrapped in a
<span class="name-of-pattern">...</span>
. The first matching pattern stops the matching, but path-expressions are handled separate from line expressions, so paths can be styled inside matching lines.I am unsure if the class names should be extended by a prefix like
"line-"
or may be
"process-palette-line-"
.When using many expressions, I would also like to have them default to enabled, but that's another topic, I guess.
(I'm new to atom, so forgive me if I am doing something wrong...)