-
Notifications
You must be signed in to change notification settings - Fork 328
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
Replace termbox-go with tcell #439
Conversation
@Provessor Hey, thanks a lot for sending a patch. This seems like a lot of work. We had just made a new release, so it is perfect time for such a major overhaul. I need some time to understand, review, and test this as I'm still not familiar with tcell. I will be somewhat busy in the next few days, but hopefully I can take a proper look at this in the weekend. I'm not planning to push anything to the repo before this so don't worry about conflicts. |
Here's something I didn't think of before. In the PR I note that;
Which was done here:
Could be expanded so that everything lf receives from the previewer will be stored, instead of just what will fit on the current screen.
The current state in this PR is probably the most performant but having more of a file shown after a resize would be nicer. This probably belongs in another commit/PR though. Also a custom previewer could handle the situation where requesting more lines is expensive / has high latency such as over a network connection. EDIT: here is a little patch if you want to apply that after :^) |
@Provessor I don't resize my terminal often, at least not horizontally, so I was unaware of those bugs and glitches with cached previews. I still think cutting reading early with SIGPIPE is a useful optimization especially for long files. I would be ok to hide this behind an option, though I think it would be better to invalidate file caches with such resize events to fix this issue. It's probably worth discussing this in a separate issue. I appreciate you only stick to porting without anything else. The patch seems to work fine without any issues, though I wasn't able to test it with unicode rich files as I don't have many of those and I didn't play much with colors either. On windows, the screen flickers with almost all operations for some reason. Windows built was also broken (you need to mirror new definitions in I'm not sure if you have looked at it but the only reason we implemented
It's fine, these are not working with termbox either. As far as I remember, plan9 doesn't have such terminal interfaces, solaris was not building with termbox, and cygwin/mintty are not officially supported by Go. Actually it's more than fine since Tcell already seems to be more portable than termbox so we might be able add new platforms to our cross build system.
As far as I know, termbox have mouse events as well, it's just that I never had the chance to work on integrating them in
I must admit, that issue was a little worrying to read. I'm not against donations but it can become a slippery slope when it is meant to be the main income of someone. I hope we are not locking ourselves to a mandatory donation scheme. On the bright side, tcell is used in popular projects and fixes are more likely, and termbox is not maintained anyways. |
I assume you mean vertically but yes invalidating caches would probably be the better option.
My mistake with the definitions, they were sort of a last minute change when I realised that the colours were off on terminals that supported 24-bit colour. When working on this, the only access I have to a windows machine is through a rather slow RDP connection with limited permissions so it makes testing (especially for performance) rather difficult and time consuming. My next focus was going to be having a look at trying to reduce how much lf outputs to the screen. The flickering is probably because
However this is exactly what is done currently so my only thoughts is tcell is clearing the screen in a different way? The flickering may be reduced by filling the screen with spaces instead of using a sequence? Next week I should have physical access to a windows machine so I could spend a some time trying to remedy this.
The
I was also concerned about the result of that issue but tcell seems to be by far the most popular library for this used by a few very popular projects so worst-case it would probably end up maintained by one of them. And as you mentioned some maintenance is much better than none. |
@Provessor You're right, clearing seems to be different in termbox and tcell, former just clearing the buffer and latter clearing the buffer and flushing the screen. I tried putting space characters as you said similar to the function in termbox compat layer as below: Flickers are gone with this. However, there is a noticeable slowdown with tcell compared to the termbox version. Even with no clearing tcell seems to be slower than termbox so I think flushing may be the bottleneck. Maybe tcell is not optimized on windows? |
That would seem strange given it has a Windows specific It could be worth testing against the other screen type even though the comment states Windows would be unhappier with it.
IIRC, its been a long time since I've seriously worked with the Windows Terminal but it used to be very slow, especially on scrolling, and didn't even support all of the VT100 sequences. The problem may arise -- like you said -- from the amount of sequences that are sent after a sync. It might help testing against an alternative terminal like ConEmu.
That seems strange as after looking through tcell, that seems to be what it does on Windows systems It is probably not worth me testing any of this until I get physical access so all I can do right now is speculate. |
Also I got an issue about coloured output that doesn't display right with tcell currently. They also mention that it works fine with fzf which also uses tcell so it could be something I'm doing wrong in this patch.
|
@Provessor
check this link for more info |
@shabahengam as you listed in your post, to display 256 colours it is Lines 111 to 115 in ad533e4
Which skips over the next 2 entries ( What does your |
for example this is I have for go files |
@shabahengam @Provessor I think the first check should be @Provessor I didn't have a chance to look at this on windows again. I agree windows console is generally slow, though we should not make it slower if possible. I don't know if we have many windows users, but somehow it is the second most popular platform after linux for github downloads, though this may not mean much. Did you have a chance to look at this on windows yet? |
I would've thought at least the tests could have caught this (the 256 colour case is the same) but it does make sense that it should be the other way around.
Definitely
I got to have a bit of a look, but not enough to work out why it was slower. I'll write some tests to try and work out if it is intrinsic to tcell or something lf could avoid. |
@Provessor Today I have been reading tcell code as well as going through issues to see anything relevant to slowness on Windows and I have seen that 24 bit color support for windows is merged yesterday and there is now a mention of a v2 in the readme. I tried v2 with your patch and it still works, though the slowness is still there unfortunately. I have also been experimenting with different terminals and programs. Among the terminals, windows terminal works the fastest for me, followed by conemu, followed by cmd/powershell. Windows terminal is almost usable but still noticeably slower than termbox. I also tried Maybe there is more coming in v2 in the upcoming days. Perhaps it's a good idea to open an issue about slowness to report our experience as well. |
@gokcehan Thank you a lot for this, I decided to try and dual boot Windows 10 on one of my potatoes this weekend as I haven't been able to get any decent amount of time during the week to test it yet. If both |
@Provessor I was looking at the patch today again, and strangely I don't experience the slowness anymore. I was testing the speed by caching all file previews in the source repo by previewing them once, and then check the time the current file goes from top to bottom when I don't think I have changed anything in the code. I have upgraded my go version about two weeks ago from 1.13 to 1.15 to work on another issue. Maybe there was something cached in build directories, though I can't reproduce the issue now with older versions. Tcell also had another version 1.4 released along with 2.0, though I tried it now with 1.3 and no issue either. Maybe there was an update to one of the dependencies of tcell. Or maybe I was doing something silly before but I don't know what. By the way, I was looking at this patch today for #451 and it seems that termbox is now broken with wide CJK characters and tcell handles them correctly. I see you already removed the We also still need to move Lastly, tcell v2 also works without a problem, but maybe it's better to wait until they move from |
@gokcehan That's great you aren't having any slowness anymore, strange for it to just disappear randomly though. Which Windows build is this on? That reminds me, would you like me to add a "Fixes: " list to OP for all the issues that this should solve? I've put the flickering and I do think it would be better to leave v2 for now, there still isn't much of an indication as to what could change in the future so I would wait at least until a release candidate or equivalent is formed. |
@Provessor I'm stuck in Windows 1903 for the while. I have been using this for a while so it might as well just be a random bug. I would have been happier if I could have found a way to reproduce it though. I wish this had happened earlier. Sorry for troubling you with Windows.
Doesn't matter much. If you already have the list, you can do it. You can ping me when you're done. |
@gokcehan I managed to get a handle on a couple of different Windows builds and from my rudimentary tests it seems to have the same performance as r16 using the portable go-1.15 build from golang.org. I'll squash the commits now. EDIT: for some reason it wants an empty commit to fix merge issues; I'm not skilled enough at git to be able to fix this. |
Fix colour construction issue This also has a test to mitigate it in the future Remove `colormode` option The original issue it was trying to solve is no longer present with tcell (it being a holdover from `color256` on termbox) so it is not needed. retire gitter channel in favor of irc/matrix Export options as environment variables (gokcehan#448) * Export options as environment variables Any options from gOpts are available via lf_OPTION environment variables. For now it works only on booleans, integers and strings (no array support) * Do not export some of the options * Add support for arrays and fix numbers * Fix comments * Replace 1 and 0 with true and false * Export hidden,reverse,dirfirst and sortby options * Fix comments * Little fix * Simplify boolean conversion log readlink errors instead of fail Related gokcehan#447 and gokcehan#374
@Provessor Alright, it looks good to me, thanks again for the patch. |
@Provessor Strange things are now happening again after the merge. I tried upgrading my installed version with Colors are gray and the current file is not highlighted on gray items. Then I tried downloading the repo to the desktop and then build it from there. This way, colors are working. However slowness is back again in both cases. I now recorded a screencast to show what I mean: (Let me know if the video link doesn't work) This is with I will post updates here if I can figure things out. Ideas are welcomed. |
@Provessor I tried clearing the cache with I'm still looking for a solution for the gray color issue. |
I'm completely newbie in golang but I think something is wrong in this is index b94b2e5..7b3f958 100644
--- a/go.sum
+++ b/go.sum
@@ -1,10 +1,16 @@
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
+github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
+github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
+github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
+github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
+golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8= |
@gokcehan Very strange that it goes away after a reboot. I had another look through the issues for tcell mentioning "Windows" and none of them mention any issue like this so there is a chance it is just on your machine or build (most of my testing was on 1809 LTSC, none of it on 1903). Probably worth opening an issue at tcell about this but if you can't reliably reproduce it then that might not help much. Also it seems like the maintainer gdamore runs Windows 10 at least some times so I doubt this would be a widespread issue. |
@shabahengam Yes, that could be updated but it is more about minimum requirements. In your diff the lines without |
@Provessor I figured out the color problem. I had assumed I have reproduced the slowness a few more times. It happens when I install a new version of the binary and goes away after a reboot. I think you're right that it may be a Windows problem but I can't upgrade to the latest version at the moment. In any case, rebooting seems to fix the problem so if anyone else experiences the same issue we can simply recommend rebooting. @shabahengam As @Provessor said, that version is about the minimum, and I have already bumped our travis version to 1.15 recently. Having a dirty repository may prevent updates so it can be annoying. I have seen in the documentation that there is a flag mentioned |
@gokcehan great, those might be worth documenting in the wiki or somewhere else easier to find. |
@gokcehan definitely agree that this should be in the output of |
@mohkale I have now updated the source build instructions in the readme and the tutorial to include |
This completely replaces termbox-go with tcell. A few sections needed quite a bit of work because of how tcell constructs colours and events differently. This breakdown hopefully covers everything this would mean for the project, to save extra work by others later.
Hopefully this breakdown contains all of the changes, I have spent quite a while trying to get this as close as possible to the termbox-go implementation whilst modifying the structure as little as possible.
Fixes: #302 and #223 (with configuration)
Breakdown
User Perspective
color256
option is gone and a use will receive a warning ifcolor256
or any of its variants is used.$TCELL_TRUECOLOR
set to "disable" if it is unset on launch.drawbox
.Output
tcell requires a context (screen) to print onto, to remedy this a screen is passed around to whoever needs to print.
tcell operates on styles instead of colours, a style contains a foreground, background and any other attributes the text may have. The foreground/background split has been replaced everywhere with styles instead.
Some terminals/systems are noted as being not supported, these include
However, the best I can find about their status with termbox is an issue from ~2015 about them not working.
I held this off until I had somewhat official documentation for all of the colour parsing sections (instead of just converting the existing code) so I can guarantee any changes I made match the standards.
Some of the colours are named differently.
Events
EventError
s (such as when the tty goes away), otherwise it will endlessly spin inreadEvent()
if something goes wrong.Fini()
, asking for an event will always returnnil
(not error), now all goroutines that handle events will check for this after passing the event down the tree. This lets us close the screen any time without worrying about zombie goroutines. This could be improved to also handleEventError
s but lf will always exit immediately when encountering it. There is an open issue for tcell around the first event disappearing when working with multiple screens, however I haven't encountered this and there is a workaround if it ever becomes an issue. This is also why the screen is closed afterapp.loop()
returns instead of withdefer
(in case ofapp.ui.screen
changing).Tests
colormode
limiting modes.int64
) instead of comparing the colours.