-
Notifications
You must be signed in to change notification settings - Fork 321
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
Highlighting code #5
Comments
Issues are fine for feature requests. We don't have anything else for discussion anyway. You mean syntax highlight in the preview pane? Currently it is not possible to do that but it may change in the future. There are a couple of issues that needs to be addressed first though. Your best option for now may be to use a syntax highlighting pager if you're not using any yet. |
Yes, syntax highlighting in the preview pane. I wondered if the well known 'highlight' program, if installed on the host, could be used to do the work. That way you wouldn't have to bother with how it's done, but I need a way to "inline" this with the text going to the preview pane. Maybe something that could be configured/handled by a lfrc macro? |
I think that would be a nice addition. I will try to take a look at it in a few hours. Couple of points that worry me though:
|
I have tried an example with ansi escape codes from |
I planned to write about this as well, but got away on weekend and I see things unrolled without me anyway. The way I thought about it, I'd let user set any command as "preview preprocessor" and call it with file type (mime-type?) as first argument, then pipe in the file contents to The ranger abstraction is AFAIK a bit "lower", i.e. there are certain apps assigned to previewing certain filetypes. For example, if you have *) I'm afraid image previews might not work that way, though. Aside from macOS's iTerm, I don't think there are any terminals that have image display support. Using Just my two cents. |
I'm thinking the same thing about the preview processor @KenjiTakahashi but it's important to make ansi escape codes work first, at least for the sake of this issue. The rest should be straightforward. I have checked ranger's scope.sh and it seems that they are using Yesterday I have tried to manually move the cursor using ansi codes and print directly to the preview pane without termbox and it was kind of a mess as I thought it would be. I think the only viable option we have is to do this with termbox. I have been reading the termbox source today and found the related section here. It looks like termbox converts all characters less than Meanwhile, I'm getting less convinced that this is an essential feature. Ranger needs to do this since it is using the same thing for it's preview pane and built-in pager. In |
Ok, so I have pushed a commit to evaluate ansi codes while printing. To be honest it was easier than imagined. It turned out to be a clean and reasonable solution that we can maintain. This makes it possible to view colors in a file when they are coded with ansi codes. You can try this with something like Second commit is to do this automatically by setting an executable with I tried this with ranger's scope.sh and I can feel some lag moving between files. Since this is an optional feature I think it is ok for now. We may try to optimize it if possible when we start profiling the code. I suspect though this is probably because ranger is doing the preview asynchronously. I haven't updated the documentation yet as we still need some polish. I'm leaving this issue open for now. |
Hello, Best, From: gokcehan [notifications@github.com] Ok, so I have pushed a commit to evaluate ansi codes while printing. To be honest it was easier than imagined. It turned out to be a clean and reasonable solution that we can maintain. This makes it possible to view colors in a file when they are coded with ansi codes. You can try this with something like highlight --out-format=ansi foo.go > out.txt and then preview out.txt in lf. Second commit is to do this automatically by setting an executable with previewer option. I was thinking of making this a command just like open-file so that it would be possible to write a custom script right inside the configuration file but it looks difficult with the current structure of the code. Plus we should only allow $ commands for file preview. Also people are likely to use the same filter for both preview and pager and without an external script I'm not sure how to do that without duplication in the configuration. So maybe this is better for now. I tried this with ranger's scope.shhttps://github.com/ranger/ranger/blob/master/ranger/data/scope.sh and I can feel some lag moving between files. Since this is an optional feature I think it is ok for now. We may try to optimize it if possible when we start profiling the code. I suspect though this is probably because ranger is doing the preview asynchronously. I haven't updated the documentation yet as we still need some polish. I'm leaving this issue open for now. � |
Hello again, Best, From: gokcehan [notifications@github.com] Ok, so I have pushed a commit to evaluate ansi codes while printing. To be honest it was easier than imagined. It turned out to be a clean and reasonable solution that we can maintain. This makes it possible to view colors in a file when they are coded with ansi codes. You can try this with something like highlight --out-format=ansi foo.go > out.txt and then preview out.txt in lf. Second commit is to do this automatically by setting an executable with previewer option. I was thinking of making this a command just like open-file so that it would be possible to write a custom script right inside the configuration file but it looks difficult with the current structure of the code. Plus we should only allow $ commands for file preview. Also people are likely to use the same filter for both preview and pager and without an external script I'm not sure how to do that without duplication in the configuration. So maybe this is better for now. I tried this with ranger's scope.shhttps://github.com/ranger/ranger/blob/master/ranger/data/scope.sh and I can feel some lag moving between files. Since this is an optional feature I think it is ok for now. We may try to optimize it if possible when we start profiling the code. I suspect though this is probably because ranger is doing the preview asynchronously. I haven't updated the documentation yet as we still need some polish. I'm leaving this issue open for now. � |
Hey, Best, From: gokcehan [notifications@github.com] Ok, so I have pushed a commit to evaluate ansi codes while printing. To be honest it was easier than imagined. It turned out to be a clean and reasonable solution that we can maintain. This makes it possible to view colors in a file when they are coded with ansi codes. You can try this with something like highlight --out-format=ansi foo.go > out.txt and then preview out.txt in lf. Second commit is to do this automatically by setting an executable with previewer option. I was thinking of making this a command just like open-file so that it would be possible to write a custom script right inside the configuration file but it looks difficult with the current structure of the code. Plus we should only allow $ commands for file preview. Also people are likely to use the same filter for both preview and pager and without an external script I'm not sure how to do that without duplication in the configuration. So maybe this is better for now. I tried this with ranger's scope.shhttps://github.com/ranger/ranger/blob/master/ranger/data/scope.sh and I can feel some lag moving between files. Since this is an optional feature I think it is ok for now. We may try to optimize it if possible when we start profiling the code. I suspect though this is probably because ranger is doing the preview asynchronously. I haven't updated the documentation yet as we still need some polish. I'm leaving this issue open for now. � |
@davmaz Please keep issues on topic, when possible, so others do not get spammed with unrelated notifications. Thanks :-). |
@KenjiTakahashi @davmaz I have now added a google groups mailing list and a gitter chat (seems to support IRC as well) for questions and discussions. You can find the links in the readme if you are interested. |
I have now added file previewing to the documentation. Now the only thing left to do is to call the preview script asynchronously. I have tried something but couldn't get my head around synchronization so I leave it as it is for now. |
By calling cmd with |
Hm, sth's not right. My previewer stopped working after the last update. Will check why tomorrow, no time now. |
@KenjiTakahashi Ahh, it's leaking without It's probably not working because I have removed width parameter as it wasn't immediately available where I moved the code. I can add it back but as you said it is not very useful anyways. |
Right! Works again now. I don't care about width, either, so I think we can leave it the way it is now. Maybe it will be useful when I get to displaying images, but I don't know yet, it's not very easy :-). |
Asynchronous previewing is implemented while working on #92. I'm closing this issue now. If there is anything left to do or there are some regressions we can track it in the other issue. Particularly we could store the modification date of the file during preview and invalidate the value in the cache if the current modification date is more recent. I need to see if need an extra stat call for this purpose. P.S It's always encouraging to see an 18+ month-old issue going down :) |
Is it possible to use the highlight program to highlight go code when you display it? This would be a really cool enhancement since most users are gophers.
Sorry for the request when it's not really an issue. Regardless, I'm addicted to "lf" already -- great work!
The text was updated successfully, but these errors were encountered: