-
Notifications
You must be signed in to change notification settings - Fork 89
Thoughts On Creating The IRC Client (Day 2)
I've decided that it makes more sense to load the ircBot into the Demo snapshot - there'll be more example morphs to look at and play with. So I've loaded up the demo snapshot and immediately see some text on the screen. I'm pretty sure these are all just morph objects, so I'm going to grab and make a duplicate of the first one: 'To share this window with a friend…'.
OK, I've made a duplicate of that morph, and loaded in the ircBot code. Now I'm going to connect to the irc sever, and see if I can't get the morph to display the lines slot of the ircBot. From having played around after close last night, I know that I'm going to want to append all of the lines into a single string, but I don't remember how to append strings. + doesn't seem to work, and the code in bootstrap read:From: used a method of it's own devising:
concat: n With: p = ( | lobby = lobby | n _ByteVectorConcatenate: p Prototype: lobby mutableString )
I don't understand that code well enough to feel comfortable just stealing it - I prefer to steal things when I know what they're good for. going to pull up the traits mutableString object and see if it's got anything interesting.
I'm surprised to find that the mutableString prototype didn't have anything that looked like it dealt with concating. Did a quick Google search and still came up with nothing - but the knowledge that Self is a bad google search term. Enough other languages use 'self' as a keyword that I couldn't come up with a query that didn't drown me in python, or Objective-C, or some other language references. Instead of climbing down the rat hole, I'm going to step back and see if I can't find a way to display all the lines that doesn't involve contacting.
[Note from the future: it appears the comma is the string concat character. i.e. 'commas ' , 'concat ' , ' strings.' becomes 'commas concat strings'. I knew that, just didn't remember knowing that.]
So as I'm digging through the Morphs there's one mystery solved - where does the actual String live? The morph I duplicated is a 'labelMorph' which has a myLabel slot, but that was set to the empty string. Eventually I found the rawMorphs slot on the label morph, which appears to basically be a list of children morphs. The rawMorphs slot contains a vector, which contains a single labelMorph, which has it's myLabel slot set to the display string (i.e. 'To share this window with a friend…'). Not sure why the extra level of indirection, but there it is.
OK, back to the ircBot. Call the connect slot, and again the lines slot gets populated. Now I want to create a reference from ircBot to the labelMorph that I've got… Seems like there should be some nice click-drag-and-drop way to create a reference between two morphs, but I'm not seeing it…. After poking around some menus, I don't see a painfully-easy way to create a reference from an outline to an existing object, so I'll have to look for a just-easy way. Going to create a labelMorph slot on the ircBot, and see what I can do from there. (note, I don't consider any of this good Self programming. I should be working on a clone of the ircBot, the labelMorph is probably the wrong morph for the job, and in the end it may make more sense for the morph to reference the ircBot than vice-vs - but I'm just playing).
OK, created a new slot on the ircBot:
labelMorph = nil.
after hitting save, I could pull up the reference to nil and then change that reference to point at the labelMorph. I couldn't drag the reference directly onto the label morph though, I had to pull up the outliner for the labelMorph and drag the reference to that. Still pretty easy. Now I'm going to set the labelMorph's label to be the contents of the first line.
That worked! kind of.... The morph didn't auto-redraw itself when I set it's myLabel slot, but as soon as I scrolled in the world environment it updated. It's also leaving behind a trail of characters when I drag it, but those eventually disappear on their own. Now to try and display all of the lines….
I've looked at the way the tutorial 'book' works, and it appears to just be a labelMorph with a bunch of embedded labelMorphs representing each line. I'm going to try doing something similar from the ircBot.
OK, it wasn't clear if adding the submorphs to a labelMorph would lay them out correctly, so I was looking at the self handbook when I saw a reference to the editorMorph. That seemed like it might handle my need for laying out multiple lines of text - or at the very least would have code that'd show me how to do it - so I pulled up one of those by doing a Get It on:
editorMorph clone
in an evaluator. Then I had to do a Show Morph from the outliners middle menu (control-click on a Mac) to actually see the morph. I've dragged the labelMorph reference from the labelMorph to the editorMorph, and we're in business. I then typed the following into the ircBot evaluator:
lines do: [ | :line | labelMorph appendString: line. labelMorph appendString: '\r'].
And just like that, the response from the irc server appeared in the text editor!
Now I'm going to try and figure out how to update the text editor whenever we receive a line from the server. For my first approach I'm going to look at having the ircBot directly update the editorMorph whenever a new line is read.
More later....