• fried brain

    From X V Lxxix@VERT to All on Fri May 9 10:54:00 2008
    Can anyone take a look at this and tell me why, when given a string and a ãspecified width for word wrapping, it sometimes trims the string way too ãshort, or 3 or 4 characters too long? I've been frying my brain with this and ãI just can't get it straightened out:ããthis.FitMsg=function(text)ã{ã var msg=text;ã if(console.strlen(msg)>=this.width) {ã while(console.strlen(msg)>=this.width) {ã var test_index=this.width;ã while(console.strlen(text.substring(0,test_index)) ã<this.width) ã {ã if(msg.charAt(test_index)==" " || ã msg.charAt(test_index+1)==" ") break;ã else if(msg.charAt(test_index)=="\1") {ã test_index++;ã }ã test_index++;ã }ã var push=this.RemoveSpaces(msg.substring ã(0,test_index));ã if(push.lastIndexOf(" ")>(this.width/2)) {ã test_index=push.lastIndexOf(" ");ã push=this.RemoveSpaces(push.substring ã(0,test_index));ã }ã this.messages.push(push);ã this.log.Log("adding text to msg buffer: " + push);ã msg=this.RemoveSpaces(msg.slice(test_index));ã }ã this.messages.push(this.RemoveSpaces(msg));ã }ã else
    this.messages.push(text);ã while(this.messages.length>this.height) ã this.message_history=this.messages.shift();ã this.needs_update=true;ã}ãthis.RemoveSpaces=function(text)ã{ã while(text.indexOf(" ")==0) text=text.slice(1);ã return truncsp(text);ã}ãããthis is an excerpt from a larger piece of code, so some of the variables used ãin the functions are declared elsewhere.ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From X V Lxxix@VERT to X V Lxxix on Fri May 9 11:02:30 2008
    Can anyone take a look at this and tell me why, when given a string and a ã > specified width for word wrapping, it sometimes trims the string way too ã > short, or 3 or 4 characters too long? I've been frying my brain with this ã > and I just can't get it straightened out:ãã > this.FitMsg=function(text)ã > {ããugh nevermind I figured it out almost immediately after I posted that..ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Deuce@VERT/SYNCNIX to X V Lxxix on Fri May 9 13:40:56 2008
    Re: fried brainã By: X V Lxxix to All on Fri May 09 2008 10:54 amãã > Can anyone take a look at this and tell me why, when given a string and aã > specified width for word wrapping, it sometimes trims the string way tooã > short, or 3 or 4 characters too long? I've been frying my brain with thisã > and I just can't get it straightened out:ããHave you looked at the word_wrap() global function?ãã--- ãSynchronet - Jump on the Web 0.2 bandwagon!ãã---ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From MCMLXXIX@VERT/MDJ to Deuce on Fri May 9 23:20:31 2008
    Re: fried brainã By: Deuce to X V Lxxix on Fri May 09 2008 13:40:56ãã > Re: fried brainã > By: X V Lxxix to All on Fri May 09 2008 10:54 amã > ã > > Can anyone take a look at this and tell me why, when given a string and aã > > specified width for word wrapping, it sometimes trims the string way tooã > > short, or 3 or 4 characters too long? I've been frying my brain with thisã > > and I just can't get it straightened out:ã > ã > Have you looked at the word_wrap() global function?ã > ããyes.. it wraps to a new line on the left side. I needed to make something thatãwraps within a specified "window" on the screen. I'm pretty sure it does thatãanyway. I'm actually checking it right nowãã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Sat May 10 11:07:46 2008
    Re: fried brainã By: MCMLXXIX to Deuce on Fri May 09 2008 11:20 pmãã > > Have you looked at the word_wrap() global function?ã >ã >ã > yes.. it wraps to a new line on the left side. I needed to make somethingã > that wraps within a specified "window" on the screen. I'm pretty sure itã > does that anyway. I'm actually checking it right nowããYou can pass in the width as an argument. :-)ãã--- ãSynchronet - Jump on the Web 0.2 bandwagon!ãã---ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From MCMLXXIX@VERT/MDJ to Deuce on Sun May 11 17:35:22 2008
    Re: fried brainã By: Deuce to MCMLXXIX on Sat May 10 2008 11:07:46ãã > Re: fried brainã > By: MCMLXXIX to Deuce on Fri May 09 2008 11:20 pmã > ã > > > Have you looked at the word_wrap() global function?ã > >ã > >ã > > yes.. it wraps to a new line on the left side. I needed to make somethingã > > that wraps within a specified "window" on the screen. I'm pretty sure itã > > does that anyway. I'm actually checking it right nowã > ã > You can pass in the width as an argument. :-)ã > ããYeah, but it still wraps to the left side of the screen. I need it wrap awayãfrom the left side. Unless I'm just not doing it right... that is always aãpossibility when it comes to me.ãã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Mon May 12 12:44:52 2008
    Re: fried brainã By: MCMLXXIX to Deuce on Sun May 11 2008 05:35 pmãã > > You can pass in the width as an argument. :-)ã >ã >ã > Yeah, but it still wraps to the left side of the screen. I need it wrapã > away from the left side. Unless I'm just not doing it right... that isã > always a possibility when it comes to me.ããI'm sure I misunderstand the question. The word_wrap() function doesn't doãanything with the screen.ãã--- ãSynchronet - Jump on the Web 0.2 bandwagon!ãã---ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From MCMLXXIX@VERT/MDJ to Deuce on Mon May 12 16:30:53 2008
    Re: fried brainã By: Deuce to MCMLXXIX on Mon May 12 2008 12:44:52ãã > Re: fried brainã > By: MCMLXXIX to Deuce on Sun May 11 2008 05:35 pmã > ã > > > You can pass in the width as an argument. :-)ã > >ã > >ã > > Yeah, but it still wraps to the left side of the screen. I need it wrapã > > away from the left side. Unless I'm just not doing it right... that isã > > always a possibility when it comes to me.ã > ã > I'm sure I misunderstand the question. The word_wrap() function doesn't doã > anything with the screen.ã > ããexample:ããstring="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdfljkh";ãconsole.gotoxy(10,1); //move to the first row, 10 spaces from the left edgeããconsole.putmsg(word_wrap(string,10)); ããresult:ãã kljhsadflkãasfdjkhasãflhsadlfjhãetc....ãã----------------------------ãããWhat I needed was for the string to wrap at a distance from the left side,ãbut the word_wrap function displays the rest of the wrapped lines at the ãbeginning of the next line.ããdesired result:ãã kljhsadflkã asfdjkhasã flhsadlfjhã etc..ããyou dig? I got it working, at any rate, just wanted to get on the same page ãwith you in case you know of a better/easier way to do it.ãã-Mãã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Mon May 12 15:01:10 2008
    Re: fried brainã By: MCMLXXIX to Deuce on Mon May 12 2008 04:30 pmãã > string="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdfljkhã > "; console.gotoxy(10,1); //move to the first row, 10 spaces from the leftã > edgeã >ã > console.putmsg(word_wrap(string,10));ããAh...ããconsole.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));ãã--- ãSynchronet - Jump on the Web 0.2 bandwagon!ãã---ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From MCMLXXIX@VERT/MDJ to Deuce on Mon May 12 18:10:51 2008
    Re: fried brainã By: Deuce to MCMLXXIX on Mon May 12 2008 15:01:10ãã > Re: fried brainã > By: MCMLXXIX to Deuce on Mon May 12 2008 04:30 pmã > ã > > string="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdflã > > "; console.gotoxy(10,1); //move to the first row, 10 spaces from the leftã > > edgeã > >ã > > console.putmsg(word_wrap(string,10));ã > ã > Ah...ã > ã > console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));ã > ããthat would work, sort of... but the idea is to make the text wrap within aãwindow at either a menu, or in the midst of another script, so havingãpreceeding spaces would mess up the surrounding graphics. the distance from theãleft will also be supplied as a variable and will change depending on what'sãgoing on.. ããyou should make word_wrap take a starting_column argument! .... :)ãã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Mon May 12 18:44:37 2008
    Re: fried brainã By: MCMLXXIX to Deuce on Mon May 12 2008 06:10 pmãã > > console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));ã >ã >ã > that would work, sort of... but the idea is to make the text wrap within aã > window at either a menu, or in the midst of another script, so havingã > preceeding spaces would mess up the surrounding graphics. the distance fromã > the left will also be supplied as a variable and will change depending onã > what's going on..ããOk...ãconsole.putmsg(word_wrap(string, 10).replace(/\n/,"\n\1"+ascii(127+10)));ãã > you should make word_wrap take a starting_column argument! .... :)ããThe word wrap function is in now way connected to output... so aãstarting_column argument is pointless.ããRegarding windows, they aren't supported natively. You could do thisãfunctionality using the graphic.js library though:ããload("graphic.js");ãvar window=new Graphic(10,24);ãwindow.putmsg(word_wrap(1,1,string, window.width));ãwindow.draw(1, 10);ãã--- ãSynchronet - Jump on the Web 0.2 bandwagon!ãã---ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From Angus McLeod@VERT/ANJO to Deuce on Mon May 12 23:16:00 2008
    Re: fried brainã By: Deuce to MCMLXXIX on Mon May 12 2008 18:44:00ãã > > you should make word_wrap take a starting_column argument! .... :)ã > ã > The word wrap function is in now way connected to output... so aã > starting_column argument is pointless.ããYou could split() the word_wrap()ed result on /\n/ and process the ãreturned array elements individually, to place them in the "window". Where ãis word_wrap() implemented? Could it be altered to optionally return an ãarray type?ãããã---ãPlaying: "I don't even know myself" by "The Who" from the "Who's next" album.ã þ Synchronet þ Making sure Jason works OK at The ANJO BBSã
  • From MCMLXXIX@VERT/MDJ to Deuce on Mon May 12 23:10:51 2008
    Re: fried brainã By: Deuce to MCMLXXIX on Mon May 12 2008 18:44:37ãã > Re: fried brainã > By: MCMLXXIX to Deuce on Mon May 12 2008 06:10 pmã > ã > > > console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));ã > >ã > >ã > > that would work, sort of... but the idea is to make the text wrap within ã > > window at either a menu, or in the midst of another script, so havingã > > preceeding spaces would mess up the surrounding graphics. the distance frã > > the left will also be supplied as a variable and will change depending onã > > what's going on..ã > ã > Ok...ã > console.putmsg(word_wrap(string, 10).replace(/\n/,"\n\1"+ascii(127+10)));ã > ã > > you should make word_wrap take a starting_column argument! .... :)ã > ã > The word wrap function is in now way connected to output... so aã > starting_column argument is pointless.ã > ã > Regarding windows, they aren't supported natively. You could do thisã > functionality using the graphic.js library though:ã > ã > load("graphic.js");ã > var window=new Graphic(10,24);ã > window.putmsg(word_wrap(1,1,string, window.width));ã > window.draw(1, 10);ã > ããI actually had no idea that could be done with Graphic.js, but it didn't seemãto work when I tested it anyway. What does word_wrap do? put an \r\n in theãsupplied string at the supplied width? ããI have a working function for this, and seems to running just fine now...ãthough that console.putmsg(word_wrap..........); line you wrote up there was aãlearning experience in itself.ãã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã
  • From Deuce@VERT/SYNCNIX to Angus McLeod on Tue May 13 00:01:42 2008
    Re: fried brainã By: Angus McLeod to Deuce on Mon May 12 2008 11:16 pmãã > You could split() the word_wrap()ed result on /\n/ and process theã > returned array elements individually, to place them in the "window". Whereã > is word_wrap() implemented? Could it be altered to optionally return anã > array type?ããIt's implemented in js_global.c. It could return an array, but if you want anãarray, just do a .split(/[\r\n]+/) or something. That way you get to use coolãstring methods and I don't have to do anything. :-)ãã--- ãSynchronet - Jump on the Web 0.2 bandwagon!ãã---ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Tue May 13 00:03:20 2008
    Re: fried brainã By: MCMLXXIX to Deuce on Mon May 12 2008 11:10 pmãã > I actually had no idea that could be done with Graphic.js, but it didn'tã > seem to work when I tested it anyway. What does word_wrap do? put an \r\nã > in the supplied string at the supplied width?ããword_wrap() splits a string of text into multiple lines on word boundaries soãthat no line is longer than the specified width. It will not place a newlineãin the middle of a word unless that word is longer than the line width.ãã--- ãSynchronet - Jump on the Web 0.2 bandwagon!ãã---ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From MCMLXXIX@VERT/MDJ to Deuce on Tue May 13 09:11:15 2008
    Re: fried brainã By: Deuce to MCMLXXIX on Tue May 13 2008 00:03:20ãã > Re: fried brainã > By: MCMLXXIX to Deuce on Mon May 12 2008 11:10 pmã > ã > > I actually had no idea that could be done with Graphic.js, but it didn'tã > > seem to work when I tested it anyway. What does word_wrap do? put an \r\nã > > in the supplied string at the supplied width?ã > ã > word_wrap() splits a string of text into multiple lines on word boundaries sã > that no line is longer than the specified width. It will not place a newlinã > in the middle of a word unless that word is longer than the line width.ã > ããOk, I actually wasted a lot of time writing my own similar word wrap function,ãI guess. I didn't realize that word_wrap actually added newline characters toãthe string as its return value.. makes sense though. Just never thought aboutãit. Should shorten that portion of my code by about 20 lines (yeah....K.I.S.S.)ãã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã
  • From Angus McLeod@VERT/ANJO to Deuce on Tue May 13 20:05:00 2008
    Re: fried brainã By: Deuce to Angus McLeod on Tue May 13 2008 00:01:00ãã > > Where is word_wrap() implemented? Could it be altered to optionally ã > > return an array type?ã > ã > It's implemented in js_global.c. It could return an array, but if you want ã > array, just do a .split(/[\r\n]+/) or something. That way you get to use coã > string methods and I don't have to do anything. :-)ããLazy bugger! :-)ãã---ãPlaying: "The Magdalene laundries" by "Chieftains"ã from the "Tears Of Stone" album.ã þ Synchronet þ Making sure Jason works OK at The ANJO BBSã