-
Notifications
You must be signed in to change notification settings - Fork 3
Create tutorial.md #60
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
Port of the tcell tutorial
WalkthroughAdds a new tutorial document Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 5
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
demos/tutorial.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
demos/tutorial.md
[grammar] ~9-~9: Use a hyphen to join words.
Context: ...es, it may be easier to utilize a higher level framework. A number of such framew...
(QB_NEW_EN_HYPHEN)
[grammar] ~38-~38: Ensure spelling is correct
Context: ...set toKey.esc` is dispatched. When other key is pressed, it is available as the ...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🪛 markdownlint-cli2 (0.18.1)
demos/tutorial.md
45-45: Hard tabs
Column: 5
(MD010, no-hard-tabs)
dejlek
left a comment
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.
Looks good to me.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.
Actionable comments posted: 1
♻️ Duplicate comments (6)
demos/tutorial.md (6)
33-33: Correct enum case: use lowercasekeyfor event type.In Dcell, all enum members are lowercase. Use
EventType.keyinstead ofEventType.Key.-When a key is pressed, applications receive an event of type `EventType.Key`. +When a key is pressed, applications receive an event of type `EventType.key`.Based on learnings, dcell enums consistently use lowercase naming.
45-45: Replace hard tabs with spaces.Hard tabs detected on line 45. Use spaces for consistent indentation throughout the document.
- info(i"Esc key was pressed"); + info(i"Esc key was pressed");
38-38: Fix grammar: use "another" instead of "other" for singular.When used with a singular noun, use "another" instead of "other".
-When other key is pressed, it is available as the `Key.graph` of the event. +When another key is pressed, it is available as the `Key.graph` of the event.
20-29: Fix logic error: resize event accessing undefined mouse position.
EventType.resizeevents don't contain mouse data. Accessingev.mouse.poscauses undefined behavior. Either omit the position info or uses.size()to report the new dimensions.Apply one of these diffs:
Option 1: Remove position info entirely
case EventType.resize: s.resize(); s.sync(); - info(i"Resized to $(ev.mouse.pos)"); + info("Resized"); break;Option 2: Report dimensions using s.size()
case EventType.resize: s.resize(); s.sync(); - info(i"Resized to $(ev.mouse.pos)"); + auto newSize = s.size(); + info(i"Resized to $(newSize)"); break;Based on learnings, the second approach provides more useful feedback to users.
338-347: Fix logic error: first condition swallows unreachable Ctrl+C branch.The unconditional check for
(ev.key.ch == 'C' || ev.key.ch == 'c')on line 338 matches all c/C keypresses, making the Ctrl+C check on line 343 unreachable. Test the modifier first, or restructure to avoid shadowing.case Key.graph: - if (ev.key.ch == 'C' || ev.key.ch == 'c') + if ((ev.key.ch == 'C' || ev.key.ch == 'c') && ev.key.mod == Modifiers.ctrl) { s.style = def; s.clear(); + } + else if (ev.key.ch == 'C' || ev.key.ch == 'c') + { + s.stop(); + exit(0); } - else if ((ev.key.ch == 'C' || ev.key.ch == 'c') && ev.key.mod == Modifiers.ctrl) - { - s.stop(); - exit(0); - } // Ctrl-L (without other modifiers) is used to redraw (UNIX convention) else if (ev.key.ch == 'l' && ev.key.mod == Modifiers.ctrl) {Wait, re-reading the intent: the first block clears, the second block should exit. Let me correct:
case Key.graph: - if (ev.key.ch == 'C' || ev.key.ch == 'c') + if ((ev.key.ch == 'C' || ev.key.ch == 'c') && ev.key.mod == Modifiers.ctrl) { - s.style = def; - s.clear(); + s.stop(); + exit(0); } - else if ((ev.key.ch == 'C' || ev.key.ch == 'c') && ev.key.mod == Modifiers.ctrl) + else if (ev.key.ch == 'C' || ev.key.ch == 'c') { - s.stop(); - exit(0); + s.style = def; + s.clear(); } // Ctrl-L (without other modifiers) is used to redraw (UNIX convention) else if (ev.key.ch == 'l' && ev.key.mod == Modifiers.ctrl)This way, Ctrl+C exits (modifier-first check), and plain C/c clears (fallback check).
99-119: Add missings.start()call after screen creation.The screen must be initialized with
s.start()before calling any other screen methods. This is currently missing from the usage example, though correctly included in the demo application below.auto s = newScreen(); assert(s !is null); +s.start(); scope (exit) { s.stop(); }Based on learnings,
s.start()must be called after creating the screen and before any terminal interactions likeenableMouse()orenablePaste().
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
demos/tutorial.md(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-12-17T22:06:23.076Z
Learnt from: dejlek
Repo: gdamore/dcell PR: 60
File: demos/tutorial.md:26-26
Timestamp: 2025-12-17T22:06:23.076Z
Learning: In Dcell (D language), when handling EventType.resize events, do not access ev.mouse properties. To get the new terminal dimensions after a resize event, call s.size() instead.
Applied to files:
demos/tutorial.md
📚 Learning: 2025-12-15T05:12:35.344Z
Learnt from: gdamore
Repo: gdamore/dcell PR: 56
File: source/dcell/vt.d:2-2
Timestamp: 2025-12-15T05:12:35.344Z
Learning: In D language (used in gdamore/dcell), when you have a variable of enum type (e.g., `Attr attr`), both `attr.EnumMember` and `Attr.EnumMember` are aliased to the same enum value. This means using the lowercase variable name instead of the uppercase type name in case statements is not a compile error, though using the type name is preferred for consistency.
Applied to files:
demos/tutorial.md
🪛 LanguageTool
demos/tutorial.md
[grammar] ~38-~38: Ensure spelling is correct
Context: ...set toKey.esc` is dispatched. When other key is pressed, it is available as the ...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🪛 markdownlint-cli2 (0.18.1)
demos/tutorial.md
45-45: Hard tabs
Column: 5
(MD010, no-hard-tabs)
Fixes from 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.
Actionable comments posted: 1
♻️ Duplicate comments (1)
demos/tutorial.md (1)
45-45: Replace hard tab with spaces.Line 45 uses a hard tab for indentation. Convert it to spaces to match the rest of the file.
case Key.esc: { - info("Esc key was pressed"); + info("Esc key was pressed"); s.stop(); exit(0); }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
demos/tutorial.md(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-12-17T22:06:23.076Z
Learnt from: dejlek
Repo: gdamore/dcell PR: 60
File: demos/tutorial.md:26-26
Timestamp: 2025-12-17T22:06:23.076Z
Learning: In Dcell (D language), when handling EventType.resize events, do not access ev.mouse properties. To get the new terminal dimensions after a resize event, call s.size() instead.
Applied to files:
demos/tutorial.md
📚 Learning: 2025-12-15T05:12:35.344Z
Learnt from: gdamore
Repo: gdamore/dcell PR: 56
File: source/dcell/vt.d:2-2
Timestamp: 2025-12-15T05:12:35.344Z
Learning: In D language (used in gdamore/dcell), when you have a variable of enum type (e.g., `Attr attr`), both `attr.EnumMember` and `Attr.EnumMember` are aliased to the same enum value. This means using the lowercase variable name instead of the uppercase type name in case statements is not a compile error, though using the type name is preferred for consistency.
Applied to files:
demos/tutorial.md
🪛 markdownlint-cli2 (0.18.1)
demos/tutorial.md
45-45: Hard tabs
Column: 5
(MD010, no-hard-tabs)
🔇 Additional comments (4)
demos/tutorial.md (4)
26-26: Correctly usess.size()for resize event reporting.Good fix—the code avoids accessing
ev.mouse.poson resize events and properly callss.size()to report dimensions.
297-304: Verifys.start()is called before terminal interactions.Line 304 calls
s.start(), which is correct. However, ensure this pattern is consistent:newScreen()→start()→ thenshowCursor(),enableMouse(), etc. The current code order looks good.
343-352: Logic correctly prioritizes Ctrl+C before plain C/c.The condition checks for Ctrl+C first (line 343), then falls through to plain C/c (line 348). This avoids unreachable code and preserves the intended behavior.
85-97: Mouse button enum names are correct.The table correctly shows lowercase camelCase enum members (
button1,button2, etc.) and their lowercase aliases (primary,secondary,middle), matching dcell's naming conventions.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.
Actionable comments posted: 1
♻️ Duplicate comments (1)
demos/tutorial.md (1)
45-45: Replace hard tab with spaces.Static analysis flagged a hard tab character at line 45. Replace it with spaces to match the indentation style used throughout the rest of the file.
case Key.esc: { - info("Esc key was pressed"); + info("Esc key was pressed"); s.stop(); exit(0); }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
demos/tutorial.md(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-12-17T22:06:23.076Z
Learnt from: dejlek
Repo: gdamore/dcell PR: 60
File: demos/tutorial.md:26-26
Timestamp: 2025-12-17T22:06:23.076Z
Learning: In Dcell (D language), when handling EventType.resize events, do not access ev.mouse properties. To get the new terminal dimensions after a resize event, call s.size() instead.
Applied to files:
demos/tutorial.md
📚 Learning: 2025-12-15T05:12:35.344Z
Learnt from: gdamore
Repo: gdamore/dcell PR: 56
File: source/dcell/vt.d:2-2
Timestamp: 2025-12-15T05:12:35.344Z
Learning: In D language (used in gdamore/dcell), when you have a variable of enum type (e.g., `Attr attr`), both `attr.EnumMember` and `Attr.EnumMember` are aliased to the same enum value. This means using the lowercase variable name instead of the uppercase type name in case statements is not a compile error, though using the type name is preferred for consistency.
Applied to files:
demos/tutorial.md
🪛 markdownlint-cli2 (0.18.1)
demos/tutorial.md
45-45: Hard tabs
Column: 5
(MD010, no-hard-tabs)
🔇 Additional comments (1)
demos/tutorial.md (1)
1-395: Approve the tutorial content and structure.The tutorial is well-organized and comprehensively covers Dcell's event model, screen management, rendering, and includes a complete working demo application. All major logic issues from previous review rounds have been correctly addressed: resize events now use
s.size(), key event modifiers are checked first, enum names use lowercase camelCase, ands.start()is properly called before mouse/paste setup. The code examples are clear and follow the library's conventions.
Port of the tcell tutorial from Go.
Maybe some polish will be required.
Let me know in case you would like to add something else.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.