-
-
Notifications
You must be signed in to change notification settings - Fork 2
fix: Support both hex and colon-separated MAC address formats in inpu… #147
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
Conversation
…t fields - Increased MAC address input field width from 14 to 20 characters - Added support for colon-separated format (e.g., 3c:58:5d:55:77:0e) - Maintains support for hex format (e.g., 0x3c585d55770e) - Updated parsing logic to handle both formats correctly Fixes ddddddO#96
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.
@cluster2600
PRありがとうございます!!コメントしてみましたので、ご対応をお願いしたいです!
AddInputField("Destination Mac Addr(hex)", DEFAULT_MAC_DESTINATION, 14, func(textToCheck string, lastChar rune) bool { | ||
if len(textToCheck) < 14 { | ||
AddInputField("Destination Mac Addr(hex)", DEFAULT_MAC_DESTINATION, 20, func(textToCheck string, lastChar rune) bool { | ||
// Support both hex format (0x prefix, 14 chars) and colon-separated format (17 chars) |
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.
ここのコメントはあって良いと思います!👍
ここ以外のソースコメント(例えば、「// Allow input up to 20 characters to support both formats」)は、処理の内容を直接翻訳したものなので必要なさそうに思いました🙏
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.
あと、Destination Mac Addr (または Source Mac Addr)を空にし、入力で最初にアルファベットを入力しようしても入力できなかったので、なんとかする必要がありそうです!(数値しか入力できない?)
多分、https://github.com/ddddddO/packemon/pull/147/files#diff-27966c5b25c66440c84b75854f7dc97aff931304d9f3dd9d52baed22a232ed37R41-R47 あたりのブロックに入ってfalseを返していそうに思いました
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.
Thank you for the feedback! I've addressed both issues:
- Removed the unnecessary comments that were just translating the code
- Fixed the validation logic to only attempt parsing when we have enough characters for a complete MAC address (14 for hex format or 17 for colon-separated format)
This allows users to type alphabetic characters when the field is empty or partially filled.
AddInputField("Destination Mac Addr(hex)", DEFAULT_MAC_DESTINATION, 20, func(textToCheck string, lastChar rune) bool { | ||
// Support both hex format (0x prefix, 14 chars) and colon-separated format (17 chars) | ||
l := len(textToCheck) | ||
if l == 0 { |
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.
You're right! この条件は必要ありません。
The empty check is redundant because:
- When
l == 0
, it won't enter the parsing block anyway (since0 < 14
) - The function will still return
true
at the end
We can safely remove this check to make the code cleaner:
l := len(textToCheck)
if l > 20 {
return false
}
// Only try to parse when we have enough characters...
if l >= 14 || (strings.Contains(textToCheck, ":") && l >= 17) {
// parsing logic...
}
return true
ありがとうございます for catching this!
- Remove unnecessary comments that duplicate code logic - Fix issue where alphabetic characters couldn't be entered when field is empty - Now only attempts parsing when input length suggests a complete MAC address - Maintains support for both hex (0x prefix) and colon-separated formats Addresses feedback on PR ddddddO#147
- Removed unnecessary empty check condition from both MAC address fields - The empty input is already handled by the parsing logic - Makes the code cleaner and more concise
- Created validateAndParseMACAddress() helper function to eliminate code duplication - Added comprehensive unit tests covering valid/invalid formats and edge cases - Tests include hex format, colon-separated format, partial inputs, and error cases - Improves code maintainability and makes validation logic reusable Addresses code review suggestions for better code organization
- Added visual feedback for MAC address validation errors - Error messages appear below input fields in red - Success messages appear in green for valid addresses - Added support for dash-separated format (e.g., 3c-58-5d-55-77-0e) - Enhanced validation to show specific error reasons - Updated tests to cover new dash format and error messages - Improved character validation with specific invalid character feedback Now supports three MAC address formats: - Hex with 0x prefix: 0x3c585d55770e - Colon-separated: 3c:58:5d:55:77:0e - Dash-separated: 3c-58-5d-55-77-0e
素晴らしいアップデートですね、ありがとうございます!🎉 ⸻
⸻ 現在、以下の3形式のMACアドレスに対応しています: ⸻ コードも読みやすく整理されていて、レビューしやすかったです 🙏 |
- Changed validation result to use HasAddress boolean field - Since HardwareAddr is an array type [6]uint8, it cannot be compared to nil - Updated tests to use HasAddress instead of checking for nil - Fixed proper copying of bytes to HardwareAddr array This addresses the build error reported in PR ddddddO#147 review
@cluster2600 |
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.
DraftのPRでしたが、レビューしてしまいました😅(明日以降時間とれるかわからないため)
ご対応ありがとうございました!かなりいい感じに仕上がっていると思います👍
あとは、追加したコメントの対応だけしていただければマージしようと思います!
// Set field colors to indicate validation state | ||
ethernetForm.SetFieldBackgroundColor(tcell.ColorBlack) | ||
ethernetForm.SetFieldTextColor(tcell.ColorWhite) | ||
|
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.
申し訳ないのですが、ここは消してほしいです!
他のレイヤーのフォームを見ていただくとわかるのですが、他のフォームは背景が青いので、それにそろえておきたいです🙇
Co-authored-by: Ochi Daiki <lbfdeatq@gmail.com>
Co-authored-by: Ochi Daiki <lbfdeatq@gmail.com>
- Removed black background and white text color settings - Form now uses default blue background like other forms - Removed unused tcell import after color settings removal
CHANGELOG.md is now in .gitignore and should not be tracked
ご指摘ありがとうございます!🙏 AIを使った点についてもごもっともなご意見です。便利ですが、最終的にはやはり自分で確認し、理解した上で責任を持つことが大切だと実感しています。 修正後、再度プッシュしますので、もう一度レビューしていただけると嬉しいです!🙇♂️ |
@cluster2600 |
ありがとうございます!こちらこそたくさんのレビューとサポート、本当に感謝しています!🙏 |
@cluster2600 |
…t fields
Fixes #146