DEV Community

cychu42
cychu42

Posted on • Updated on

Hacktoberfest Week 3: Text Output

The Issue

This week's issue is about adding a new feature to a text reader that output each individual word from a file to the screen for fast reading. The new feature would allow the user to instead input the text into the CLI instead. The pull request is here.

With the current design, the user would be able to add text into the shell for the tool to read, as long as the text is in "" or ''.

Usage:
metaxa read <text> <delay>

Example:
metaxa read "Hello, my name is John. How are you?" 40

Change

Code Snippet
Image description

In index.js, a new option 'read' is added, keeping almost the same code as start option, minus the code for reading a file from a path.

Process

It ended up being a lot more simple than I thought initially.
I studied the code and realized I can easily convert the default code for reading a text file for this feature. All I had to do was to place the same code under a new option and get rid of the codes relevant for reading a file. Instead, the code skip to processing the text.

The repo owner is nice. I did tried to ask for another issue as well, but there's no reply for that one. Maybe they wont to assign me one at a time, or they simply missed it. I'm not sure.

Learning

It feels good to find a solution without having to do a lot of changes, and it's entirely consistent with existing code, but it also made me feel I was not putting enough effort just because it took little time to actually write the code itself. Maybe sometimes elegant solutions feel easy, and the hard part is really coming up with it.

I even thought about making it more advanced, but I stopped myself, since it might not be what the repo owner is looking for, as the program seems to be about outputting simple text.

It pays to really understand the code before working on your solution. Sometimes, the answer is right there in the code.

Top comments (0)