Reading from a Pipe
Last time, I was trying to get a shell script to give me back the results of a calculation sent to the command line utility bc. By writing the shell script that takes an argument, like
mybc “2+2”
I get back the right answer:
4
Amazing. A computer doing math! In my previous post, I bitched about how hard NSPipe is to use, so I was avoiding it.
Implementing Calculations
Just to get started, I wanted to create a text editor that would detect when a mathematical expression is entered, and supply an answer. Using NSEvents’ keyDown: method, I can detect when the equal sign is entered, and then parse the expression by overriding the insertText: method:
– (void)insertText:(NSString *)input { if([input isEqual:@”=”]) { [super insertText:input]; myCalc = [[Calculator alloc] init]; [super insertText:[myCalc calc:@”2+2″]];
So, for now I’m not parsing what the user actually enters, because I haven’t figured out how to do that yet.
Introducing Napkin
So here’s what I’ve got. Imagine a text editor that also has the capabilities of a spreadsheet. At its most basic level, you could type a mathematical expression, hit the equal sign and get an answer. Further, you could write out items in column format using nothing more than the tab key. The app would know to keep columns lined up, and it could perform math both across rows and down columns.
The Choices
At the core, I’m running a business here. I really want to learn how to program in ObjC/Cocoa, but my day job keeps me pretty busy, and I haven’t had the time to really, really learn it. Yet, I’ve got some potentially great ideas here that I’d like to put on the market. What to do?I joined the Toronto chapter of Cocoaheads — Tacow — first of all. There I met other local Cocoa developers, all at varying stages of knowledge.
What I’m Doing Here
This is the first in what I hope will be an enlightening series of posts tracking the development of my first Cocoa Mac application, Napkin. Getting to this point has been a long journey, and I can see there’s still a long way to go. But at this point, at least, I’m starting to write some code, and I’d like to have a way of documenting this very complicated process: share my forks in the road, and how I chose a particular way.