-
-
Notifications
You must be signed in to change notification settings - Fork 44
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 to tcell from termbox #32
Conversation
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
===========================================
- Coverage 89.61% 76.45% -13.16%
===========================================
Files 6 6
Lines 597 756 +159
===========================================
+ Hits 535 578 +43
- Misses 44 159 +115
- Partials 18 19 +1 |
Hi, @tjmtmmnk. Thanks a lot for your great work! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! I commented on some points.
@@ -30,7 +30,7 @@ jobs: | |||
run: go build | |||
|
|||
- name: Test | |||
run: go test -v -coverpkg ./... -covermode atomic -coverprofile coverage.txt -tags fuzz -numCases 3000 -numEvents 300 ./... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not a part of the changes PR's title describes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change related to #32 (comment)
|
||
// SetSize changes the pseudo-size of the window. | ||
// Note that SetSize resets added cells. | ||
func (m *TerminalMock) SetSize(w, h int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change breaks TerminalMock
's backward-compatibility. Could you define TerminalMockV2
instead of modifying TerminalMock
?
Or, we may be able to put a new method SetTcellEvents
into TerminalMock
without breaking the current interface (maybe this is better if possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I will define TerminalMockV2
.
It wasn't such a simple problem, so I'll think about it for a moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me TerminalMock
seemed to be used only for testing purposes.
I didn't understand why backwards compatibility was needed so please let me know...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is used only for testing. However, according to the import compatibility rule of Go modules, public interfaces should be compatible, regardless of whether they are for testing or not.
Please let me know if there seems to be no way to keep backward compatibility; I will consider making a v2 release...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for introducing useful article!
I tried to make the public interface backwards compatible.
tcell.go
Outdated
type termImpl struct { | ||
screen tcell.Screen | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's clearer to simply use embedding.
type termImpl struct { | |
screen tcell.Screen | |
} | |
type termImpl struct { | |
tcell.Screen | |
} |
@@ -553,7 +618,6 @@ func (f *finder) find(slice interface{}, itemFunc func(i int) string, opts []Opt | |||
if err := f.initFinder(items, matched, opt); err != nil { | |||
return nil, errors.Wrap(err, "failed to initialize the fuzzy finder") | |||
} | |||
defer f.term.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call f.term.Screen().Fini()
at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I misunderstood...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, is there any reason to call f.term.Fini()
in Find
and FindMulti
instead of find
? I thought it would work fine if we left it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was misunderstanding, as you say, I can call Fini()
in find
fuzzyfinder.go
Outdated
func sendExtraEventFix() { | ||
kb, err := keybd_event.NewKeyBonding() | ||
if err != nil { | ||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use panic, return the error instead.
fuzzyfinder.go
Outdated
@@ -604,6 +672,20 @@ func (f *finder) find(slice interface{}, itemFunc func(i int) string, opts []Opt | |||
} | |||
} | |||
|
|||
// This method avoid tcell bug https://github.com/gdamore/tcell/issues/194 | |||
// Aditional EOL event is sent to ensure, consequent events, are correctly handled | |||
func sendExtraEventFix() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great hack 👍
Co-authored-by: ktr <ktr@syfm.me>
I fixed 3 points. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tjmtmmnk
I'm really sorry I'm always late...
It's almost perfect, but I'd like you to fix a few minor things before we merge it 🙏
helper_test.go
Outdated
@@ -11,3 +11,11 @@ func NewWithMockedTerminal() (*finder, *TerminalMock) { | |||
m.SetSize(w, h) | |||
return f, m | |||
} | |||
|
|||
func NewWithMockedTerminalV2() (*finder, *TerminalMock) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to define a v2 function because helper_test.go
is only for testing and it is referenced only from fuzzyfinder_test.go
. So you can rename it to NewWithMockedTerminal
and remove the old one.
func NewWithMockedTerminalV2() (*finder, *TerminalMock) { | |
func NewWithMockedTerminal() (*finder, *TerminalMock) { |
mock.go
Outdated
func (m *TerminalMock) close() {} | ||
|
||
// UseMockedTerminal switches the terminal, which is used from | ||
// this package to a mocked one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment for deprecation? (ref. https://github.com/golang/go/wiki/Deprecated)
// this package to a mocked one. | |
// this package to a mocked one. | |
// | |
// Deprecated: Use UseMockedTerminalV2. |
mock.go
Outdated
return buf.String() | ||
} | ||
|
||
// parseAttrV2 parses color and attribute for test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[super nits]
// parseAttrV2 parses color and attribute for test | |
// parseAttrV2 parses color and attribute for testing. |
mock.go
Outdated
@@ -45,12 +49,30 @@ func (m *TerminalMock) SetSize(w, h int) { | |||
m.cells = make([]*cell, w*h) | |||
} | |||
|
|||
func (m *TerminalMock) SetSizeV2(w, h int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you switch the implementation of SetSize
based on a bool
field such as m.v2
instead of defining SetSizeV2
? (It looks like the variable v2
can be set inside of UseTerminalMockV2
)
For example:
// SetSize changes the pseudo-size of the window.
// Note that SetSize resets added cells.
func (m *TerminalMock) SetSize(w, h int) {
if m.v2 {
m.simScreen.SetSize(w, h)
return
}
m.sizeMu.Lock()
defer m.sizeMu.Unlock()
m.cellsMu.Lock()
defer m.cellsMu.Unlock()
m.width = w
m.height = h
m.cells = make([]*cell, w*h)
}
// SetEvents sets all events, which are fetched by pollEvent. | ||
// A user of this must set the EscKey event at the end. | ||
func (m *TerminalMock) SetEvents(e ...termbox.Event) { | ||
func (m *TerminalMock) SetEvents(events ...termbox.Event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
mock.go
Outdated
@@ -61,6 +83,63 @@ func (m *TerminalMock) GetResult() string { | |||
return m.result | |||
} | |||
|
|||
func (m *TerminalMock) GetResultV2() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the review comment on SetSizeV2
.
Sorry for the delay, and thank you for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for your contribution. I'm sure that this change will be very helpful for go-fuzzyfinder
's future.
Have a happy new year holiday 🍺
Thank you!! |
Related Issue: #15
Thanks great library!
This PR is intended to replace completely from termbox to tcell.
I think this migration has two merits.
It is stated that termbox will not be maintained anymore (ref). So, migrate to maintained tcell, make this product more stable.
tcell has a lot of useful features. For example, Ansi color in preview mode #29 can solve easily by using code used in tview etc (ref).
The problem reported in #17, can solve by using workaround(ref).
I could confirm the code(reproduce the problem) work well in local.