{"action":"created","issue":{"url":"https://api.github.com/repos/morassman/process-palette/issues/36","repository_url":"https://api.github.com/repos/morassman/process-palette","labels_url":"https://api.github.com/repos/morassman/process-palette/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/morassman/process-palette/issues/36/comments","events_url":"https://api.github.com/repos/morassman/process-palette/issues/36/events","html_url":"https://github.com/morassman/process-palette/pull/36","id":210332980,"number":36,"title":"allow styling of output lines by non-path patterns and styles.less","user":{"login":"hg42","id":4707597,"avatar_url":"https://avatars1.githubusercontent.com/u/4707597?v=3","gravatar_id":"","url":"https://api.github.com/users/hg42","html_url":"https://github.com/hg42","followers_url":"https://api.github.com/users/hg42/followers","following_url":"https://api.github.com/users/hg42/following{/other_user}","gists_url":"https://api.github.com/users/hg42/gists{/gist_id}","starred_url":"https://api.github.com/users/hg42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hg42/subscriptions","organizations_url":"https://api.github.com/users/hg42/orgs","repos_url":"https://api.github.com/users/hg42/repos","events_url":"https://api.github.com/users/hg42/events{/privacy}","received_events_url":"https://api.github.com/users/hg42/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":90,"created_at":"2017-02-26T17:22:45Z","updated_at":"2017-04-15T19:21:52Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/morassman/process-palette/pulls/36","html_url":"https://github.com/morassman/process-palette/pull/36","diff_url":"https://github.com/morassman/process-palette/pull/36.diff","patch_url":"https://github.com/morassman/process-palette/pull/36.patch"},"body":"coming from scite and loving process-palette, I thought, I'll extend the functionality a bit.\r\nThis PR implements styling the output lines via pattern expressions and the user's styles.less.\r\n\r\nsnippet from process-palette.json:\r\n```\r\n...\r\n  \"patterns\": {\r\n    \"dashes\": {\r\n      \"expression\": \"^--\"\r\n    },\r\n    \"command\": {\r\n      \"expression\": \"^>\"\r\n    },\r\n    \"exclamation\": {\r\n      \"expression\": \"^ *!\"\r\n    },\r\n...\r\n```\r\nsnippet from styles.less:\r\n```\r\natom-panel .process-palette-output-panel .dashes\r\n{\r\n  color: #009999 !important;\r\n}\r\n\r\natom-panel .process-palette-output-panel .command\r\n{\r\n  color: #0000ff !important;\r\n}\r\n\r\natom-panel .process-palette-output-panel .exclamation\r\n{\r\n  color: #009900 !important;\r\n}\r\n```\r\n\r\nPatterns 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.\r\n\r\nI am unsure if the class names should be extended by a prefix like\r\n  `\"line-\"`\r\nor may be\r\n  `\"process-palette-line-\"`.\r\n\r\nWhen using many expressions, I would also like to have them default to enabled, but that's another topic, I guess.\r\n\r\n(I'm new to atom, so forgive me if I am doing something wrong...)\r\n"},"comment":{"url":"https://api.github.com/repos/morassman/process-palette/issues/comments/294312884","html_url":"https://github.com/morassman/process-palette/pull/36#issuecomment-294312884","issue_url":"https://api.github.com/repos/morassman/process-palette/issues/36","id":294312884,"user":{"login":"hg42","id":4707597,"avatar_url":"https://avatars1.githubusercontent.com/u/4707597?v=3","gravatar_id":"","url":"https://api.github.com/users/hg42","html_url":"https://github.com/hg42","followers_url":"https://api.github.com/users/hg42/followers","following_url":"https://api.github.com/users/hg42/following{/other_user}","gists_url":"https://api.github.com/users/hg42/gists{/gist_id}","starred_url":"https://api.github.com/users/hg42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hg42/subscriptions","organizations_url":"https://api.github.com/users/hg42/orgs","repos_url":"https://api.github.com/users/hg42/repos","events_url":"https://api.github.com/users/hg42/events{/privacy}","received_events_url":"https://api.github.com/users/hg42/received_events","type":"User","site_admin":false},"created_at":"2017-04-15T19:21:51Z","updated_at":"2017-04-15T19:21:51Z","body":"Note, the above example (`\"(path)\"`) is very trivial, because it doesn't matter if the quotes are included in styling.\r\nThe original use-case was from my tracing outputs:\r\n```\r\n   \\ func ( x=1 y=2 z=3 )\r\n     ...\r\n   / func ( x=1 y=2 z=3 ) = \"some result of func\"\r\n```\r\nwhere I wanted to style only the function result `= \"some result of func\"` but only in trace lines starting with `\\s*/\\s+` (= end of function).\r\nIt should look something like this:\r\n\r\n   / func ( x=1 y=2 z=3 ) **= \"some result of func\"**\r\n\r\nThis was impossible with javascript regexps because I cannot get the character index (position in line) of the group.\r\n\r\nI 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 configure it wrong.\r\n\r\nNow with regexp-tree, I can parse the regexp configured by the user, wrap all non-grouped parts in groups and in the match result calculate the positions by cumulating the lengths of each detected group result.\r\nExample:\r\nI want to detect this:\r\n```\r\nabc.*?(\\d+).*xyz\r\n```\r\nwhich is a number preceded somewhere by \"abc\" and followed somewhere by a \"xyz\".\r\nOnly the number should be styled.\r\nSay we have some string `\"foo abc test 123 test xyz bar\"`.\r\nThe coffee-script:\r\n```\r\n  text = \"foo abc test 123 test xyz bar\"\r\n  re = /abc.*?(\\d+).*xyz/\r\n  console.log text.match re\r\n```\r\nreturns:\r\n```\r\n[ 'abc test 123 test xyz',\r\n  '123',\r\n  index: 4,\r\n  input: 'foo abc test 123 test xyz bar' ]\r\n```\r\nSo, you only get the position of \"a\" in the line (`index: 4`) and the whole matched string and the group (`'123'`).\r\n\r\nWith this result, you have no way to determine the position of the number.\r\nSo you can only style this way:\r\n\r\n  foo **abc test 123 test xyz** bar\r\n\r\nbut it should look like this:\r\n\r\n  foo abc test **123** test xyz bar\r\n\r\nWith regexp-tree the regexp is parsed and I can convert the regexp to:\r\n```\r\n(abc.*?)(\\d+)(.*xyz)\r\n```\r\nand remember the group numbers of the original groups.\r\nWith\r\n```\r\n  text = \"foo abc test 123 test xyz bar\"\r\n  re = /(abc.*?)(\\d+)(.*xyz)/\r\n  console.log text.match re\r\n```\r\nI get:\r\n```\r\n[ 'abc test 123 test xyz',\r\n  'abc test ',\r\n  '123',\r\n  ' test xyz',\r\n  index: 4,\r\n  input: 'foo abc test 123 test xyz bar' ]\r\n```\r\nSo I can split the pre and post parts of the result as usual (`\"foo \"`, `\" bar\"`) and I can use the length of the first group to determine the position of the number (`pos_number = index + match[1].length`).\r\n\r\nGenerally all grouped elements should be styled and the surrounding strings should not.\r\nIf they are nested, the inner groups are ignored. The same for non-capturing groups.\r\nSo:\r\n```\r\nabc.*(\\d+).*klmn.*(<(\\d+|\\w)>).*xyz\r\n```\r\nshould style the first number and the second number or word including `<` and `>`.\r\nBut \"abc\" or \"klmn\" or \"xyz\" or all other parts are left unstyled.\r\n\r\n@morassman I also want to replace the regexp for paths etc. with named groups:\r\n```\r\n  getPathExpression: (hasLine) ->\r\n    if os.platform == \"win32\"\r\n      return \"(?:[a-z]:\\\\\\\\|\\\\\\\\)?[\\\\w\\\\.\\\\-\\\\\\\\]+[.\\\\\\\\][\\\\w\\\\.\\\\-\\\\\\\\]+\";\r\n    return \"(?:~\\\\/|\\\\/)?[\\\\w\\\\.\\\\-\\\\/]+[.\\\\/][\\\\w\\\\.\\\\-\\\\/]+\";\r\n```\r\nwould then look like this:\r\n```\r\n  getPathExpression: (hasLine) ->\r\n    if os.platform == \"win32\"\r\n      return \"(?<path>(?:[a-z]:\\\\\\\\|\\\\\\\\)?[\\\\w\\\\.\\\\-\\\\\\\\]+[.\\\\\\\\][\\\\w\\\\.\\\\-\\\\\\\\]+)\";\r\n    return \"(?<path>(?:~\\\\/|\\\\/)?[\\\\w\\\\.\\\\-\\\\/]+[.\\\\/][\\\\w\\\\.\\\\-\\\\/]+)\";\r\n```\r\n\r\nadvantages:\r\n* we can easily extract the path from the result by `match.groups.path` and the line by `match.groups.line` without storing an index for them.\r\n* the user can have his own path expression by simple using a `(?<path>...)` construct instead of `(path)` and this would work automatically. The same would work for line (but there's no advantage).\r\n* this also allows to remove the third column \"Path RegEx\".\r\n\r\nIs this ok for you?"}}
{"actor":{"display_login":"hg42"}}